Skip to content

Commit

Permalink
fix schedule rate changes form for destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
artemlutsenko authored and gigorok committed Apr 17, 2024
1 parent 3a6bc41 commit 4530705
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/admin/routing/destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions app/forms/destination/schedule_rate_changes_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 29 additions & 8 deletions spec/features/routing/destinations/schedule_rate_changes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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 }

Expand Down

0 comments on commit 4530705

Please sign in to comment.