commit: 05e4728de781209d13405240eca0dd4f3ef6baa8
parent: b51945f09649a4c010b8f4a8279f6f7856c832dd
Author: Akihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>
Date: Mon, 19 Jun 2017 08:38:50 +0900
Cover Favourite more (#3841)
Diffstat:
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git 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