Skip to content

Instantly share code, notes, and snippets.

@Marchino
Created July 18, 2011 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchino/1089042 to your computer and use it in GitHub Desktop.
Save Marchino/1089042 to your computer and use it in GitHub Desktop.
what's wrong with this?
class ItemImage < ActiveRecord::Base
belongs_to :item, :polymorphic => true
mount_uploader :image, ImageUploader
scope :the_cover, where(:cover => true)
end
class Book < ActiveRecord::Base
has_many :item_images, :as => :item
end
class Comicbook < ActiveRecord::Base
has_many :item_images, :as => :item
end
context 'This book' do
setup do
@bookshop = Factory.create(:bookshop)
@rare_book = Factory.create(:rare_book, :price => 50, :currency => 'EUR')
@bookshop.items << @rare_book
end
should "have images" do
assert @rare_book.item_images.empty?
@rare_book.item_images << Factory.create(:item_image, :cover => "1")
@rare_book.save
assert_equal true, @rare_book.item_images.first.cover
assert !@rare_book.item_images.empty?
assert !@rare_book.item_images.the_cover.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment