Skip to content

Instantly share code, notes, and snippets.

@Bivek
Created December 17, 2013 16:34
Show Gist options
  • Save Bivek/8007908 to your computer and use it in GitHub Desktop.
Save Bivek/8007908 to your computer and use it in GitHub Desktop.
module FactoryGirlAdditions
# create instance without running callbacks and validations
def insert(*args)
record = FactoryGirl.build(*args)
def record.run_callbacks(*args, &block)
if block_given?
block.arity.zero? ? yield : yield(self)
end
end
record.save!
record
end
def pure(*args)
factory_name = args.shift
if args.last.is_a?(Hash)
options = args.pop
else
options = {}
end
traits = [:pure] | args
FactoryGirl.build(factory_name, *traits, options)
end
end
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include FactoryGirlAdditions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment