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

Bugs/broken subdir mode #2

Merged
merged 2 commits into from
Nov 29, 2012
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
4 changes: 2 additions & 2 deletions lib/history_file.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'history_file/file_delegator'
require 'history_file/history_file'
require_relative 'history_file/file_delegator'
require_relative 'history_file/history_file'
6 changes: 5 additions & 1 deletion lib/history_file/file_delegator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def file_fallback(original_filename, target_filename)
return false unless @fallback_glob
dir = File.dirname(original_filename.to_s)
file = File.basename(original_filename.to_s)
glob = File.join(dir, @fallback_glob+file)
if @subdir
glob = File.join(dir, @fallback_glob, file)
else
glob = File.join(dir, "#{@fallback_glob}-#{file}")
end
candidates = Dir[glob].sort.select do |c|
c < target_filename
end.last
Expand Down
2 changes: 1 addition & 1 deletion lib/history_file/history_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.mode=(mode)
def self.[](offset)
validate_offset(offset)
use_subdirs = @mode == :subdir
fallback_glob = "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-"
fallback_glob = "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]"
FileDelegator.new(prefix: prefix(offset),
fallback_glob: fallback_glob,
use_subdirs: use_subdirs)
Expand Down
39 changes: 23 additions & 16 deletions spec/history_file/history_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,43 @@
# We run these tests twice
[:subdir, :filename].each do |mode|

HistoryFile.mode = mode
context "falling back to older files in #{mode} mode" do
before(:all) do
[1,2,3,6,7].each do |i|
it "sets up things correctly" do
HistoryFile.mode = mode
[2,3,6,7,8].each do |i|
date = DateTime.now - i
HistoryFile[date].open("ht.txt", "w") do |file|
HistoryFile[date].open("ht_#{mode}.txt", "w") do |file|
file.write "Day #{i} #{mode}"
end
end
end

after(:all) do
[1,2,3,6,7].each do |i|
date = DateTime.now - i
HistoryFile[date].unlink("ht.txt")
end
Dir.unlink("some_prefix") rescue nil
end

it "to yesterday's file" do
it "to a four days old file" do
HistoryFile.mode = mode
date = DateTime.now - 4
HistoryFile[date].read("ht.txt").should == "Day 6 #{mode}"
HistoryFile[date].read("ht_#{mode}.txt").should == "Day 6 #{mode}"
end

it "to an error if nothing older exists" do
HistoryFile.mode = mode
expect{
date = DateTime.now - 8
HistoryFile[date].read("ht.txt")
date = DateTime.now - 9
HistoryFile[date].read("ht_#{mode}.txt")
}.to raise_error(Errno::ENOENT)
end

it "removes stuff we assumed we created" do
HistoryFile.mode = mode
[2,3,6,7,8].each do |i|
date = DateTime.now - i
HistoryFile[date].unlink("ht_#{mode}.txt")
if mode == :subdir
dir = File.dirname(HistoryFile[date].prefixed_filename("ht_#{mode}.txt"))
Dir.unlink(dir)
end
end
end

end
end
end