Skip to content

Instantly share code, notes, and snippets.

@jsmestad
Created October 4, 2010 02:24
Show Gist options
  • Save jsmestad/609173 to your computer and use it in GitHub Desktop.
Save jsmestad/609173 to your computer and use it in GitHub Desktop.
Fabricator(:product) do
items(:count => 1) { Fabricate(:item) }
end
Fabricator(:item) do
name "An Item"
end
class Product < ActiveRecord::Base
has_many :items
def self.has_items
self.items.available.count
end
end
class Item < ActiveRecord::Base
belongs_to :product
scope :available, where(:available => true)
end
@jsmestad
Copy link
Author

jsmestad commented Oct 4, 2010

If your test ever calls Product#has_items it will error on L5 (of models.rb) saying that you cannot call .available on

@paulelliott
Copy link

Try changing has_items to an instance method and see if that fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment