pet type model, controller

This commit is contained in:
Emi Matchu 2010-05-16 15:33:56 -04:00
parent 230026597b
commit f69f64f18f
5 changed files with 26 additions and 2 deletions

View 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

View file

@ -1,2 +1,5 @@
class PetType < ActiveRecord::Base
def as_json(options={})
{:id => id, :body_id => body_id}
end
end

View file

@ -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

View file

@ -0,0 +1,4 @@
require 'spec_helper'
describe PetTypesController do
end

View 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