adrian 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,9 @@ module Adrian
15
15
  end
16
16
 
17
17
  def pop
18
- verify_age!(pop_item)
18
+ item = pop_item
19
+ item.queue = self if item
20
+ verify_age!(item)
19
21
  end
20
22
 
21
23
  def push(item)
@@ -1,6 +1,7 @@
1
1
  module Adrian
2
2
  class QueueItem
3
3
  attr_reader :value, :created_at
4
+ attr_accessor :queue
4
5
 
5
6
  def initialize(value, created_at = Time.now)
6
7
  @value = value
@@ -1,3 +1,3 @@
1
1
  module Adrian
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -26,6 +26,14 @@ describe Adrian::CompositeQueue do
26
26
  @q1.pop.must_be_nil
27
27
  @q2.pop.must_be_nil
28
28
  end
29
+
30
+ it 'sets the original queue on the item' do
31
+ @q1.push(1)
32
+ @q2.push(2)
33
+
34
+ @q.pop.queue.must_equal @q1
35
+ @q.pop.queue.must_equal @q2
36
+ end
29
37
  end
30
38
 
31
39
  describe "pushing" do
@@ -25,6 +25,24 @@ describe Adrian::Queue do
25
25
  @q.push(item)
26
26
  lambda { @q.pop }.must_raise(Adrian::Queue::ItemTooOldError)
27
27
  end
28
+
29
+ end
30
+
31
+ it 'sets the queue on the items' do
32
+ q = TestQueue.new
33
+
34
+ item = Adrian::QueueItem.new('value', Time.now)
35
+
36
+ item.queue.must_be_nil
37
+
38
+ q.push(item)
39
+
40
+ item.queue.must_be_nil
41
+
42
+ popped_item = q.pop
43
+
44
+ popped_item.must_equal item
45
+ item.queue.must_equal q
28
46
  end
29
47
 
30
48
  end
@@ -7,10 +7,12 @@ describe Adrian::RotatingDirectoryQueue do
7
7
  before do
8
8
  @root_path = Dir.mktmpdir('dir_queue_test')
9
9
  @q = Adrian::RotatingDirectoryQueue.create(:path => @root_path)
10
+ Timecop.freeze
10
11
  end
11
12
 
12
13
  after do
13
- FileUtils.rm_r(@root_path, :force => true)
14
+ Timecop.return
15
+ FileUtils.rm_r(@root_path, :force => true)
14
16
  end
15
17
 
16
18
  describe 'pop' do
@@ -19,20 +21,18 @@ describe Adrian::RotatingDirectoryQueue do
19
21
  @item2 = Adrian::FileItem.new(Tempfile.new('item2').path)
20
22
  @item3 = Adrian::FileItem.new(Tempfile.new('item3').path)
21
23
 
22
- Time.stub(:now, Time.now) do
23
- todays_directory = File.join(@root_path, Time.now.strftime('%Y-%m-%d'))
24
- tomorrows_directory = File.join(@root_path, (Time.now + 60 * 60 * 24).strftime('%Y-%m-%d'))
24
+ todays_directory = File.join(@root_path, Time.now.strftime('%Y-%m-%d'))
25
+ tomorrows_directory = File.join(@root_path, (Time.now + 60 * 60 * 24).strftime('%Y-%m-%d'))
25
26
 
26
- FileUtils.mkdir_p(todays_directory)
27
- FileUtils.mkdir_p(tomorrows_directory)
27
+ FileUtils.mkdir_p(todays_directory)
28
+ FileUtils.mkdir_p(tomorrows_directory)
28
29
 
29
- @item1.move(todays_directory)
30
- @item2.move(tomorrows_directory)
31
- @item3.move(@root_path)
30
+ @item1.move(todays_directory)
31
+ @item2.move(tomorrows_directory)
32
+ @item3.move(@root_path)
32
33
 
33
- @q.pop.must_equal @item1
34
- @q.pop.must_be_nil
35
- end
34
+ @q.pop.must_equal @item1
35
+ @q.pop.must_be_nil
36
36
  end
37
37
  end
38
38
 
@@ -42,15 +42,13 @@ describe Adrian::RotatingDirectoryQueue do
42
42
  end
43
43
 
44
44
  it 'moves the file to the time-stamped available directory' do
45
- Time.stub(:now, Time.now) do
46
- original_path = @item.path
47
- @q.push(@item)
45
+ original_path = @item.path
46
+ @q.push(@item)
48
47
 
49
- assert_equal false, File.exist?(original_path)
50
- assert_equal true, File.exist?(File.join(@q.available_path, @item.name))
48
+ assert_equal false, File.exist?(original_path)
49
+ assert_equal true, File.exist?(File.join(@q.available_path, @item.name))
51
50
 
52
- @item.path.must_equal File.join(@root_path, Time.now.strftime('%Y-%m-%d'), @item.name)
53
- end
51
+ @item.path.must_equal File.join(@root_path, Time.now.strftime('%Y-%m-%d'), @item.name)
54
52
  end
55
53
  end
56
54
 
@@ -10,3 +10,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
10
  require 'adrian'
11
11
 
12
12
  require 'minitest/autorun'
13
+ require 'timecop'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adrian
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-15 00:00:00.000000000 Z
13
+ date: 2013-01-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake