Commit c214d400

mo khan <mo@mokhan.ca>
2015-01-28 05:27:29
add specs for updating a profile.
1 parent f653e80
Changed files (1)
spec
spec/controllers/api/v1/profiles_controller_spec.rb
@@ -0,0 +1,50 @@
+require 'rails_helper'
+
+module Api
+  module V1
+    describe ProfilesController do
+      render_views
+      let(:user) { create(:user) }
+
+      before :each do
+        request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token)
+      end
+
+      describe "#show" do
+        it 'loads the current users profile' do
+          xhr :get, :show, id: 'me'
+          expect(assigns(:profile)).to eql(user)
+        end
+      end
+
+      describe "#update" do
+        it 'updates the users profile' do
+          new_attributes = {
+            name: 'new name',
+            email: 'new@example.com',
+            city: 'new town',
+            website: 'http://example.com',
+            twitter: 'blabber',
+            facebook: 'facebookie',
+          }
+
+          xhr :patch, :update, id: 'me', profile: new_attributes
+
+          user.reload
+          expect(user.name).to eql('new name')
+          expect(user.email).to eql('new@example.com')
+          expect(user.city).to eql('new town')
+          expect(user.website).to eql('http://example.com')
+          expect(user.twitter).to eql('blabber')
+          expect(user.facebook).to eql('facebookie')
+        end
+
+        it 'returns errors' do
+          xhr :patch, :update, id: 'me', profile: { email: '' }
+          json = JSON.parse(response.body)
+          expect(json["email"]).to_not be_empty
+        end
+      end
+    end
+  end
+end