Last active
June 2, 2016 13:54
-
-
Save aldesantis/53c78d0f75826f74c2b843c59f428023 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
RSpec.describe Photo | |
let(:house) { House.create! } | |
subject { described_class.new(house: house) } | |
it 'is marked as cover when saved' do | |
expect { | |
subject.save! | |
subject.reload | |
}.to change(subject, :cover).to(true) | |
end | |
it 'overwrites the previous cover photo when created as cover' do | |
old_cover = described_class.create!(house: house, cover: true) | |
subject.cover = true | |
expect { | |
subject.save! | |
old_cover.reload | |
}.to change(old_cover, :cover).to(false) | |
end | |
it 'overwrites the previous cover photo when marked as cover' do | |
old_cover = described_class.create!(house: house, cover: true) | |
expect { | |
subject.update!(cover: true) | |
old_cover.reload | |
}.to change(old_cover, :cover).to(false) | |
end | |
it 'marks the other photo as the cover when destroyed' do | |
photo2 = described_class.create(house: house) | |
subject.cover = true | |
subject.save! | |
expect { | |
subject.destroy! | |
photo2.reload | |
}.to change(photo2, :cover).to(true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment