Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2015 05:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
FactoryGirl attribute_for does not create associations for obvious performance reason. However, sometime it is useful to get all attributes with ids of association to test a POST#create request for example. To enable, just create a macro in your spec/support folder with the following content. Then call attributes_with_foreign_keys instead of att…
module ControllerMacros
def attributes_with_foreign_keys(*args)*args).attributes.delete_if do |k, v|
["id", "type", "created_at", "updated_at"].member?(k)
RSpec.configure do |config|
config.include ControllerMacros, :type => :controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment