about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--spec/models/favourite_spec.rb28
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