Class: JSONAPI::Resources::Matchers::HavePrimaryKey
- Inherits:
-
Object
- Object
- JSONAPI::Resources::Matchers::HavePrimaryKey
- Defined in:
- lib/jsonapi/resources/matchers/have_primary_key.rb
Instance Attribute Summary collapse
-
#expected_primary_key ⇒ Object
Returns the value of attribute expected_primary_key.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name) ⇒ HavePrimaryKey
constructor
A new instance of HavePrimaryKey.
- #matches?(resource) ⇒ Boolean
Constructor Details
#initialize(name) ⇒ HavePrimaryKey
Returns a new instance of HavePrimaryKey.
8 9 10 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 8 def initialize(name) self.expected_primary_key = name end |
Instance Attribute Details
#expected_primary_key ⇒ Object
Returns the value of attribute expected_primary_key.
6 7 8 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 6 def expected_primary_key @expected_primary_key end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 6 def resource @resource end |
Instance Method Details
#description ⇒ Object
12 13 14 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 12 def description "have primary key `#{self.expected_primary_key}`" end |
#failure_message ⇒ Object
22 23 24 25 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 22 def resource_name = resource.class.name.demodulize %Q(expected `#{resource_name}` to use primary key `#{self.expected_primary_key}`) end |
#matches?(resource) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/jsonapi/resources/matchers/have_primary_key.rb', line 16 def matches?(resource) self.resource = resource self.resource.class._primary_key.to_s == self.expected_primary_key.to_s end |