Class: JSONAPI::Resources::Matchers::HaveCreatableField

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/resources/matchers/have_creatable_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HaveCreatableField

Returns a new instance of HaveCreatableField.



8
9
10
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 8

def initialize(name)
  self.name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 6

def name
  @name
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 6

def resource
  @resource
end

Instance Method Details

#descriptionObject



27
28
29
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 27

def description
  "have creatable field `#{name}`"
end

#failure_messageObject



17
18
19
20
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 17

def failure_message
  resource_name = resource.class.name.demodulize
  %Q(expected #{resource_name} to have creatable field `#{name}`)
end

#failure_message_when_negatedObject



22
23
24
25
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 22

def failure_message_when_negated
  resource_name = resource.class.name.demodulize
  %Q(expected #{resource_name} not to have creatable field `#{name}`)
end

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/jsonapi/resources/matchers/have_creatable_field.rb', line 12

def matches?(resource)
  self.resource = resource
  resource.class.creatable_fields(resource.context).include?(name)
end