Sha256: 017b10b462d18ebc85135a2830d3bf251289e9007e8ef834bde56bbdc28d5029

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

require 'whyvalidationssuckin96/skippable_validation'
require 'whyvalidationssuckin96/attribute_based_validation'

module WhyValidationsSuckIn96
  
  # Validates the acceptance of an attribute, such as the "I agree to the terms and conditions" checkbox value returned
  # by a form post.
  # 
  # @example Default usage
  #   setup_validations do
  #     validates_acceptance_of :privacy_policy, :terms_and_conditions
  #   end
  #
  # @example Changing the :accept value
  #   setup_validations do
  #     validates_acceptance_of :privacy_policy, :accept => "yep"
  #   end
  class ValidatesAcceptance < Validation
    DefaultOptions = {:allow_nil => true, :accept => "1", :message => "must be accepted"}
    
    include WhyValidationsSuckIn96::SkippableValidation
    include WhyValidationsSuckIn96::AttributeBasedValidation
    
    def validate
      super
      if options[:accept] == attribute_value
        pass
      else
        fail
      end
    end
    
  end # Validation

  ValidationBuilder.register_macro :validates_acceptance_of, WhyValidationsSuckIn96::ValidatesAcceptance
end   # WhyValidationsSuckIn96

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.4 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.6.3 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.6.2 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.6.1 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.6.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.5 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.4 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.3 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.2 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.1 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.5.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.4.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.3.1 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.3.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.2.3 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.2.2 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.2.1 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.2.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.1.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb
whyvalidationssuckin96-1.0.0 lib/whyvalidationssuckin96/macros/validates_acceptance.rb