Skip to content

Commit

Permalink
Test: Demonsrate associations made with out-of-scope objects.
Browse files Browse the repository at this point in the history
This test mimics acts_as_tenant:/spec/models/model_extensions.rb:194,
'associations can only be made with in-scope objects'.

See ErwinM/acts_as_tenant#255.
  • Loading branch information
Yong Bakos committed Mar 16, 2021
1 parent 4483421 commit 5fc399d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/models/account_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
require "test_helper"

class AccountTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end

test 'associations can be made with out-of-scope objects (but should not!)' do
# See acts_as_tenant:/spec/models/model_extensions.rb:194,
# "associations can only be made with in-scope objects"
room2 = accounts(:two).rooms.create!(name: 'Account 2 room')
ActsAsTenant.current_tenant = accounts(:one)
room1 = Room.create!(name: "Account 1 room")
person = room1.people.create!(name: 'First account person')
person.room = room2
refute person.valid? # This should pass, but it fails!
refute person.update(room_id: room2.id) # This should pass, but it fails!
end
end

0 comments on commit 5fc399d

Please sign in to comment.