Created
October 4, 2010 02:24
-
-
Save jsmestad/609173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fabricator(:product) do | |
items(:count => 1) { Fabricate(:item) } | |
end | |
Fabricator(:item) do | |
name "An Item" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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
If your test ever calls Product#has_items it will error on L5 (of models.rb) saying that you cannot call .available on