gearheads
/
mastodon
Archived
2
0
Fork 0

Cover Favourite more (#3841)

gh/stable
Akihiko Odaki (@fn_aki@pawoo.net) 2017-06-19 08:38:50 +09:00 committed by Eugen Rochko
parent b51945f096
commit 05e4728de7
1 changed files with 24 additions and 4 deletions

View File

@ -1,9 +1,29 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Favourite, type: :model do RSpec.describe Favourite, type: :model do
let(:alice) { Fabricate(:account, username: 'alice') } let(:account) { Fabricate(:account) }
let(:bob) { Fabricate(:account, username: 'bob') }
let(:status) { Fabricate(:status, account: bob) }
subject { Favourite.new(account: alice, status: status) } context 'when status is a reblog' do
let(:reblog) { Fabricate(:status, reblog: nil) }
let(:status) { Fabricate(:status, reblog: reblog) }
it 'invalidates if the reblogged status is already a favourite' do
Favourite.create!(account: account, status: reblog)
expect(Favourite.new(account: account, status: status).valid?).to eq false
end
it 'replaces status with the reblogged one if it is a reblog' do
favourite = Favourite.create!(account: account, status: status)
expect(favourite.status).to eq reblog
end
end
context 'when status is not a reblog' do
let(:status) { Fabricate(:status, reblog: nil) }
it 'saves with the specified status' do
favourite = Favourite.create!(account: account, status: status)
expect(favourite.status).to eq status
end
end
end end