@@ -19,6 +19,10 @@ def test_engine_boolean
1919 primary_resource_klass : MyEngine ::Api ::V1 ::PersonResource
2020 ) . engine? , "MyEngine should be considered an Engine"
2121
22+ assert JSONAPI ::LinkBuilder . new (
23+ primary_resource_klass : ApiV2Engine ::PersonResource
24+ ) . engine? , "ApiV2 shouldn't be considered an Engine"
25+
2226 refute JSONAPI ::LinkBuilder . new (
2327 primary_resource_klass : Api ::V1 ::PersonResource
2428 ) . engine? , "Api shouldn't be considered an Engine"
@@ -30,6 +34,11 @@ def test_engine_name
3034 primary_resource_klass : MyEngine ::Api ::V1 ::PersonResource
3135 ) . engine_name
3236
37+ assert_equal ApiV2Engine ::Engine ,
38+ JSONAPI ::LinkBuilder . new (
39+ primary_resource_klass : ApiV2Engine ::PersonResource
40+ ) . engine_name
41+
3342 assert_equal nil ,
3443 JSONAPI ::LinkBuilder . new (
3544 primary_resource_klass : Api ::V1 ::PersonResource
@@ -53,6 +62,22 @@ def test_self_link_regular_app
5362 end
5463
5564 def test_self_link_with_engine_app
65+ primary_resource_klass = ApiV2Engine ::PersonResource
66+
67+ config = {
68+ base_url : @base_url ,
69+ route_formatter : @route_formatter ,
70+ primary_resource_klass : primary_resource_klass ,
71+ }
72+
73+ builder = JSONAPI ::LinkBuilder . new ( config )
74+ source = primary_resource_klass . new ( @steve , nil )
75+ expected_link = "#{ @base_url } /api_v2/people/#{ source . id } "
76+
77+ assert_equal expected_link , builder . self_link ( source )
78+ end
79+
80+ def test_self_link_with_engine_namespaced_app
5681 primary_resource_klass = MyEngine ::Api ::V1 ::PersonResource
5782
5883 config = {
@@ -98,6 +123,19 @@ def test_primary_resources_url_for_regular_app
98123 end
99124
100125 def test_primary_resources_url_for_engine
126+ config = {
127+ base_url : @base_url ,
128+ route_formatter : @route_formatter ,
129+ primary_resource_klass : ApiV2Engine ::PersonResource
130+ }
131+
132+ builder = JSONAPI ::LinkBuilder . new ( config )
133+ expected_link = "#{ @base_url } /api_v2/people"
134+
135+ assert_equal expected_link , builder . primary_resources_url
136+ end
137+
138+ def test_primary_resources_url_for_namespaced_engine
101139 config = {
102140 base_url : @base_url ,
103141 route_formatter : @route_formatter ,
@@ -127,6 +165,22 @@ def test_relationships_self_link_for_regular_app
127165 end
128166
129167 def test_relationships_self_link_for_engine
168+ config = {
169+ base_url : @base_url ,
170+ route_formatter : @route_formatter ,
171+ primary_resource_klass : ApiV2Engine ::PersonResource
172+ }
173+
174+ builder = JSONAPI ::LinkBuilder . new ( config )
175+ source = ApiV2Engine ::PersonResource . new ( @steve , nil )
176+ relationship = JSONAPI ::Relationship ::ToMany . new ( "posts" , { } )
177+ expected_link = "#{ @base_url } /api_v2/people/#{ @steve . id } /relationships/posts"
178+
179+ assert_equal expected_link ,
180+ builder . relationships_self_link ( source , relationship )
181+ end
182+
183+ def test_relationships_self_link_for_namespaced_engine
130184 config = {
131185 base_url : @base_url ,
132186 route_formatter : @route_formatter ,
@@ -159,6 +213,22 @@ def test_relationships_related_link_for_regular_app
159213 end
160214
161215 def test_relationships_related_link_for_engine
216+ config = {
217+ base_url : @base_url ,
218+ route_formatter : @route_formatter ,
219+ primary_resource_klass : ApiV2Engine ::PersonResource
220+ }
221+
222+ builder = JSONAPI ::LinkBuilder . new ( config )
223+ source = ApiV2Engine ::PersonResource . new ( @steve , nil )
224+ relationship = JSONAPI ::Relationship ::ToMany . new ( "posts" , { } )
225+ expected_link = "#{ @base_url } /api_v2/people/#{ @steve . id } /posts"
226+
227+ assert_equal expected_link ,
228+ builder . relationships_related_link ( source , relationship )
229+ end
230+
231+ def test_relationships_related_link_for_namespaced_engine
162232 config = {
163233 base_url : @base_url ,
164234 route_formatter : @route_formatter ,
@@ -234,6 +304,20 @@ def test_query_link_for_regular_app_with_dasherized_scope
234304 end
235305
236306 def test_query_link_for_engine
307+ config = {
308+ base_url : @base_url ,
309+ route_formatter : @route_formatter ,
310+ primary_resource_klass : ApiV2Engine ::PersonResource
311+ }
312+
313+ query = { page : { offset : 0 , limit : 12 } }
314+ builder = JSONAPI ::LinkBuilder . new ( config )
315+ expected_link = "#{ @base_url } /api_v2/people?page%5Blimit%5D=12&page%5Boffset%5D=0"
316+
317+ assert_equal expected_link , builder . query_link ( query )
318+ end
319+
320+ def test_query_link_for_namespaced_engine
237321 config = {
238322 base_url : @base_url ,
239323 route_formatter : @route_formatter ,
0 commit comments