timberline 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,11 @@ class Timberline
14
14
  if File.exists?(config_file)
15
15
  load_from_yaml(config_file)
16
16
  end
17
+ elsif defined? Rails.root
18
+ config_file = File.join(Rails.root, 'config', 'timberline.yaml')
19
+ if File.exists?(config_file)
20
+ load_from_yaml(config_file)
21
+ end
17
22
  end
18
23
 
19
24
  # load defaults
@@ -1,3 +1,3 @@
1
1
  class Timberline
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
 
3
- require 'shoulda'
3
+ require 'nutrasuite'
4
4
 
5
5
  # include the gem
6
6
  require 'timberline'
@@ -1,12 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ConfigTest < Test::Unit::TestCase
4
- context "Without any preset YAML configs" do
5
- setup do
4
+ a "Config object without any preset YAML configs" do
5
+ before do
6
6
  @config = Timberline::Config.new
7
7
  end
8
8
 
9
- should "build a proper config hash for Redis" do
9
+ it "builds a proper config hash for Redis" do
10
10
  @logger = Logger.new STDERR
11
11
 
12
12
  @config.host = "localhost"
@@ -27,7 +27,7 @@ class ConfigTest < Test::Unit::TestCase
27
27
 
28
28
  end
29
29
 
30
- should "reads configuration from a YAML config file" do
30
+ it "reads configuration from a YAML config file" do
31
31
  base_dir = File.dirname(File.path(__FILE__))
32
32
  yaml_file = File.join(base_dir, "..", "test_config.yaml")
33
33
  @config.load_from_yaml(yaml_file)
@@ -40,17 +40,17 @@ class ConfigTest < Test::Unit::TestCase
40
40
  end
41
41
  end
42
42
 
43
- context "when in a Rails app without a config file" do
44
- setup do
43
+ a "Config object in a Rails app without a config file" do
44
+ before do
45
45
  Object::RAILS_ROOT = File.join(File.dirname(File.path(__FILE__)), "..", "gibberish")
46
46
  @config = Timberline::Config.new
47
47
  end
48
48
 
49
- teardown do
49
+ after do
50
50
  Object.send(:remove_const, :RAILS_ROOT)
51
51
  end
52
52
 
53
- should "load successfully without any configs." do
53
+ it "loads successfully without any configs." do
54
54
  ["database","host","port","timeout","password","logger"].each do |setting|
55
55
  assert_equal nil, @config.instance_variable_get("@#{setting}")
56
56
  end
@@ -62,17 +62,17 @@ class ConfigTest < Test::Unit::TestCase
62
62
  end
63
63
  end
64
64
 
65
- context "when in a Rails app with a config file" do
66
- setup do
65
+ a "Config object in a Rails app with a config file" do
66
+ before do
67
67
  Object::RAILS_ROOT = File.join(File.dirname(File.path(__FILE__)), "..", "fake_rails")
68
68
  @config = Timberline::Config.new
69
69
  end
70
70
 
71
- teardown do
71
+ after do
72
72
  Object.send(:remove_const, :RAILS_ROOT)
73
73
  end
74
74
 
75
- should "load the config/timberline.yaml file" do
75
+ it "loads the config/timberline.yaml file" do
76
76
  assert_equal "localhost", @config.host
77
77
  assert_equal 12345, @config.port
78
78
  assert_equal 10, @config.timeout
@@ -82,17 +82,17 @@ class ConfigTest < Test::Unit::TestCase
82
82
  end
83
83
  end
84
84
 
85
- context "when TIMBERLINE_YAML is defined" do
86
- setup do
85
+ a "Config object when TIMBERLINE_YAML is defined" do
86
+ before do
87
87
  Object::TIMBERLINE_YAML = File.join(File.dirname(File.path(__FILE__)), "..", "test_config.yaml")
88
88
  @config = Timberline::Config.new
89
89
  end
90
90
 
91
- teardown do
91
+ after do
92
92
  Object.send(:remove_const, :TIMBERLINE_YAML)
93
93
  end
94
94
 
95
- should "load the specified yaml file" do
95
+ it "loads the specified yaml file" do
96
96
  assert_equal "localhost", @config.host
97
97
  assert_equal 12345, @config.port
98
98
  assert_equal 10, @config.timeout
@@ -102,16 +102,16 @@ class ConfigTest < Test::Unit::TestCase
102
102
  end
103
103
  end
104
104
 
105
- context "when TIMBERLINE_YAML is defined, but doesn't exist" do
106
- setup do
105
+ a "Config object when TIMBERLINE_YAML is defined, but doesn't exist" do
106
+ before do
107
107
  Object::TIMBERLINE_YAML = File.join(File.dirname(File.path(__FILE__)), "..", "fake_config.yaml")
108
108
  end
109
109
 
110
- teardown do
110
+ after do
111
111
  Object.send(:remove_const, :TIMBERLINE_YAML)
112
112
  end
113
113
 
114
- should "raise an exception" do
114
+ it "raises an exception" do
115
115
  assert_raises RuntimeError do
116
116
  @config = Timberline::Config.new
117
117
  end
@@ -3,51 +3,51 @@ require 'date'
3
3
 
4
4
  class EnvelopeTest < Test::Unit::TestCase
5
5
 
6
- context "newly instantiated" do
7
- setup do
6
+ a "newly instantiated Envelope object" do
7
+ before do
8
8
  @envelope = Timberline::Envelope.new
9
9
  end
10
10
 
11
- should "raises a MissingContentException when to_s is called because the contents are nil" do
11
+ it "raises a MissingContentException when to_s is called because the contents are nil" do
12
12
  assert_raises Timberline::MissingContentException do
13
13
  @envelope.to_s
14
14
  end
15
15
  end
16
16
 
17
- should "has an empty hash for metadata" do
17
+ it "has an empty hash for metadata" do
18
18
  assert_equal({}, @envelope.metadata)
19
19
  end
20
20
 
21
- should "allows for the reading of attributes via method_missing magic" do
21
+ it "allows for the reading of attributes via method_missing magic" do
22
22
  @envelope.metadata["original_queue"] = "test_queue"
23
23
  assert_equal "test_queue", @envelope.original_queue
24
24
  end
25
25
 
26
- should "allows for the setting of attributes via method_missing magic" do
26
+ it "allows for the setting of attributes via method_missing magic" do
27
27
  @envelope.original_queue = "test_queue"
28
28
  assert_equal "test_queue", @envelope.metadata["original_queue"]
29
29
  end
30
30
  end
31
31
 
32
- context "with contents" do
33
- setup do
32
+ an "Envelope object with contents" do
33
+ before do
34
34
  @envelope = Timberline::Envelope.new
35
35
  @envelope.contents = "Test data"
36
36
  end
37
37
 
38
- should "returns a JSON string when to_s is called" do
38
+ it "returns a JSON string when to_s is called" do
39
39
  json_string = @envelope.to_s
40
40
  json_data = JSON.parse(json_string)
41
41
  assert_equal "Test data", json_data["contents"]
42
42
  end
43
43
 
44
- should "only includes a 'contents' parameter by default" do
44
+ it "only includes a 'contents' parameter by default" do
45
45
  json_string = @envelope.to_s
46
46
  json_data = JSON.parse(json_string)
47
47
  assert_equal 1, json_data.keys.size
48
48
  end
49
49
 
50
- should "also includes metadata, if provided" do
50
+ it "also includes metadata, if provided" do
51
51
  time = DateTime.now
52
52
  time_s = DateTime.now.to_s
53
53
  @envelope.first_posted = time
@@ -59,7 +59,7 @@ class EnvelopeTest < Test::Unit::TestCase
59
59
  assert_equal time_s, json_data["first_posted"]
60
60
  end
61
61
 
62
- should "parses itself back correctly using from_json" do
62
+ it "parses itself back correctly using from_json" do
63
63
  json_string = @envelope.to_s
64
64
  new_envelope = Timberline::Envelope.from_json(json_string)
65
65
  assert_equal @envelope.contents, new_envelope.contents
@@ -1,51 +1,51 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class QueueTest < Test::Unit::TestCase
4
- context "newly instantiated" do
5
- setup do
4
+ a "newly instantiated Queue" do
5
+ before do
6
6
  clear_test_db
7
7
  @queue = Timberline::Queue.new("test_queue")
8
8
  end
9
9
 
10
- should "saves the passed-in string as its queue name" do
10
+ it "saves the passed-in string as its queue name" do
11
11
  assert_equal "test_queue", @queue.queue_name
12
12
  end
13
13
 
14
- should "saves its existence in timberline_queue_names" do
14
+ it "saves its existence in timberline_queue_names" do
15
15
  assert_equal true, Timberline.redis.sismember("timberline_queue_names", "test_queue")
16
16
  end
17
17
 
18
- should "has a length of 0" do
18
+ it "has a length of 0" do
19
19
  assert_equal 0, @queue.length
20
20
  end
21
21
 
22
- should "starts in an unpaused state" do
22
+ it "starts in an unpaused state" do
23
23
  assert_equal false, @queue.paused?
24
24
  end
25
25
 
26
- should "allows itself to be paused and unpaused" do
26
+ it "allows itself to be paused and unpaused" do
27
27
  @queue.pause
28
28
  assert_equal true, @queue.paused?
29
29
  @queue.unpause
30
30
  assert_equal false, @queue.paused?
31
31
  end
32
32
 
33
- should "has a default read_timeout of 0" do
33
+ it "has a default read_timeout of 0" do
34
34
  assert_equal 0, @queue.read_timeout
35
35
  end
36
36
 
37
- should "responds nil to a pop request after the read_timeout occurs" do
37
+ it "responds nil to a pop request after the read_timeout occurs" do
38
38
  # Let's set the read_timeout to 1 in order for this test to return
39
39
  @queue.instance_variable_set("@read_timeout", 1)
40
40
  assert_equal nil, @queue.pop
41
41
  end
42
42
 
43
- should "puts an item on the queue when that item is pushed" do
43
+ it "puts an item on the queue when that item is pushed" do
44
44
  test_item = "Test Queue Item"
45
45
  assert_equal 1, @queue.push(test_item)
46
46
  end
47
47
 
48
- should "wraps an item in an envelope when that item is pushed" do
48
+ it "wraps an item in an envelope when that item is pushed" do
49
49
  test_item = "Test Queue Item"
50
50
  assert_equal 1, @queue.push(test_item)
51
51
  data = @queue.pop
@@ -53,7 +53,7 @@ class QueueTest < Test::Unit::TestCase
53
53
  assert_equal test_item, data.contents
54
54
  end
55
55
 
56
- should "doesn't wrap an envelope that gets pushed in another envelope" do
56
+ it "doesn't wrap an envelope that gets pushed in another envelope" do
57
57
  test_item = "Test Queue Item"
58
58
  env = Timberline::Envelope.new
59
59
  env.contents = test_item
@@ -63,7 +63,7 @@ class QueueTest < Test::Unit::TestCase
63
63
  assert_equal test_item, data.contents
64
64
  end
65
65
 
66
- should "removes everything associated with the queue when delete! is called" do
66
+ it "removes everything associated with the queue when delete! is called" do
67
67
  test_item = "Test Queue Item"
68
68
  assert_equal 1, @queue.push(test_item)
69
69
  Timberline.redis[@queue.attr("test")] = "test"
@@ -78,7 +78,7 @@ class QueueTest < Test::Unit::TestCase
78
78
  assert_equal false, Timberline.redis.sismember("timberline_queue_names","test_queue")
79
79
  end
80
80
 
81
- should "uses any passed-in metadata to push when building the envelope" do
81
+ it "uses any passed-in metadata to push when building the envelope" do
82
82
  @queue.push("Howdy kids.", { :special_notes => "Super-awesome."})
83
83
  assert_equal 1, @queue.length
84
84
  data = @queue.pop
@@ -88,23 +88,23 @@ class QueueTest < Test::Unit::TestCase
88
88
 
89
89
  end
90
90
 
91
- context "with one item" do
92
- setup do
91
+ a "Queue with one item" do
92
+ before do
93
93
  clear_test_db
94
94
  @test_item = "Test Queue Item"
95
95
  @queue = Timberline::Queue.new("test_queue")
96
96
  @queue.push(@test_item)
97
97
  end
98
98
 
99
- should "has a length of 1" do
99
+ it "has a length of 1" do
100
100
  assert_equal 1, @queue.length
101
101
  end
102
102
 
103
- should "responds to pop with the one item" do
103
+ it "responds to pop with the one item" do
104
104
  assert_equal @test_item, @queue.pop.contents
105
105
  end
106
106
 
107
- should "responds nil to a second pop" do
107
+ it "responds nil to a second pop" do
108
108
  # Let's set the read_timeout to 1 in order for this test to return
109
109
  @queue.instance_variable_set("@read_timeout", 1)
110
110
  assert_equal @test_item, @queue.pop.contents
@@ -1,59 +1,59 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TimberlineTest < Test::Unit::TestCase
4
- context "Freshly set up" do
5
- setup do
4
+ a "Freshly set up Timberline" do
5
+ before do
6
6
  reset_timberline
7
7
  end
8
8
 
9
- should "creates a new queue when asked if it doesn't exist" do
9
+ it "creates a new queue when asked if it doesn't exist" do
10
10
  queue = Timberline.queue("test_queue")
11
11
  assert_kind_of Timberline::Queue, queue
12
12
  assert_equal queue, Timberline.instance_variable_get("@queue_list")["test_queue"]
13
13
  end
14
14
 
15
- should "doesn't create a new queue if a queue by the same name already exists" do
15
+ it "doesn't create a new queue if a queue by the same name already exists" do
16
16
  queue = Timberline.queue("test_queue")
17
17
  new_queue = Timberline.queue("test_queue")
18
18
  assert_equal queue, new_queue
19
19
  end
20
20
 
21
- should "creates a new queue as necessary when 'push' is called and pushes the item" do
21
+ it "creates a new queue as necessary when 'push' is called and pushes the item" do
22
22
  Timberline.push("test_queue", "Howdy kids.")
23
23
  queue = Timberline.queue("test_queue")
24
24
  assert_equal 1, queue.length
25
25
  assert_equal "Howdy kids.", queue.pop.contents
26
26
  end
27
27
 
28
- should "logs the existence of the queue so that other managers can see it" do
28
+ it "logs the existence of the queue so that other managers can see it" do
29
29
  queue = Timberline.queue("test_queue")
30
30
  assert_equal 1, Timberline.all_queues.size
31
31
  assert_equal "test_queue", Timberline.all_queues.first.queue_name
32
32
  end
33
33
 
34
- should "saves a passed-in redis namespace" do
34
+ it "saves a passed-in redis namespace" do
35
35
  redis = Redis.new
36
36
  redisns = Redis::Namespace.new("timberline", redis)
37
37
  Timberline.redis = redisns
38
38
  assert_equal redisns, Timberline.redis
39
39
  end
40
40
 
41
- should "Converts a standard redis server into a namespace" do
41
+ it "Converts a standard redis server into a namespace" do
42
42
  redis = Redis.new
43
43
  Timberline.redis = redis
44
44
  assert_equal Redis::Namespace, Timberline.redis.class
45
45
  assert_equal redis, Timberline.redis.instance_variable_get("@redis")
46
46
  end
47
47
 
48
- should "generates a redis namespace on request if one isn't present" do
48
+ it "generates a redis namespace on request if one isn't present" do
49
49
  assert_equal Redis::Namespace, Timberline.redis.class
50
50
  end
51
51
 
52
- should "uses a default namespace of 'timberline'" do
52
+ it "uses a default namespace of 'timberline'" do
53
53
  assert_equal "timberline", Timberline.redis.namespace
54
54
  end
55
55
 
56
- should "can be configured" do
56
+ it "can be configured" do
57
57
  Timberline.config do |c|
58
58
  c.database = 3
59
59
  end
@@ -61,7 +61,7 @@ class TimberlineTest < Test::Unit::TestCase
61
61
  assert_equal 3, Timberline.instance_variable_get("@config").database
62
62
  end
63
63
 
64
- should "uses a pre-defined namespace name if configured" do
64
+ it "uses a pre-defined namespace name if configured" do
65
65
  Timberline.config do |c|
66
66
  c.namespace = "skyline"
67
67
  end
@@ -69,7 +69,7 @@ class TimberlineTest < Test::Unit::TestCase
69
69
  assert_equal "skyline", Timberline.redis.namespace
70
70
  end
71
71
 
72
- should "properly configures Redis" do
72
+ it "properly configures Redis" do
73
73
  @logger = Logger.new STDERR
74
74
  Timberline.config do |c|
75
75
  c.host = "localhost"
@@ -87,7 +87,7 @@ class TimberlineTest < Test::Unit::TestCase
87
87
 
88
88
  end
89
89
 
90
- should "allows you to retry a job that has failed" do
90
+ it "allows you to retry a job that has failed" do
91
91
  Timberline.push("test_queue", "Howdy kids.")
92
92
  queue = Timberline.queue("test_queue")
93
93
  data = queue.pop
@@ -105,7 +105,7 @@ class TimberlineTest < Test::Unit::TestCase
105
105
  assert_kind_of Time, Time.at(data.last_tried_at)
106
106
  end
107
107
 
108
- should "will continue retrying until we pass the max retries (defaults to 5)" do
108
+ it "will continue retrying until we pass the max retries (defaults to 5)" do
109
109
  Timberline.push("test_queue", "Howdy kids.")
110
110
  queue = Timberline.queue("test_queue")
111
111
  data = queue.pop
@@ -126,7 +126,7 @@ class TimberlineTest < Test::Unit::TestCase
126
126
  assert_equal 1, Timberline.error_queue.length
127
127
  end
128
128
 
129
- should "will allow you to directly error out a job" do
129
+ it "will allow you to directly error out a job" do
130
130
  Timberline.push("test_queue", "Howdy kids.")
131
131
  queue = Timberline.queue("test_queue")
132
132
  data = queue.pop
data/timberline.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_runtime_dependency "trollop"
28
28
  s.add_runtime_dependency "daemons"
29
29
 
30
- s.add_development_dependency "shoulda"
30
+ s.add_development_dependency "nutrasuite"
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timberline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-14 00:00:00.000000000 Z
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70354056089500 !ruby/object:Gem::Requirement
16
+ requirement: &70170052225180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70354056089500
24
+ version_requirements: *70170052225180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70354056077200 !ruby/object:Gem::Requirement
27
+ requirement: &70170052221160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70354056077200
35
+ version_requirements: *70170052221160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis-expiring-set
38
- requirement: &70354056075820 !ruby/object:Gem::Requirement
38
+ requirement: &70170052235160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70354056075820
46
+ version_requirements: *70170052235160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70354056073880 !ruby/object:Gem::Requirement
49
+ requirement: &70170052233420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70354056073880
57
+ version_requirements: *70170052233420
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: daemons
60
- requirement: &70354056071600 !ruby/object:Gem::Requirement
60
+ requirement: &70170052228980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70354056071600
68
+ version_requirements: *70170052228980
69
69
  - !ruby/object:Gem::Dependency
70
- name: shoulda
71
- requirement: &70354056070520 !ruby/object:Gem::Requirement
70
+ name: nutrasuite
71
+ requirement: &70170052243880 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70354056070520
79
+ version_requirements: *70170052243880
80
80
  description: Timberline is a simple and extensible queuing system built in Ruby and
81
81
  backed by Redis. It makes as few assumptions as possible about how you want to interact
82
82
  with your queues while also allowing for some functionality that should be universally
@@ -102,10 +102,10 @@ files:
102
102
  - test/partial_minispec.rb
103
103
  - test/test_config.yaml
104
104
  - test/test_helper.rb
105
- - test/unit/test_config.rb
106
- - test/unit/test_envelope.rb
107
- - test/unit/test_queue.rb
108
- - test/unit/test_timberline.rb
105
+ - test/unit/config_test.rb
106
+ - test/unit/envelope_test.rb
107
+ - test/unit/queue_test.rb
108
+ - test/unit/timberline_test.rb
109
109
  - timberline.gemspec
110
110
  homepage: http://github.com/duwanis/timberline
111
111
  licenses: []
@@ -137,7 +137,8 @@ test_files:
137
137
  - test/partial_minispec.rb
138
138
  - test/test_config.yaml
139
139
  - test/test_helper.rb
140
- - test/unit/test_config.rb
141
- - test/unit/test_envelope.rb
142
- - test/unit/test_queue.rb
143
- - test/unit/test_timberline.rb
140
+ - test/unit/config_test.rb
141
+ - test/unit/envelope_test.rb
142
+ - test/unit/queue_test.rb
143
+ - test/unit/timberline_test.rb
144
+ has_rdoc: