Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created July 19, 2011 20:44
Show Gist options
  • Select an option

  • Save metaskills/1093662 to your computer and use it in GitHub Desktop.

Select an option

Save metaskills/1093662 to your computer and use it in GitHub Desktop.
class Merchant < ActiveRecord::Base
def foobarable?
# ...
end
end
class Customer < ActiveRecord::Base
belongs_to :merchant
def foobar=(something_else)
self[:foobar] = something_else if merchant.foobarable?
end
end
FactoryGirl.define do
factory :merchant do
end
factory :customer do
association :merchant
end
end
# How can I make sure that the merchant attribute/association is set first so
# that the foobar attribute checks my passed in merchant?
c = FactoryGirl.create :customer, :merchant => @some_merchant, :foobar => 'xyz'
@stephan-buckmaster
Copy link

I don't know if "that's a cure". Looks like asking for trouble: if someone isn't aware of the ordering requirement.

It seems to me when a Hash is accepted as an argument, then the message is that order is not important (in other languages too. of course).

@metaskills
Copy link
Author

I'm not disagreeing on that too, hence why I am using the patch till I hear other feedback from the authors.

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