1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
require 'spec_helper'
require 'tdiary'
require 'tdiary/cache/file'
require 'tdiary/io/default'
require 'tdiary/diary_container'
describe TDiary::DiaryContainer do
let(:conf) { TDiary::Configuration.new }
let(:today) { Time.local(2005, 1, 20, 12, 0, 0) }
let(:tdiary_conf_org) { File.join(TDiary::root, "spec/fixtures/tdiary.conf.webrick") }
let(:tdiary_conf) { File.join(TDiary::root, "tdiary.conf") }
before do
# create sample confing
FileUtils.cp_r tdiary_conf_org, tdiary_conf, verbose: false
# create sample diary
tdiary = DummyTDiary.new
tdiary.conf = conf
io = TDiary::IO::Default.new(tdiary)
io.transaction(today) do |diaries|
date = today.strftime('%Y%m%d')
diary = io.diary_factory(date, "foo", "", "wiki")
diaries[date] = diary.append("bar")
TDiary::TDiaryBase::DIRTY_DIARY
end
end
after do
FileUtils.rm_f tdiary_conf
["/tmp/data/#{today.year}"].each do |dir|
FileUtils.rm_rf File.join(TDiary.root, dir)
end
end
context "with find_by_month" do
let(:diary) { TDiary::DiaryContainer.find_by_month(conf, "200501") }
it { expect(diary).to be_a_kind_of TDiary::DiaryContainer }
describe "#conf" do
subject { diary.conf }
it { expect(subject).to be_a_kind_of TDiary::Configuration }
end
describe "#diaries" do
subject { diary.diaries }
it { expect(subject).to be_a_kind_of Hash }
it { expect(subject.keys).to include('20050120') }
it { expect(subject.values).to include(be_a_kind_of TDiary::Style::WikiDiary) }
end
end
context "with find_by_day" do
let(:diary) { TDiary::DiaryContainer.find_by_day(conf, "20050120") }
it { expect(diary).to be_a_kind_of TDiary::DiaryContainer }
describe "#conf" do
subject { diary.conf }
it { expect(subject).to be_a_kind_of TDiary::Configuration }
end
describe "#diaries" do
subject { diary.diaries }
it { expect(subject).to be_a_kind_of Hash }
it { expect(subject.keys).to include('20050120') }
it { expect(subject.values).to include(be_a_kind_of TDiary::Style::WikiDiary) }
end
end
end
|