Sha256: 4acc2eff1d6fba591006a477d5b0cccb7e48d90c0df09a03a5c32ad80922527a
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module Remarkable module ActiveRecord module Matchers class AllowMassAssignmentOfMatcher < Remarkable::ActiveRecord::Base #:nodoc: arguments :collection => :attributes, :as => :attribute assertion :allows? collection_assertions :is_protected?, :is_accessible? protected # If no attribute is given, check if no attribute is being protected, # otherwise it fails. # def allows? !@attributes.empty? || protected_attributes.empty? end def is_protected? protected_attributes.empty? || !protected_attributes.include?(@attribute.to_s) end def is_accessible? accessible_attributes.empty? || accessible_attributes.include?(@attribute.to_s) end def interpolation_options if @subject array = protected_attributes.to_a { :protected_attributes => array.empty? ? "[]" : array_to_sentence(array) } else {} end end private def accessible_attributes @accessible_attributes ||= subject_class.accessible_attributes || [] end def protected_attributes @protected_attributes ||= subject_class.protected_attributes || [] end end # Ensures that the attribute can be set on mass update. # # == Examples # # should_allow_mass_assignment_of :email, :name # it { should allow_mass_assignment_of(:email, :name) } # def allow_mass_assignment_of(*attributes, &block) AllowMassAssignmentOfMatcher.new(*attributes, &block).spec(self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
remarkable_activerecord-3.1.3 | lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb |