From 4530705daf82ef069a944544788437ff37dd71e6 Mon Sep 17 00:00:00 2001 From: artemlutsenko Date: Tue, 16 Apr 2024 19:33:32 +0300 Subject: [PATCH] fix schedule rate changes form for destinations --- app/admin/routing/destinations.rb | 2 +- ...ctive_admin_scoped_collection_actions.scss | 5 +++ .../destination/schedule_rate_changes_form.rb | 10 ++--- .../schedule_rate_changes_spec.rb | 37 +++++++++++++++---- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app/admin/routing/destinations.rb b/app/admin/routing/destinations.rb index 3848fe64c..ed9e6930b 100644 --- a/app/admin/routing/destinations.rb +++ b/app/admin/routing/destinations.rb @@ -24,7 +24,7 @@ form.ids_sql = scoped_collection_records.select(:id).to_sql if form.save - flash[:notice] = 'Rate changes is scheduled' + flash[:notice] = 'Rate changes are scheduled' else flash[:error] = "Validation Error: #{form.errors.full_messages.to_sentence}" end diff --git a/app/assets/stylesheets/active_admin/components/active_admin_scoped_collection_actions.scss b/app/assets/stylesheets/active_admin/components/active_admin_scoped_collection_actions.scss index a26d83a2d..927250ec5 100644 --- a/app/assets/stylesheets/active_admin/components/active_admin_scoped_collection_actions.scss +++ b/app/assets/stylesheets/active_admin/components/active_admin_scoped_collection_actions.scss @@ -16,6 +16,11 @@ } } +// fixed input height for display datepicker bellow input +.active_admin_dialog_mass_update_by_filter form ul li input[type='datepicker'] { + height: 30px; +} + button.scoped_collection_action_button { background-image: none; border: none; diff --git a/app/forms/destination/schedule_rate_changes_form.rb b/app/forms/destination/schedule_rate_changes_form.rb index a3b5a8aa9..c3399e1e8 100644 --- a/app/forms/destination/schedule_rate_changes_form.rb +++ b/app/forms/destination/schedule_rate_changes_form.rb @@ -3,11 +3,11 @@ module Destination class ScheduleRateChangesForm < ApplicationForm attribute :apply_time, :date - attribute :initial_interval, :integer - attribute :initial_rate, :decimal - attribute :next_interval, :integer - attribute :next_rate, :decimal - attribute :connect_fee, :decimal + attribute :initial_interval + attribute :initial_rate + attribute :next_interval + attribute :next_rate + attribute :connect_fee attribute :ids_sql, :string validates :initial_rate, :next_rate, :connect_fee, numericality: true diff --git a/spec/features/routing/destinations/schedule_rate_changes_spec.rb b/spec/features/routing/destinations/schedule_rate_changes_spec.rb index 690ec7f75..29168a805 100644 --- a/spec/features/routing/destinations/schedule_rate_changes_spec.rb +++ b/spec/features/routing/destinations/schedule_rate_changes_spec.rb @@ -23,11 +23,11 @@ let(:apply_time) { 1.month.from_now.to_date } let(:apply_time_formatted) { apply_time.to_fs(:db) } - let(:initial_interval) { 60 } - let(:initial_rate) { 0.1 } - let(:next_interval) { 60 } - let(:next_rate) { 0.2 } - let(:connect_fee) { 0.03 } + let(:initial_interval) { '60' } + let(:initial_rate) { '0.1' } + let(:next_interval) { '60' } + let(:next_rate) { '0.2' } + let(:connect_fee) { '0.03' } let(:filter!) { nil } let(:fill_form!) do @@ -50,7 +50,7 @@ expect do subject - expect(page).to have_flash_message('Rate changes is scheduled', type: :notice) + expect(page).to have_flash_message('Rate changes are scheduled', type: :notice) end.to have_enqueued_job(Worker::ScheduleRateChanges).on_queue('batch_actions').with( ids_sql, { @@ -81,7 +81,7 @@ expect do subject - expect(page).to have_flash_message('Rate changes is scheduled', type: :notice) + expect(page).to have_flash_message('Rate changes are scheduled', type: :notice) end.to have_enqueued_job(Worker::ScheduleRateChanges).on_queue('batch_actions').with( ids_sql, { @@ -123,7 +123,7 @@ expect do subject - expect(page).to have_flash_message('Rate changes is scheduled', type: :notice) + expect(page).to have_flash_message('Rate changes are scheduled', type: :notice) end.to have_enqueued_job(Worker::ScheduleRateChanges).on_queue('batch_actions').with( ids_sql, { @@ -171,6 +171,27 @@ end end + context 'with invalid form values' do + let(:apply_time_formatted) { 'invalid' } + let(:initial_interval) { 'invalid' } + let(:initial_rate) { 'invalid' } + let(:next_interval) { 'invalid' } + let(:next_rate) { 'invalid' } + let(:connect_fee) { 'invalid' } + + it 'should show error message' do + expect do + subject + + expect(page).to have_flash_message( + 'Validation Error: Initial rate is not a number, Next rate is not a number, Connect fee is not a number,'\ + " Initial interval is not a number, Next interval is not a number, and Apply time can't be blank", + type: :error + ) + end.not_to have_enqueued_job(Worker::ScheduleRateChanges) + end + end + context 'when apply_time is in the past' do let(:apply_time) { 1.second.ago.to_date }