]> git.openstreetmap.org Git - rails.git/blob - test/functional/user_preference_controller_test.rb
Add tests for make_friend and remove_friend
[rails.git] / test / functional / user_preference_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class UserPreferenceControllerTest < ActionController::TestCase
4   fixtures :users, :user_preferences
5
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/api/0.6/user/preferences", :method => :get },
11       { :controller => "user_preference", :action => "read" }
12     )
13     assert_routing(
14       { :path => "/api/0.6/user/preferences", :method => :put },
15       { :controller => "user_preference", :action => "update" }
16     )
17     assert_routing(
18       { :path => "/api/0.6/user/preferences/key", :method => :get },
19       { :controller => "user_preference", :action => "read_one", :preference_key => "key" }
20     )
21     assert_routing(
22       { :path => "/api/0.6/user/preferences/key", :method => :put },
23       { :controller => "user_preference", :action => "update_one", :preference_key => "key" }
24     )
25     assert_routing(
26       { :path => "/api/0.6/user/preferences/key", :method => :delete },
27       { :controller => "user_preference", :action => "delete_one", :preference_key => "key" }
28     )
29   end
30
31   def test_read
32     # first try without auth
33     get :read
34     assert_response :unauthorized, "should be authenticated"
35     
36     # now set the auth
37     basic_authorization("test@openstreetmap.org", "test")
38     
39     get :read
40     assert_response :success
41     assert_select "osm" do
42       assert_select "preferences", :count => 1 do
43         assert_select "preference", :count => 2
44         assert_select "preference[k=\"#{user_preferences(:a).k}\"][v=\"#{user_preferences(:a).v}\"]", :count => 1
45         assert_select "preference[k=\"#{user_preferences(:two).k}\"][v=\"#{user_preferences(:two).v}\"]", :count => 1
46       end
47     end
48   end
49 end