]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/user_blocks_controller_test.rb
Fixed tests + Added new ones
[rails.git] / test / controllers / user_blocks_controller_test.rb
index ffb5744ea25a510ef1f36fae293e826829b960b1..839dadf193dac0bc0fccce78eeea188d0cb3e123 100644 (file)
@@ -1,4 +1,4 @@
-require 'test_helper'
+require "test_helper"
 
 class UserBlocksControllerTest < ActionController::TestCase
   fixtures :users, :user_roles, :user_blocks
@@ -210,8 +210,8 @@ class UserBlocksControllerTest < ActionController::TestCase
     # A bogus block period should result in an error
     assert_no_difference "UserBlock.count" do
       post :create,
-        :display_name => users(:unblocked_user).display_name,
-        :user_block_period => "99"
+           :display_name => users(:unblocked_user).display_name,
+           :user_block_period => "99"
     end
     assert_redirected_to new_user_block_path(:display_name => users(:unblocked_user).display_name)
     assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
@@ -219,16 +219,17 @@ class UserBlocksControllerTest < ActionController::TestCase
     # Check that creating a block works
     assert_difference "UserBlock.count", 1 do
       post :create,
-        :display_name => users(:unblocked_user).display_name,
-        :user_block_period => "12",
-        :user_block => { :needs_view => false, :reason => "Vandalism" }
+           :display_name => users(:unblocked_user).display_name,
+           :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
+    assert_in_delta Time.now + 12.hours, b.ends_at, 1
     assert_equal false, b.needs_view
     assert_equal "Vandalism", b.reason
     assert_equal "markdown", b.reason_format
@@ -267,9 +268,9 @@ class UserBlocksControllerTest < ActionController::TestCase
     # Check that only the person who created a block can update it
     assert_no_difference "UserBlock.count" do
       put :update,
-        :id => user_blocks(:active_block).id,
-        :user_block_period => "12",
-        :user_block => { :needs_view => true, :reason => "Vandalism" }
+          :id => user_blocks(:active_block).id,
+          :user_block_period => "12",
+          :user_block => { :needs_view => true, :reason => "Vandalism" }
     end
     assert_redirected_to edit_user_block_path(:id => user_blocks(:active_block).id)
     assert_equal "Only the moderator who created this block can edit it.", flash[:error]
@@ -280,8 +281,8 @@ class UserBlocksControllerTest < ActionController::TestCase
     # A bogus block period should result in an error
     assert_no_difference "UserBlock.count" do
       put :update,
-        :id => user_blocks(:active_block).id,
-        :user_block_period => "99"
+          :id => user_blocks(:active_block).id,
+          :user_block_period => "99"
     end
     assert_redirected_to edit_user_block_path(:id => user_blocks(:active_block).id)
     assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
@@ -289,9 +290,9 @@ class UserBlocksControllerTest < ActionController::TestCase
     # Check that updating a block works
     assert_no_difference "UserBlock.count" do
       put :update,
-        :id => user_blocks(:active_block).id,
-        :user_block_period => "12",
-        :user_block => { :needs_view => true, :reason => "Vandalism" }
+          :id => user_blocks(:active_block).id,
+          :user_block_period => "12",
+          :user_block => { :needs_view => true, :reason => "Vandalism" }
     end
     assert_redirected_to user_block_path(:id => user_blocks(:active_block).id)
     assert_equal "Block updated.", flash[:notice]