acts_as_tenant 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +9 -0
- data/acts_as_tenant.gemspec +1 -1
- data/lib/acts_as_tenant/model_extensions.rb +7 -3
- data/lib/acts_as_tenant/version.rb +1 -1
- data/spec/acts_as_tenant/model_extensions_spec.rb +23 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzI5YTBmNmY5NjY3MDFmYjU5MzcxZjY3NzU4NjMwNzMxOGM3MTgzZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTExMzUxY2U4YjYzMzcwOTExNjk0MzRhMWRkNjAxOTU1Y2Y5YmYyMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTZmZThmMDZlYTg5OWU1YzBkOTQ1NjdmNWJhYjE2MjI4MjJhYzU5OGRkYWJk
|
10
|
+
ZTg0OGQwNWNjZTBkNDdiMGFkNDIzOTRmODNmOWNhNzEzY2E2YTZhODk5ZDIz
|
11
|
+
ZjRiMmY0OWJjNTI0ZDA1MTQ1M2Y2ZTdjMzFhMTAxZDMzNzlhZDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWYzNzlkODkyM2EyMTMxN2MxMjY1ZWRmZDVhN2UxZjIxOTNmMzYzMjJlNTdj
|
14
|
+
ODMxNTdmMWMxZTJlODcyNmIwNzM4YjUxOTMyYWE0M2M0MTM2M2Y1ZDZmZTY2
|
15
|
+
MDBjMWRiNGRiY2M4ZTViZjZhMDc5MDMxMjVlMWJmMWY5OGQwNTc=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.3.7
|
2
|
+
-----
|
3
|
+
* Fix for proper handling of polymorphic associations (thx sol1dus)
|
4
|
+
* Fix fefault scope to generate correct sql when using database prefix (thx IgorDobryn)
|
5
|
+
* Added ability to specify a custom Primary Key (thx matiasdim)
|
6
|
+
* Sidekiq 3.2.2+ no longer supports Ruby 1.9. Locking Sidekiq in gemspec at 3.2.1.
|
7
|
+
* Update RSPEC to 3.0. Convert all specs (thx petergoldstein)
|
8
|
+
* support sidekiq 3 interface (thx davekaro)
|
9
|
+
|
1
10
|
0.3.6
|
2
11
|
-----
|
3
12
|
* Added method `set_current_tenant_by_subdomain_or_domain` (thx preth00nker)
|
data/acts_as_tenant.gemspec
CHANGED
@@ -53,7 +53,7 @@ module ActsAsTenant
|
|
53
53
|
if ActsAsTenant.configuration.require_tenant && ActsAsTenant.current_tenant.nil?
|
54
54
|
raise ActsAsTenant::Errors::NoTenantSet
|
55
55
|
end
|
56
|
-
where(
|
56
|
+
where(fkey.to_sym => ActsAsTenant.current_tenant.id) if ActsAsTenant.current_tenant
|
57
57
|
}
|
58
58
|
|
59
59
|
# Add the following validations to the receiving model:
|
@@ -66,11 +66,15 @@ module ActsAsTenant
|
|
66
66
|
end
|
67
67
|
}, :on => :create
|
68
68
|
|
69
|
+
polymorphic_foreign_keys = reflect_on_all_associations.select do |a|
|
70
|
+
a.options[:polymorphic]
|
71
|
+
end.map { |a| a.foreign_key }
|
72
|
+
|
69
73
|
reflect_on_all_associations.each do |a|
|
70
|
-
unless a == reflect_on_association(tenant) || a.macro != :belongs_to || a.
|
74
|
+
unless a == reflect_on_association(tenant) || a.macro != :belongs_to || polymorphic_foreign_keys.include?(a.foreign_key)
|
71
75
|
association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
|
72
76
|
validates_each a.foreign_key.to_sym do |record, attr, value|
|
73
|
-
record.errors.add attr, "association is invalid [ActsAsTenant]" unless value.nil? || association_class.where(
|
77
|
+
record.errors.add attr, "association is invalid [ActsAsTenant]" unless value.nil? || association_class.where(association_class.primary_key.to_sym => value).present?
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
@@ -52,6 +52,12 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
52
52
|
t.column :accountID, :integer
|
53
53
|
end
|
54
54
|
|
55
|
+
create_table :comments, :force => true do |t|
|
56
|
+
t.column :commentable_id, :integer
|
57
|
+
t.column :commentable_type, :string
|
58
|
+
t.column :account_id, :integer
|
59
|
+
end
|
60
|
+
|
55
61
|
end
|
56
62
|
|
57
63
|
# Setup the models
|
@@ -100,6 +106,12 @@ class CustomForeignKeyTask < ActiveRecord::Base
|
|
100
106
|
validates_uniqueness_to_tenant :name
|
101
107
|
end
|
102
108
|
|
109
|
+
class Comment < ActiveRecord::Base
|
110
|
+
belongs_to :commentable, polymorphic: true
|
111
|
+
belongs_to :task, -> { where(comments: { commentable_type: 'Task' }) }, foreign_key: 'commentable_id'
|
112
|
+
acts_as_tenant :account
|
113
|
+
end
|
114
|
+
|
103
115
|
# Start testing!
|
104
116
|
describe ActsAsTenant do
|
105
117
|
after { ActsAsTenant.current_tenant = nil }
|
@@ -251,6 +263,17 @@ describe ActsAsTenant do
|
|
251
263
|
it { expect(AliasedTask.create(:name => 'foo', :project_alias => @project2).valid?).to eq(true) }
|
252
264
|
end
|
253
265
|
|
266
|
+
describe "It should be possible to use associations with foreign_key from polymorphic" do
|
267
|
+
before do
|
268
|
+
@account = Account.create!(name: 'foo')
|
269
|
+
ActsAsTenant.current_tenant = @account
|
270
|
+
@project = Project.create!(name: 'project', account: @account)
|
271
|
+
@comment = Comment.new commentable: @project, account: @account
|
272
|
+
end
|
273
|
+
|
274
|
+
it { expect(@comment.save!).to eq(true) }
|
275
|
+
end
|
276
|
+
|
254
277
|
# Additional default_scopes
|
255
278
|
describe 'When dealing with a user defined default_scope' do
|
256
279
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_tenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erwin Matthijssen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: sidekiq
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 3.2.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 3.2.1
|
111
111
|
description: Integrates multi-tenancy into a Rails application in a convenient and
|
112
112
|
out-of-your way manner
|
113
113
|
email:
|