Sha256: 74cba81178479c57c967634b2bf03d1e7adf6fc9fa93712748bf5e9141e55996

Contents?: true

Size: 841 Bytes

Versions: 11

Compression:

Stored size: 841 Bytes

Contents

module UnitTests
  module ActiveModelHelpers
    def self.configure_example_group(example_group)
      example_group.include(self)
    end

    def custom_validation(options = {}, &block)
      attribute_name = options.fetch(:attribute_name, :attr)
      attribute_type = options.fetch(:attribute_type, :integer)
      column_options = options.fetch(:column_options, {})
      attribute_options = { type: attribute_type, options: column_options }

      define_model(:example, attribute_name => attribute_options) do
        validate :custom_validation

        define_method(:custom_validation, &block)
      end.new
    end
    alias record_with_custom_validation custom_validation

    def validating_format(options)
      define_model :example, attr: :string do
        validates_format_of :attr, options
      end.new
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
shoulda-matchers-3.1.3 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-4.0.0.rc1 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.1.2 spec/support/unit/helpers/active_model_helpers.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.1.1 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.1.0 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.0.1 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.0.0 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-3.0.0.rc1 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-2.8.0 spec/support/unit/helpers/active_model_helpers.rb
shoulda-matchers-2.8.0.rc2 spec/support/unit/helpers/active_model_helpers.rb