diff options
| author | Robert | 2017-09-29 17:55:58 +0200 | 
|---|---|---|
| committer | Robert | 2017-10-02 10:52:07 +0200 | 
| commit | f034dc2999a56295178c64921e6f059adc1a7bd9 (patch) | |
| tree | d9cf98cd0df42e7f776a727e09fefb02499a6d59 /spec/support/data_modifier.rb | |
| parent | ea6537e2f520ca9abba0ca63c68ee42afe08d872 (diff) | |
| download | chouette-core-f034dc2999a56295178c64921e6f059adc1a7bd9.tar.bz2 | |
Refs: #4627@0.75h;
Got some data_modifier support for attribute generation w/w-o defaults for model tests generic_attribute_control
Diffstat (limited to 'spec/support/data_modifier.rb')
| -rw-r--r-- | spec/support/data_modifier.rb | 51 | 
1 files changed, 51 insertions, 0 deletions
| 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 | 
