Created
February 17, 2014 01:05
-
-
Save kstevens715/9042981 to your computer and use it in GitHub Desktop.
Make Factory Girl's `create` method give the name of the class that raises ActiveRecord::RecordInvalid. Useful when you have nested factories whose models have attributes with similar names ex. `name`.
This file contains hidden or 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
include FactoryGirl::Syntax::Methods | |
def create_with_info(*args, &block) | |
create_without_info(*args, &block) | |
rescue => e | |
raise unless e.is_a? ActiveRecord::RecordInvalid | |
raise $!, "#{e.message} (Class #{e.record.class.name})", $!.backtrace | |
end | |
alias_method_chain :create, :info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment