Created
May 17, 2016 12:30
-
-
Save Tonkonozhenko/95438d1b8f33e137ff706164eb69cd38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A < ActiveRecord::Base | |
has_and_belongs_to_many :bs | |
end | |
class B < ActiveRecord::Base | |
has_and_belongs_to_many :as | |
end | |
class Ab < ActiveRecord::Base | |
self.table_name = :as_bs | |
end | |
RSpec.describe A, type: :model do | |
let(:n) { 10 } | |
it do | |
a = A.create | |
a.bs = n.times.map { B.create } | |
a.save | |
expect(a.bs.count).to eq(n) | |
expect(B.count).to eq(n) | |
expect(Ab.count).to eq(n) | |
expect do | |
expect do | |
a.bs.destroy_all | |
end.not_to change(B, :count) | |
end.to change(Ab, :count).by(-n) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment