diff --git a/app/controllers/pet_types_controller.rb b/app/controllers/pet_types_controller.rb new file mode 100644 index 00000000..09574d8e --- /dev/null +++ b/app/controllers/pet_types_controller.rb @@ -0,0 +1,6 @@ +class PetTypesController < ApplicationController + def show + pet_type = PetType.find_by_color_id_and_species_id(params[:color_id], params[:species_id]) + render :json => pet_type + end +end diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 56f61d69..a82a563e 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -1,2 +1,5 @@ class PetType < ActiveRecord::Base + def as_json(options={}) + {:id => id, :body_id => body_id} + end end diff --git a/config/routes.rb b/config/routes.rb index 6b4a9574..c5cd53e4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,8 @@ OpenneoImpressItems::Application.routes.draw do |map| - get "swf_assets/index" - match '/' => 'items#index', :as => :items match '/:id' => 'items#show', :as => :item + match '/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets + + match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show' end diff --git a/spec/controllers/pet_types_controller_spec.rb b/spec/controllers/pet_types_controller_spec.rb new file mode 100644 index 00000000..b04bf917 --- /dev/null +++ b/spec/controllers/pet_types_controller_spec.rb @@ -0,0 +1,4 @@ +require 'spec_helper' + +describe PetTypesController do +end diff --git a/spec/models/pet_type_spec.rb b/spec/models/pet_type_spec.rb new file mode 100644 index 00000000..5b974bbb --- /dev/null +++ b/spec/models/pet_type_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe PetType do + context "object" do + specify "should return id, body_id in JSON" do + pet_type = PetType.create :color_id => 2, :species_id => 3, :body_id => 4 + pet_type.as_json.should == {:id => 1, :body_id => 4} + end + end +end