Class: Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AcceptNestedAttributesForMatcher

Returns a new instance of AcceptNestedAttributesForMatcher.



99
100
101
102
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 99

def initialize(name)
  @name = name
  @options = {}
end

Instance Method Details

#allow_destroy(allow_destroy) ⇒ Object



104
105
106
107
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 104

def allow_destroy(allow_destroy)
  @options[:allow_destroy] = allow_destroy
  self
end

#descriptionObject



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 135

def description
  description = "accepts_nested_attributes_for :#{@name}"
  if @options.key?(:allow_destroy)
    description += " allow_destroy => #{@options[:allow_destroy]}"
  end
  if @options.key?(:limit)
    description += " limit => #{@options[:limit]}"
  end
  if @options.key?(:update_only)
    description += " update_only => #{@options[:update_only]}"
  end
  description
end

#failure_messageObject



127
128
129
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 127

def failure_message
  "Expected #{expectation} (#{@problem})"
end

#failure_message_when_negatedObject



131
132
133
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 131

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#limit(limit) ⇒ Object



109
110
111
112
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 109

def limit(limit)
  @options[:limit] = limit
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 119

def matches?(subject)
  @subject = subject
  exists? &&
    allow_destroy_correct? &&
    limit_correct? &&
    update_only_correct?
end

#update_only(update_only) ⇒ Object



114
115
116
117
# File 'lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb', line 114

def update_only(update_only)
  @options[:update_only] = update_only
  self
end