Skip to content

Commit

Permalink
Check deactivates_at to report if block was read after its end date
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 6, 2025
1 parent 97b14ce commit 7e8fd5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/user_blocks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def block_short_status(block)
end
else
if block.revoker_id.nil?
if block.updated_at > block.ends_at
if block.deactivates_at > block.ends_at
t("user_blocks.helper.short.read_html", :time => block_short_time_in_past(block.updated_at))
else
t("user_blocks.helper.short.ended")
Expand Down
32 changes: 32 additions & 0 deletions test/helpers/user_blocks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ def test_block_short_status
end
end

def test_block_short_status_with_immediate_update
freeze_time do
block = UserBlock.new :user => create(:user),
:creator => create(:moderator_user),
:reason => "because",
:created_at => Time.now.utc,
:ends_at => Time.now.utc,
:deactivates_at => Time.now.utc,
:needs_view => false

travel 1.second

block.save

assert_equal "ended", block_short_status(block)
end
end

def test_block_short_status_read
freeze_time do
block = create(:user_block, :needs_view, :ends_at => Time.now.utc)

travel 24.hours

assert_equal "active until read", block_short_status(block)

block.update(:needs_view => false, :deactivates_at => Time.now.utc)

assert_match "read at", block_short_status(block)
end
end

def test_block_duration_in_words
words = block_duration_in_words(364.days)
assert_equal "11 months", words
Expand Down

0 comments on commit 7e8fd5d

Please sign in to comment.