activeasync 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.3 (2012-02-07)
2
+ * Ability to set ActiveAsync.background via ActiveAsync.mode = :resque or :fake_resque
3
+ * RSpec around blocks: :enable_resque, :stub_resque
4
+
1
5
  ## 0.0.2 (2012-01-26)
2
6
  * railtie for initializing activeasync in rails
3
7
  * rspec module for use in testing
data/README.md CHANGED
@@ -5,6 +5,11 @@ and ruby classes to run methods asynchronously.
5
5
 
6
6
  ActiveAsync currently depends on Resque and ActiveSupport.
7
7
 
8
+ Ruby support:
9
+ - 1.8.7
10
+ - 1.9.2
11
+ - 1.9.3
12
+
8
13
  [![Build Status](https://secure.travis-ci.org/challengepost/activeasync.png)](http://travis-ci.org/challengepost/activeasync)
9
14
 
10
15
  ## Install
@@ -28,10 +33,9 @@ require 'active_async'
28
33
  class HeavyLifter
29
34
  include ActiveAsync::Async
30
35
 
31
- def lift(*stuff)
36
+ def self.lift(*stuff)
32
37
  # heavy lifting
33
38
  end
34
-
35
39
  end
36
40
 
37
41
  HeavyLifter.async(:lift, 1, 2, 3)
@@ -45,11 +49,9 @@ require 'active_async/railtie'
45
49
 
46
50
  # app/models/risky_business.rb
47
51
  class RiskyBusiness < ActiveRecord::Base
48
-
49
52
  def party_time
50
53
  # all night long
51
54
  end
52
-
53
55
  end
54
56
 
55
57
  business = RiskyBusiness.last
@@ -65,7 +67,6 @@ class LateNite < ActiveRecord::Base
65
67
  def drive_home
66
68
  # traffic jam
67
69
  end
68
-
69
70
  end
70
71
 
71
72
  late_nite = LateNite.last
@@ -77,15 +78,13 @@ late_nite.save # runs late_night#drive_home asynchronously after
77
78
  ActiveAsync comes with some helpers support for RSpec.
78
79
 
79
80
  To remove Resque dependency from some of your specs, use the :stub_resque option in
80
- selectd spec blocks. Async methods will run in the foreground.
81
+ selected spec blocks. Async methods will run in the foreground.
81
82
 
82
83
  ``` ruby
83
84
  # spec/spec_helper.rb
84
-
85
85
  require 'active_async/rspec'
86
86
 
87
87
  # spec/models/late_nite_spec.rb
88
-
89
88
  it "drive home after late nite save", :stub_resque do
90
89
  # all methods run in foreground
91
90
  end
data/lib/active_async.rb CHANGED
@@ -7,6 +7,8 @@ require "active_async/callbacks"
7
7
  module ActiveAsync
8
8
  extend self
9
9
 
10
+ class ModeNotSupportedError < StandardError; end
11
+
10
12
  def background
11
13
  @background ||= ::Resque
12
14
  end
@@ -15,8 +17,36 @@ module ActiveAsync
15
17
  @background = background
16
18
  end
17
19
 
20
+ def enqueue(*args)
21
+ background.enqueue(*args)
22
+ end
23
+
18
24
  def reset!
19
25
  @background = nil
26
+ @mode = nil
27
+ end
28
+
29
+ def mode=(mode)
30
+ set_background_for_mode(mode)
31
+ @mode = mode
32
+ end
33
+
34
+ def mode
35
+ @mode || (mode = :resque)
36
+ end
37
+
38
+ private
39
+
40
+ def set_background_for_mode(mode)
41
+ case mode
42
+ when :resque
43
+ @background = ::Resque
44
+ when :fake_resque
45
+ require 'active_async/fake_resque'
46
+ @background = FakeResque
47
+ else
48
+ raise ModeNotSupportedError
49
+ end
20
50
  end
21
51
 
22
52
  end
@@ -3,11 +3,19 @@ require 'active_async/fake_resque'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.treat_symbols_as_metadata_keys_with_true_values = true
6
- config.before(:each, :stub_resque) do |example|
7
- ActiveAsync.background = ActiveAsync::FakeResque
6
+
7
+ config.around(:each, :stub_resque) do |example|
8
+ async_mode = ActiveAsync.mode
9
+ ActiveAsync.mode = :fake_resque
10
+ example.run
11
+ ActiveAsync.mode = async_mode
8
12
  end
9
13
 
10
- config.after(:each, :stub_resque) do |example|
11
- ActiveAsync.background = Resque
14
+ config.around(:each, :enable_resque) do |example|
15
+ async_mode = ActiveAsync.mode
16
+ ActiveAsync.mode = :resque
17
+ example.run
18
+ ActiveAsync.mode = async_mode
12
19
  end
20
+
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveAsync
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ActiveAsync::RSpec" do
4
+
5
+ describe ":stub_resque block" do
6
+
7
+ it "should set async mode to ::Resque in example", :stub_resque do
8
+ ActiveAsync.mode.should == :fake_resque
9
+ end
10
+
11
+ it "should stub_resque in example", :stub_resque do
12
+ ActiveAsync.background.should == ActiveAsync::FakeResque
13
+ end
14
+
15
+ it "should set async mode to ActiveAsync::FakeResque in example", :enable_resque do
16
+ ActiveAsync.mode.should == :resque
17
+ end
18
+
19
+ it "should set async mode to ActiveAsync::FakeResque in example", :enable_resque do
20
+ ActiveAsync.background.should == ::Resque
21
+ end
22
+ end
23
+ end
@@ -16,4 +16,38 @@ describe ActiveAsync do
16
16
  ActiveAsync.background.should == ActiveAsync::FakeResque
17
17
  end
18
18
  end
19
+
20
+ describe "enqueue", :stub_resque do
21
+
22
+ it "should call enqueue on background strategy" do
23
+ ActiveAsync::FakeResque.should_receive(:enqueue).with(:args)
24
+ ActiveAsync.enqueue(:args)
25
+ end
26
+ end
27
+
28
+ describe "mode=" do
29
+ before(:each) do
30
+ ActiveAsync.reset!
31
+ end
32
+
33
+ it "setting to :fake_resque enables FakeResque" do
34
+ ActiveAsync.mode = :fake_resque
35
+ ActiveAsync.background.should == ActiveAsync::FakeResque
36
+ end
37
+
38
+ it "setting to :resque enables Resque" do
39
+ ActiveAsync.mode = :resque
40
+ ActiveAsync.background.should == ::Resque
41
+ end
42
+
43
+ it "should raise ModeNotSupportedError otherwise" do
44
+ lambda { ActiveAsync.mode = :mode_doesnt_exist }.should raise_error(ActiveAsync::ModeNotSupportedError)
45
+ end
46
+
47
+ it "should return mode" do
48
+ ActiveAsync.mode = :fake_resque
49
+ ActiveAsync.mode.should == :fake_resque
50
+ end
51
+ end
52
+
19
53
  end
metadata CHANGED
@@ -1,90 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activeasync
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Ross Kaffenberger
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-01-29 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: resque
16
- requirement: &70145636764700 !ruby/object:Gem::Requirement
17
+
18
+ date: 2012-02-07 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
23
+ requirements:
19
24
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.10'
25
+ - !ruby/object:Gem::Version
26
+ hash: 27
27
+ segments:
28
+ - 1
29
+ - 10
30
+ version: "1.10"
31
+ requirement: *id001
32
+ prerelease: false
33
+ name: resque
22
34
  type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 7
42
+ segments:
43
+ - 3
44
+ - 0
45
+ version: "3.0"
46
+ requirement: *id002
23
47
  prerelease: false
24
- version_requirements: *70145636764700
25
- - !ruby/object:Gem::Dependency
26
48
  name: activesupport
27
- requirement: &70145636764160 !ruby/object:Gem::Requirement
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
28
52
  none: false
29
- requirements:
53
+ requirements:
30
54
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '3.0'
33
- type: :runtime
55
+ - !ruby/object:Gem::Version
56
+ hash: 7
57
+ segments:
58
+ - 3
59
+ - 0
60
+ version: "3.0"
61
+ requirement: *id003
34
62
  prerelease: false
35
- version_requirements: *70145636764160
36
- - !ruby/object:Gem::Dependency
37
63
  name: rails
38
- requirement: &70145636763680 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '3.0'
44
64
  type: :development
45
- prerelease: false
46
- version_requirements: *70145636763680
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: &70145636763200 !ruby/object:Gem::Requirement
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
67
  none: false
51
- requirements:
68
+ requirements:
52
69
  - - ~>
53
- - !ruby/object:Gem::Version
70
+ - !ruby/object:Gem::Version
71
+ hash: 47
72
+ segments:
73
+ - 2
74
+ - 8
75
+ - 0
54
76
  version: 2.8.0
55
- type: :development
77
+ requirement: *id004
56
78
  prerelease: false
57
- version_requirements: *70145636763200
58
- - !ruby/object:Gem::Dependency
59
- name: database_cleaner
60
- requirement: &70145636762700 !ruby/object:Gem::Requirement
79
+ name: rspec
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
61
83
  none: false
62
- requirements:
84
+ requirements:
63
85
  - - ~>
64
- - !ruby/object:Gem::Version
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ - 7
91
+ - 0
65
92
  version: 0.7.0
93
+ requirement: *id005
94
+ prerelease: false
95
+ name: database_cleaner
66
96
  type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ version_requirements: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirement: *id006
67
108
  prerelease: false
68
- version_requirements: *70145636762700
69
- - !ruby/object:Gem::Dependency
70
109
  name: sqlite3
71
- requirement: &70145636762300 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
110
  type: :development
78
- prerelease: false
79
- version_requirements: *70145636762300
80
- description: ! 'Provides async methods ruby objects for queuing background jobs. Currently
81
- supports Resque. Bonus: callback hooks for ActiveRecord objects'
82
- email:
111
+ description: "Provides async methods ruby objects for queuing background jobs. Currently supports Resque. Bonus: callback hooks for ActiveRecord objects"
112
+ email:
83
113
  - rosskaff@gmail.com
84
114
  executables: []
115
+
85
116
  extensions: []
117
+
86
118
  extra_rdoc_files: []
87
- files:
119
+
120
+ files:
88
121
  - .gitignore
89
122
  - .travis.yml
90
123
  - CHANGELOG.md
@@ -105,6 +138,7 @@ files:
105
138
  - spec/active_async/async_spec.rb
106
139
  - spec/active_async/callbacks_spec.rb
107
140
  - spec/active_async/fake_resque_spec.rb
141
+ - spec/active_async/rspec_spec.rb
108
142
  - spec/active_async_spec.rb
109
143
  - spec/dummy/.gitignore
110
144
  - spec/dummy/Rakefile
@@ -137,28 +171,38 @@ files:
137
171
  - spec/dummy/log/.gitkeep
138
172
  - spec/dummy/script/rails
139
173
  - spec/spec_helper.rb
140
- homepage: ''
174
+ homepage: ""
141
175
  licenses: []
176
+
142
177
  post_install_message:
143
178
  rdoc_options: []
144
- require_paths:
179
+
180
+ require_paths:
145
181
  - lib
146
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
147
183
  none: false
148
- requirements:
149
- - - ! '>='
150
- - !ruby/object:Gem::Version
151
- version: '0'
152
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ hash: 3
188
+ segments:
189
+ - 0
190
+ version: "0"
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
192
  none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ hash: 3
197
+ segments:
198
+ - 0
199
+ version: "0"
158
200
  requirements: []
201
+
159
202
  rubyforge_project: activeasync
160
- rubygems_version: 1.8.5
203
+ rubygems_version: 1.8.10
161
204
  signing_key:
162
205
  specification_version: 3
163
206
  summary: Add async support to ruby objects
164
207
  test_files: []
208
+