]> cat aescling's git repositories - mastodon.git/commitdiff
Add specs for RemoteInteractionController (#9524)
authorysksn <bluewhale1982@gmail.com>
Fri, 14 Dec 2018 19:36:40 +0000 (04:36 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 14 Dec 2018 19:36:40 +0000 (20:36 +0100)
spec/controllers/remote_interaction_controller_spec.rb [new file with mode: 0644]

diff --git a/spec/controllers/remote_interaction_controller_spec.rb b/spec/controllers/remote_interaction_controller_spec.rb
new file mode 100644 (file)
index 0000000..bb0074b
--- /dev/null
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe RemoteInteractionController, type: :controller do
+  render_views
+
+  let(:status) { Fabricate(:status) }
+
+  describe 'GET #new' do
+    it 'returns 200' do
+      get :new, params: { id: status.id }
+      expect(response).to have_http_status(200)
+    end
+  end
+
+  describe 'POST #create' do
+    context '@remote_follow is valid' do
+      it 'returns 302' do
+        allow_any_instance_of(RemoteFollow).to receive(:valid?) { true }
+        allow_any_instance_of(RemoteFollow).to receive(:addressable_template) do
+          Addressable::Template.new('https://hoge.com')
+        end
+
+        post :create, params: { id: status.id, remote_follow: { acct: '@hoge' } }
+        expect(response).to have_http_status(302)
+      end
+    end
+
+    context '@remote_follow is invalid' do
+      it 'returns 200' do
+        allow_any_instance_of(RemoteFollow).to receive(:valid?) { false }
+        post :create, params: { id: status.id, remote_follow: { acct: '@hoge' } }
+
+        expect(response).to have_http_status(200)
+      end
+    end
+  end
+end