zone model in order to be able to include depth for swf_asset JSON
This commit is contained in:
parent
8baa09d633
commit
a5866a19e3
6 changed files with 68 additions and 0 deletions
|
@ -1,3 +1,23 @@
|
||||||
class SwfAsset < ActiveRecord::Base
|
class SwfAsset < ActiveRecord::Base
|
||||||
set_inheritance_column 'inheritance_type'
|
set_inheritance_column 'inheritance_type'
|
||||||
|
|
||||||
|
belongs_to :zone
|
||||||
|
|
||||||
|
delegate :depth, :to => :zone
|
||||||
|
|
||||||
|
def local_url
|
||||||
|
uri = URI.parse(url)
|
||||||
|
uri.host = RemoteImpressHost
|
||||||
|
pieces = uri.path.split('/')
|
||||||
|
uri.path = "/assets/swf/outfit/#{pieces[2]}/#{pieces[4..7].join('/')}"
|
||||||
|
uri.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_json
|
||||||
|
{
|
||||||
|
:id => id,
|
||||||
|
:depth => depth,
|
||||||
|
:local_url => local_url
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
3
app/models/zone.rb
Normal file
3
app/models/zone.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Zone < ActiveRecord::Base
|
||||||
|
set_inheritance_column 'inheritance_type'
|
||||||
|
end
|
|
@ -27,3 +27,5 @@ OpenneoImpressItems::Application.configure do
|
||||||
# like if you have constraints or database-specific column types
|
# like if you have constraints or database-specific column types
|
||||||
# config.active_record.schema_format = :sql
|
# config.active_record.schema_format = :sql
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RemoteImpressHost = 'impress.openneo.net'
|
||||||
|
|
35
spec/models/swf_asset_spec.rb
Normal file
35
spec/models/swf_asset_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe SwfAsset do
|
||||||
|
it "belongs to a zone" do
|
||||||
|
zone = Factory.create :zone, :label => 'foo'
|
||||||
|
asset = Factory.create :swf_asset, :zone_id => 1
|
||||||
|
asset.zone_id.should == 1
|
||||||
|
asset.zone.id.should == 1
|
||||||
|
asset.zone.label.should == 'foo'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "delegates depth to zone" do
|
||||||
|
zone = Factory.create :zone, :depth => 12
|
||||||
|
asset = Factory.create :swf_asset, :zone_id => 1
|
||||||
|
asset.depth.should == 12
|
||||||
|
end
|
||||||
|
|
||||||
|
it "converts neopets URL to impress URL" do
|
||||||
|
asset = Factory.create :swf_asset, :url => 'http://images.neopets.com/cp/items/swf/000/000/012/12211_9969430b3a.swf'
|
||||||
|
asset.local_url.should == 'http://impress.openneo.net/assets/swf/outfit/items/000/000/012/12211_9969430b3a.swf'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should contain id, depth, and local_url as JSON" do
|
||||||
|
zone = Factory.create :zone, :depth => 12
|
||||||
|
asset = Factory.create :swf_asset,
|
||||||
|
:id => 123,
|
||||||
|
:zone_id => 1,
|
||||||
|
:url => 'http://images.neopets.com/cp/items/swf/000/000/012/12211_9969430b3a.swf'
|
||||||
|
asset.as_json.should == {
|
||||||
|
:id => 123,
|
||||||
|
:depth => 12,
|
||||||
|
:local_url => 'http://impress.openneo.net/assets/swf/outfit/items/000/000/012/12211_9969430b3a.swf'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,4 +3,6 @@ Factory.define :swf_asset do |s|
|
||||||
s.zone_id 0
|
s.zone_id 0
|
||||||
s.zones_restrict ''
|
s.zones_restrict ''
|
||||||
s.body_id 0
|
s.body_id 0
|
||||||
|
s.add_attribute :type, 'object'
|
||||||
|
s.sequence(:id) { |n| n }
|
||||||
end
|
end
|
||||||
|
|
6
test/factories/zone.rb
Normal file
6
test/factories/zone.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Factory.define :zone do |z|
|
||||||
|
z.label 'foo'
|
||||||
|
z.depth 1
|
||||||
|
z.add_attribute :type, 'FOO'
|
||||||
|
z.type_id 1
|
||||||
|
end
|
Loading…
Reference in a new issue