44
55class LinkBuilderTest < ActionDispatch ::IntegrationTest
66 def setup
7+ # the route format is being set directly in test_helper and is being set differently depending on
8+ # the order in which the namespaces get loaded. in order to prevent random test seeds to fail we need to set the
9+ # default configuration in the test 'setup'.
10+ JSONAPI . configuration . route_format = :underscored_route
11+
712 @base_url = "http://example.com"
813 @route_formatter = JSONAPI . configuration . route_formatter
914 @steve = Person . create ( name : "Steve Rogers" , date_joined : "1941-03-01" )
@@ -214,6 +219,20 @@ def test_query_link_for_regular_app_with_camel_case_scope
214219 assert_equal expected_link , builder . query_link ( query )
215220 end
216221
222+ def test_query_link_for_regular_app_with_dasherized_scope
223+ config = {
224+ base_url : @base_url ,
225+ route_formatter : DasherizedRouteFormatter ,
226+ primary_resource_klass : DasherizedNamespace ::V1 ::PersonResource
227+ }
228+
229+ query = { page : { offset : 0 , limit : 12 } }
230+ builder = JSONAPI ::LinkBuilder . new ( config )
231+ expected_link = "#{ @base_url } /dasherized-namespace/v1/people?page%5Blimit%5D=12&page%5Boffset%5D=0"
232+
233+ assert_equal expected_link , builder . query_link ( query )
234+ end
235+
217236 def test_query_link_for_engine
218237 config = {
219238 base_url : @base_url ,
@@ -228,6 +247,20 @@ def test_query_link_for_engine
228247 assert_equal expected_link , builder . query_link ( query )
229248 end
230249
250+ def test_query_link_for_engine_with_dasherized_scope
251+ config = {
252+ base_url : @base_url ,
253+ route_formatter : DasherizedRouteFormatter ,
254+ primary_resource_klass : MyEngine ::DasherizedNamespace ::V1 ::PersonResource
255+ }
256+
257+ query = { page : { offset : 0 , limit : 12 } }
258+ builder = JSONAPI ::LinkBuilder . new ( config )
259+ expected_link = "#{ @base_url } /boomshaka/dasherized-namespace/v1/people?page%5Blimit%5D=12&page%5Boffset%5D=0"
260+
261+ assert_equal expected_link , builder . query_link ( query )
262+ end
263+
231264 def test_query_link_for_engine_with_camel_case_scope
232265 config = {
233266 base_url : @base_url ,
0 commit comments