about summary refs log tree commit diff
diff options
context:
space:
mode:
authorysksn <bluewhale1982@gmail.com>2018-12-28 18:09:32 +0900
committerYamagishi Kazutoshi <ykzts@desire.sh>2018-12-28 18:09:32 +0900
commitd01c840e14d544e933d90f6e474ff0078bc4a899 (patch)
tree6c150e7eea92f932339dc6e405c1440ca08b0190
parentccb9c1b952e87dd954bfb651db59dc02a4d9341f (diff)
Add specs for StatusPinValidator (#9648)
-rw-r--r--spec/validators/status_pin_validator_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/validators/status_pin_validator_spec.rb b/spec/validators/status_pin_validator_spec.rb
new file mode 100644
index 000000000..06532e5b3
--- /dev/null
+++ b/spec/validators/status_pin_validator_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe StatusPinValidator, type: :validator do
+  describe '#validate' do
+    before do
+      subject.validate(pin)
+    end
+
+    let(:pin) { double(account: account, errors: errors, status: status, account_id: pin_account_id) }
+    let(:status) { double(reblog?: reblog, account_id: status_account_id, visibility: visibility) }
+    let(:account)     { double(status_pins: status_pins, local?: local) }
+    let(:status_pins) { double(count: count) }
+    let(:errors)      { double(add: nil) }
+    let(:pin_account_id)    { 1 }
+    let(:status_account_id) { 1 }
+    let(:visibility)  { 'public' }
+    let(:local)       { false }
+    let(:reblog)      { false }
+    let(:count)       { 0 }
+
+    context 'pin.status.reblog?' do
+      let(:reblog) { true }
+
+      it 'calls errors.add' do
+        expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.reblog'))
+      end
+    end
+
+    context 'pin.account_id != pin.status.account_id' do
+      let(:pin_account_id)    { 1 }
+      let(:status_account_id) { 2 }
+
+      it 'calls errors.add' do
+        expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.ownership'))
+      end
+    end
+
+    context 'unless %w(public unlisted).include?(pin.status.visibility)' do
+      let(:visibility) { '' }
+
+      it 'calls errors.add' do
+        expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.private'))
+      end
+    end
+
+    context 'pin.account.status_pins.count > 4 && pin.account.local?' do
+      let(:count) { 5 }
+      let(:local) { true }
+
+      it 'calls errors.add' do
+        expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.limit'))
+      end
+    end
+  end
+end