From f034dc2999a56295178c64921e6f059adc1a7bd9 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 29 Sep 2017 17:55:58 +0200 Subject: Refs: #4627@0.75h; Got some data_modifier support for attribute generation w/w-o defaults for model tests generic_attribute_control --- spec/support/data_modifier.rb | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/support/data_modifier.rb (limited to 'spec/support/data_modifier.rb') diff --git a/spec/support/data_modifier.rb b/spec/support/data_modifier.rb new file mode 100644 index 000000000..7fb0db6f6 --- /dev/null +++ b/spec/support/data_modifier.rb @@ -0,0 +1,51 @@ +require_relative 'data_modifier/enum' +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 +end -- cgit v1.2.3