Merge branch 'rails41'

This commit is contained in:
Tom Hughes 2014-07-21 08:53:44 +01:00
commit c53db246f6
29 changed files with 248 additions and 209 deletions

View file

@ -163,10 +163,10 @@ class TraceControllerTest < ActionController::TestCase
# Check that the list of changesets is displayed
def test_list
get :list
check_trace_list Trace.public
check_trace_list Trace.visible_to_all
get :list, :tag => "London"
check_trace_list Trace.tagged("London").public
check_trace_list Trace.tagged("London").visible_to_all
end
# Check that I can get mine
@ -188,15 +188,15 @@ class TraceControllerTest < ActionController::TestCase
def test_list_user
# Test a user with no traces
get :list, :display_name => users(:second_public_user).display_name
check_trace_list users(:second_public_user).traces.public
check_trace_list users(:second_public_user).traces.visible_to_all
# Test a user with some traces - should see only public ones
get :list, :display_name => users(:public_user).display_name
check_trace_list users(:public_user).traces.public
check_trace_list users(:public_user).traces.visible_to_all
# Should still see only public ones when authenticated as another user
get :list, {:display_name => users(:public_user).display_name}, {:user => users(:normal_user).id}
check_trace_list users(:public_user).traces.public
check_trace_list users(:public_user).traces.visible_to_all
# Should see all traces when authenticated as the target user
get :list, {:display_name => users(:public_user).display_name}, {:user => users(:public_user).id}
@ -210,16 +210,16 @@ class TraceControllerTest < ActionController::TestCase
# Check that the rss loads
def test_rss
get :georss, :format => :rss
check_trace_feed Trace.public
check_trace_feed Trace.visible_to_all
get :georss, :tag => "London", :format => :rss
check_trace_feed Trace.tagged("London").public
check_trace_feed Trace.tagged("London").visible_to_all
get :georss, :display_name => users(:public_user).display_name, :format => :rss
check_trace_feed users(:public_user).traces.public
check_trace_feed users(:public_user).traces.visible_to_all
get :georss, :display_name => users(:public_user).display_name, :tag => "Birmingham", :format => :rss
check_trace_feed users(:public_user).traces.tagged("Birmingham").public
check_trace_feed users(:public_user).traces.tagged("Birmingham").visible_to_all
end
# Test viewing a trace

View file

@ -223,9 +223,10 @@ class UserBlocksControllerTest < ActionController::TestCase
:user_block_period => "12",
:user_block => { :needs_view => false, :reason => "Vandalism" }
end
assert_redirected_to user_block_path(:id => 4)
id = UserBlock.order(:id).ids.last
assert_redirected_to user_block_path(:id => id)
assert_equal "Created a block on user #{users(:unblocked_user).display_name}.", flash[:notice]
b = UserBlock.find(4)
b = UserBlock.find(id)
assert_in_delta Time.now, b.created_at, 1
assert_in_delta Time.now, b.updated_at, 1
assert_in_delta Time.now + 12.hour, b.ends_at, 1

View file

@ -92,10 +92,10 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -109,10 +109,10 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -123,7 +123,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -143,7 +143,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -157,7 +157,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -167,7 +167,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
##
@ -178,7 +178,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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")
@ -191,7 +191,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
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
@ -200,7 +200,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
end
assert_response :not_found
assert_raises ActiveRecord::RecordNotFound do
UserPreference.find(1, "key")
UserPreference.find([1, "key"])
end
end
end

View file

@ -7,6 +7,10 @@ class ApplicationHelperTest < ActionView::TestCase
I18n.locale = "en"
end
def setup
I18n.locale = "en"
end
def test_linkify
%w(http://example.com/test ftp://example.com/test https://example.com/test).each do |link|
text = "Test #{link} is made into a link"

View file

@ -12,6 +12,10 @@ class BrowseHelperTest < ActionView::TestCase
I18n.locale = "en"
end
def teardown
I18n.locale = "en"
end
def test_printable_name
assert_equal "17", printable_name(current_nodes(:redacted_node))
assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))

View file

@ -27,8 +27,8 @@ class TraceTest < ActiveSupport::TestCase
check_query(Trace.visible_to(3), [:public_trace_file, :identifiable_trace_file])
end
def test_public
check_query(Trace.public, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file])
def test_visible_to_all
check_query(Trace.visible_to_all, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file])
end
def test_tagged

View file

@ -180,10 +180,10 @@ class UserTest < ActiveSupport::TestCase
end
end
def test_public
assert_equal 16, User.public.count
def test_identifiable
assert_equal 16, User.identifiable.count
assert_raise ActiveRecord::RecordNotFound do
User.public.find(users(:normal_user).id)
User.identifiable.find(users(:normal_user).id)
end
end