Class: FoundationApi::ShouldaMatcher::AttributeAliasMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(alias_name) ⇒ AttributeAliasMatcher

Returns a new instance of AttributeAliasMatcher.



4
5
6
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 4

def initialize(alias_name)
  @expected_alias_name = alias_name.to_s
end

Instance Method Details

#descriptionObject



22
23
24
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 22

def description
  "have attribute alias #{@expected_alias_name}"
end

#failure_messageObject



14
15
16
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 14

def failure_message
  "Expected attribute alias #{@expected_alias_name} for #{@source_attribute || 'unspecified source attribute'}"
end

#for(source_attribute) ⇒ Object



26
27
28
29
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 26

def for(source_attribute)
  @source_attribute = source_attribute.to_s
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 8

def matches?(subject)
  @klass = subject.class
  @klass.attribute_aliases.has_key?(@expected_alias_name) && 
    (@source_attribute ? @klass.attribute_aliases[@expected_alias_name] == @source_attribute : true)
end

#negative_failure_messageObject



18
19
20
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 18

def negative_failure_message
  "Didn't expect attribute alias #{@expected_alias_name} but got one anyway"
end