Sha256: d28af8209795404660c3120cc792b9a8a4dac0ec3124a7ada8a2de9b7352acd5

Contents?: true

Size: 1.03 KB

Versions: 41

Compression:

Stored size: 1.03 KB

Contents

module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:

      # Ensures that the model cannot be saved the given attribute is not
      # accepted.
      #
      # Options:
      # * <tt>with_message</tt> - value the test expects to find in
      #   <tt>errors.on(:attribute)</tt>. Regexp or string.  Defaults to the
      #   translation for <tt>:accepted</tt>.
      #
      # Example:
      #   it { should validate_acceptance_of(:eula) }
      #
      def validate_acceptance_of(attr)
        ValidateAcceptanceOfMatcher.new(attr)
      end

      class ValidateAcceptanceOfMatcher < ValidationMatcher # :nodoc:

        def with_message(message)
          if message
            @expected_message = message
          end
          self
        end

        def matches?(subject)
          super(subject)
          @expected_message ||= :accepted
          disallows_value_of(false, @expected_message)
        end

        def description
          "require #{@attribute} to be accepted"
        end
      end
    end
  end
end

Version data entries

41 entries across 31 versions & 4 rubygems

Version Path
challah-1.0.0 vendor/bundle/gems/shoulda-matchers-2.2.0/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-2.2.0 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-2.1.0/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-1.5.6/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-2.1.0 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-2.0.0 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.6 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.5 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.4 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.2 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.1 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.5.0 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
shoulda-matchers-1.4.2 lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb