Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::SourceMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, name) ⇒ SourceMatcher

Returns a new instance of SourceMatcher.



9
10
11
12
13
# File 'lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb', line 9

def initialize(source, name)
  @source = source
  @name = name
  @missing_option = ''
end

Instance Attribute Details

#missing_optionObject

Returns the value of attribute missing_option.



7
8
9
# File 'lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb', line 7

def missing_option
  @missing_option
end

Instance Method Details

#descriptionObject



15
16
17
# File 'lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb', line 15

def description
  "source => #{source}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb', line 19

def matches?(subject)
  self.subject = ModelReflector.new(subject, name)

  if option_verifier.correct_for_string?(:source, source)
    true
  else
    self.missing_option =
      "#{name} should have #{source} as source option"
    false
  end
end