Skip to content

Commit

Permalink
Time.new -> Time.now
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Chapweske committed Nov 29, 2012
1 parent 7af4573 commit 0dc7f21
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/adrian/file_item.rb
Expand Up @@ -48,7 +48,7 @@ def created_at
@created_at ||= mtime
end

def touch(updated_at = Time.new)
def touch(updated_at = Time.now)
@updated_at = updated_at.utc
File.utime(updated_at, created_at, path)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/adrian/filters.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(options = {})
end

def allow?(item)
item.updated_at <= (Time.new - duration)
item.updated_at <= (Time.now - duration)
end

def duration
Expand All @@ -39,7 +39,7 @@ def allow?(item)
end

def lock_expired?(item)
item.updated_at <= (Time.new - duration)
item.updated_at <= (Time.now - duration)
end

def locked?(item)
Expand Down
12 changes: 6 additions & 6 deletions test/directory_queue_test.rb
Expand Up @@ -58,21 +58,21 @@
assert reserved_item
one_hour = 3_600

Time.stub(:new, reserved_item.updated_at + one_hour - 1) do
Time.stub(:now, reserved_item.updated_at + one_hour - 1) do
assert_equal nil, @q.pop
end

Time.stub(:new, reserved_item.updated_at + one_hour) do
Time.stub(:now, reserved_item.updated_at + one_hour) do
assert_equal @item, @q.pop
end

end

it 'touches the item' do
@q.push(@item)
now = Time.new + 100
now = Time.now + 100
item = nil
Time.stub(:new, now) { item = @q.pop }
Time.stub(:now, now) { item = @q.pop }

assert_equal now.to_i, item.updated_at.to_i
end
Expand Down Expand Up @@ -111,8 +111,8 @@ def @q.files
end

it 'touches the item' do
now = Time.new - 100
Time.stub(:new, now) { @q.push(@item) }
now = Time.now - 100
Time.stub(:now, now) { @q.push(@item) }

assert_equal now.to_i, @item.updated_at.to_i
end
Expand Down
4 changes: 2 additions & 2 deletions test/file_item_test.rb
Expand Up @@ -115,7 +115,7 @@

it 'changes the update timestamp to the current time' do
now = Time.now - 100
Time.stub(:new, now) { @item.touch }
Time.stub(:now, now) { @item.touch }

assert_equal now.to_i, @item.updated_at.to_i
end
Expand All @@ -124,7 +124,7 @@
atime = File.atime(@item.path).to_i

now = (Time.now - 100)
Time.stub(:new, now) { @item.touch }
Time.stub(:now, now) { @item.touch }

now.to_i.wont_equal atime
File.atime(@item.path).to_i.must_equal now.to_i
Expand Down
8 changes: 4 additions & 4 deletions test/filters_test.rb
Expand Up @@ -46,12 +46,12 @@ module Updatable
@filter = Adrian::Filters::Delay.new
@updatable_item = Adrian::QueueItem.new("hello")
@updatable_item.extend(Updatable)
@updatable_item.updated_at = Time.new
@updatable_item.updated_at = Time.now
@fifteen_minutes = 900
end

it "allows items that have not been recently updated" do
Time.stub(:new, @updatable_item.updated_at + @fifteen_minutes) do
Time.stub(:now, @updatable_item.updated_at + @fifteen_minutes) do
assert_equal true, @filter.allow?(@updatable_item)
end
end
Expand Down Expand Up @@ -82,13 +82,13 @@ module Updatable
end

it "allows items with an expired lock" do
@locked_item.stub(:updated_at, Time.new - @one_hour) do
@locked_item.stub(:updated_at, Time.now - @one_hour) do
assert_equal true, @filter.allow?(@locked_item)
end
end

it "does not allow items with a fresh lock" do
@locked_item.stub(:updated_at, Time.new) do
@locked_item.stub(:updated_at, Time.now) do
assert_equal false, @filter.allow?(@locked_item)
end
end
Expand Down

0 comments on commit 0dc7f21

Please sign in to comment.