Commit 31b5a3cf
Changed files (5)
app
controllers
api
views
api
v2
tutorials
config
spec
controllers
api
app/controllers/api/v2/tutorials_controller.rb
@@ -4,6 +4,10 @@ module Api
def index
@tutorials = Tutorial.page(page).per(per_page)
end
+
+ def show(id = params[:id])
+ @tutorial = Tutorial.find(id)
+ end
end
end
end
app/views/api/v2/tutorials/_tutorial.json.jbuilder
@@ -1,7 +1,8 @@
json.cache! ['v2', tutorial] do
+ json.id tutorial.id
json.heading tutorial.heading
json.description tutorial.description
json.url tutorial.url
- json.image_url tutorial.image_url
+ json.imageUrl tutorial.image_url
json.submitter tutorial.user.id
end
app/views/api/v2/tutorials/show.json.jbuilder
@@ -0,0 +1,3 @@
+json.tutorial do
+ json.partial! @tutorial, tutorial: @tutorial
+end
config/routes.rb
@@ -72,7 +72,7 @@ Cake::Application.routes.draw do
resources :photos, only: [:index, :show]
resources :users, only: [:index, :show]
resources :categories, only: [:index, :show]
- resources :tutorials, only: [:index]
+ resources :tutorials, only: [:index, :show]
end
end
spec/controllers/api/v2/tutorials_controller_spec.rb
@@ -18,11 +18,21 @@ module Api
it 'responds with json' do
json = JSON.parse(response.body)
expect(json['tutorials'].count).to eql(1)
+ expect(json['tutorials'][0]['id']).to eql(tutorial.id)
expect(json['tutorials'][0]['heading']).to eql(tutorial.heading)
expect(json['tutorials'][0]['description']).to eql(tutorial.description)
expect(json['tutorials'][0]['url']).to eql(tutorial.url)
expect(json['tutorials'][0]['submitter']).to eql(tutorial.user.id)
- expect(json['tutorials'][0]['image_url']).to eql(tutorial.image_url)
+ expect(json['tutorials'][0]['imageUrl']).to eql(tutorial.image_url)
+ end
+ end
+
+ describe "#show" do
+ let!(:tutorial) { create(:tutorial) }
+
+ it 'loads the single tutorial' do
+ xhr :get, :show, id: tutorial.id
+ expect(assigns(:tutorial)).to eql(tutorial)
end
end
end