Add file storage
This commit is contained in:
@ -3,16 +3,6 @@ require "./spec_helper"
|
||||
module Dayoff::Test
|
||||
extend self
|
||||
|
||||
def d(day)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, location: location)
|
||||
end
|
||||
|
||||
def t(day, hour, min = 0)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, hour, min, location: location)
|
||||
end
|
||||
|
||||
def create_profile
|
||||
storage = MemoryStorage.new
|
||||
storage.set_planned_dates [
|
||||
|
@ -1,2 +1,25 @@
|
||||
require "spec"
|
||||
require "../src/dayoff/**"
|
||||
|
||||
def d(day)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, location: location)
|
||||
end
|
||||
|
||||
def t(day, hour, min = 0)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, hour, min, location: location)
|
||||
end
|
||||
|
||||
def with_temp_dir(&block)
|
||||
tmpdir = File.tempname("dayoff_file_storage")
|
||||
Dir.mkdir tmpdir
|
||||
begin
|
||||
yield tmpdir
|
||||
ensure
|
||||
Dir.glob(tmpdir + "/*") do |f|
|
||||
File.delete f
|
||||
end
|
||||
Dir.rmdir tmpdir
|
||||
end
|
||||
end
|
||||
|
17
spec/storage_spec.cr
Normal file
17
spec/storage_spec.cr
Normal file
@ -0,0 +1,17 @@
|
||||
require "./spec_helper"
|
||||
|
||||
module Dayoff::Test
|
||||
describe Storage do
|
||||
it "can store data in file" do
|
||||
with_temp_dir do |tmpdir|
|
||||
storage = FileStorage.new tmpdir
|
||||
storage.set_planned_dates [
|
||||
PlannedDate.new(d(1), 8),
|
||||
PlannedDate.new(d(1), 8),
|
||||
]
|
||||
entries = Dir.glob(tmpdir + "/*")
|
||||
1.should eq entries.size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user