X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/44ec0e02fc259d3a41a8e48da02ebd54f48e241b..0535615fd5de95efd0f7db20bfb0383df4ae6c41:/test/helpers/user_blocks_helper_test.rb diff --git a/test/helpers/user_blocks_helper_test.rb b/test/helpers/user_blocks_helper_test.rb index 99f59af47..d308f46ea 100644 --- a/test/helpers/user_blocks_helper_test.rb +++ b/test/helpers/user_blocks_helper_test.rb @@ -30,6 +30,47 @@ class UserBlocksHelperTest < ActionView::TestCase 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) + + read_date = Time.now.utc.to_date.strftime + short_status_dom = Rails::Dom::Testing.html_document.parse(block_short_status(block)) + assert_dom short_status_dom, ":root", :text => "read at #{read_date}" + + travel 24.hours + + block.update(:reason => "updated reason") + + short_status_dom = Rails::Dom::Testing.html_document.parse(block_short_status(block)) + assert_dom short_status_dom, ":root", :text => "read at #{read_date}" + end + end + def test_block_duration_in_words words = block_duration_in_words(364.days) assert_equal "11 months", words