Parent

Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher

Public Class Methods

new(name) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 25
def initialize(name)
  @name = name
  @options = {}
end

Public Instance Methods

allow_destroy(allow_destroy) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 30
def allow_destroy(allow_destroy)
  @options[:allow_destroy] = allow_destroy
  self
end
description() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 61
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_message_for_should() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 53
def failure_message_for_should
  "Expected #{expectation} (#{@problem})"
end
failure_message_for_should_not() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 57
def failure_message_for_should_not
  "Did not expect #{expectation}"
end
limit(limit) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 35
def limit(limit)
  @options[:limit] = limit
  self
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 45
def matches?(subject)
  @subject = subject
  exists? &&
    allow_destroy_correct? &&
    limit_correct? &&
    update_only_correct?
end
update_only(update_only) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 40
def update_only(update_only)
  @options[:update_only] = update_only
  self
end

Protected Instance Methods

allow_destroy_correct?() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 86
def allow_destroy_correct?
  failure_message = "#{should_or_should_not(@options[:allow_destroy])} allow destroy"
  verify_option_is_correct(:allow_destroy, failure_message)
end
config() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 114
def config
  model_config[@name]
end
exists?() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 77
def exists?
  if config
    true
  else
    @problem = 'is not declared'
    false
  end
end
expectation() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 126
def expectation
  "#{model_class.name} to accept nested attributes for #{@name}"
end
limit_correct?() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 91
def limit_correct?
  failure_message = "limit should be #{@options[:limit]}, got #{config[:limit]}"
  verify_option_is_correct(:limit, failure_message)
end
model_class() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 122
def model_class
  @subject.class
end
model_config() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 118
def model_config
  model_class.nested_attributes_options
end
should_or_should_not(value) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 130
def should_or_should_not(value)
  if value
    'should'
  else
    'should not'
  end
end
update_only_correct?() click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 96
def update_only_correct?
  failure_message = "#{should_or_should_not(@options[:update_only])} be update only"
  verify_option_is_correct(:update_only, failure_message)
end
verify_option_is_correct(option, failure_message) click to toggle source
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 101
def verify_option_is_correct(option, failure_message)
  if @options.key?(option)
    if @options[option] == config[option]
      true
    else
      @problem = failure_message
      false
    end
  else
    true
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.