Sha256: 97e0160a8dce93e4a1eb3743d841afc45bb2ddc398965a0287fa1f5d635416ab

Contents?: true

Size: 1.01 KB

Versions: 153

Compression:

Stored size: 1.01 KB

Contents

module Shoulda # :nodoc:
  module ActiveRecord # :nodoc:
    module Matchers

      # 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)
          @expected_message = message if message
          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

153 entries across 123 versions & 25 rubygems

Version Path
challah-0.2.1 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
challah-0.2.0 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
chida_fib-0.1.0 shoulda/ruby/1.8/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.10 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.10 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.10 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.9 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.9 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.9 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.8 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.8 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.8 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.7 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.7 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.7 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.6 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.6 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.6 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.5 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
dirty_history-0.4.5 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb