Commit f9b44b24
Changed files (2)
app
controllers
api
spec
controllers
api
app/controllers/api/v1/photos_controller.rb
@@ -1,18 +1,16 @@
module Api
module V1
class PhotosController < ApiController
- respond_to :json
-
def index
- respond_with(@photos = current_user.creations.find(params[:cake_id]).photos)
+ @photos = current_user.creations.find(params[:cake_id]).photos
end
def show
- respond_with(@photo = current_user.creations.find(params[:cake_id]).photos.find(params[:id]))
+ @photo = current_user.creations.find(params[:cake_id]).photos.find(params[:id])
end
def create
- respond_with(@photo = UploadPhoto.new.run(params[:cake_id], params))
+ @photo = UploadPhoto.new.run(params[:cake_id], params)
end
end
end
spec/controllers/api/v1/photos_controller_spec.rb
@@ -0,0 +1,22 @@
+require 'rails_helper'
+
+module Api
+ module V1
+ describe PhotosController do
+ let(:user) { create(:user) }
+ let!(:cake) { create(:creation) }
+
+ describe "#index" do
+ before :each do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token)
+ user.creations << cake
+ end
+
+ it 'loads the cakes photos' do
+ xhr :get, :index, cake_id: cake.id
+ expect(assigns(:photos)).to match_array(cake.photos)
+ end
+ end
+ end
+ end
+end