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…
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
module ControllerMacros | |
def attributes_with_foreign_keys(*args) | |
FactoryGirl.build(*args).attributes.delete_if do |k, v| | |
["id", "type", "created_at", "updated_at"].member?(k) | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.include ControllerMacros, :type => :controller | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment