-require 'test_helper'
+require "test_helper"
class UserPreferenceControllerTest < ActionController::TestCase
fixtures :users, :user_preferences
assert_select "preference", :count => 0
end
end
-
+
# authenticate as a user with preferences
basic_authorization("test@openstreetmap.org", "test")
put :update
end
assert_response :unauthorized, "should be authenticated"
- assert_equal "value", UserPreference.find(1, "key").v
- assert_equal "some_value", UserPreference.find(1, "some_key").v
+ assert_equal "value", UserPreference.find([1, "key"]).v
+ assert_equal "some_value", UserPreference.find([1, "some_key"]).v
assert_raises ActiveRecord::RecordNotFound do
- UserPreference.find(1, "new_key")
+ UserPreference.find([1, "new_key"])
end
# authenticate as a user with preferences
assert_response :success
assert_equal "text/plain", @response.content_type
assert_equal "", @response.body
- assert_equal "new_value", UserPreference.find(1, "key").v
- assert_equal "value", UserPreference.find(1, "new_key").v
+ assert_equal "new_value", UserPreference.find([1, "key"]).v
+ assert_equal "value", UserPreference.find([1, "new_key"]).v
assert_raises ActiveRecord::RecordNotFound do
- UserPreference.find(1, "some_key")
+ UserPreference.find([1, "some_key"])
end
# try a put with duplicate keys
assert_response :bad_request
assert_equal "text/plain", @response.content_type
assert_equal "Duplicate preferences with key key", @response.body
- assert_equal "new_value", UserPreference.find(1, "key").v
+ assert_equal "new_value", UserPreference.find([1, "key"]).v
# try a put with invalid content
assert_no_difference "UserPreference.count" do
end
assert_response :unauthorized, "should be authenticated"
assert_raises ActiveRecord::RecordNotFound do
- UserPreference.find(1, "new_key")
+ UserPreference.find([1, "new_key"])
end
# authenticate as a user with preferences
assert_response :success
assert_equal "text/plain", @response.content_type
assert_equal "", @response.body
- assert_equal "new_value", UserPreference.find(1, "new_key").v
+ assert_equal "new_value", UserPreference.find([1, "new_key"]).v
# try changing the value of a preference
assert_no_difference "UserPreference.count" do
assert_response :success
assert_equal "text/plain", @response.content_type
assert_equal "", @response.body
- assert_equal "newer_value", UserPreference.find(1, "new_key").v
+ assert_equal "newer_value", UserPreference.find([1, "new_key"]).v
end
##
delete :delete_one, :preference_key => "key"
end
assert_response :unauthorized, "should be authenticated"
- assert_equal "value", UserPreference.find(1, "key").v
+ assert_equal "value", UserPreference.find([1, "key"]).v
# authenticate as a user with preferences
basic_authorization("test@openstreetmap.org", "test")
assert_equal "text/plain", @response.content_type
assert_equal "", @response.body
assert_raises ActiveRecord::RecordNotFound do
- UserPreference.find(1, "key")
+ UserPreference.find([1, "key"])
end
# try the delete again for the same key
end
assert_response :not_found
assert_raises ActiveRecord::RecordNotFound do
- UserPreference.find(1, "key")
+ UserPreference.find([1, "key"])
end
end
end