pet type model, controller
This commit is contained in:
parent
230026597b
commit
f69f64f18f
5 changed files with 26 additions and 2 deletions
6
app/controllers/pet_types_controller.rb
Normal file
6
app/controllers/pet_types_controller.rb
Normal file
|
@ -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
|
|
@ -1,2 +1,5 @@
|
||||||
class PetType < ActiveRecord::Base
|
class PetType < ActiveRecord::Base
|
||||||
|
def as_json(options={})
|
||||||
|
{:id => id, :body_id => body_id}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
OpenneoImpressItems::Application.routes.draw do |map|
|
OpenneoImpressItems::Application.routes.draw do |map|
|
||||||
get "swf_assets/index"
|
|
||||||
|
|
||||||
match '/' => 'items#index', :as => :items
|
match '/' => 'items#index', :as => :items
|
||||||
match '/:id' => 'items#show', :as => :item
|
match '/:id' => 'items#show', :as => :item
|
||||||
|
|
||||||
match '/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets
|
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
|
end
|
||||||
|
|
4
spec/controllers/pet_types_controller_spec.rb
Normal file
4
spec/controllers/pet_types_controller_spec.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe PetTypesController do
|
||||||
|
end
|
10
spec/models/pet_type_spec.rb
Normal file
10
spec/models/pet_type_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue