From 05e4728de781209d13405240eca0dd4f3ef6baa8 Mon Sep 17 00:00:00 2001 From: "Akihiko Odaki (@fn_aki@pawoo.net)" Date: Mon, 19 Jun 2017 08:38:50 +0900 Subject: [PATCH] Cover Favourite more (#3841) --- spec/models/favourite_spec.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb index 5b712650..ba1410a4 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