diff --git a/app/models/parent_swf_asset_relationship.rb b/app/models/parent_swf_asset_relationship.rb index fccc0ab8..f44abfdc 100644 --- a/app/models/parent_swf_asset_relationship.rb +++ b/app/models/parent_swf_asset_relationship.rb @@ -11,11 +11,11 @@ class ParentSwfAssetRelationship < ActiveRecord::Base self.parent_id = replacement.id end - def pet_type + def pet_state parent end - def pet_type=(replacement) + def pet_state=(replacement) self.parent_id = replacement.id end end diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb new file mode 100644 index 00000000..2b6594b0 --- /dev/null +++ b/app/models/pet_state.rb @@ -0,0 +1,4 @@ +class PetState < ActiveRecord::Base + include SwfAssetParent + SwfAssetType = 'biology' +end diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 2387b904..0d1018ca 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -1,7 +1,5 @@ class PetType < ActiveRecord::Base - include SwfAssetParent - - SwfAssetType = 'biology' + has_many :pet_states BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml')) diff --git a/spec/models/pet_state_spec.rb b/spec/models/pet_state_spec.rb new file mode 100644 index 00000000..b7cbe19f --- /dev/null +++ b/spec/models/pet_state_spec.rb @@ -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 diff --git a/spec/models/pet_type_spec.rb b/spec/models/pet_type_spec.rb index f1430ace..3c42ef8a 100644 --- a/spec/models/pet_type_spec.rb +++ b/spec/models/pet_type_spec.rb @@ -37,19 +37,11 @@ describe PetType do pet_type.image_hash.should be nil 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 - 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, :item => pet_type, :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_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'] + [1, 1, 2].each { |x| Factory.create :pet_state, :pet_type_id => x } + pet_type.pet_state_ids.should == [1, 2] + pet_type.pet_states.map(&:id).should == [1, 2] end end end diff --git a/test/factories/pet_state.rb b/test/factories/pet_state.rb new file mode 100644 index 00000000..502f7607 --- /dev/null +++ b/test/factories/pet_state.rb @@ -0,0 +1,4 @@ +Factory.define :pet_state do |ps| + ps.pet_type_id 1 + ps.swf_asset_ids '1,2,3' +end