about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShuhei Kitagawa <shuheiktgw@users.noreply.github.com>2018-06-24 19:55:55 +0900
committerYamagishi Kazutoshi <ykzts@desire.sh>2018-06-24 19:55:55 +0900
commit23955d956e799538b3e05fcd967390a541cfe473 (patch)
tree56c2d35658548ddd1303ed029c4c9c1a3cabf5b1
parent245fa1446aec609271e8d51d871ff9474e7298ae (diff)
Add tests for remote_unfollows_controller (#7879)
-rw-r--r--app/controllers/remote_unfollows_controller.rb (renamed from app/controllers/remote_unfollows.rb)0
-rw-r--r--spec/controllers/remote_unfollows_controller_spec.rb38
2 files changed, 38 insertions, 0 deletions
diff --git a/app/controllers/remote_unfollows.rb b/app/controllers/remote_unfollows_controller.rb
index af5943363..af5943363 100644
--- a/app/controllers/remote_unfollows.rb
+++ b/app/controllers/remote_unfollows_controller.rb
diff --git a/spec/controllers/remote_unfollows_controller_spec.rb b/spec/controllers/remote_unfollows_controller_spec.rb
new file mode 100644
index 000000000..223ed64af
--- /dev/null
+++ b/spec/controllers/remote_unfollows_controller_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe RemoteUnfollowsController do
+  render_views
+
+  describe '#create' do
+    subject { post :create, params: { acct: acct } }
+
+    let(:current_user) { Fabricate(:user, account: current_account) }
+    let(:current_account) { Fabricate(:account) }
+    let(:remote_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
+    before do
+      sign_in current_user
+      current_account.follow!(remote_account)
+      stub_request(:post, 'http://example.com/inbox'){ { status: 200 } }
+    end
+
+    context 'when successfully unfollow remote account' do
+      let(:acct) {"acct:#{ remote_account.username }@#{ remote_account.domain }"}
+
+      it do
+        is_expected.to render_template :success
+        expect(current_account.following?(remote_account)).to be false
+      end
+    end
+
+    context 'when fails to unfollow remote account' do
+      let(:acct) {"acct:#{ remote_account.username + '_test' }@#{ remote_account.domain }"}
+
+      it do
+        is_expected.to render_template :error
+        expect(current_account.following?(remote_account)).to be true
+      end
+    end
+  end
+end