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
@@ -0,0 +1,13 @@
1
+ module ActsAsTenant
2
+ module ControllerExtensions
3
+ module Filter
4
+ extend ActiveSupport::Concern
5
+
6
+ private
7
+
8
+ def set_current_tenant(current_tenant_object)
9
+ ActsAsTenant.current_tenant = current_tenant_object
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module ActsAsTenant
2
+ module ControllerExtensions
3
+ module Subdomain
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ cattr_accessor :tenant_class, :tenant_column, :subdomain_lookup
8
+ before_action :find_tenant_by_subdomain
9
+ end
10
+
11
+ private
12
+
13
+ def find_tenant_by_subdomain
14
+ if (subdomain = request.subdomains.send(subdomain_lookup))
15
+ ActsAsTenant.current_tenant = tenant_class.where(tenant_column => subdomain.downcase).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module ActsAsTenant
2
+ module ControllerExtensions
3
+ module SubdomainOrDomain
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ cattr_accessor :tenant_class, :tenant_primary_column, :tenant_second_column, :subdomain_lookup
8
+ before_action :find_tenant_by_subdomain_or_domain
9
+ end
10
+
11
+ private
12
+
13
+ def find_tenant_by_subdomain_or_domain
14
+ subdomain = request.subdomains.send(subdomain_lookup)
15
+ query = subdomain.present? ? {tenant_primary_column => subdomain.downcase} : {tenant_second_column => request.domain.downcase}
16
+ ActsAsTenant.current_tenant = tenant_class.where(query).first
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,15 +5,14 @@ module ActsAsTenant
5
5
  module Errors
6
6
  class ModelNotScopedByTenant < ActsAsTenant::Error
7
7
  end
8
-
8
+
9
9
  class NoTenantSet < ActsAsTenant::Error
10
10
  end
11
-
11
+
12
12
  class ModelNotScopedByTenant < ActsAsTenant::Error
13
13
  end
14
-
14
+
15
15
  class TenantIsImmutable < ActsAsTenant::Error
16
16
  end
17
-
18
17
  end
19
18
  end
@@ -1,96 +1,34 @@
1
1
  module ActsAsTenant
2
- @@tenant_klass = nil
3
-
4
- def self.set_tenant_klass(klass)
5
- @@tenant_klass = klass
6
- end
7
-
8
- def self.tenant_klass
9
- @@tenant_klass
10
- end
11
-
12
- def self.fkey
13
- "#{@@tenant_klass.to_s}_id"
14
- end
15
-
16
- def self.current_tenant=(tenant)
17
- RequestStore.store[:current_tenant] = tenant
18
- end
19
-
20
- def self.current_tenant
21
- RequestStore.store[:current_tenant] || self.default_tenant
22
- end
23
-
24
- def self.unscoped=(unscoped)
25
- RequestStore.store[:acts_as_tenant_unscoped] = unscoped
26
- end
27
-
28
- def self.unscoped
29
- RequestStore.store[:acts_as_tenant_unscoped]
30
- end
31
-
32
- def self.unscoped?
33
- !!unscoped
34
- end
35
-
36
- class << self
37
- attr_accessor :default_tenant
38
- end
39
-
40
- def self.with_tenant(tenant, &block)
41
- if block.nil?
42
- raise ArgumentError, "block required"
43
- end
44
-
45
- old_tenant = self.current_tenant
46
- self.current_tenant = tenant
47
- value = block.call
48
- return value
49
-
50
- ensure
51
- self.current_tenant = old_tenant
52
- end
53
-
54
- def self.without_tenant(&block)
55
- if block.nil?
56
- raise ArgumentError, "block required"
57
- end
58
-
59
- old_tenant = current_tenant
60
- old_unscoped = unscoped
61
-
62
- self.current_tenant = nil
63
- self.unscoped = true
64
- value = block.call
65
- return value
66
-
67
- ensure
68
- self.current_tenant = old_tenant
69
- self.unscoped = old_unscoped
70
- end
71
-
72
2
  module ModelExtensions
73
- def self.included(base)
74
- base.extend(ClassMethods)
75
- end
3
+ extend ActiveSupport::Concern
76
4
 
77
- module ClassMethods
78
- def acts_as_tenant(tenant = :account, options = {})
5
+ class_methods do
6
+ def acts_as_tenant(tenant = :account, **options)
79
7
  ActsAsTenant.set_tenant_klass(tenant)
80
8
 
9
+ ActsAsTenant.add_global_record_model(self) if options[:has_global_records]
10
+
81
11
  # Create the association
82
- valid_options = options.slice(:foreign_key, :class_name, :inverse_of)
12
+ valid_options = options.slice(:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache)
83
13
  fkey = valid_options[:foreign_key] || ActsAsTenant.fkey
84
- belongs_to tenant, valid_options
14
+ pkey = valid_options[:primary_key] || ActsAsTenant.pkey
15
+ polymorphic_type = valid_options[:foreign_type] || ActsAsTenant.polymorphic_type
16
+ belongs_to tenant, **valid_options
85
17
 
86
18
  default_scope lambda {
87
19
  if ActsAsTenant.configuration.require_tenant && ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
88
20
  raise ActsAsTenant::Errors::NoTenantSet
89
21
  end
22
+
90
23
  if ActsAsTenant.current_tenant
91
- where(fkey.to_sym => ActsAsTenant.current_tenant.id)
24
+ keys = [ActsAsTenant.current_tenant.send(pkey)].compact
25
+ keys.push(nil) if options[:has_global_records]
26
+
27
+ query_criteria = {fkey.to_sym => keys}
28
+ query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
29
+ where(query_criteria)
92
30
  else
93
- Rails::VERSION::MAJOR < 4 ? scoped : all
31
+ ActiveRecord::VERSION::MAJOR < 4 ? scoped : all
94
32
  end
95
33
  }
96
34
 
@@ -98,25 +36,30 @@ module ActsAsTenant
98
36
  # - new instances should have the tenant set
99
37
  # - validate that associations belong to the tenant, currently only for belongs_to
100
38
  #
101
- before_validation Proc.new {|m|
39
+ before_validation proc { |m|
102
40
  if ActsAsTenant.current_tenant
103
- m.send "#{fkey}=".to_sym, ActsAsTenant.current_tenant.id
41
+ if options[:polymorphic]
42
+ m.send("#{fkey}=".to_sym, ActsAsTenant.current_tenant.class.to_s) if m.send(fkey.to_s).nil?
43
+ m.send("#{polymorphic_type}=".to_sym, ActsAsTenant.current_tenant.class.to_s) if m.send(polymorphic_type.to_s).nil?
44
+ else
45
+ m.send "#{fkey}=".to_sym, ActsAsTenant.current_tenant.send(pkey)
46
+ end
104
47
  end
105
- }, :on => :create
48
+ }, on: :create
106
49
 
107
- polymorphic_foreign_keys = reflect_on_all_associations(:belongs_to).select do |a|
50
+ polymorphic_foreign_keys = reflect_on_all_associations(:belongs_to).select { |a|
108
51
  a.options[:polymorphic]
109
- end.map { |a| a.foreign_key }
52
+ }.map { |a| a.foreign_key }
110
53
 
111
54
  reflect_on_all_associations(:belongs_to).each do |a|
112
55
  unless a == reflect_on_association(tenant) || polymorphic_foreign_keys.include?(a.foreign_key)
113
- association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
56
+ association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
114
57
  validates_each a.foreign_key.to_sym do |record, attr, value|
115
- primary_key = if association_class.respond_to?(:primary_key)
116
- association_class.primary_key
117
- else
118
- a.primary_key
119
- end.to_sym
58
+ primary_key = if a.respond_to?(:active_record_primary_key)
59
+ a.active_record_primary_key
60
+ else
61
+ a.primary_key
62
+ end.to_sym
120
63
  record.errors.add attr, "association is invalid [ActsAsTenant]" unless value.nil? || association_class.where(primary_key => value).any?
121
64
  end
122
65
  end
@@ -126,27 +69,19 @@ module ActsAsTenant
126
69
  # - Rewrite the accessors to make tenant immutable
127
70
  # - Add an override to prevent unnecessary db hits
128
71
  # - Add a helper method to verify if a model has been scoped by AaT
129
- to_include = Module.new do
72
+ to_include = Module.new {
130
73
  define_method "#{fkey}=" do |integer|
131
- write_attribute("#{fkey}", integer)
74
+ write_attribute(fkey.to_s, integer)
132
75
  raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil?
133
76
  integer
134
77
  end
135
78
 
136
- define_method "#{ActsAsTenant.tenant_klass.to_s}=" do |model|
79
+ define_method "#{ActsAsTenant.tenant_klass}=" do |model|
137
80
  super(model)
138
81
  raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil?
139
82
  model
140
83
  end
141
-
142
- define_method "#{ActsAsTenant.tenant_klass.to_s}" do
143
- if !ActsAsTenant.current_tenant.nil? && send(fkey) == ActsAsTenant.current_tenant.id
144
- return ActsAsTenant.current_tenant
145
- else
146
- super()
147
- end
148
- end
149
- end
84
+ }
150
85
  include to_include
151
86
 
152
87
  class << self
@@ -156,17 +91,37 @@ module ActsAsTenant
156
91
  end
157
92
  end
158
93
 
159
- def validates_uniqueness_to_tenant(fields, args ={})
94
+ def validates_uniqueness_to_tenant(fields, args = {})
160
95
  raise ActsAsTenant::Errors::ModelNotScopedByTenant unless respond_to?(:scoped_by_tenant?)
161
96
  fkey = reflect_on_association(ActsAsTenant.tenant_klass).foreign_key
162
- #tenant_id = lambda { "#{ActsAsTenant.fkey}"}.call
163
- if args[:scope]
164
- args[:scope] = Array(args[:scope]) << fkey
97
+ # tenant_id = lambda { "#{ActsAsTenant.fkey}"}.call
98
+ args[:scope] = if args[:scope]
99
+ Array(args[:scope]) << fkey
165
100
  else
166
- args[:scope] = fkey
101
+ fkey
167
102
  end
168
103
 
169
104
  validates_uniqueness_of(fields, args)
105
+
106
+ if ActsAsTenant.models_with_global_records.include?(self)
107
+ validate do |instance|
108
+ Array(fields).each do |field|
109
+ if instance.new_record?
110
+ unless self.class.where(fkey.to_sym => [nil, instance[fkey]],
111
+ field.to_sym => instance[field]).empty?
112
+ errors.add(field, "has already been taken")
113
+ end
114
+ else
115
+ unless self.class.where(fkey.to_sym => [nil, instance[fkey]],
116
+ field.to_sym => instance[field])
117
+ .where.not(id: instance.id).empty?
118
+ errors.add(field, "has already been taken")
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
170
125
  end
171
126
  end
172
127
  end
@@ -2,11 +2,13 @@ module ActsAsTenant::Sidekiq
2
2
  # Get the current tenant and store in the message to be sent to Sidekiq.
3
3
  class Client
4
4
  def call(worker_class, msg, queue, redis_pool)
5
- msg['acts_as_tenant'] ||=
6
- {
7
- 'class' => ActsAsTenant.current_tenant.class.name,
8
- 'id' => ActsAsTenant.current_tenant.id
9
- } if ActsAsTenant.current_tenant.present?
5
+ if ActsAsTenant.current_tenant.present?
6
+ msg["acts_as_tenant"] ||=
7
+ {
8
+ "class" => ActsAsTenant.current_tenant.class.name,
9
+ "id" => ActsAsTenant.current_tenant.id
10
+ }
11
+ end
10
12
 
11
13
  yield
12
14
  end
@@ -15,8 +17,8 @@ module ActsAsTenant::Sidekiq
15
17
  # Pull the tenant out and run the current thread with it.
16
18
  class Server
17
19
  def call(worker_class, msg, queue)
18
- if msg.has_key?('acts_as_tenant')
19
- account = msg['acts_as_tenant']['class'].constantize.find msg['acts_as_tenant']['id']
20
+ if msg.has_key?("acts_as_tenant")
21
+ account = msg["acts_as_tenant"]["class"].constantize.find msg["acts_as_tenant"]["id"]
20
22
  ActsAsTenant.with_tenant account do
21
23
  yield
22
24
  end
@@ -38,6 +40,12 @@ Sidekiq.configure_server do |config|
38
40
  chain.add ActsAsTenant::Sidekiq::Client
39
41
  end
40
42
  config.server_middleware do |chain|
41
- chain.insert_before Sidekiq::Middleware::Server::RetryJobs, ActsAsTenant::Sidekiq::Server
43
+ if defined?(Sidekiq::Middleware::Server::RetryJobs)
44
+ chain.insert_before Sidekiq::Middleware::Server::RetryJobs, ActsAsTenant::Sidekiq::Server
45
+ elsif defined?(Sidekiq::Batch::Server)
46
+ chain.insert_before Sidekiq::Batch::Server, ActsAsTenant::Sidekiq::Server
47
+ else
48
+ chain.add ActsAsTenant::Sidekiq::Server
49
+ end
42
50
  end
43
51
  end
@@ -0,0 +1,7 @@
1
+ module ActsAsTenant
2
+ module TenantHelper
3
+ def current_tenant
4
+ ActsAsTenant.current_tenant
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module ActsAsTenant
2
+ class TestTenantMiddleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ previously_set_test_tenant = ActsAsTenant.test_tenant
9
+ ActsAsTenant.test_tenant = nil
10
+ @app.call(env)
11
+ ensure
12
+ ActsAsTenant.test_tenant = previously_set_test_tenant
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,28 +1,17 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActsAsTenant::Configuration do
4
- describe 'no configuration given' do
5
- before do
6
- ActsAsTenant.configure
7
- end
4
+ after { ActsAsTenant.configure }
8
5
 
9
- it 'provides defaults' do
10
- expect(ActsAsTenant.configuration.require_tenant).not_to be_truthy
11
- end
6
+ it "provides defaults" do
7
+ expect(ActsAsTenant.configuration.require_tenant).not_to be_truthy
12
8
  end
13
9
 
14
- describe 'with config block' do
15
- after do
16
- ActsAsTenant.configure
17
- end
18
-
19
- it 'stores config' do
20
- ActsAsTenant.configure do |config|
21
- config.require_tenant = true
22
- end
23
-
24
- expect(ActsAsTenant.configuration.require_tenant).to eq(true)
10
+ it "stores config" do
11
+ ActsAsTenant.configure do |config|
12
+ config.require_tenant = true
25
13
  end
26
14
 
15
+ expect(ActsAsTenant.configuration.require_tenant).to eq(true)
27
16
  end
28
17
  end
@@ -1,28 +1,27 @@
1
- require 'spec_helper'
2
- require 'sidekiq'
3
- require 'acts_as_tenant/sidekiq'
1
+ require "spec_helper"
2
+ require "sidekiq"
3
+ require "acts_as_tenant/sidekiq"
4
4
 
5
5
  describe ActsAsTenant::Sidekiq do
6
- after { ActsAsTenant.current_tenant = nil }
7
6
  let(:account) { Account.new(id: 1234) }
8
- let(:message) { { 'acts_as_tenant' => { 'class' => 'Account', 'id' => 1234 } } }
7
+ let(:message) { {"acts_as_tenant" => {"class" => "Account", "id" => 1234}} }
9
8
 
10
9
  describe ActsAsTenant::Sidekiq::Client do
11
10
  subject { ActsAsTenant::Sidekiq::Client.new }
12
11
 
13
- it 'saves tenant if present' do
12
+ it "saves tenant if present" do
14
13
  ActsAsTenant.current_tenant = account
15
14
 
16
15
  msg = {}
17
- subject.call(nil, msg, nil, nil) { }
16
+ subject.call(nil, msg, nil, nil) {}
18
17
  expect(msg).to eq message
19
18
  end
20
19
 
21
- it 'does not set tenant if not present' do
20
+ it "does not set tenant if not present" do
22
21
  expect(ActsAsTenant.current_tenant).to be_nil
23
22
 
24
23
  msg = {}
25
- subject.call(nil, msg, nil, nil) { }
24
+ subject.call(nil, msg, nil, nil) {}
26
25
  expect(msg).not_to eq message
27
26
  end
28
27
  end
@@ -30,7 +29,7 @@ describe ActsAsTenant::Sidekiq do
30
29
  describe ActsAsTenant::Sidekiq::Server do
31
30
  subject { ActsAsTenant::Sidekiq::Server.new }
32
31
 
33
- it 'restores tenant if tenant saved' do
32
+ it "restores tenant if tenant saved" do
34
33
  expect(Account).to receive(:find).with(1234).once { account }
35
34
 
36
35
  msg = message
@@ -40,7 +39,7 @@ describe ActsAsTenant::Sidekiq do
40
39
  expect(ActsAsTenant.current_tenant).to be_nil
41
40
  end
42
41
 
43
- it 'runs without tenant if no tenant saved' do
42
+ it "runs without tenant if no tenant saved" do
44
43
  expect(Account).not_to receive(:find)
45
44
 
46
45
  msg = {}
@@ -51,13 +50,9 @@ describe ActsAsTenant::Sidekiq do
51
50
  end
52
51
  end
53
52
 
54
- describe 'Sidekiq configuration' do
55
- describe 'client configuration' do
56
- it 'includes ActsAsTenant client' do
57
- expect(Sidekiq.client_middleware.exists?(ActsAsTenant::Sidekiq::Client)).to eq(true)
58
- end
59
- end
60
-
61
- # unable to test server configuration
53
+ it "includes ActsAsTenant client middleware" do
54
+ expect(Sidekiq.client_middleware.exists?(ActsAsTenant::Sidekiq::Client)).to eq(true)
62
55
  end
56
+
57
+ # unable to test server configuration
63
58
  end