X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/f75eb6fe9ef1e0a755c1a1810c5ca15ed58d9d08..f73b7205f42ac690ee659f4a92d86a56138a7ea2:/test/controllers/user_blocks_controller_test.rb diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index d5db89615..2c363be3d 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -240,9 +240,9 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_redirected_to user_block_path(:id => id) assert_equal "Created a block on user #{target_user.display_name}.", flash[:notice] 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.hours, b.ends_at, 1 + assert_in_delta Time.now.utc, b.created_at, 1 + assert_in_delta Time.now.utc, b.updated_at, 1 + assert_in_delta Time.now.utc + 12.hours, b.ends_at, 1 assert_not b.needs_view assert_equal "Vandalism", b.reason assert_equal "markdown", b.reason_format @@ -261,6 +261,21 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_select "h1", "The user non_existent_user does not exist" end + ## + # test the duration of a created block + def test_create_duration + target_user = create(:user) + moderator_user = create(:moderator_user) + + session_for(moderator_user) + post user_blocks_path(:display_name => target_user.display_name, + :user_block_period => "336", + :user_block => { :needs_view => false, :reason => "Vandalism" }) + + block = UserBlock.order(:id).last + assert_equal 1209600, block.ends_at - block.created_at + end + ## # test the update action def test_update @@ -311,7 +326,7 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_redirected_to user_block_path(active_block) assert_equal "Block updated.", flash[:notice] b = UserBlock.find(active_block.id) - assert_in_delta Time.now, b.updated_at, 1 + assert_in_delta Time.now.utc, b.updated_at, 1 assert b.needs_view assert_equal "Vandalism", b.reason @@ -351,11 +366,18 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_select "input[type='submit'][value='Revoke!']", :count => 1 end - # Check that revoking a block works + # Check that revoking a block using GET should fail + get revoke_user_block_path(:id => active_block, :confirm => true) + assert_response :success + assert_template "revoke" + b = UserBlock.find(active_block.id) + assert_operator b.ends_at - Time.now.utc, :>, 100 + + # Check that revoking a block works using POST post revoke_user_block_path(:id => active_block, :confirm => true) assert_redirected_to user_block_path(active_block) b = UserBlock.find(active_block.id) - assert_in_delta Time.now, b.ends_at, 1 + assert_in_delta Time.now.utc, b.ends_at, 1 # We should get an error if the block doesn't exist get revoke_user_block_path(:id => 99999)