summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-11-22 09:31:55 -0700
committermo khan <mo@mokhan.ca>2014-11-22 09:31:55 -0700
commit31b5a3cf55d273dfc93385be8cf28ce1f8f8abd2 (patch)
treed39963b8f893fbfd86b3a772a4805e7a84cfd5b2
parent4454bd91253ae68108ddc5f79d73b544e6c8a524 (diff)
add tutorial show route.
-rw-r--r--app/controllers/api/v2/tutorials_controller.rb4
-rw-r--r--app/views/api/v2/tutorials/_tutorial.json.jbuilder3
-rw-r--r--app/views/api/v2/tutorials/show.json.jbuilder3
-rw-r--r--config/routes.rb2
-rw-r--r--spec/controllers/api/v2/tutorials_controller_spec.rb12
5 files changed, 21 insertions, 3 deletions
diff --git a/app/controllers/api/v2/tutorials_controller.rb b/app/controllers/api/v2/tutorials_controller.rb
index 6b4279b6..b72321b2 100644
--- a/app/controllers/api/v2/tutorials_controller.rb
+++ b/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
diff --git a/app/views/api/v2/tutorials/_tutorial.json.jbuilder b/app/views/api/v2/tutorials/_tutorial.json.jbuilder
index c467e5e4..cc11f4b2 100644
--- a/app/views/api/v2/tutorials/_tutorial.json.jbuilder
+++ b/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
diff --git a/app/views/api/v2/tutorials/show.json.jbuilder b/app/views/api/v2/tutorials/show.json.jbuilder
new file mode 100644
index 00000000..1782ee3b
--- /dev/null
+++ b/app/views/api/v2/tutorials/show.json.jbuilder
@@ -0,0 +1,3 @@
+json.tutorial do
+ json.partial! @tutorial, tutorial: @tutorial
+end
diff --git a/config/routes.rb b/config/routes.rb
index 5a8c19fa..395dcd3f 100644
--- a/config/routes.rb
+++ b/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
diff --git a/spec/controllers/api/v2/tutorials_controller_spec.rb b/spec/controllers/api/v2/tutorials_controller_spec.rb
index 46077b2d..c8d896ce 100644
--- a/spec/controllers/api/v2/tutorials_controller_spec.rb
+++ b/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