Skip to content

Commit

Permalink
AP-633 Update following review - improve way state change is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
reggieb committed Jun 21, 2019
1 parent e5ea501 commit ae130bb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def show
def update
authorize legal_aid_application
@form = LegalAidApplications::SubstantiveApplicationForm.new(form_params)
render :show unless save_continue_or_draft(@form)
if save_continue_or_draft(@form)
legal_aid_application.provider_used_delegated_functions!
else
render :show
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def substantive_application_deadline_on
attributes['substantive_application_deadline_on'] ||= substantive_application_deadline
end

def save
super && model.provider_used_delegated_functions!
end

private

def substantive_application_deadline
Expand Down
2 changes: 1 addition & 1 deletion app/models/bank_holiday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BankHoliday < ApplicationRecord

def self.dates
BankHolidayUpdateWorker.perform_in 10.seconds
instance = by_updated_at.last || create
instance = by_updated_at.last || create!
instance.dates
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/bank_holiday_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def data
def dates(group)
return if data.empty?

data.dig(group, 'events')&.map { |details| details['date'] }
data.dig(group, 'events')&.pluck('date')
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
expect(application).not_to be_substantive_application
end

it 'changes the state' do
expect { subject.save }.to change { application.reload.state }.to('delegated_functions_used')
end

context 'when a deadline is already set' do
let(:deadline) { 3.days.from_now.to_date }
let(:application) do
Expand All @@ -61,10 +57,6 @@
expect(subject.save).to be true
expect(application).to be_substantive_application
end

it 'changes the state' do
expect { subject.save }.to change { application.reload.state }.to('delegated_functions_used')
end
end

context 'with no entry' do
Expand All @@ -74,10 +66,6 @@
expect(subject.save).to be false
expect(application.substantive_application).to be_nil
end

it 'changes the state' do
expect { subject.save }.not_to change { application.reload.state }
end
end
end
end

0 comments on commit ae130bb

Please sign in to comment.