Sha256: d117b6f59664845fb4df447e6918970c22fb873b7699ece926501e93a9d141f9
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
module Remarkable module ActiveRecord module Matchers class ValidateAcceptanceOfMatcher < Remarkable::ActiveRecord::Base arguments :collection => :attributes, :as => :attribute optional :accept, :message optional :allow_nil, :default => true collection_assertions :requires_acceptance?, :accept_is_valid?, :allow_nil? default_options :message => :accepted protected def requires_acceptance? bad?(false) end def accept_is_valid? return true unless @options.key?(:accept) good?(@options[:accept]) end end # Ensures that the model cannot be saved if one of the attributes listed is not accepted. # # == Options # # * <tt>:accept</tt> - the expected value to be accepted. # * <tt>:allow_nil</tt> - when supplied, validates if it allows nil or not. # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>. # Regexp, string or symbol. Default = <tt>I18n.translate('activerecord.errors.messages.accepted')</tt> # # == Examples # # should_validate_acceptance_of :eula, :terms # should_validate_acceptance_of :eula, :terms, :accept => true # # it { should validate_acceptance_of(:eula, :terms) } # it { should validate_acceptance_of(:eula, :terms, :accept => true) } # def validate_acceptance_of(*attributes) ValidateAcceptanceOfMatcher.new(*attributes).spec(self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
remarkable_activerecord-3.0.0 | lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb |