acts_as_tenant 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ 0.2.2
2
+ -----
3
+ * Enhancements
4
+ * Added support for aliased associations ( belongs_to :something, :class_name => 'SomethingElse'). In previous version these would raise an 'uninitialized constant' error.
5
+
6
+ 0.2.1
7
+ -----
8
+ * Initial release
@@ -70,8 +70,11 @@ module ActsAsTenant
70
70
  # exempt them
71
71
  reflect_on_all_associations.each do |a|
72
72
  unless a == reflection || a.macro == :has_many || a.options[:polymorphic]
73
+ # check if the association is aliasing another class, if so
74
+ # find the unaliased class name
75
+ association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
73
76
  validates_each a.foreign_key.to_sym do |record, attr, value|
74
- record.errors.add attr, "is invalid" unless a.name.to_s.classify.constantize.where(:id => value).present?
77
+ record.errors.add attr, "is invalid" unless association_class.where(:id => value).present?
75
78
  end
76
79
  end
77
80
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -26,6 +26,11 @@ ActiveRecord::Schema.define(:version => 1) do
26
26
  t.column :name, :string
27
27
  end
28
28
 
29
+ create_table :sub_tasks, :force => true do |t|
30
+ t.column :name, :string
31
+ t.column :something_else, :integer
32
+ end
33
+
29
34
  end
30
35
 
31
36
  # Setup the models
@@ -48,11 +53,13 @@ class Task < ActiveRecord::Base
48
53
  validates_uniqueness_of :name
49
54
  end
50
55
 
51
-
52
56
  class City < ActiveRecord::Base
53
57
  validates_uniqueness_of :name
54
58
  end
55
59
 
60
+ class SubTask < ActiveRecord::Base
61
+ belongs_to :something_else, :class_name => "Project"
62
+ end
56
63
 
57
64
  # Start testing!
58
65
  describe ActsAsTenant do
@@ -83,6 +90,21 @@ describe ActsAsTenant do
83
90
  it { @projects.should == [@project1] }
84
91
  end
85
92
 
93
+ describe 'Project.unscoped.all should return the unscoped value' do
94
+ before do
95
+ @account1 = Account.create!(:name => 'foo')
96
+ @account2 = Account.create!(:name => 'bar')
97
+
98
+ @project1 = @account1.projects.create!(:name => 'foobar')
99
+ @project2 = @account2.projects.create!(:name => 'baz')
100
+
101
+ ActsAsTenant.current_tenant= @account1
102
+ @projects = Project.unscoped.all
103
+ end
104
+
105
+ it { @projects.length.should == 2 }
106
+ end
107
+
86
108
  describe 'Associations should be correctly scoped by current tenant' do
87
109
  before do
88
110
  @account = Account.create!(:name => 'foo')
@@ -175,4 +197,10 @@ describe ActsAsTenant do
175
197
  @city2 = City.create(:name => 'foo').valid?.should == false
176
198
  end
177
199
  end
200
+
201
+ describe "It should be possible to use aliased associations" do
202
+ it { @sub_task = SubTask.create(:name => 'foo').valid?.should == true }
203
+ end
204
+
205
+
178
206
  end
data/spec/spec_helper.rb CHANGED
@@ -23,7 +23,7 @@ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
23
23
  #RSpec.configure do |config|
24
24
  #end
25
25
 
26
- Spec::Runner.configure do |config|
26
+ RSpec.configure do |config|
27
27
 
28
28
  config.before(:suite) do
29
29
  DatabaseCleaner.strategy = :transaction
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.1
4
+ version: 0.2.2
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: 2011-10-03 00:00:00.000000000Z
12
+ date: 2011-10-09 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
@@ -21,6 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
23
  - .rvmrc
24
+ - CHANGELOG.md
24
25
  - Gemfile
25
26
  - MIT-LICENSE
26
27
  - README.md