-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multi tenancy capabilities with ecto meta prefix #25
Merged
izelnakri
merged 32 commits into
izelnakri:master
from
dreamingechoes:add-multi-tenancy-capabilities-with-ecto-meta-prefix
Aug 12, 2017
Merged
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e9f28cb
Add new add_prefix function in paper_trail module
dreamingechoes c27bbc8
Add default value for the new :prefix option on the functions definit…
dreamingechoes 61737dc
Add patter matching case for nil prefix on add_prefix function
dreamingechoes d4d8e40
Add defdelegate in PaperTrail module to PaperTrail.VersionQueries
dreamingechoes 59f34c4
Add new definition for version_query function to merge options into t…
dreamingechoes e71b3d4
Add new definitions for all the functions in PaperTrail.VersionQueries
dreamingechoes ad52cb4
Remove result type from PaperTrail.VersionQueries and specifies the v…
dreamingechoes 83a0d7a
Change param names in defdelegates for better readability
dreamingechoes 4ef58a0
Add some multi tenancy documentation on README.md
dreamingechoes 696a6c3
Add new MultiTenantHelper module into example test support folder
dreamingechoes a50177a
Add new MultiTenantHelper module into lib test support folder
dreamingechoes f2519db
Add new QueryHelper module into example test support folder
dreamingechoes c62150e
Add new ChangesetHelper module into example test support folder
dreamingechoes 2c4aa4d
Require new support helpers in example test_helper file
dreamingechoes 9bd355f
Add refactor in example company test in order to use helpers
dreamingechoes 77b669c
Add refactor in example person test in order to use helpers
dreamingechoes 4975d2b
Add new multi_tenant_company_test file
dreamingechoes 96ecccd
Add new multi_tenant_person_test file
dreamingechoes d01fedf
Add tests for multi tenant in bang_functions_simple_mode_test
dreamingechoes 95b3312
Add tests for multi tenant in bang_functions_strict_mode_test
dreamingechoes 8a2dfb5
Add new count functions for multi tenancy in test support models
dreamingechoes a1ffd44
Add new functions for multi tenancy in lib/version.ex
dreamingechoes 8a42220
Add changes in tests to use new definition of Version functions with …
dreamingechoes cf638d6
Require new support helper in lib test_helper file
dreamingechoes b914cfd
Add multi tenancy tests in paper_trail_version_test file
dreamingechoes 7414a66
Add some changes to the previous code added in paper_trail_version_te…
dreamingechoes 5f51b7e
Add multi tenancy tests in version_queries_test file
dreamingechoes c50eef8
Add dreamingechoes to credits section in README.md
dreamingechoes 0604631
Remove changeset_helper.exs and query_helper.exs from example/test/su…
dreamingechoes ead9cc6
Add final refactor to example app test files
dreamingechoes 64231d7
Propagate options to repo actions in delete functions
dreamingechoes 1359026
Add some additional assertions in tests
dreamingechoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
defmodule MultiTenantCompanyTest do | ||
use ExUnit.Case | ||
import Ecto.Query | ||
|
||
setup_all do | ||
MultiTenantHelper.setup_tenant(Repo) | ||
:ok | ||
end | ||
|
||
test "[multi tenant] creating a company creates a company version with correct attributes" do | ||
{:ok, result} = | ||
%{name: "Acme LLC", is_active: true, city: "Greenwich", people: []} | ||
|> ChangesetHelper.new_company(:multitenant) | ||
|> PaperTrail.insert(origin: "test", prefix: MultiTenantHelper.tenant()) | ||
|
||
company_count = QueryHelper.company_count(:multitenant) |> Repo.all() | ||
version_count = QueryHelper.version_count(:multitenant) |> Repo.all() | ||
first_company = QueryHelper.first_company(:multitenant) |> Repo.one() | ||
|
||
company = result[:model] |> Map.drop([:__meta__, :__struct__, :inserted_at, :updated_at, :id]) | ||
version = result[:version] |> Map.drop([:__meta__, :__struct__, :inserted_at]) | ||
|
||
assert company_count == [1] | ||
assert version_count == [1] | ||
|
||
assert company == %{ | ||
name: "Acme LLC", | ||
is_active: true, | ||
city: "Greenwich", | ||
website: nil, | ||
address: nil, | ||
facebook: nil, | ||
twitter: nil, | ||
founded_in: nil, | ||
people: [] | ||
} | ||
|
||
assert Map.drop(version, [:id]) == %{ | ||
event: "insert", | ||
item_type: "Company", | ||
item_id: first_company.id, | ||
item_changes: Map.drop(result[:model], [:__meta__, :__struct__, :people]), | ||
origin: "test", | ||
originator_id: nil, | ||
meta: nil | ||
} | ||
end | ||
|
||
test "[multi tenant] updating a company creates a company version with correct item_changes" do | ||
first_company = QueryHelper.first_company(:multitenant) |> Repo.one() | ||
|
||
{:ok, result} = | ||
ChangesetHelper.update_company(first_company, %{ | ||
city: "Hong Kong", | ||
website: "http://www.acme.com", | ||
facebook: "acme.llc" | ||
}, :multitenant) |> PaperTrail.update(prefix: MultiTenantHelper.tenant()) | ||
|
||
company_count = QueryHelper.company_count(:multitenant) |> Repo.all() | ||
version_count = QueryHelper.version_count(:multitenant) |> Repo.all() | ||
|
||
company = result[:model] |> Map.drop([:__meta__, :__struct__, :inserted_at, :updated_at, :id]) | ||
version = result[:version] |> Map.drop([:__meta__, :__struct__, :inserted_at]) | ||
|
||
assert company_count == [1] | ||
assert version_count == [2] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert Version.count == [0] |
||
assert company == %{ | ||
name: "Acme LLC", | ||
is_active: true, | ||
city: "Hong Kong", | ||
website: "http://www.acme.com", | ||
address: nil, | ||
facebook: "acme.llc", | ||
twitter: nil, | ||
founded_in: nil, | ||
people: [] | ||
} | ||
|
||
assert Map.drop(version, [:id]) == %{ | ||
event: "update", | ||
item_type: "Company", | ||
item_id: first_company.id, | ||
item_changes: %{city: "Hong Kong", website: "http://www.acme.com", facebook: "acme.llc"}, | ||
origin: nil, | ||
originator_id: nil, | ||
meta: nil | ||
} | ||
end | ||
|
||
test "[multi tenant] deleting a company creates a company version with correct attributes" do | ||
company = QueryHelper.first_company(:multitenant) |> Repo.one() | ||
|
||
{:ok, result} = | ||
company | ||
|> PaperTrail.delete(prefix: MultiTenantHelper.tenant()) | ||
|
||
company_count = QueryHelper.company_count(:multitenant) |> Repo.all() | ||
version_count = QueryHelper.version_count(:multitenant) |> Repo.all() | ||
|
||
company_ref = result[:model] |> Map.drop([:__meta__, :__struct__, :inserted_at, :updated_at, :id]) | ||
version = result[:version] |> Map.drop([:__meta__, :__struct__, :inserted_at]) | ||
|
||
assert company_count == [0] | ||
assert version_count == [3] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert Version.count == [0] |
||
assert company_ref == %{ | ||
name: "Acme LLC", | ||
is_active: true, | ||
city: "Hong Kong", | ||
website: "http://www.acme.com", | ||
address: nil, | ||
facebook: "acme.llc", | ||
twitter: nil, | ||
founded_in: nil, | ||
people: [] | ||
} | ||
|
||
assert Map.drop(version, [:id]) == %{ | ||
event: "delete", | ||
item_type: "Company", | ||
item_id: company.id, | ||
item_changes: %{ | ||
id: company.id, | ||
inserted_at: company.inserted_at, | ||
updated_at: company.updated_at, | ||
name: "Acme LLC", | ||
is_active: true, | ||
website: "http://www.acme.com", | ||
city: "Hong Kong", | ||
address: nil, | ||
facebook: "acme.llc", | ||
twitter: nil, | ||
founded_in: nil | ||
}, | ||
origin: nil, | ||
originator_id: nil, | ||
meta: nil | ||
} | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version.count == [0]