acts_as_tenant 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +9 -4
- data/lib/acts_as_tenant/model_extensions.rb +2 -2
- data/lib/acts_as_tenant/version.rb +1 -1
- metadata +3 -4
- data/.rvmrc +0 -1
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ In addition, acts_as_tenant:
|
|
11
11
|
|
12
12
|
* sets the current tenant using the subdomain or allows you to pass in the current tenant yourself
|
13
13
|
* protects against various types of nastiness directed at circumventing the tenant scoping
|
14
|
-
* adds a method to validate uniqueness to a tenant, validates_uniqueness_to_tenant
|
14
|
+
* adds a method to validate uniqueness to a tenant, `validates_uniqueness_to_tenant`
|
15
15
|
* sets up a helper method containing the current tenant
|
16
16
|
|
17
17
|
Installation
|
@@ -66,7 +66,7 @@ acts_as_tenant requires each scoped model to have a column in its schema linking
|
|
66
66
|
Some examples to illustrate this behavior:
|
67
67
|
|
68
68
|
# This manually sets the current tenant for testing purposes. In your app this is handled by the gem.
|
69
|
-
|
69
|
+
ActsAsTenant.current_tenant = Account.find(3)
|
70
70
|
|
71
71
|
# All searches are scoped by the tenant, the following searches will only return objects
|
72
72
|
# where account_id == 3
|
@@ -82,16 +82,21 @@ Some examples to illustrate this behavior:
|
|
82
82
|
|
83
83
|
# It will not allow association with objects outside the current tenant scope
|
84
84
|
# Assuming the Project with ID: 2 does not belong to Account with ID: 3
|
85
|
-
@task = Task.new # => <#Task id: nil, name:
|
85
|
+
@task = Task.new # => <#Task id: nil, name: nil, project_id: nil, :account_id: 3>
|
86
86
|
|
87
87
|
Acts_as_tenant uses Rails' default_scope method to scope models. Rails 3.1 changed the way default_scope works in a good way. A user defined default_scope should integrate seamlessly with the one added by acts_as_tenant.
|
88
88
|
|
89
89
|
**Validating attribute uniqueness**
|
90
|
+
|
90
91
|
If you need to validate for uniqueness, chances are that you want to scope this validation to a tenant. You can do so by using:
|
91
92
|
|
92
93
|
validates_uniqueness_to_tenant :name, :email
|
93
94
|
|
94
|
-
All options available to Rails' own
|
95
|
+
All options available to Rails' own `validates_uniqueness_of` are also available to this method.
|
96
|
+
|
97
|
+
Note on testing
|
98
|
+
---------------
|
99
|
+
Whenever you set the `current_tenant` in your tests, either through integration tests or directly by calling `ActsAsTenant.current_tenant = some_tenant`, make sure to clean up the tenant after each test by calling `ActsAsTenant.current_tenant = nil`.
|
95
100
|
|
96
101
|
To Do
|
97
102
|
-----
|
@@ -40,7 +40,7 @@ module ActsAsTenant
|
|
40
40
|
# set the current_tenant on newly created objects
|
41
41
|
before_validation Proc.new {|m|
|
42
42
|
return unless ActsAsTenant.current_tenant
|
43
|
-
m.send "#{association}=".to_sym, ActsAsTenant.current_tenant
|
43
|
+
m.send "#{association}_id=".to_sym, ActsAsTenant.current_tenant.id
|
44
44
|
}, :on => :create
|
45
45
|
|
46
46
|
# set the default_scope to scope to current tenant
|
@@ -76,7 +76,7 @@ module ActsAsTenant
|
|
76
76
|
validates_each a.foreign_key.to_sym do |record, attr, value|
|
77
77
|
# Invalidate the association unless the parent is known to the tenant or no association has
|
78
78
|
# been set.
|
79
|
-
record.errors.add attr, "is invalid" unless association_class.where(:id => value).present?
|
79
|
+
record.errors.add attr, "is invalid (Acts_as_Tenant)" unless value.nil? || association_class.where(:id => value).present?
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_tenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-28 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Integrates multi-tenancy into a Rails application in a convenient and
|
15
15
|
out-of-your way manner
|
@@ -20,7 +20,6 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- .gitignore
|
23
|
-
- .rvmrc
|
24
23
|
- CHANGELOG.md
|
25
24
|
- Gemfile
|
26
25
|
- MIT-LICENSE
|
@@ -55,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
54
|
version: '0'
|
56
55
|
requirements: []
|
57
56
|
rubyforge_project: acts_as_tenant
|
58
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.10
|
59
58
|
signing_key:
|
60
59
|
specification_version: 3
|
61
60
|
summary: Add multi-tenancy to Rails applications using a shared db strategy
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.2@rails31
|