Skip to content

Commit

Permalink
Move acts_as_tenant declaration after other associations.
Browse files Browse the repository at this point in the history
The tests were failing, and they should have been passing.
Now watch this: move the acts_as_tenant declaration after the other
associations declarations. The tests now pass.

See ErwinM/acts_as_tenant#255.
  • Loading branch information
Yong Bakos committed Mar 16, 2021
1 parent 528bdcf commit 56b3646
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Person < ApplicationRecord
acts_as_tenant(:account)
belongs_to :room
acts_as_tenant(:account)
end
2 changes: 1 addition & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Room < ApplicationRecord
acts_as_tenant(:account)
has_many :people
acts_as_tenant(:account)
end
4 changes: 2 additions & 2 deletions test/models/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AccountTest < ActiveSupport::TestCase
room1 = Room.create!(name: "Account 1 room")
person = room1.people.create!(name: 'Account 1 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!
refute person.valid? # This now passes, and it should.
refute person.update(room_id: room2.id) # This now passes, and it should.
end
end
6 changes: 3 additions & 3 deletions test/models/person_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class PersonTest < ActiveSupport::TestCase
refute person.account == second_room.account
person.room = second_room # person's account is not the same as second_room's account

refute person.valid? # This should pass, but it fails.
refute person.save # This should pass, but it fails.
assert_raises(ActiveRecord::RecordInvalid) { person.save! } # This should pass, but it fails.
refute person.valid? # This now passes, and it should.
refute person.save # This now passes, and it should.
assert_raises(ActiveRecord::RecordInvalid) { person.save! } # This now passes, and it should.
end
end
end

0 comments on commit 56b3646

Please sign in to comment.