diff options
author | Akihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp> | 2017-06-19 08:38:50 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-06-19 01:38:50 +0200 |
commit | 05e4728de781209d13405240eca0dd4f3ef6baa8 (patch) | |
tree | 111dd491091c628967e9ac1def8c5857e6fc057b /spec/models/favourite_spec.rb | |
parent | b51945f09649a4c010b8f4a8279f6f7856c832dd (diff) |
Cover Favourite more (#3841)
Diffstat (limited to 'spec/models/favourite_spec.rb')
-rw-r--r-- | spec/models/favourite_spec.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb index 5b7126506..ba1410a45 100644 --- a/spec/models/favourite_spec.rb +++ b/spec/models/favourite_spec.rb @@ -1,9 +1,29 @@ require 'rails_helper' RSpec.describe Favourite, type: :model do - let(:alice) { Fabricate(:account, username: 'alice') } - let(:bob) { Fabricate(:account, username: 'bob') } - let(:status) { Fabricate(:status, account: bob) } + let(:account) { Fabricate(:account) } - 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 |