diff options
| author | mo khan <mo@mokhan.ca> | 2014-11-21 16:57:33 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-11-21 16:57:33 -0700 |
| commit | 1cd098e291367cebc52e5a09f3e2e6fb7646de4e (patch) | |
| tree | 248038c6a342358c7b0c21c0fa90258b2f0313d1 | |
| parent | 51265f238e29b224a85510c96d944dbec0449683 (diff) | |
add specs for categories controller.
| -rw-r--r-- | app/controllers/api/v2/categories_controller.rb | 2 | ||||
| -rw-r--r-- | app/views/api/v2/categories/index.json.jbuilder | 3 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/api/v2/categories_controller_spec.rb | 26 |
4 files changed, 31 insertions, 2 deletions
diff --git a/app/controllers/api/v2/categories_controller.rb b/app/controllers/api/v2/categories_controller.rb index 86454855..365544b6 100644 --- a/app/controllers/api/v2/categories_controller.rb +++ b/app/controllers/api/v2/categories_controller.rb @@ -2,7 +2,7 @@ module Api module V2 class CategoriesController < ApplicationController def show - @category = Category.find(params[:id]) + @category = @categories.find(params[:id]) end end end diff --git a/app/views/api/v2/categories/index.json.jbuilder b/app/views/api/v2/categories/index.json.jbuilder new file mode 100644 index 00000000..4cec0c2e --- /dev/null +++ b/app/views/api/v2/categories/index.json.jbuilder @@ -0,0 +1,3 @@ +json.categories @categories do |category| + json.partial! category, category: category +end diff --git a/config/routes.rb b/config/routes.rb index 2891b953..28506416 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,7 @@ Cake::Application.routes.draw do resources :cakes, only: [:index, :show] resources :photos, only: [:index, :show] resources :users, only: [:show] - resources :categories, only: [:show] + resources :categories, only: [:index, :show] end end diff --git a/spec/controllers/api/v2/categories_controller_spec.rb b/spec/controllers/api/v2/categories_controller_spec.rb new file mode 100644 index 00000000..5a913145 --- /dev/null +++ b/spec/controllers/api/v2/categories_controller_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +module Api + module V2 + describe CategoriesController do + describe "#index" do + let!(:category) { create(:category) } + + it 'loads all the categories' do + xhr :get, :index + expect(assigns(:categories)).to match_array([category]) + end + end + + describe "#show" do + let!(:other_category) { create(:category) } + let!(:category) { create(:category) } + + it 'loads the specified category' do + xhr :get, :show, id: category.id + expect(assigns(:category)).to eql(category) + end + end + end + end +end |
