Permalink
Browse files

Added spec to test for has_and_belongs_to_many tenant scoping

  • Loading branch information...
1 parent 633c071 commit c230e487c101999cd2ef149f7d5e3c535a033271 Mitch Statz committed Sep 21, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 spec/model_extensions_spec.rb
@@ -245,6 +245,30 @@ class Tool < ActiveRecord::Base
@manager.save.should == true
end
+ describe "It should be possible to use direct many-to-many associations" do
+ @manager = Manager.create!(:name => 'fool')
+ @manager.tools.new(:name => 'golden hammer')
+ @manager.save.should == true
+ end
+
+ describe "When using direct many-to-many associations they are correctly scoped to the tenant" do
+ before do
+ @account1 = Account.create!(:name => 'foo')
+ @account2 = Account.create!(:name => 'bar')
+
+ ActsAsTenant.current_tenant= @account1
+ @manager1 = Manager.create!(:name => 'fool')
+ @tool1 = @manager1.tools.create!(:name => 'golden hammer')
+
+ ActsAsTenant.current_tenant= @account2
+ @manager2 = Manager.create!(:name => 'pitty')
+ @tool2 = @manager2.tools.create!(:name => 'golden saw')
+
+ @tools = Tool.all
+ end
+ it { @tools.should == [@tool2] }
+ end
+
describe "::with_tenant" do
it "should set current_tenant to the specified tenant inside the block" do
@account = Account.create!(:name => 'baz')

0 comments on commit c230e48

Please sign in to comment.