Commit c182d3ce
Changed files (3)
spec
controllers
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
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
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