diff options
| author | Luc Donnet | 2017-10-16 23:52:06 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-10-16 23:52:06 +0200 |
| commit | f480ad0739e5c0ec2c0c8bb890344b9c4777ba35 (patch) | |
| tree | a19bc6b43449b8b978a53c33476fb3eb571d4dda /spec/support/data_modifier.rb | |
| parent | b611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff) | |
| parent | 51a1ea5b141032121913f807a162d305828bec54 (diff) | |
| download | chouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec/support/data_modifier.rb')
| -rw-r--r-- | spec/support/data_modifier.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/support/data_modifier.rb b/spec/support/data_modifier.rb new file mode 100644 index 000000000..2b3b00ac5 --- /dev/null +++ b/spec/support/data_modifier.rb @@ -0,0 +1,53 @@ +require_relative 'data_modifier/enum' +require_relative 'data_modifier/hash' +module Support + module DataModifier + module InstanceMethods + CannotModify = Class.new RuntimeError + + def advance_values(atts, *keys) + keys.inject(atts){ |h, k| h.merge( k => atts[k].next) } + end + + # return array of atts wich each value modified, unboxing + # values if needed + def modify_atts(base_atts) + base_atts.keys.map do | key | + modify_att base_atts, key + end.compact + end + + private + def modify_att atts, key + atts.merge(key => modify_value(atts[key])) + rescue CannotModify + nil + end + def modify_value value + case value + when String + "#{value}." + when Fixnum + value + 1 + when TrueClass + false + when FalseClass + true + when Float + value * 1.1 + when Date + value + 1.day + when Box + value.next.value + else + raise CannotModify + end + end + end + end +end + +RSpec.configure do | c | + c.include Support::DataModifier::InstanceMethods, type: :checksum + c.include Support::DataModifier::InstanceMethods, type: :model +end |
