Class: FoundationApi::ShouldaMatcher::PersistenceMethodMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(method) ⇒ PersistenceMethodMatcher

Returns a new instance of PersistenceMethodMatcher.



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

def initialize(method)
  @expected_method = method
  @options = []
end

Instance Method Details

#calling(interface) ⇒ Object



30
31
32
33
# File 'lib/foundation_api/shoulda_matcher/persistence_method_matcher.rb', line 30

def calling(interface)
  @interface = interface.to_s
  self
end

#descriptionObject



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

def description
  "specified persistence method #{@expected_method}" 
end

#failure_messageObject



14
15
16
17
18
19
20
# File 'lib/foundation_api/shoulda_matcher/persistence_method_matcher.rb', line 14

def failure_message
  message = []
  message << "You specified an illegal caller #{@expected_method.inspect}" unless method_supported?
  message << "One of the options you specified #{@options.inspect} is not backed by the method #{@expected_method.inspect}" unless acceptable_options?
  message << option_failure? if option_failure?
  message.join(" and\n")
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  @klass = subject.class
  method_supported? && interface_matches? && acceptable_options? && !option_failure?
end

#negative_failure_messageObject



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

def negative_failure_message
  "Something did not match. However should_not does not make sense here"
end

#with_destoy_type(type) ⇒ Object



47
48
49
50
51
# File 'lib/foundation_api/shoulda_matcher/persistence_method_matcher.rb', line 47

def with_destoy_type(type)
  @options << :destroy_type
  @destroy_type = type
  self
end

#with_destroy_key(key) ⇒ Object



41
42
43
44
45
# File 'lib/foundation_api/shoulda_matcher/persistence_method_matcher.rb', line 41

def with_destroy_key(key)
  @options << :destroy_key
  @destroy_key = key
  self
end

#with_uniqueness_of(attribute) ⇒ Object



35
36
37
38
39
# File 'lib/foundation_api/shoulda_matcher/persistence_method_matcher.rb', line 35

def with_uniqueness_of(attribute)
  @options << :unique
  @unique = attribute
  self
end