From 6bb18436a31bc192c20f3df5caf15ac5888471b5 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 14 Apr 2021 16:11:57 +0100 Subject: [PATCH] Add tests for routing and to ensure output format 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 | 2 +- test/controllers/api/user_preferences_controller_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/user_preferences_controller.rb b/app/controllers/api/user_preferences_controller.rb index 10b01d696..40ccfccbb 100644 --- a/app/controllers/api/user_preferences_controller.rb +++ b/app/controllers/api/user_preferences_controller.rb @@ -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 diff --git a/test/controllers/api/user_preferences_controller_test.rb b/test/controllers/api/user_preferences_controller_test.rb index bf36c5d44..3d3f79712 100644 --- a/test/controllers/api/user_preferences_controller_test.rb +++ b/test/controllers/api/user_preferences_controller_test.rb @@ -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 ## -- 2.45.2