+ get api_users_path, :params => { :users => user2.id, :format => "json" }, :headers => good_auth
+ assert_response :success
+ assert_equal "application/json", response.media_type
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 1, js["users"].count
+ check_json_details(js["users"][0], user2, false, false)
+
+ get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => good_auth
+ assert_response :success
+ assert_equal "application/json", response.media_type
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 2, js["users"].count
+ check_json_details(js["users"][0], user1, true, false)
+ check_json_details(js["users"][1], user3, false, false)
+
+ get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => bad_auth
+ assert_response :success
+ assert_equal "application/json", response.media_type
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 2, js["users"].count
+ check_json_details(js["users"][0], user1, false, false)
+ check_json_details(js["users"][1], user3, false, false)
+
+ get api_users_path, :params => { :users => create(:user, :suspended).id }, :headers => good_auth
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+ assert_select "user", :count => 0
+
+ get api_users_path, :params => { :users => create(:user, :deleted).id }, :headers => good_auth
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+ assert_select "user", :count => 0
+
+ get api_users_path, :params => { :users => 0 }, :headers => good_auth
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+ assert_select "user", :count => 0
+ end
+
+ private
+
+ def check_xml_details(user, include_private, include_email)
+ assert_select "user[id='#{user.id}']", :count => 1 do
+ assert_select "description", :count => 1, :text => user.description
+
+ assert_select "contributor-terms", :count => 1 do
+ if user.terms_agreed.present?
+ assert_select "[agreed='true']", :count => 1
+ else
+ assert_select "[agreed='false']", :count => 1
+ end
+
+ if include_private
+ assert_select "[pd='false']", :count => 1
+ else
+ assert_select "[pd]", :count => 0
+ end
+ end
+
+ assert_select "img", :count => 0
+
+ assert_select "roles", :count => 1 do
+ assert_select "role", :count => 0
+ end
+
+ assert_select "changesets", :count => 1 do
+ assert_select "[count='0']", :count => 1
+ end
+
+ assert_select "traces", :count => 1 do
+ assert_select "[count='0']", :count => 1
+ end
+
+ assert_select "blocks", :count => 1 do
+ assert_select "received", :count => 1 do
+ assert_select "[count='0'][active='0']", :count => 1
+ end
+
+ assert_select "issued", :count => 0
+ end
+
+ if include_private && user.home_lat.present? && user.home_lon.present?
+ assert_select "home", :count => 1 do
+ assert_select "[lat='12.1'][lon='23.4'][zoom='3']", :count => 1
+ end
+ else
+ assert_select "home", :count => 0
+ end
+
+ if include_private
+ assert_select "languages", :count => 1 do
+ assert_select "lang", :count => user.languages.count
+
+ user.languages.each do |language|
+ assert_select "lang", :count => 1, :text => language
+ end
+ end
+
+ assert_select "messages", :count => 1 do
+ assert_select "received", :count => 1 do
+ assert_select "[count='#{user.messages.count}'][unread='0']", :count => 1
+ end
+
+ assert_select "sent", :count => 1 do
+ assert_select "[count='#{user.sent_messages.count}']", :count => 1
+ end
+ end
+ else
+ assert_select "languages", :count => 0
+ assert_select "messages", :count => 0
+ end
+
+ if include_email
+ assert_select "email", :count => 1, :text => user.email
+ else
+ assert_select "email", :count => 0
+ end
+ end