aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-04-30 10:09:34 +0100
committerGareth Rees <gareth@mysociety.org>2015-04-30 10:09:34 +0100
commit4246e8de08d3ab8a86806b74ad422a1be431f4e3 (patch)
treeb9a22d6e561f9da339d8e29dd8d17d8e7ed2bea5
parent2f2415d8d126423c17dd85d29f8fb543b56b946d (diff)
parent196cce975887aca513b0fca6e90f8024aff981e5 (diff)
Merge branch 'hotfix/0.21.0.24'0.21.0.24
-rw-r--r--app/models/holiday_import.rb12
-rw-r--r--spec/models/holiday_import_spec.rb22
2 files changed, 26 insertions, 8 deletions
diff --git a/app/models/holiday_import.rb b/app/models/holiday_import.rb
index c6019fac0..98a9b96fc 100644
--- a/app/models/holiday_import.rb
+++ b/app/models/holiday_import.rb
@@ -84,10 +84,14 @@ class HolidayImport
end
def populate_from_suggestions
- holiday_info = Holidays.between(start_date, end_date, @country_code.to_sym, :observed)
- holiday_info.each do |holiday_info_hash|
- holidays << Holiday.new(:description => holiday_info_hash[:name],
- :day => holiday_info_hash[:date])
+ begin
+ holiday_info = Holidays.between(start_date, end_date, @country_code.to_sym, :observed)
+ holiday_info.each do |holiday_info_hash|
+ holidays << Holiday.new(:description => holiday_info_hash[:name],
+ :day => holiday_info_hash[:date])
+ end
+ rescue Holidays::UnknownRegionError
+ []
end
end
end
diff --git a/spec/models/holiday_import_spec.rb b/spec/models/holiday_import_spec.rb
index 21061f63f..7ec5c04d5 100644
--- a/spec/models/holiday_import_spec.rb
+++ b/spec/models/holiday_import_spec.rb
@@ -88,21 +88,35 @@ describe HolidayImport do
describe 'when populating a set of holidays to import from suggestions' do
- before do
- holidays = [ { :date => Date.new(2014, 1, 1), :name => "New Year's Day", :regions => [:gb] } ]
+ it 'should populate holidays from the suggestions' do
+ holidays = [ { :date => Date.new(2014, 1, 1),
+ :name => "New Year's Day",
+ :regions => [:gb] } ]
Holidays.stub!(:between).and_return(holidays)
@holiday_import = HolidayImport.new(:source => 'suggestions')
@holiday_import.populate
- end
- it 'should populate holidays from the suggestions' do
@holiday_import.holidays.size.should == 1
holiday = @holiday_import.holidays.first
holiday.description.should == "New Year's Day"
holiday.day.should == Date.new(2014, 1, 1)
end
+ it 'returns an empty array for an unknown country code' do
+ AlaveteliConfiguration.stub(:iso_country_code).and_return('UNKNOWN_COUNTRY_CODE')
+ @holiday_import = HolidayImport.new(:source => 'suggestions')
+ @holiday_import.populate
+ expect(@holiday_import.holidays).to be_empty
+ end
+
it 'should return a flag that it has been populated' do
+ holidays = [ { :date => Date.new(2014, 1, 1),
+ :name => "New Year's Day",
+ :regions => [:gb] } ]
+ Holidays.stub!(:between).and_return(holidays)
+ @holiday_import = HolidayImport.new(:source => 'suggestions')
+ @holiday_import.populate
+
@holiday_import.populated.should == true
end