]> git.openstreetmap.org Git - rails.git/commitdiff
Add tests for routing and to ensure output format
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 14 Apr 2021 15:11:57 +0000 (16:11 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 14 Apr 2021 15:11:57 +0000 (16:11 +0100)
This avoids the tests passing if the json output is an array of kv pairs,
instead of the desired hash of attributes.

app/controllers/api/user_preferences_controller.rb
test/controllers/api/user_preferences_controller_test.rb

index 10b01d69688ebdebeff0c4b4d2cff6dbd42c6543..40ccfccbbc4a222a841c67f312d6665a13998a10 100644 (file)
@@ -10,7 +10,7 @@ module Api
     before_action :set_request_formats
 
     ##
-    # return all the preferences as an XML document
+    # return all the preferences
     def index
       @user_preferences = current_user.preferences
 
index bf36c5d4461ef26c1ecf5bc2c1e4eed5b2e17f33..3d3f7971201e6951967e53ea54512c8785ed403a 100644 (file)
@@ -9,6 +9,10 @@ module Api
         { :path => "/api/0.6/user/preferences", :method => :get },
         { :controller => "api/user_preferences", :action => "index" }
       )
+      assert_routing(
+        { :path => "/api/0.6/user/preferences.json", :method => :get },
+        { :controller => "api/user_preferences", :action => "index", :format => "json" }
+      )
       assert_routing(
         { :path => "/api/0.6/user/preferences", :method => :put },
         { :controller => "api/user_preferences", :action => "update_all" }
@@ -71,6 +75,7 @@ module Api
       js = ActiveSupport::JSON.decode(@response.body)
       assert_not_nil js
       assert_equal 2, js["preferences"].count
+      assert_equal user_preference.v, js["preferences"][user_preference.k]
     end
 
     ##