- def test_index_oauth1
- user1 = create(:user, :description => "test1", :terms_agreed => Date.yesterday)
- user2 = create(:user, :description => "test2", :terms_agreed => Date.yesterday)
- user3 = create(:user, :description => "test3", :terms_agreed => Date.yesterday)
- good_token = create(:access_token, :user => user1, :allow_read_prefs => true)
- bad_token = create(:access_token, :user => user1)
-
- signed_get api_users_path, :params => { :users => user1.id }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 1 do
- check_xml_details(user1, true, false)
- assert_select "user[id='#{user2.id}']", :count => 0
- assert_select "user[id='#{user3.id}']", :count => 0
- end
-
- signed_get api_users_path, :params => { :users => user2.id }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 1 do
- assert_select "user[id='#{user1.id}']", :count => 0
- check_xml_details(user2, false, false)
- assert_select "user[id='#{user3.id}']", :count => 0
- end
-
- signed_get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 2 do
- check_xml_details(user1, true, false)
- assert_select "user[id='#{user2.id}']", :count => 0
- check_xml_details(user3, false, false)
- end
-
- signed_get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :oauth => { :token => bad_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 2 do
- check_xml_details(user1, false, false)
- assert_select "user[id='#{user2.id}']", :count => 0
- check_xml_details(user3, false, false)
- end
-
- signed_get api_users_path, :params => { :users => user1.id, :format => "json" }, :oauth => { :token => good_token }
- 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], user1, true, false)
-
- signed_get api_users_path, :params => { :users => user2.id, :format => "json" }, :oauth => { :token => good_token }
- 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)
-
- signed_get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :oauth => { :token => good_token }
- 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)
-
- signed_get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :oauth => { :token => bad_token }
- 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)
-
- signed_get api_users_path, :params => { :users => create(:user, :suspended).id }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 0
-
- signed_get api_users_path, :params => { :users => create(:user, :deleted).id }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 0
-
- signed_get api_users_path, :params => { :users => 0 }, :oauth => { :token => good_token }
- assert_response :success
- assert_equal "application/xml", response.media_type
- assert_select "user", :count => 0
- end
-