about summary refs log tree commit diff
path: root/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-31 15:36:24 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-31 21:36:24 +0200
commit5c6352397257d82e75b90cc5e7de1a3922bde7bd (patch)
tree38d617da023ed80e36d1255f8190b22b4a624c75 /spec/controllers/api/v1/accounts/credentials_controller_spec.rb
parentde4681b2be0b0efa1dede092445a53d4a593c140 (diff)
Spec coverage and refactor for the api/v1/accounts controllers (#3451)
Diffstat (limited to 'spec/controllers/api/v1/accounts/credentials_controller_spec.rb')
-rw-r--r--spec/controllers/api/v1/accounts/credentials_controller_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
new file mode 100644
index 000000000..89dbca111
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
@@ -0,0 +1,55 @@
+require 'rails_helper'
+
+describe Api::V1::Accounts::CredentialsController do
+  render_views
+
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #show' do
+    it 'returns http success' do
+      get :show
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'PATCH #update' do
+    describe 'with valid data' do
+      before do
+        patch :update, params: {
+          display_name: "Alice Isn't Dead",
+          note: "Hi!\n\nToot toot!",
+          avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
+          header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
+        }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'updates account info' do
+        user.account.reload
+
+        expect(user.account.display_name).to eq("Alice Isn't Dead")
+        expect(user.account.note).to eq("Hi!\n\nToot toot!")
+        expect(user.account.avatar).to exist
+        expect(user.account.header).to exist
+      end
+    end
+
+    describe 'with invalid data' do
+      before do
+        patch :update, params: { note: 'This is too long. ' * 10 }
+      end
+
+      it 'returns http unprocessable entity' do
+        expect(response).to have_http_status(:unprocessable_entity)
+      end
+    end
+  end
+end