Merge branch 'pull/3164'
This commit is contained in:
commit
28af501924
3 changed files with 24 additions and 2 deletions
|
@ -7,12 +7,17 @@ module Api
|
||||||
|
|
||||||
around_action :api_call_handle_error
|
around_action :api_call_handle_error
|
||||||
|
|
||||||
|
before_action :set_request_formats
|
||||||
|
|
||||||
##
|
##
|
||||||
# return all the preferences as an XML document
|
# return all the preferences
|
||||||
def index
|
def index
|
||||||
@user_preferences = current_user.preferences
|
@user_preferences = current_user.preferences
|
||||||
|
|
||||||
render :formats => [:xml]
|
respond_to do |format|
|
||||||
|
format.xml
|
||||||
|
format.json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
3
app/views/api/user_preferences/index.json.jbuilder
Normal file
3
app/views/api/user_preferences/index.json.jbuilder
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
json.partial! "api/root_attributes"
|
||||||
|
|
||||||
|
json.preferences @user_preferences.map { |pref| [pref.k, pref.v] }.to_h
|
|
@ -9,6 +9,10 @@ module Api
|
||||||
{ :path => "/api/0.6/user/preferences", :method => :get },
|
{ :path => "/api/0.6/user/preferences", :method => :get },
|
||||||
{ :controller => "api/user_preferences", :action => "index" }
|
{ :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(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/user/preferences", :method => :put },
|
{ :path => "/api/0.6/user/preferences", :method => :put },
|
||||||
{ :controller => "api/user_preferences", :action => "update_all" }
|
{ :controller => "api/user_preferences", :action => "update_all" }
|
||||||
|
@ -62,6 +66,16 @@ module Api
|
||||||
assert_select "preference[k=\"#{user_preference2.k}\"][v=\"#{user_preference2.v}\"]", :count => 1
|
assert_select "preference[k=\"#{user_preference2.k}\"][v=\"#{user_preference2.v}\"]", :count => 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test json
|
||||||
|
get user_preferences_path(:format => "json"), :headers => auth_header
|
||||||
|
assert_response :success
|
||||||
|
assert_equal "application/json", @response.media_type
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue