Created
March 20, 2013 18:15
-
-
Save jlberglund/5207078 to your computer and use it in GitHub Desktop.
Returns attributes for a factory with associations
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
# spec/support/controllers_helper.rb | |
module ControllersHelper | |
# Since FactoryGirl.attributes_for excludes associations, use FactoryGirl.build and then | |
# strip out the protected attributes. | |
def build_attributes(*args) | |
build_object = FactoryGirl.build(*args) | |
build_object.attributes.slice(*build_object.class.accessible_attributes).symbolize_keys | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this, really appreciate it. Saved the day!