acts_as_tenant 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +90 -26
  3. data/Rakefile +5 -14
  4. data/lib/acts_as_tenant.rb +114 -12
  5. data/lib/acts_as_tenant/configuration.rb +6 -19
  6. data/lib/acts_as_tenant/controller_extensions.rb +11 -56
  7. data/lib/acts_as_tenant/controller_extensions/filter.rb +13 -0
  8. data/lib/acts_as_tenant/controller_extensions/subdomain.rb +20 -0
  9. data/lib/acts_as_tenant/controller_extensions/subdomain_or_domain.rb +20 -0
  10. data/lib/acts_as_tenant/errors.rb +3 -4
  11. data/lib/acts_as_tenant/model_extensions.rb +62 -107
  12. data/lib/acts_as_tenant/sidekiq.rb +16 -8
  13. data/lib/acts_as_tenant/tenant_helper.rb +7 -0
  14. data/lib/acts_as_tenant/test_tenant_middleware.rb +15 -0
  15. data/lib/acts_as_tenant/version.rb +1 -1
  16. data/spec/acts_as_tenant/configuration_spec.rb +8 -19
  17. data/spec/acts_as_tenant/sidekiq_spec.rb +14 -19
  18. data/spec/controllers/filter_spec.rb +28 -0
  19. data/spec/controllers/subdomain_or_domain_spec.rb +55 -0
  20. data/spec/controllers/subdomain_spec.rb +49 -0
  21. data/spec/dummy/.ruby-version +1 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/config/manifest.js +2 -0
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  27. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/javascript/packs/application.js +15 -0
  32. data/spec/dummy/app/jobs/application_job.rb +7 -0
  33. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/spec/dummy/app/mailers/user_mailer.rb +5 -0
  35. data/spec/dummy/app/models/account.rb +4 -0
  36. data/spec/dummy/app/models/aliased_task.rb +4 -0
  37. data/spec/dummy/app/models/article.rb +3 -0
  38. data/spec/dummy/app/models/comment.rb +5 -0
  39. data/spec/dummy/app/models/concerns/.keep +0 -0
  40. data/spec/dummy/app/models/custom_counter_cache_task.rb +4 -0
  41. data/spec/dummy/app/models/custom_foreign_key_task.rb +4 -0
  42. data/spec/dummy/app/models/custom_primary_key_task.rb +4 -0
  43. data/spec/dummy/app/models/global_project.rb +6 -0
  44. data/spec/dummy/app/models/manager.rb +4 -0
  45. data/spec/dummy/app/models/polymorphic_tenant_comment.rb +5 -0
  46. data/spec/dummy/app/models/project.rb +8 -0
  47. data/spec/dummy/app/models/task.rb +7 -0
  48. data/spec/dummy/app/models/unique_task.rb +5 -0
  49. data/spec/dummy/app/models/unscoped_model.rb +3 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  52. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  53. data/spec/dummy/bin/rails +4 -0
  54. data/spec/dummy/bin/rake +4 -0
  55. data/spec/dummy/bin/setup +33 -0
  56. data/spec/dummy/config.ru +5 -0
  57. data/spec/dummy/config/application.rb +19 -0
  58. data/spec/dummy/config/boot.rb +5 -0
  59. data/spec/dummy/config/cable.yml +10 -0
  60. data/spec/dummy/config/database.yml +19 -0
  61. data/spec/dummy/config/environment.rb +5 -0
  62. data/spec/dummy/config/environments/development.rb +62 -0
  63. data/spec/dummy/config/environments/production.rb +112 -0
  64. data/spec/dummy/config/environments/test.rb +49 -0
  65. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  66. data/spec/dummy/config/initializers/assets.rb +12 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  69. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  70. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  71. data/spec/dummy/config/initializers/inflections.rb +16 -0
  72. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +40 -0
  75. data/spec/dummy/config/puma.rb +38 -0
  76. data/spec/dummy/config/routes.rb +4 -0
  77. data/spec/dummy/config/spring.rb +6 -0
  78. data/spec/dummy/config/storage.yml +34 -0
  79. data/spec/dummy/db/schema.rb +84 -0
  80. data/spec/dummy/lib/assets/.keep +0 -0
  81. data/spec/dummy/log/.keep +0 -0
  82. data/spec/dummy/public/404.html +67 -0
  83. data/spec/dummy/public/422.html +67 -0
  84. data/spec/dummy/public/500.html +66 -0
  85. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  86. data/spec/dummy/public/apple-touch-icon.png +0 -0
  87. data/spec/dummy/public/favicon.ico +0 -0
  88. data/spec/dummy/tmp/development_secret.txt +1 -0
  89. data/spec/fixtures/accounts.yml +10 -0
  90. data/spec/fixtures/custom_primary_key_tasks.yml +2 -0
  91. data/spec/fixtures/global_projects.yml +13 -0
  92. data/spec/fixtures/projects.yml +10 -0
  93. data/spec/helpers/tenant_helper_spec.rb +16 -0
  94. data/spec/middlewares/test_tenant_middleware_spec.rb +86 -0
  95. data/spec/models/model_extensions_spec.rb +383 -0
  96. data/spec/spec_helper.rb +10 -15
  97. metadata +196 -54
  98. data/.gitignore +0 -7
  99. data/.travis.yml +0 -6
  100. data/CHANGELOG.md +0 -101
  101. data/Gemfile +0 -4
  102. data/acts_as_tenant.gemspec +0 -33
  103. data/rails/init.rb +0 -2
  104. data/spec/active_record_helper.rb +0 -22
  105. data/spec/active_record_models.rb +0 -109
  106. data/spec/acts_as_tenant/model_extensions_spec.rb +0 -394
  107. data/spec/acts_as_tenant/tenant_by_filter_spec.rb +0 -33
  108. data/spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb +0 -46
  109. data/spec/acts_as_tenant/tenant_by_subdomain_spec.rb +0 -32
  110. data/spec/database.yml +0 -3
  111. data/spec/mongoid.yml +0 -6
  112. data/spec/mongoid_helper.rb +0 -23
  113. data/spec/mongoid_models.rb +0 -81
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- #Setup test specific ApplicationController
4
- class Account
5
- attr_accessor :name
6
- end
7
-
8
- class ApplicationController2 < ActionController::Base
9
- include Rails.application.routes.url_helpers
10
- set_current_tenant_through_filter
11
- before_filter :your_method_that_finds_the_current_tenant
12
-
13
- def your_method_that_finds_the_current_tenant
14
- current_account = Account.new
15
- current_account.name = 'account1'
16
- set_current_tenant(current_account)
17
- end
18
-
19
- end
20
-
21
- # Start testing
22
- describe ApplicationController2, :type => :controller do
23
- controller do
24
- def index
25
- render :text => "custom called"
26
- end
27
- end
28
-
29
- it 'Finds the correct tenant using the filter command' do
30
- get :index
31
- expect(ActsAsTenant.current_tenant.name).to eq 'account1'
32
- end
33
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- #Setup test specific ApplicationController
4
- class Account; end # this is so the spec will work in isolation
5
-
6
- class ApplicationController < ActionController::Base
7
- include Rails.application.routes.url_helpers
8
- set_current_tenant_by_subdomain_or_domain
9
- end
10
-
11
- # Start testing
12
- describe ApplicationController, :type => :controller do
13
- controller do
14
- def index
15
- render :text => "custom called"
16
- end
17
- end
18
-
19
- it 'Finds the correct tenant with a example1.com' do
20
- @request.host = "example1.com"
21
- expect(Account).to receive(:where).with({domain: 'example1.com'}) {['account1']}
22
- get :index
23
- expect(ActsAsTenant.current_tenant).to eq 'account1'
24
- end
25
-
26
- it 'Finds the correct tenant with a subdomain.example.com' do
27
- @request.host = "subdomain.example.com"
28
- expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
29
- get :index
30
- expect(ActsAsTenant.current_tenant).to eq "account1"
31
- end
32
-
33
- it 'Finds the correct tenant with a www.subdomain.example.com' do
34
- @request.host = "subdomain.example.com"
35
- expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
36
- get :index
37
- expect(ActsAsTenant.current_tenant).to eq "account1"
38
- end
39
-
40
- it 'Ignores case when finding tenant by subdomain' do
41
- @request.host = "SubDomain.example.com"
42
- expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
43
- get :index
44
- expect(ActsAsTenant.current_tenant).to eq "account1"
45
- end
46
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- #Setup test specific ApplicationController
4
- class Account; end # this is so the spec will work in isolation
5
-
6
- class ApplicationController < ActionController::Base
7
- include Rails.application.routes.url_helpers
8
- set_current_tenant_by_subdomain
9
- end
10
-
11
- # Start testing
12
- describe ApplicationController, :type => :controller do
13
- controller do
14
- def index
15
- render :text => "custom called"
16
- end
17
- end
18
-
19
- it 'Finds the correct tenant with a subdomain.example.com' do
20
- @request.host = "account1.example.com"
21
- expect(Account).to receive(:where).with({subdomain: 'account1'}) {['account1']}
22
- get :index
23
- expect(ActsAsTenant.current_tenant).to eq 'account1'
24
- end
25
-
26
- it 'Finds the correct tenant with a www.subdomain.example.com' do
27
- @request.host = "www.account1.example.com"
28
- expect(Account).to receive(:where).with({subdomain: 'account1'}) {['account1']}
29
- get :index
30
- expect(ActsAsTenant.current_tenant).to eq 'account1'
31
- end
32
- end
@@ -1,3 +0,0 @@
1
- sqlite:
2
- adapter: sqlite3
3
- database: spec/actsastenant.sqlite3
@@ -1,6 +0,0 @@
1
- test:
2
- sessions:
3
- default:
4
- database: acts_as_tenant_test
5
- hosts:
6
- - localhost:27017
@@ -1,23 +0,0 @@
1
- require "action_controller/railtie"
2
- require "action_mailer/railtie"
3
- require 'mongoid'
4
- require 'database_cleaner'
5
-
6
- Mongoid.logger = Moped.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
7
- Mongoid.logger.level = Moped.logger.level = Logger::DEBUG
8
- Mongoid.load!(File.join(File.dirname(__FILE__), "/mongoid.yml"), :test)
9
-
10
- RSpec.configure do |config|
11
- config.before(:suite) do
12
- DatabaseCleaner[:mongoid].strategy = :truncation
13
- DatabaseCleaner[:mongoid].clean_with(:truncation)
14
- end
15
-
16
- config.before(:each) do
17
- DatabaseCleaner[:mongoid].start
18
- end
19
-
20
- config.after(:each) do
21
- DatabaseCleaner[:mongoid].clean
22
- end
23
- end
@@ -1,81 +0,0 @@
1
- class Account
2
- include Mongoid::Document
3
- include ActsAsTenant::ModelExtensions
4
- field :name, type: String
5
- field :subdomain, type: String
6
- field :domain, type: String
7
- has_many :projects
8
- end
9
-
10
- class Project
11
- include Mongoid::Document
12
- include ActsAsTenant::ModelExtensions
13
- field :name, type: String
14
- has_one :manager
15
- has_many :tasks
16
- acts_as_tenant :account
17
-
18
- validates_uniqueness_to_tenant :name
19
- end
20
-
21
- class Manager
22
- include Mongoid::Document
23
- include ActsAsTenant::ModelExtensions
24
- field :name, type: String
25
- belongs_to :project
26
- acts_as_tenant :account
27
- end
28
-
29
- class Task
30
- include Mongoid::Document
31
- include ActsAsTenant::ModelExtensions
32
- field :name, type: String
33
- field :completed, type: Boolean
34
- belongs_to :project
35
- default_scope -> { where(:completed => nil).order("name" => :asc) }
36
-
37
- acts_as_tenant :account
38
- validates_uniqueness_of :name
39
- end
40
-
41
- class UnscopedModel
42
- include Mongoid::Document
43
- include ActsAsTenant::ModelExtensions
44
- field :name, type: String
45
- validates_uniqueness_of :name
46
- end
47
-
48
- class AliasedTask
49
- include Mongoid::Document
50
- include ActsAsTenant::ModelExtensions
51
- field :name, type: String
52
- acts_as_tenant(:account)
53
- belongs_to :project_alias, :class_name => "Project"
54
- end
55
-
56
- class UniqueTask
57
- include Mongoid::Document
58
- include ActsAsTenant::ModelExtensions
59
- field :name, type: String
60
- field :user_defined_scope, type: String
61
- acts_as_tenant(:account)
62
- belongs_to :project
63
- validates_uniqueness_to_tenant :name, scope: :user_defined_scope
64
- end
65
-
66
- class CustomForeignKeyTask
67
- include Mongoid::Document
68
- include ActsAsTenant::ModelExtensions
69
- field :name, type: String
70
- field :accountID, type: Integer
71
- acts_as_tenant(:account, :foreign_key => "accountID")
72
- validates_uniqueness_to_tenant :name
73
- end
74
-
75
- class Comment
76
- include Mongoid::Document
77
- include ActsAsTenant::ModelExtensions
78
- belongs_to :commentable, polymorphic: true
79
- belongs_to :task, foreign_key: 'commentable_id'
80
- acts_as_tenant :account
81
- end