Skip to content

Instantly share code, notes, and snippets.

@kstevens715
Created February 17, 2014 01:05
Show Gist options
  • Save kstevens715/9042981 to your computer and use it in GitHub Desktop.
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`.
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