forked from OpenNeo/impress
groundwork for preview, swf asset and relationship model
This commit is contained in:
parent
0e08045e17
commit
230026597b
24 changed files with 555 additions and 34 deletions
5
app/controllers/swf_assets_controller.rb
Normal file
5
app/controllers/swf_assets_controller.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class SwfAssetsController < ApplicationController
|
||||
def index
|
||||
render :json => Item.find(params[:item_id]).swf_assets
|
||||
end
|
||||
end
|
|
@ -1,2 +1,12 @@
|
|||
module ItemsHelper
|
||||
StandardSpeciesImageFormat = 'http://pets.neopets.com/cp/%s/1/1.png'
|
||||
|
||||
def standard_species_images
|
||||
colors = Species::StandardColors
|
||||
raw(Species.all.inject('') do |html, species|
|
||||
color = colors[rand(colors.size)]
|
||||
src = sprintf(StandardSpeciesImageFormat, species.hash_for_color(color))
|
||||
html + image_tag(src, 'data-color' => color, 'data-species' => species.name)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,9 @@ class Item < ActiveRecord::Base
|
|||
cattr_reader :per_page
|
||||
@@per_page = 30
|
||||
|
||||
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id'
|
||||
has_many :swf_assets, :through => :parent_swf_asset_relationships
|
||||
|
||||
scope :alphabetize, order('name ASC')
|
||||
|
||||
# Not defining validations, since this app is currently read-only
|
||||
|
@ -14,6 +17,7 @@ class Item < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def species_support_ids=(replacement)
|
||||
@species_support_ids_array = nil
|
||||
replacement = replacement.join(',') if replacement.is_a?(Array)
|
||||
write_attribute('species_support_ids', replacement)
|
||||
end
|
||||
|
|
16
app/models/parent_swf_asset_relationship.rb
Normal file
16
app/models/parent_swf_asset_relationship.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class ParentSwfAssetRelationship < ActiveRecord::Base
|
||||
set_table_name 'parents_swf_assets'
|
||||
|
||||
belongs_to :parent, :class_name => 'Item'
|
||||
belongs_to :swf_asset
|
||||
|
||||
default_scope where(Table('parents_swf_assets')[:swf_asset_type].eq('object'))
|
||||
|
||||
def item
|
||||
parent
|
||||
end
|
||||
|
||||
def item=(replacement)
|
||||
self.parent = replacement
|
||||
end
|
||||
end
|
2
app/models/pet_type.rb
Normal file
2
app/models/pet_type.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class PetType < ActiveRecord::Base
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
require 'yaml'
|
||||
|
||||
class Species
|
||||
attr_accessor :id, :name
|
||||
|
||||
|
@ -10,6 +12,17 @@ class Species
|
|||
species.name = name
|
||||
end
|
||||
|
||||
StandardColors = %w(blue green yellow red)
|
||||
StandardHashes = YAML::load_file(Rails.root.join('config', 'standard_type_hashes.yml'))
|
||||
|
||||
def hash_for_color(color)
|
||||
StandardHashes[name][color]
|
||||
end
|
||||
|
||||
def self.all
|
||||
@objects
|
||||
end
|
||||
|
||||
def self.find(id)
|
||||
@objects[id-1]
|
||||
end
|
||||
|
|
3
app/models/swf_asset.rb
Normal file
3
app/models/swf_asset.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class SwfAsset < ActiveRecord::Base
|
||||
set_inheritance_column 'inheritance_type'
|
||||
end
|
|
@ -18,4 +18,18 @@ body.show {
|
|||
@include inline-block;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
#item-preview div {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
#item-preview-swf {
|
||||
height: 50%;
|
||||
}
|
||||
|
||||
#item-preview img {
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,3 +3,15 @@
|
|||
%h2#item-name= @item.name
|
||||
|
||||
%p= @item.description
|
||||
|
||||
%h3 Preview
|
||||
|
||||
#item-preview
|
||||
#item-preview-species= standard_species_images
|
||||
#item-preview-swf
|
||||
Javascript and Flash are required to preview wearables. Sorry!
|
||||
|
||||
- content_for :javascripts do
|
||||
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js',
|
||||
'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
|
||||
'items/show'
|
||||
|
|
|
@ -11,3 +11,4 @@
|
|||
= text_field_tag :q, @query
|
||||
= submit_tag 'Search', :name => nil
|
||||
= yield
|
||||
= yield(:javascripts)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
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
|
||||
end
|
||||
|
|
270
config/standard_type_hashes.yml
Normal file
270
config/standard_type_hashes.yml
Normal file
|
@ -0,0 +1,270 @@
|
|||
acara:
|
||||
blue: mnbztxxn
|
||||
green: obxdjm88
|
||||
red: 7njwqlq8
|
||||
yellow: o3wj6s77
|
||||
aisha:
|
||||
blue: n9ozx4z5
|
||||
green: vw3j5rnt
|
||||
red: r27dkxdc
|
||||
yellow: t4osnjxq
|
||||
blumaroo:
|
||||
blue: 8dng4bvh
|
||||
green: xmqmg3m9
|
||||
red: j77lzlmx
|
||||
yellow: kfonqhdc
|
||||
bori:
|
||||
blue: cdtgf7jo
|
||||
green: 6c8dvw76
|
||||
red: tg7hx55j
|
||||
yellow: sc2hhvhn
|
||||
bruce:
|
||||
blue: w3hljbx7
|
||||
green: gwgc67tt
|
||||
red: 72d26x2b
|
||||
yellow: wqz8xn4t
|
||||
buzz:
|
||||
blue: rkvgtzv3
|
||||
green: schfx5c4
|
||||
red: gddkkb5j
|
||||
yellow: jc9klfxm
|
||||
chia:
|
||||
blue: d65mc9gf
|
||||
green: 8d4949sr
|
||||
red: 4lrb4n3f
|
||||
yellow: oqs3kzmf
|
||||
chomby:
|
||||
blue: h3qctoxg
|
||||
green: 552mzx7r
|
||||
red: 9swsd8ln
|
||||
yellow: bdml26md
|
||||
cybunny:
|
||||
blue: v8shwcoq
|
||||
green: xl6msllv
|
||||
red: lfkscvgd
|
||||
yellow: cwlv6zz9
|
||||
draik:
|
||||
blue: 2g4jtrfh
|
||||
green: 438o4dv5
|
||||
red: vd2joxxq
|
||||
yellow: bob39shq
|
||||
elephante:
|
||||
blue: 4ckkjxjj
|
||||
green: r22hl9oh
|
||||
red: jhhhbrww
|
||||
yellow: jf9ww4om
|
||||
eyrie:
|
||||
blue: m5mvxv23
|
||||
green: s42o6oon
|
||||
red: 6kngmhvs
|
||||
yellow: d6b8fqnm
|
||||
flotsam:
|
||||
blue: hwdo7rlb
|
||||
green: 47vt32x2
|
||||
red: xhob45wn
|
||||
yellow: r8r7jmvr
|
||||
gelert:
|
||||
blue: 4g7n9mh5
|
||||
green: jfmwlmk8
|
||||
red: l95vq4w2
|
||||
yellow: 5nrd2lvd
|
||||
gnorbu:
|
||||
blue: 6c275jcg
|
||||
green: ghfgo5tn
|
||||
red: qozzjgmg
|
||||
yellow: 5lrvftfb
|
||||
grarrl:
|
||||
blue: j7q65fv4
|
||||
green: t3mstkl6
|
||||
red: r946sq53
|
||||
yellow: jtg67z98
|
||||
grundo:
|
||||
blue: nwx8v2rb
|
||||
green: 5xn4kjf8
|
||||
red: qjcb6t8x
|
||||
yellow: n2g9d94f
|
||||
hissi:
|
||||
blue: 7ls55f33
|
||||
green: dz5dwsbx
|
||||
red: jsfvcqwt
|
||||
yellow: z24m7h7l
|
||||
ixi:
|
||||
blue: ro3qcd6s
|
||||
green: w32r74vo
|
||||
red: zs2m6862
|
||||
yellow: oggkzvq7
|
||||
jetsam:
|
||||
blue: w3rl2k9n
|
||||
green: cwss4w3s
|
||||
red: ghddf93g
|
||||
yellow: kz43rnld
|
||||
jubjub:
|
||||
blue: 8mf5gzov
|
||||
green: m267j935
|
||||
red: szckt2tj
|
||||
yellow: 78hdsnmw
|
||||
kacheek:
|
||||
blue: tvnq2l5s
|
||||
green: fkzfcb47
|
||||
red: 9hbtocjh
|
||||
yellow: 4gsrb59g
|
||||
kau:
|
||||
blue: ktlxmrtr
|
||||
green: x9ww69qo
|
||||
red: mrdtwkto
|
||||
yellow: 78w49w7x
|
||||
kiko:
|
||||
blue: 2qlfqqnd
|
||||
green: 42j5q3zx
|
||||
red: mcodrwlt
|
||||
yellow: 86b5xdn6
|
||||
koi:
|
||||
blue: tjvv5cq8
|
||||
green: ncfn87wk
|
||||
red: f3wvzz6r
|
||||
yellow: 4f6cvzgh
|
||||
korbat:
|
||||
blue: 4qxwv7w7
|
||||
green: d2ow9co8
|
||||
red: omx9c876
|
||||
yellow: nsxodd8z
|
||||
kougra:
|
||||
blue: rfsbh59t
|
||||
green: otvq569n
|
||||
red: x8hsckbh
|
||||
yellow: x7bbg59h
|
||||
krawk:
|
||||
blue: hxgsm5d4
|
||||
green: 7ngw8z4f
|
||||
red: kzwxb3dn
|
||||
yellow: m2gq59r5
|
||||
kyrii:
|
||||
blue: ojmo7qgg
|
||||
green: t3b8s9nz
|
||||
red: 6fvg9ngs
|
||||
yellow: blxmjgbk
|
||||
lenny:
|
||||
blue: jfc75n44
|
||||
green: 242k4kdq
|
||||
red: kc4w238d
|
||||
yellow: 8r94jhfq
|
||||
lupe:
|
||||
blue: r552fqj8
|
||||
green: ohmx4lc9
|
||||
red: 6jwlghsg
|
||||
yellow: z42535zh
|
||||
lutari:
|
||||
blue: qgg6z8s7
|
||||
green: wtjv7hw4
|
||||
red: lgws33oo
|
||||
yellow: 8x37fgjf
|
||||
meerca:
|
||||
blue: wwwhjf88
|
||||
green: lg9bb6tf
|
||||
red: v7g8w8w6
|
||||
yellow: kk2nn2jr
|
||||
moehog:
|
||||
blue: moot839l
|
||||
green: jgkoro5z
|
||||
red: dk47mfk8
|
||||
yellow: g84ovct7
|
||||
mynci:
|
||||
blue: xwlo9657
|
||||
green: s33qzokw
|
||||
red: f828tkrc
|
||||
yellow: tdfhsndr
|
||||
nimmo:
|
||||
blue: bx7fho8x
|
||||
green: mb4mcwj5
|
||||
red: mok2fcl4
|
||||
yellow: 9559onds
|
||||
ogrin:
|
||||
blue: 26v2sx49
|
||||
green: lg5bzqkq
|
||||
red: 3xgoz429
|
||||
yellow: rjzmx24v
|
||||
peophin:
|
||||
blue: 996t7zfg
|
||||
green: c9qo7zzt
|
||||
red: kokc52kh
|
||||
yellow: 4khvfnwl
|
||||
poogle:
|
||||
blue: 5n2vx7v2
|
||||
green: fw6lvf3c
|
||||
red: xhcwbdd5
|
||||
yellow: xozlhd68
|
||||
pteri:
|
||||
blue: 82d369sm
|
||||
green: slqmqr78
|
||||
red: tjhwbro3
|
||||
yellow: 4gkkb57f
|
||||
quiggle:
|
||||
blue: 4zs6b32m
|
||||
green: vbrsgqrl
|
||||
red: xrmt72wr
|
||||
yellow: jdto7mj4
|
||||
ruki:
|
||||
blue: qsgbm5f6
|
||||
green: vgml65cz
|
||||
red: sm55zs3q
|
||||
yellow: n43szv42
|
||||
scorchio:
|
||||
blue: ohb3b486
|
||||
green: kmb82xw8
|
||||
red: hkjoncsx
|
||||
yellow: hgfofbl2
|
||||
shoyru:
|
||||
blue: dj7n2zk8
|
||||
green: 3qwwn4n2
|
||||
red: 3zb2s2zw
|
||||
yellow: mmvn4tkg
|
||||
skeith:
|
||||
blue: 7c847jkn
|
||||
green: qdgwwz6c
|
||||
red: fc4cxk3t
|
||||
yellow: 533nc7rj
|
||||
techo:
|
||||
blue: vl8qro4r
|
||||
green: 2zc3vd47
|
||||
red: zgl2gjjn
|
||||
yellow: 84gvowmj
|
||||
tonu:
|
||||
blue: jd433863
|
||||
green: 6mcv27mn
|
||||
red: oskw3hqd
|
||||
yellow: 5bhqs7sv
|
||||
tuskaninny:
|
||||
blue: jj6t6cqd
|
||||
green: stl4mm78
|
||||
red: 48z4o75j
|
||||
yellow: q39wn6vq
|
||||
uni:
|
||||
blue: 74xvb24d
|
||||
green: njzvoflw
|
||||
red: jzfbdomk
|
||||
yellow: 5qdfrtcq
|
||||
usul:
|
||||
blue: xff976n8
|
||||
green: 5245lzmh
|
||||
red: rox4mgh5
|
||||
yellow: vxn8b4vr
|
||||
wocky:
|
||||
blue: xonntr5f
|
||||
green: 4ssorlcs
|
||||
red: 743smd5v
|
||||
yellow: dnr2kj4b
|
||||
xweetok:
|
||||
blue: ddhdrt2o
|
||||
green: thzwbqsq
|
||||
red: tdkqr2b6
|
||||
yellow: o36btnbf
|
||||
yurble:
|
||||
blue: nhn5lxb4
|
||||
green: mjgbr7vb
|
||||
red: h95cs547
|
||||
yellow: vfqkbvv6
|
||||
zafara:
|
||||
blue: x8c57g2l
|
||||
green: tq56zj3x
|
||||
red: n32sgrvm
|
||||
yellow: onxr95x6
|
|
@ -1,14 +0,0 @@
|
|||
class CreateObjects < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :objects do |t|
|
||||
t.string :name
|
||||
t.string :species_support_ids
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :objects
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
class AddDescriptionToObjects < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :objects, :description, :text
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :objects, :description
|
||||
end
|
||||
end
|
108
db/schema.rb
108
db/schema.rb
|
@ -9,14 +9,110 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20100515020945) do
|
||||
ActiveRecord::Schema.define(:version => 24) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
t.string "name", :limit => 40, :null => false
|
||||
t.text "icon", :null => false
|
||||
t.text "gateway", :null => false
|
||||
t.string "secret", :limit => 64, :null => false
|
||||
end
|
||||
|
||||
create_table "contributions", :force => true do |t|
|
||||
t.string "contributed_class", :limit => 0, :null => false
|
||||
t.integer "contributed_id", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.timestamp "created_at", :null => false
|
||||
end
|
||||
|
||||
create_table "login_cookies", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "series", :null => false
|
||||
t.integer "token", :null => false
|
||||
end
|
||||
|
||||
add_index "login_cookies", ["user_id", "series"], :name => "login_cookies_user_id_and_series"
|
||||
add_index "login_cookies", ["user_id"], :name => "login_cookies_user_id"
|
||||
|
||||
create_table "objects", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "species_support_ids"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "description"
|
||||
t.text "zones_restrict", :limit => 255, :null => false
|
||||
t.text "thumbnail_url", :null => false
|
||||
t.string "name", :limit => 100, :null => false
|
||||
t.text "description", :null => false
|
||||
t.string "category", :limit => 50, :null => false
|
||||
t.string "type", :limit => 50, :null => false
|
||||
t.string "rarity", :limit => 25, :null => false
|
||||
t.integer "rarity_index", :limit => 1, :null => false
|
||||
t.integer "price", :limit => 3, :null => false
|
||||
t.integer "weight_lbs", :limit => 2, :null => false
|
||||
t.text "species_support_ids"
|
||||
t.integer "sold_in_mall", :limit => 1, :null => false
|
||||
t.timestamp "last_spidered"
|
||||
end
|
||||
|
||||
add_index "objects", ["last_spidered"], :name => "objects_last_spidered"
|
||||
add_index "objects", ["name"], :name => "name"
|
||||
|
||||
create_table "parents_swf_assets", :id => false, :force => true do |t|
|
||||
t.integer "parent_id", :limit => 3, :null => false
|
||||
t.integer "swf_asset_id", :limit => 3, :null => false
|
||||
t.string "swf_asset_type", :limit => 0
|
||||
end
|
||||
|
||||
add_index "parents_swf_assets", ["parent_id", "swf_asset_id", "swf_asset_type"], :name => "unique_parents_swf_assets", :unique => true
|
||||
add_index "parents_swf_assets", ["parent_id"], :name => "parent_swf_assets_parent_id"
|
||||
add_index "parents_swf_assets", ["swf_asset_id"], :name => "parents_swf_assets_swf_asset_id"
|
||||
|
||||
create_table "pet_states", :force => true do |t|
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
t.text "swf_asset_ids", :limit => 255, :null => false
|
||||
end
|
||||
|
||||
add_index "pet_states", ["pet_type_id"], :name => "pet_states_pet_type_id"
|
||||
|
||||
create_table "pet_types", :force => true do |t|
|
||||
t.integer "color_id", :limit => 1, :null => false
|
||||
t.integer "species_id", :limit => 1, :null => false
|
||||
t.timestamp "created_at", :null => false
|
||||
t.integer "body_id", :limit => 2, :null => false
|
||||
t.string "image_hash", :limit => 8
|
||||
end
|
||||
|
||||
add_index "pet_types", ["species_id", "color_id"], :name => "pet_types_species_color", :unique => true
|
||||
|
||||
create_table "pets", :force => true do |t|
|
||||
t.string "name", :limit => 20, :null => false
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
end
|
||||
|
||||
add_index "pets", ["name"], :name => "pets_name", :unique => true
|
||||
add_index "pets", ["pet_type_id"], :name => "pets_pet_type_id"
|
||||
|
||||
create_table "swf_assets", :id => false, :force => true do |t|
|
||||
t.string "type", :limit => 0, :null => false
|
||||
t.integer "id", :limit => 3, :null => false
|
||||
t.text "url", :null => false
|
||||
t.integer "zone_id", :limit => 1, :null => false
|
||||
t.text "zones_restrict", :limit => 255, :null => false
|
||||
t.timestamp "created_at", :null => false
|
||||
t.integer "body_id", :limit => 2, :null => false
|
||||
end
|
||||
|
||||
add_index "swf_assets", ["body_id"], :name => "swf_assets_body_id_and_object_id"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name", :limit => 20, :null => false
|
||||
t.integer "auth_server_id", :limit => 1, :null => false
|
||||
t.integer "remote_id", :null => false
|
||||
t.integer "points", :null => false
|
||||
end
|
||||
|
||||
create_table "zones", :force => true do |t|
|
||||
t.integer "depth", :limit => 1, :null => false
|
||||
t.integer "type_id", :limit => 1, :null => false
|
||||
t.string "type", :limit => 40, :null => false
|
||||
t.string "label", :limit => 40, :null => false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
12
public/javascripts/items/show.js
Normal file
12
public/javascripts/items/show.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var PREVIEW_SWF_ID = 'item-preview-swf';
|
||||
|
||||
swfobject.embedSWF(
|
||||
'http://impress.openneo.net/assets/swf/preview.swf', // URL
|
||||
PREVIEW_SWF_ID, // ID
|
||||
400, // width
|
||||
400, // height
|
||||
9, // required version
|
||||
'http://impress.openneo.net/assets/js/swfobject/expressInstall.swf', // express install URL
|
||||
{'swf_assets_path': '/assets'}, // flashvars
|
||||
{'wmode': 'transparent'} // params
|
||||
)
|
|
@ -567,3 +567,17 @@ body.show #item-name {
|
|||
*vertical-align: auto;
|
||||
margin-top: 1em;
|
||||
}
|
||||
/* line 22, ../../../app/stylesheets/items/_show.scss */
|
||||
body.show #item-preview div {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
/* line 27, ../../../app/stylesheets/items/_show.scss */
|
||||
body.show #item-preview-swf {
|
||||
height: 50%;
|
||||
}
|
||||
/* line 31, ../../../app/stylesheets/items/_show.scss */
|
||||
body.show #item-preview img {
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
}
|
||||
|
|
5
spec/controllers/swf_assets_controller_spec.rb
Normal file
5
spec/controllers/swf_assets_controller_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SwfAssetsController do
|
||||
|
||||
end
|
|
@ -2,12 +2,25 @@ require 'spec_helper'
|
|||
|
||||
describe Item do
|
||||
context "an item" do
|
||||
before(:each) do
|
||||
@item = Factory.build :item
|
||||
end
|
||||
|
||||
specify "should accept string or array for species_support_ids" do
|
||||
items = [
|
||||
Factory.build(:item, :species_support_ids => '1,2,3'),
|
||||
Factory.build(:item, :species_support_ids => [1,2,3])
|
||||
]
|
||||
items.each { |i| i.species_support_ids.should == [1,2,3] }
|
||||
@item.species_support_ids = '1,2,3'
|
||||
@item.species_support_ids.should == [1, 2, 3]
|
||||
@item.species_support_ids = [4, 5, 6]
|
||||
@item.species_support_ids.should == [4, 5, 6]
|
||||
end
|
||||
|
||||
specify "should have many swf_assets through parent_swf_asset_relationships" do
|
||||
3.times do |n|
|
||||
swf_asset = Factory.create :swf_asset, :id => n, :url => "http://images.neopets.com/#{n}.swf", :type => 'object'
|
||||
ParentSwfAssetRelationship.create :swf_asset => swf_asset, :item => @item
|
||||
end
|
||||
@item.swf_asset_ids.should == [0, 1, 2]
|
||||
@item.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
|
||||
|
||||
|
|
23
spec/models/parent_swf_asset_relationship_spec.rb
Normal file
23
spec/models/parent_swf_asset_relationship_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ParentSwfAssetRelationship do
|
||||
context "a relationship" do
|
||||
before(:each) do
|
||||
@relationship = ParentSwfAssetRelationship.new
|
||||
Factory.create :item, :name => 'foo'
|
||||
@relationship.parent_id = 1
|
||||
end
|
||||
|
||||
specify "should belong to an item" do
|
||||
@relationship.item.id.should == 1
|
||||
@relationship.item.name.should == 'foo'
|
||||
end
|
||||
|
||||
specify "should belong to an swf_asset" do
|
||||
Factory.create :swf_asset, :type => 'object', :id => 1
|
||||
@relationship.swf_asset_id = 1
|
||||
@relationship.swf_asset.id.should == 1
|
||||
@relationship.swf_asset.type.should == 'object'
|
||||
end
|
||||
end
|
||||
end
|
5
spec/models/swf_asset_spec.rb
Normal file
5
spec/models/swf_asset_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SwfAsset do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
5
spec/views/swf_assets/index.html.erb_spec.rb
Normal file
5
spec/views/swf_assets/index.html.erb_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "swf_assets/index.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,3 +1,15 @@
|
|||
Factory.define :item do |i|
|
||||
i.name 'Test Item'
|
||||
i.description 'Test Description'
|
||||
i.thumbnail_url 'http://images.neopets.com/foo.gif'
|
||||
i.zones_restrict ''
|
||||
i.category ''
|
||||
i.add_attribute :type, ''
|
||||
i.rarity 0
|
||||
i.rarity_index 0
|
||||
i.price 0
|
||||
i.weight_lbs 0
|
||||
i.species_support_ids ''
|
||||
i.sold_in_mall false
|
||||
i.last_spidered 0
|
||||
end
|
||||
|
|
6
test/factories/swf_asset.rb
Normal file
6
test/factories/swf_asset.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
Factory.define :swf_asset do |s|
|
||||
s.url 'http://images.neopets.com/cp/bio/swf/000/000/000/0000_a1b2c3d4e5.swf'
|
||||
s.zone_id 0
|
||||
s.zones_restrict ''
|
||||
s.body_id 0
|
||||
end
|
Loading…
Reference in a new issue