]> git.openstreetmap.org Git - rails.git/blobdiff - test/functional/user_preference_controller_test.rb
Require version 0.4.0.1 of the oauth-plugin gem
[rails.git] / test / functional / user_preference_controller_test.rb
index 7ff64b30ebb7a5150674b80ea335409bdd06e23d..3921fe5362e322580b3b3ae33609a5835e5cbda2 100644 (file)
@@ -1,8 +1,49 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class UserPreferenceControllerTest < ActionController::TestCase
-  # Replace this with your real tests.
-  def test_truth
-    assert true
+  fixtures :users, :user_preferences
+
+  ##
+  # test all routes which lead to this controller
+  def test_routes
+    assert_routing(
+      { :path => "/api/0.6/user/preferences", :method => :get },
+      { :controller => "user_preference", :action => "read" }
+    )
+    assert_routing(
+      { :path => "/api/0.6/user/preferences", :method => :put },
+      { :controller => "user_preference", :action => "update" }
+    )
+    assert_routing(
+      { :path => "/api/0.6/user/preferences/key", :method => :get },
+      { :controller => "user_preference", :action => "read_one", :preference_key => "key" }
+    )
+    assert_routing(
+      { :path => "/api/0.6/user/preferences/key", :method => :put },
+      { :controller => "user_preference", :action => "update_one", :preference_key => "key" }
+    )
+    assert_routing(
+      { :path => "/api/0.6/user/preferences/key", :method => :delete },
+      { :controller => "user_preference", :action => "delete_one", :preference_key => "key" }
+    )
+  end
+
+  def test_read
+    # first try without auth
+    get :read
+    assert_response :unauthorized, "should be authenticated"
+    
+    # now set the auth
+    basic_authorization("test@openstreetmap.org", "test")
+    
+    get :read
+    assert_response :success
+    assert_select "osm" do
+      assert_select "preferences", :count => 1 do
+        assert_select "preference", :count => 2
+        assert_select "preference[k=\"#{user_preferences(:a).k}\"][v=\"#{user_preferences(:a).v}\"]", :count => 1
+        assert_select "preference[k=\"#{user_preferences(:two).k}\"][v=\"#{user_preferences(:two).v}\"]", :count => 1
+      end
+    end
   end
 end