1
0
Fork 0
forked from OpenNeo/impress

pet state models now own assets, not pet types

This commit is contained in:
Emi Matchu 2010-05-20 21:11:08 -04:00
parent cccfe08eb5
commit 7fc59745e5
6 changed files with 33 additions and 17 deletions

View file

@ -11,11 +11,11 @@ class ParentSwfAssetRelationship < ActiveRecord::Base
self.parent_id = replacement.id self.parent_id = replacement.id
end end
def pet_type def pet_state
parent parent
end end
def pet_type=(replacement) def pet_state=(replacement)
self.parent_id = replacement.id self.parent_id = replacement.id
end end
end end

4
app/models/pet_state.rb Normal file
View file

@ -0,0 +1,4 @@
class PetState < ActiveRecord::Base
include SwfAssetParent
SwfAssetType = 'biology'
end

View file

@ -1,7 +1,5 @@
class PetType < ActiveRecord::Base class PetType < ActiveRecord::Base
include SwfAssetParent has_many :pet_states
SwfAssetType = 'biology'
BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml')) BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml'))

View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe PetState do
it "has many swf_assets through parent_swf_asset_relationships" do
pet_state = Factory.create :pet_state
3.times do |n|
swf_asset = Factory.create :swf_asset, :id => n, :url => "http://images.neopets.com/#{n}.swf", :type => 'biology'
ParentSwfAssetRelationship.create :swf_asset => swf_asset, :pet_state => pet_state, :swf_asset_type => 'biology'
end
dud_swf_asset = Factory.create :swf_asset, :id => 3, :type => 'object'
ParentSwfAssetRelationship.create :swf_asset => dud_swf_asset, :parent_id => 2, :swf_asset_type => 'biology'
other_type_swf_asset = Factory.create :swf_asset, :id => 4, :type => 'biology'
ParentSwfAssetRelationship.create :swf_asset => other_type_swf_asset, :parent_id => 1, :swf_asset_type => 'object'
pet_state.swf_assets.map(&:id).should == [0, 1, 2]
pet_state.swf_assets.map(&:url).should == ['http://images.neopets.com/0.swf',
'http://images.neopets.com/1.swf', 'http://images.neopets.com/2.swf']
end
end

View file

@ -37,19 +37,11 @@ describe PetType do
pet_type.image_hash.should be nil pet_type.image_hash.should be nil
end end
specify "should have many swf_assets through parent_swf_asset_relationships" do specify "has many pet states" do
pet_type = Factory.create :pet_type pet_type = Factory.create :pet_type
3.times do |n| [1, 1, 2].each { |x| Factory.create :pet_state, :pet_type_id => x }
swf_asset = Factory.create :swf_asset, :id => n, :url => "http://images.neopets.com/#{n}.swf", :type => 'biology' pet_type.pet_state_ids.should == [1, 2]
ParentSwfAssetRelationship.create :swf_asset => swf_asset, :item => pet_type, :swf_asset_type => 'biology' pet_type.pet_states.map(&:id).should == [1, 2]
end
dud_swf_asset = Factory.create :swf_asset, :id => 3, :type => 'object'
ParentSwfAssetRelationship.create :swf_asset => dud_swf_asset, :parent_id => 2, :swf_asset_type => 'biology'
other_type_swf_asset = Factory.create :swf_asset, :id => 4, :type => 'biology'
ParentSwfAssetRelationship.create :swf_asset => other_type_swf_asset, :parent_id => 1, :swf_asset_type => 'object'
pet_type.swf_assets.map(&:id).should == [0, 1, 2]
pet_type.swf_assets.map(&:url).should == ['http://images.neopets.com/0.swf',
'http://images.neopets.com/1.swf', 'http://images.neopets.com/2.swf']
end end
end end
end end

View file

@ -0,0 +1,4 @@
Factory.define :pet_state do |ps|
ps.pet_type_id 1
ps.swf_asset_ids '1,2,3'
end