@@ -47,7 +47,9 @@ class NoMatchAbstractResource < JSONAPI::Resource
4747 abstract
4848end
4949
50- class CatResource < JSONAPI ::Resource
50+ class FelineResource < JSONAPI ::Resource
51+ model_name 'Cat'
52+
5153 attribute :name
5254 attribute :breed
5355 attribute :kind , :delegate => :breed
@@ -99,6 +101,7 @@ class RelatedResource < MyModule::RelatedResource
99101end
100102
101103class PostWithReadonlyAttributesResource < JSONAPI ::Resource
104+ model_name 'Post'
102105 attribute :title , readonly : true
103106 has_one :author , readonly : true
104107end
@@ -180,7 +183,7 @@ def test_derived_not_abstract
180183 def test_nil_model_class
181184 # ToDo:Figure out why this test does not work on Rails 4.0
182185 # :nocov:
183- if Rails ::VERSION ::MAJOR >= 4 && Rails ::VERSION ::MINOR >= 1
186+ if ( Rails ::VERSION ::MAJOR >= 4 && Rails ::VERSION ::MINOR >= 1 ) || ( Rails :: VERSION :: MAJOR >= 5 )
184187 assert_output nil , "[MODEL NOT FOUND] Model could not be found for NoMatchResource. If this a base Resource declare it as abstract.\n " do
185188 assert_nil NoMatchResource . _model_class
186189 end
@@ -199,13 +202,13 @@ def test_model_alternate
199202 end
200203
201204 def test_class_attributes
202- attrs = CatResource . _attributes
205+ attrs = FelineResource . _attributes
203206 assert_kind_of ( Hash , attrs )
204207 assert_equal ( attrs . keys . size , 4 )
205208 end
206209
207210 def test_class_relationships
208- relationships = CatResource . _relationships
211+ relationships = FelineResource . _relationships
209212 assert_kind_of ( Hash , relationships )
210213 assert_equal ( relationships . size , 2 )
211214 end
@@ -219,16 +222,16 @@ def test_replace_polymorphic_to_one_link
219222 end
220223
221224 def test_duplicate_relationship_name
222- assert_output nil , "[DUPLICATE RELATIONSHIP] `mother` has already been defined in CatResource .\n " do
223- CatResource . instance_eval do
225+ assert_output nil , "[DUPLICATE RELATIONSHIP] `mother` has already been defined in FelineResource .\n " do
226+ FelineResource . instance_eval do
224227 has_one :mother , class_name : 'Cat'
225228 end
226229 end
227230 end
228231
229232 def test_duplicate_attribute_name
230- assert_output nil , "[DUPLICATE ATTRIBUTE] `name` has already been defined in CatResource .\n " do
231- CatResource . instance_eval do
233+ assert_output nil , "[DUPLICATE ATTRIBUTE] `name` has already been defined in FelineResource .\n " do
234+ FelineResource . instance_eval do
232235 attribute :name
233236 end
234237 end
@@ -299,7 +302,7 @@ def test_find_by_key_with_customized_base_records
299302 end
300303
301304 def test_updatable_fields_does_not_include_id
302- assert ( !CatResource . updatable_fields . include? ( :id ) )
305+ assert ( !FelineResource . updatable_fields . include? ( :id ) )
303306 end
304307
305308 def test_filter_on_to_many_relationship_id
@@ -443,60 +446,60 @@ def apply_pagination(records, criteria, order_options)
443446 end
444447
445448 def test_key_type_integer
446- CatResource . instance_eval do
449+ FelineResource . instance_eval do
447450 key_type :integer
448451 end
449452
450- assert CatResource . verify_key ( '45' )
451- assert CatResource . verify_key ( 45 )
453+ assert FelineResource . verify_key ( '45' )
454+ assert FelineResource . verify_key ( 45 )
452455
453456 assert_raises JSONAPI ::Exceptions ::InvalidFieldValue do
454- CatResource . verify_key ( '45,345' )
457+ FelineResource . verify_key ( '45,345' )
455458 end
456459
457460 ensure
458- CatResource . instance_eval do
461+ FelineResource . instance_eval do
459462 key_type nil
460463 end
461464 end
462465
463466 def test_key_type_string
464- CatResource . instance_eval do
467+ FelineResource . instance_eval do
465468 key_type :string
466469 end
467470
468- assert CatResource . verify_key ( '45' )
469- assert CatResource . verify_key ( 45 )
471+ assert FelineResource . verify_key ( '45' )
472+ assert FelineResource . verify_key ( 45 )
470473
471474 assert_raises JSONAPI ::Exceptions ::InvalidFieldValue do
472- CatResource . verify_key ( '45,345' )
475+ FelineResource . verify_key ( '45,345' )
473476 end
474477
475478 ensure
476- CatResource . instance_eval do
479+ FelineResource . instance_eval do
477480 key_type nil
478481 end
479482 end
480483
481484 def test_key_type_uuid
482- CatResource . instance_eval do
485+ FelineResource . instance_eval do
483486 key_type :uuid
484487 end
485488
486- assert CatResource . verify_key ( 'f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5' )
489+ assert FelineResource . verify_key ( 'f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5' )
487490
488491 assert_raises JSONAPI ::Exceptions ::InvalidFieldValue do
489- CatResource . verify_key ( 'f1a-e77a-4d0a-acbb-ee0b98b3f6b5' )
492+ FelineResource . verify_key ( 'f1a-e77a-4d0a-acbb-ee0b98b3f6b5' )
490493 end
491494
492495 ensure
493- CatResource . instance_eval do
496+ FelineResource . instance_eval do
494497 key_type nil
495498 end
496499 end
497500
498501 def test_key_type_proc
499- CatResource . instance_eval do
502+ FelineResource . instance_eval do
500503 key_type -> ( key , context ) {
501504 return key if key . nil?
502505 if key . to_s . match ( /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ )
@@ -507,14 +510,14 @@ def test_key_type_proc
507510 }
508511 end
509512
510- assert CatResource . verify_key ( 'f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5' )
513+ assert FelineResource . verify_key ( 'f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5' )
511514
512515 assert_raises JSONAPI ::Exceptions ::InvalidFieldValue do
513- CatResource . verify_key ( 'f1a-e77a-4d0a-acbb-ee0b98b3f6b5' )
516+ FelineResource . verify_key ( 'f1a-e77a-4d0a-acbb-ee0b98b3f6b5' )
514517 end
515518
516519 ensure
517- CatResource . instance_eval do
520+ FelineResource . instance_eval do
518521 key_type nil
519522 end
520523 end
0 commit comments