Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5011'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jul 23, 2024
2 parents ac1f207 + a3282b8 commit eb0f95b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/views/user_blocks/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<%= f.form_group do %>
<%= label_tag "user_block_period", t(".period"), :class => "form-label" %>
<%= select_tag("user_block_period",
options_for_select(UserBlock::PERIODS.collect { |h| [block_duration_in_words(h.hours), h.to_s] }, params[:user_block_period]),
options_for_select(UserBlock::PERIODS.collect { |h| [block_duration_in_words(h.hours), h.to_s] },
UserBlock::PERIODS.min_by { |h| (params[:user_block_period].to_i - h).abs }),
:class => "form-select") %>
<% end %>

Expand Down
28 changes: 28 additions & 0 deletions test/controllers/user_blocks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ def test_edit
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
end

##
# test the edit action when the remaining block duration doesn't match the available select options
def test_edit_duration
moderator_user = create(:moderator_user)

freeze_time do
active_block = create(:user_block, :creator => moderator_user, :ends_at => Time.now.utc + 96.hours)

session_for(moderator_user)
get edit_user_block_path(active_block)

assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
assert_select "select#user_block_period", :count => 1 do
assert_select "option[value='96'][selected]", :count => 1
end
end

travel 2.hours
get edit_user_block_path(active_block)

assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
assert_select "select#user_block_period", :count => 1 do
assert_select "option[value='96'][selected]", :count => 1
end
end
end
end

##
# test the create action
def test_create
Expand Down

0 comments on commit eb0f95b

Please sign in to comment.