Skip to content

Instantly share code, notes, and snippets.

View hiasinho's full-sized avatar

Mathias Maisberger hiasinho

View GitHub Profile
module FactoryGirlHelper
def find_or_create(*args)
name = args.shift
clazz = nil
# convert from underscores String to camelcase Class
if name.is_a? Hash
name = name.first[0]
clazz = name.first[1].to_s.camelize.constantize
@hiasinho
hiasinho / factory_girl_strategy_find_or_create.rb
Last active May 27, 2020 18:31
FactoryGirl strategy for adding find & find_or_create
## http://stackoverflow.com/questions/7145256
module FactoryGirl
module Strategy
class Find
def association(runner)
runner.run
end
def result(evaluation)
build_class(evaluation).where(get_overrides(evaluation)).first
Ctrl+A
@hiasinho
hiasinho / regex_dec_w_unit.rb
Created January 9, 2012 15:50
Regex for decimal with unit
matchdata = "121,32 Std.".match(/([\d]+[\,|\.]?\d{0,2})+\s?(\w.*)?/)
matchdata[1] # => "121,32"
matchdata[2] # => "Std."
matchdata[0] # => "121,32 Std."