Skip to content

Instantly share code, notes, and snippets.

@jlberglund
Created March 20, 2013 18:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlberglund/5207078 to your computer and use it in GitHub Desktop.
Save jlberglund/5207078 to your computer and use it in GitHub Desktop.
Returns attributes for a factory with associations
# 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
@franciso
Copy link

Thanks for posting this, really appreciate it. Saved the day!

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