Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RatesQuery#rates method to respect relevant_date argument #2399

Merged
merged 3 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/smart_answer/calculators/rates_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ def initialize(rates_filename)
end

def rates(relevant_date = Date.today)
return @rates if @rates
rates = data.find do |rates_hash|
relevant_rates = data.find do |rates_hash|
rates_hash[:start_date] <= relevant_date && rates_hash[:end_date] >= relevant_date
end
rates ||= data.last
relevant_rates ||= data.last

@rates = OpenStruct.new(rates)
OpenStruct.new(relevant_rates)
end

private
Expand Down
1 change: 0 additions & 1 deletion test/data/calculate-statutory-sick-pay-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ lib/smart_answer_flows/calculate-statutory-sick-pay/questions/total_earnings_bef
lib/smart_answer_flows/calculate-statutory-sick-pay/questions/total_employee_earnings.govspeak.erb: 77831bed05434968d38648a40d3ce6e9
lib/smart_answer_flows/calculate-statutory-sick-pay/questions/usual_work_days.govspeak.erb: 5570b649de33ac95bf274bcae70895a9
lib/smart_answer/calculators/statutory_sick_pay_calculator.rb: 721d60e221806043c9e4acacc39409c9
lib/smart_answer/calculators/rates_query.rb: c9568eac2742cad26f93458ed2276876
lib/data/rates/statutory_sick_pay.yml: de2d34118e3016d1137c394745d33280
12 changes: 12 additions & 0 deletions test/unit/calculators/rates_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class RatesQueryTest < ActiveSupport::TestCase
test_rate.stubs(:load_path).returns(File.join("test", "fixtures", "rates"))
assert_equal 2, test_rate.rates(Date.parse('2113-03-12')).rate
end

context 'given a rate has been loaded for one date' do
setup do
@test_rate = SmartAnswer::Calculators::RatesQuery.new('exact_date_rates')
@test_rate.stubs(:load_path).returns(File.join("test", "fixtures", "rates"))
@test_rate.rates(Date.parse('2013-01-31')).rate
end

should 'return the correct rate for a different date' do
assert_equal 2, @test_rate.rates(Date.parse("2013-02-01")).rate
end
end
end

context "Married couples allowance" do
Expand Down