Set disputes starts_at as today date

This commit is contained in:
Alex Sherman 2021-04-22 14:28:20 +05:00
parent 481299453b
commit 4d200a1efc
4 changed files with 16 additions and 33 deletions

View file

@ -38,7 +38,7 @@ module Admin
# PATCH/PUT /admin/disputes/1 # PATCH/PUT /admin/disputes/1
def update def update
if @dispute.update(dispute_params.except(:domain_name)) if @dispute.update(dispute_params.except(:domain_name, :starts_at))
redirect_to admin_disputes_url, notice: 'Dispute was successfully updated.' redirect_to admin_disputes_url, notice: 'Dispute was successfully updated.'
else else
render :edit render :edit
@ -68,7 +68,9 @@ module Admin
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def dispute_params def dispute_params
params.require(:dispute).permit(:domain_name, :password, :starts_at, :comment) params.require(:dispute)
.permit(:domain_name, :password, :starts_at, :comment)
.with_defaults(starts_at: Time.zone.today)
end end
end end
end end

View file

@ -11,7 +11,7 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div> <div>
<p>As per domain law, expiry time is <%= Setting.dispute_period_in_months / 12 %> years ahead from start date.</p> <p>As per domain law, expiry time is <%= Setting.dispute_period_in_months / 12 %> years ahead from creation date (today).</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
@ -30,15 +30,6 @@
<span class="help-block"><%= t '.password_hint' %></span> <span class="help-block"><%= t '.password_hint' %></span>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label :starts_at %>
</div>
<div class="col-md-7">
<%= f.text_field(:starts_at, class: 'form-control js-datepicker') %>
<span class="help-block"><%= t '.past_or_today' %></span>
</div>
</div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :comment %> <%= f.label :comment %>
@ -47,6 +38,14 @@
<%= f.text_field(:comment, placeholder: t(:optional), class: 'form-control') %> <%= f.text_field(:comment, placeholder: t(:optional), class: 'form-control') %>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label :starts_at %>
</div>
<div class="col-md-7">
<span class="help-block"><%= t '.today' %></span>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -16,4 +16,4 @@ en:
form: form:
password_hint: Generated automatically if left blank password_hint: Generated automatically if left blank
optional: Not required by default optional: Not required by default
past_or_today: Can not be greater than today's date today: Will be explicitely set as today on creation, cannot be changed

View file

@ -22,7 +22,6 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
fill_in 'Domain name', with: 'hospital.test' fill_in 'Domain name', with: 'hospital.test'
fill_in 'Password', with: '1234' fill_in 'Password', with: '1234'
fill_in 'Starts at', with: (Time.zone.today - 2.years).to_s
fill_in 'Comment', with: 'Sample comment' fill_in 'Comment', with: 'Sample comment'
click_on 'Save' click_on 'Save'
@ -38,7 +37,6 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
fill_in 'Domain name', with: 'nonexistant.test' fill_in 'Domain name', with: 'nonexistant.test'
fill_in 'Password', with: '1234' fill_in 'Password', with: '1234'
fill_in 'Starts at', with: Time.zone.today.to_s
fill_in 'Comment', with: 'Sample comment' fill_in 'Comment', with: 'Sample comment'
click_on 'Save' click_on 'Save'
@ -46,30 +44,14 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
assert_text 'nonexistant.test' assert_text 'nonexistant.test'
end end
def test_throws_error_if_starts_at_is_in_future
assert_nil Dispute.active.find_by(domain_name: 'disputed.test')
visit admin_disputes_path
click_on 'New disputed domain'
fill_in 'Domain name', with: 'disputed.test'
fill_in 'Password', with: '1234'
fill_in 'Starts at', with: (Time.zone.today + 2.day).to_s
fill_in 'Comment', with: 'Sample comment'
click_on 'Save'
assert_text "Can not be greater than today's date"
end
def test_updates_dispute def test_updates_dispute
assert_not_equal Time.zone.today, @dispute.starts_at assert_not_equal Time.zone.today, @dispute.starts_at
visit edit_admin_dispute_path(@dispute) visit edit_admin_dispute_path(@dispute)
fill_in 'Starts at', with: Time.zone.today.to_s fill_in 'Comment', with: 'Sample comment with new text'
click_link_or_button 'Save' click_link_or_button 'Save'
assert_text 'Dispute was successfully updated' assert_text 'Dispute was successfully updated'
assert_text Time.zone.today
end end
def test_deletes_dispute def test_deletes_dispute
@ -79,11 +61,11 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
end end
def test_can_not_create_overlapping_dispute def test_can_not_create_overlapping_dispute
travel_to @dispute.starts_at + 1.day
visit admin_disputes_path visit admin_disputes_path
click_on 'New disputed domain' click_on 'New disputed domain'
fill_in 'Domain name', with: 'active-dispute.test' fill_in 'Domain name', with: 'active-dispute.test'
fill_in 'Starts at', with: @dispute.starts_at + 1.day
click_on 'Save' click_on 'Save'
assert_text 'Dispute already exists for this domain at given timeframe' assert_text 'Dispute already exists for this domain at given timeframe'