diff options
| author | mo khan <mo@mokhan.ca> | 2015-01-27 22:12:16 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-01-27 22:12:16 -0700 |
| commit | c182d3ce40a0e5cb22eefecc21992ad643184083 (patch) | |
| tree | e84a1b5345498c31d321a3a9fab414e652fd041a /spec/controllers/api | |
| parent | b6911212e1c2280d9de113e327686197255d8584 (diff) | |
add specs for loading a single photo.
Diffstat (limited to 'spec/controllers/api')
| -rw-r--r-- | spec/controllers/api/v1/categories_controller_spec.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/api/v1/logins_controller_spec.rb | 11 | ||||
| -rw-r--r-- | spec/controllers/api/v1/photos_controller_spec.rb | 22 |
3 files changed, 25 insertions, 10 deletions
diff --git a/spec/controllers/api/v1/categories_controller_spec.rb b/spec/controllers/api/v1/categories_controller_spec.rb index edd12d47..cf7cd3ba 100644 --- a/spec/controllers/api/v1/categories_controller_spec.rb +++ b/spec/controllers/api/v1/categories_controller_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' module Api module V1 describe CategoriesController do + render_views + describe "#index" do it 'loads all the categories' do xhr :get, :index diff --git a/spec/controllers/api/v1/logins_controller_spec.rb b/spec/controllers/api/v1/logins_controller_spec.rb index fedbf167..3b8d53e8 100644 --- a/spec/controllers/api/v1/logins_controller_spec.rb +++ b/spec/controllers/api/v1/logins_controller_spec.rb @@ -1,12 +1,15 @@ require "rails_helper" describe Api::V1::LoginsController do + render_views + context "when logging in with proper credentials" do let(:user) { create(:user) } - it "should return the auth token" do + it "returns the auth token" do post :create, { email: user.email, password: 'password' } - expect(response.body).to eql({ auth_token: user.authentication_token }.to_json) + expected_json = { auth_token: user.authentication_token }.to_json + expect(response.body).to eql(expected_json) end end @@ -15,8 +18,8 @@ describe Api::V1::LoginsController do before { post :create, { email: user.email, password: user.password.reverse } } - it "should return an empty auth token" do - expect(response.body).to eql({ :auth_token => "" }.to_json) + it "returns an empty auth token" do + expect(response.body).to eql({ auth_token: "" }.to_json) end end end diff --git a/spec/controllers/api/v1/photos_controller_spec.rb b/spec/controllers/api/v1/photos_controller_spec.rb index 49a8c218..286e32bc 100644 --- a/spec/controllers/api/v1/photos_controller_spec.rb +++ b/spec/controllers/api/v1/photos_controller_spec.rb @@ -3,20 +3,30 @@ require 'rails_helper' module Api module V1 describe PhotosController do + render_views + let(:user) { create(:user) } - let!(:cake) { create(:creation) } + let!(:cake) { create(:creation, user: user) } - describe "#index" do - before :each do - request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) - user.creations << cake - end + before :each do + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + end + describe "#index" do it 'loads the cakes photos' do xhr :get, :index, cake_id: cake.id expect(assigns(:photos)).to match_array(cake.photos) end end + + describe "#show" do + let(:photo) { create(:photo, imageable: cake) } + + it 'loads the photo' do + xhr :get, :show, cake_id: cake.id, id: photo.id + expect(assigns(:photo)).to eql(photo) + end + end end end end |
