about summary refs log tree commit diff
path: root/spec/controllers/settings
diff options
context:
space:
mode:
authorAlex Gessner <alex.gessner@gmail.com>2019-03-28 13:01:09 -0400
committerEugen Rochko <eugen@zeonfederated.com>2019-03-28 18:01:09 +0100
commit69141dca26f8a28d3aff63387b1c8d2bba7fdfa3 (patch)
tree258b59ecbce99855bccb4fd679a5eb3d9938acb0 /spec/controllers/settings
parent026dd75208223a8ceb8f3e82699a123d68b9a1c7 (diff)
squashed identity proof updates (#10375)
Diffstat (limited to 'spec/controllers/settings')
-rw-r--r--spec/controllers/settings/identity_proofs_controller_spec.rb57
1 files changed, 52 insertions, 5 deletions
diff --git a/spec/controllers/settings/identity_proofs_controller_spec.rb b/spec/controllers/settings/identity_proofs_controller_spec.rb
index 46af3ccf4..5c05eb83c 100644
--- a/spec/controllers/settings/identity_proofs_controller_spec.rb
+++ b/spec/controllers/settings/identity_proofs_controller_spec.rb
@@ -1,6 +1,7 @@
 require 'rails_helper'
 
 describe Settings::IdentityProofsController do
+  include RoutingHelper
   render_views
 
   let(:user) { Fabricate(:user) }
@@ -9,8 +10,15 @@ describe Settings::IdentityProofsController do
   let(:provider) { 'keybase' }
   let(:findable_id) { Faker::Number.number(5) }
   let(:unfindable_id) { Faker::Number.number(5) }
+  let(:new_proof_params) do
+    { provider: provider, provider_username: kbname, token: valid_token, username: user.account.username }
+  end
+  let(:status_text) { "i just proved that i am also #{kbname} on #{provider}." }
+  let(:status_posting_params) do
+    { post_status: '0', status_text: status_text }
+  end
   let(:postable_params) do
-    { account_identity_proof: { provider: provider, provider_username: kbname, token: valid_token } }
+    { account_identity_proof: new_proof_params.merge(status_posting_params) }
   end
 
   before do
@@ -19,10 +27,32 @@ describe Settings::IdentityProofsController do
   end
 
   describe 'new proof creation' do
-    context 'GET #new with no existing proofs' do
-      it 'redirects to :index' do
-        get :new
-        expect(response).to redirect_to settings_identity_proofs_path
+    context 'GET #new' do
+      context 'with all of the correct params' do
+        before do
+          allow_any_instance_of(ProofProvider::Keybase::Badge).to receive(:avatar_url) { full_pack_url('media/images/void.png') }
+        end
+
+        it 'renders the template' do
+          get :new, params: new_proof_params
+          expect(response).to render_template(:new)
+        end
+      end
+
+      context 'without any params' do
+        it 'redirects to :index' do
+          get :new, params: {}
+          expect(response).to redirect_to settings_identity_proofs_path
+        end
+      end
+
+      context 'with params to prove a different, not logged-in user' do
+        let(:wrong_user_params) { new_proof_params.merge(username: 'someone_else') }
+
+        it 'shows a helpful alert' do
+          get :new, params: wrong_user_params
+          expect(flash[:alert]).to eq I18n.t('identity_proofs.errors.wrong_user', proving: 'someone_else', current: user.account.username)
+        end
       end
     end
 
@@ -44,6 +74,23 @@ describe Settings::IdentityProofsController do
           post :create, params: postable_params
           expect(response).to redirect_to root_url
         end
+
+        it 'does not post a status' do
+          expect(PostStatusService).not_to receive(:new)
+          post :create, params: postable_params
+        end
+
+        context 'and the user has requested to post a status' do
+          let(:postable_params_with_status) do
+            postable_params.tap { |p| p[:account_identity_proof][:post_status] = '1' }
+          end
+
+          it 'posts a status' do
+            expect_any_instance_of(PostStatusService).to receive(:call).with(user.account, text: status_text)
+
+            post :create, params: postable_params_with_status
+          end
+        end
       end
 
       context 'when saving fails' do