File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed
Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 22
33require "yaml"
44require "date"
5+ require "pathname"
56
67module Business
78 class Calendar
@@ -37,9 +38,10 @@ def self.find_calendar_data(calendar_name)
3738 if path . is_a? ( Hash )
3839 break path [ calendar_name ] if path [ calendar_name ]
3940 else
40- next unless File . exist? ( File . join ( path , "#{ calendar_name } .yml" ) )
41+ calendar_path = Pathname . new ( path ) . join ( "#{ calendar_name } .yml" )
42+ next unless calendar_path . exist?
4143
42- break YAML . load_file ( File . join ( path , " #{ calendar_name } .yml" ) )
44+ break YAML . safe_load ( calendar_path . read , permitted_classes : [ Date ] )
4345 end
4446 end
4547 end
Original file line number Diff line number Diff line change 1313 subject ( :load_calendar ) { described_class . load ( calendar ) }
1414
1515 let ( :dummy_calendar ) { { "working_days" => [ "monday" ] } }
16+ let ( :fixture_path ) { File . join ( File . dirname ( __FILE__ ) , "../fixtures" , "calendars" ) }
1617
1718 before do
18- fixture_path = File . join ( File . dirname ( __FILE__ ) , "../fixtures" , "calendars" )
1919 described_class . load_paths = [ fixture_path , { "foobar" => dummy_calendar } ]
2020 end
2121
2525 after { described_class . load_paths = nil }
2626
2727 it "loads the yaml file" do
28- expect ( YAML ) . to receive ( :load_file ) . with ( /ecb\. yml$/ ) . and_return ( { } )
28+ path = Pathname . new ( fixture_path ) . join ( "ecb.yml" )
29+ expect ( YAML ) . to receive ( :safe_load ) .
30+ with ( path . read , permitted_classes : [ Date ] ) .
31+ and_return ( { } )
2932
3033 load_calendar
3134 end
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ working_days:
66 - friday
77
88holidays :
9- - January 1st, 2013
9+ - 2013-01-01
1010 - March 29th, 2013
1111 - April 1st, 2013
1212 - May 1st, 2013
You can’t perform that action at this time.
0 commit comments