test/file_item_test.rb in adrian-1.3.1 vs test/file_item_test.rb in adrian-1.3.2
- old
+ new
@@ -25,10 +25,14 @@
assert_equal item1, item3
end
describe 'updated_at' do
+ it 'is the atime of the file' do
+ @item.updated_at.must_equal File.atime(@item.path)
+ end
+
it 'is nil when moved by another process' do
item = Adrian::FileItem.new('moved/during/initialize')
assert_equal false, item.exist?
assert_equal nil, item.updated_at
end
@@ -42,10 +46,33 @@
assert_equal updated_at, @item.updated_at
end
end
+ describe 'created_at' do
+
+ it 'is the mtime of the file' do
+ @item.created_at.must_equal File.mtime(@item.path)
+ end
+
+ it 'is nil when moved by another process' do
+ item = Adrian::FileItem.new('moved/during/initialize')
+ assert_equal false, item.exist?
+ assert_equal nil, item.created_at
+ end
+
+ it 'is cached' do
+ created_at = @item.created_at
+ assert @item.created_at
+ File.unlink(@item.path)
+ assert_equal false, @item.exist?
+
+ assert_equal created_at, @item.created_at
+ end
+
+ end
+
describe 'move' do
before do
@destination = Dir.mktmpdir('file_item_move_test')
end
@@ -68,18 +95,50 @@
@item.move(@destination)
logger.verify
end
+ it 'does not change the atime' do
+ atime = File.atime(@item.path)
+ @item.move(@destination)
+ File.atime(@item.path).must_equal atime
+ end
+
+ it 'does not change the mtime' do
+ mtime = File.mtime(@item.path)
+ @item.move(@destination)
+ File.mtime(@item.path).must_equal mtime
+ end
+
end
describe 'touch' do
it 'changes the update timestamp to the current time' do
now = Time.now - 100
Time.stub(:new, now) { @item.touch }
assert_equal now.to_i, @item.updated_at.to_i
+ end
+
+ it 'changes the atime' do
+ atime = File.atime(@item.path).to_i
+
+ now = (Time.now - 100)
+ Time.stub(:new, now) { @item.touch }
+
+ now.to_i.wont_equal atime
+ File.atime(@item.path).to_i.must_equal now.to_i
+ end
+
+ it 'does not change the mtime' do
+ mtime = File.mtime(@item.path).to_i
+
+ now = (Time.now - 100)
+ Time.stub(:new, now) { @item.touch }
+
+ now.to_i.wont_equal mtime
+ File.mtime(@item.path).to_i.must_equal mtime
end
end
it 'exists when the file at the given path exists' do