Set block ends_at to exactly created_at + duration
This commit is contained in:
parent
cea7d44d79
commit
8c32e63492
2 changed files with 18 additions and 1 deletions
|
@ -39,11 +39,13 @@ class UserBlocksController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if @valid_params
|
if @valid_params
|
||||||
|
now = Time.now.utc
|
||||||
@user_block = UserBlock.new(
|
@user_block = UserBlock.new(
|
||||||
:user => @user,
|
:user => @user,
|
||||||
:creator => current_user,
|
:creator => current_user,
|
||||||
:reason => params[:user_block][:reason],
|
:reason => params[:user_block][:reason],
|
||||||
:ends_at => Time.now.utc + @block_period.hours,
|
:created_at => now,
|
||||||
|
:ends_at => now + @block_period.hours,
|
||||||
:needs_view => params[:user_block][:needs_view]
|
:needs_view => params[:user_block][:needs_view]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -261,6 +261,21 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_select "h1", "The user non_existent_user does not exist"
|
assert_select "h1", "The user non_existent_user does not exist"
|
||||||
end
|
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
|
# test the update action
|
||||||
def test_update
|
def test_update
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue