about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorJenkins <jenkins@jenkins.ninjawedding.org>2017-11-25 05:17:15 +0000
committerJenkins <jenkins@jenkins.ninjawedding.org>2017-11-25 05:17:15 +0000
commit86f4f8e158deb57b2672d961f7c2dfc963e2a50c (patch)
treeeb0c60264b8885e3bce2c6a8322c3f800071c189 /spec
parent167fe2ab08288ce286f5c7660ff0ed587b65b988 (diff)
parent662b8eefe891c050e6befcb5736a9a5c417014b7 (diff)
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/streamable_spec.rb63
-rw-r--r--spec/presenters/account_relationships_presenter_spec.rb82
2 files changed, 145 insertions, 0 deletions
diff --git a/spec/models/concerns/streamable_spec.rb b/spec/models/concerns/streamable_spec.rb
new file mode 100644
index 000000000..b5f2d5192
--- /dev/null
+++ b/spec/models/concerns/streamable_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Streamable do
+  class Parent
+    def title; end
+
+    def target; end
+
+    def thread; end
+
+    def self.has_one(*); end
+
+    def self.after_create; end
+  end
+
+  class Child < Parent
+    include Streamable
+  end
+
+  child = Child.new
+
+  describe '#title' do
+    it 'calls Parent#title' do
+      expect_any_instance_of(Parent).to receive(:title)
+      child.title
+    end
+  end
+
+  describe '#content' do
+    it 'calls #title' do
+      expect_any_instance_of(Parent).to receive(:title)
+      child.content
+    end
+  end
+
+  describe '#target' do
+    it 'calls Parent#target' do
+      expect_any_instance_of(Parent).to receive(:target)
+      child.target
+    end
+  end
+
+  describe '#object_type' do
+    it 'returns :activity' do
+      expect(child.object_type).to eq :activity
+    end
+  end
+
+  describe '#thread' do
+    it 'calls Parent#thread' do
+      expect_any_instance_of(Parent).to receive(:thread)
+      child.thread
+    end
+  end
+
+  describe '#hidden?' do
+    it 'returns false' do
+      expect(child.hidden?).to be false
+    end
+  end
+end
diff --git a/spec/presenters/account_relationships_presenter_spec.rb b/spec/presenters/account_relationships_presenter_spec.rb
new file mode 100644
index 000000000..f8b048d38
--- /dev/null
+++ b/spec/presenters/account_relationships_presenter_spec.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe AccountRelationshipsPresenter do
+  describe '.initialize' do
+    before do
+      allow(Account).to receive(:following_map).with(account_ids, current_account_id).and_return(default_map)
+      allow(Account).to receive(:followed_by_map).with(account_ids, current_account_id).and_return(default_map)
+      allow(Account).to receive(:blocking_map).with(account_ids, current_account_id).and_return(default_map)
+      allow(Account).to receive(:muting_map).with(account_ids, current_account_id).and_return(default_map)
+      allow(Account).to receive(:requested_map).with(account_ids, current_account_id).and_return(default_map)
+      allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
+    end
+
+    let(:presenter)          { AccountRelationshipsPresenter.new(account_ids, current_account_id, options) }
+    let(:current_account_id) { Fabricate(:account).id }
+    let(:account_ids)        { [Fabricate(:account).id] }
+    let(:default_map)        { { 1 => true } }
+
+    context 'options are not set' do
+      let(:options) { {} }
+
+      it 'sets default maps' do
+        expect(presenter.following).to       eq default_map
+        expect(presenter.followed_by).to     eq default_map
+        expect(presenter.blocking).to        eq default_map
+        expect(presenter.muting).to          eq default_map
+        expect(presenter.requested).to       eq default_map
+        expect(presenter.domain_blocking).to eq default_map
+      end
+    end
+
+    context 'options[:following_map] is set' do
+      let(:options) { { following_map: { 2 => true } } }
+
+      it 'sets @following merged with default_map and options[:following_map]' do
+        expect(presenter.following).to eq default_map.merge(options[:following_map])
+      end
+    end
+
+    context 'options[:followed_by_map] is set' do
+      let(:options) { { followed_by_map: { 3 => true } } }
+
+      it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
+        expect(presenter.followed_by).to eq default_map.merge(options[:followed_by_map])
+      end
+    end
+
+    context 'options[:blocking_map] is set' do
+      let(:options) { { blocking_map: { 4 => true } } }
+
+      it 'sets @blocking merged with default_map and options[:blocking_map]' do
+        expect(presenter.blocking).to eq default_map.merge(options[:blocking_map])
+      end
+    end
+
+    context 'options[:muting_map] is set' do
+      let(:options) { { muting_map: { 5 => true } } }
+
+      it 'sets @muting merged with default_map and options[:muting_map]' do
+        expect(presenter.muting).to eq default_map.merge(options[:muting_map])
+      end
+    end
+
+    context 'options[:requested_map] is set' do
+      let(:options) { { requested_map: { 6 => true } } }
+
+      it 'sets @requested merged with default_map and options[:requested_map]' do
+        expect(presenter.requested).to eq default_map.merge(options[:requested_map])
+      end
+    end
+
+    context 'options[:domain_blocking_map] is set' do
+      let(:options) { { domain_blocking_map: { 7 => true } } }
+
+      it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
+        expect(presenter.domain_blocking).to eq default_map.merge(options[:domain_blocking_map])
+      end
+    end
+  end
+end