carlosbrando / remarkable
- Source
- Commits
- Network (27)
- Issues (7)
- Downloads (4)
- Wiki (5)
- Graphs
-
Tree:
136267f
remarkable / remarkable_activerecord / lib / remarkable_activerecord / matchers / allow_mass_assignment_of_matcher.rb
| 61519311 » | josevalim | 2009-04-08 | 1 | module Remarkable | |
| 2 | module ActiveRecord | ||||
| 3 | module Matchers | ||||
| abfc4b0c » | josevalim | 2009-04-10 | 4 | class AllowMassAssignmentOfMatcher < Remarkable::ActiveRecord::Base #:nodoc: | |
| 40341ed6 » | josevalim | 2009-04-08 | 5 | arguments :collection => :attributes, :as => :attribute | |
| 6 | |||||
| 7 | collection_assertions :is_protected?, :is_accessible? | ||||
| 8 | |||||
| 9 | protected | ||||
| 10 | |||||
| 11 | def is_protected? | ||||
| 12 | protected = subject_class.protected_attributes || [] | ||||
| 13 | protected.empty? || !protected.include?(@attribute.to_s) | ||||
| 14 | end | ||||
| 15 | |||||
| 16 | def is_accessible? | ||||
| 17 | accessible = subject_class.accessible_attributes || [] | ||||
| 18 | accessible.empty? || accessible.include?(@attribute.to_s) | ||||
| 19 | end | ||||
| 20 | end | ||||
| 21 | |||||
| 22 | # Ensures that the attribute can be set on mass update. | ||||
| 23 | # | ||||
| 24 | # == Examples | ||||
| 25 | # | ||||
| 26 | # should_allow_mass_assignment_of :email, :name | ||||
| 27 | # it { should allow_mass_assignment_of(:email, :name) } | ||||
| 28 | # | ||||
| 29 | def allow_mass_assignment_of(*attributes) | ||||
| 30 | AllowMassAssignmentOfMatcher.new(*attributes).spec(self) | ||||
| 31 | end | ||||
| 32 | end | ||||
| 33 | end | ||||
| 34 | end | ||||

