Sha256: 4958fc423228e360463b9d2ede24a4b6fefa236b4c7c54f627ce6a79496b7df3

Contents?: true

Size: 1.22 KB

Versions: 36

Compression:

Stored size: 1.22 KB

Contents

module ConfigHelper
  extend ActiveSupport::Concern

  # Justin French tip
  def with_config(preference_name, temporary_value)
    old_value = ValidatesTimeliness.send(preference_name)
    ValidatesTimeliness.send(:"#{preference_name}=", temporary_value)
    yield
  ensure
    ValidatesTimeliness.send(:"#{preference_name}=", old_value)
  end

  def reset_validation_setup_for(model_class)
    model_class.reset_callbacks(:validate)
    model_class._validators.clear
    model_class.timeliness_validated_attributes = [] if model_class.respond_to?(:timeliness_validated_attributes)
    model_class.undefine_attribute_methods
    # This is a hack to avoid a disabled super method error message after an undef
    model_class.instance_variable_set(:@generated_attribute_methods, nil)
    model_class.instance_variable_set(:@generated_timeliness_methods, nil)
  end

  module ClassMethods
    def with_config(preference_name, temporary_value)
      original_config_value = ValidatesTimeliness.send(preference_name)

      before(:all) do
        ValidatesTimeliness.send(:"#{preference_name}=", temporary_value)
      end

      after(:all) do
        ValidatesTimeliness.send(:"#{preference_name}=", original_config_value)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 5 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/validates_timeliness-4.0.2/spec/support/config_helper.rb
validates_timeliness-4.0.2 spec/support/config_helper.rb
validates_timeliness-4.0.1 spec/support/config_helper.rb
validates_timeliness-3.0.15 spec/support/config_helper.rb
validates_timeliness-4.0.0 spec/support/config_helper.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/validates_timeliness-3.0.14/spec/support/config_helper.rb
sp-validates_timeliness-3.1.3 spec/support/config_helper.rb
sp-validates_timeliness-3.1.2 spec/support/config_helper.rb
jc-validates_timeliness-3.1.1 spec/support/config_helper.rb
jc-validates_timeliness-3.1.0 spec/support/config_helper.rb
validates_timeliness-3.0.14 spec/support/config_helper.rb
validates_timeliness-3.0.13 spec/support/config_helper.rb
validates_timeliness-3.0.12 spec/support/config_helper.rb
validates_timeliness-3.0.11 spec/support/config_helper.rb
validates_timeliness-3.0.10 spec/support/config_helper.rb
validates_timeliness-3.0.9 spec/support/config_helper.rb