From 4d200a1efc1a7965cd71bb0cacab7c22062a51a8 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 22 Apr 2021 14:28:20 +0500 Subject: [PATCH] Set disputes starts_at as today date --- app/controllers/admin/disputes_controller.rb | 6 ++++-- app/views/admin/disputes/_form.html.erb | 19 ++++++++--------- config/locales/admin/disputes.en.yml | 2 +- test/integration/admin_area/disputes_test.rb | 22 ++------------------ 4 files changed, 16 insertions(+), 33 deletions(-) diff --git a/app/controllers/admin/disputes_controller.rb b/app/controllers/admin/disputes_controller.rb index 8a8997f63..62e0c69b6 100644 --- a/app/controllers/admin/disputes_controller.rb +++ b/app/controllers/admin/disputes_controller.rb @@ -38,7 +38,7 @@ module Admin # PATCH/PUT /admin/disputes/1 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.' else render :edit @@ -68,7 +68,9 @@ module Admin # Only allow a trusted parameter "white list" through. 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 diff --git a/app/views/admin/disputes/_form.html.erb b/app/views/admin/disputes/_form.html.erb index 2a3fb722f..c6fbbee1b 100644 --- a/app/views/admin/disputes/_form.html.erb +++ b/app/views/admin/disputes/_form.html.erb @@ -11,7 +11,7 @@
-

As per domain law, expiry time is <%= Setting.dispute_period_in_months / 12 %> years ahead from start date.

+

As per domain law, expiry time is <%= Setting.dispute_period_in_months / 12 %> years ahead from creation date (today).

@@ -30,15 +30,6 @@ <%= t '.password_hint' %>
-
-
- <%= f.label :starts_at %> -
-
- <%= f.text_field(:starts_at, class: 'form-control js-datepicker') %> - <%= t '.past_or_today' %> -
-
<%= f.label :comment %> @@ -47,6 +38,14 @@ <%= f.text_field(:comment, placeholder: t(:optional), class: 'form-control') %>
+
+
+ <%= f.label :starts_at %> +
+
+ <%= t '.today' %> +
+
diff --git a/config/locales/admin/disputes.en.yml b/config/locales/admin/disputes.en.yml index 9632dde4a..b50ce12cc 100644 --- a/config/locales/admin/disputes.en.yml +++ b/config/locales/admin/disputes.en.yml @@ -16,4 +16,4 @@ en: form: password_hint: Generated automatically if left blank 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 diff --git a/test/integration/admin_area/disputes_test.rb b/test/integration/admin_area/disputes_test.rb index 81019bb66..3362b95ba 100644 --- a/test/integration/admin_area/disputes_test.rb +++ b/test/integration/admin_area/disputes_test.rb @@ -22,7 +22,6 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase fill_in 'Domain name', with: 'hospital.test' fill_in 'Password', with: '1234' - fill_in 'Starts at', with: (Time.zone.today - 2.years).to_s fill_in 'Comment', with: 'Sample comment' click_on 'Save' @@ -38,7 +37,6 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase fill_in 'Domain name', with: 'nonexistant.test' fill_in 'Password', with: '1234' - fill_in 'Starts at', with: Time.zone.today.to_s fill_in 'Comment', with: 'Sample comment' click_on 'Save' @@ -46,30 +44,14 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase assert_text 'nonexistant.test' 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 assert_not_equal Time.zone.today, @dispute.starts_at 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' assert_text 'Dispute was successfully updated' - assert_text Time.zone.today end def test_deletes_dispute @@ -79,11 +61,11 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase end def test_can_not_create_overlapping_dispute + travel_to @dispute.starts_at + 1.day visit admin_disputes_path click_on 'New disputed domain' fill_in 'Domain name', with: 'active-dispute.test' - fill_in 'Starts at', with: @dispute.starts_at + 1.day click_on 'Save' assert_text 'Dispute already exists for this domain at given timeframe'