Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing TODO for loading stage as string. Rails autoload avoids the …

…necessity of requiring each stage individually
  • Loading branch information...
commit 935a1f4f8ba5eaa1370352442411f14aedb26e12 1 parent ba4c6d8
@dtsato authored
Showing with 36 additions and 1 deletion.
  1. +0 −1  TODO
  2. +29 −0 spec/models.rb
  3. +7 −0 spec/pipeline/stage/base_spec.rb
View
1  TODO
@@ -1,6 +1,5 @@
* Add examples of view display
* view helpers?
-* Chaining stages with string (to avoid having to load stages before pipeline)
* Adapter for other persistence frameworks (ActiveModel?)
* Adapter for other background processing mechanisms (currently relying on dj's auto-retry)
* Max attempts on pipeline (or stage)
View
29 spec/models.rb
@@ -69,4 +69,33 @@ def run
private
def before_stage_callback; end
def after_stage_callback; end
+end
+
+class SampleStageWithCallback < Pipeline::Stage::Base
+ attr_writer :before_stage_executed, :after_stage_executed
+
+ before_stage do |stage|
+ puts "called"
+ stage.before_stage_executed += 1
+ end
+
+ after_stage do |stage|
+ stage.after_stage_executed += 1
+ end
+
+ def run
+ # nothing...
+ end
+
+ def before_stage_executed
+ @before_stage_executed ||= 0
+ end
+
+ def after_stage_executed
+ @after_stage_executed ||= 0
+ end
+end
+
+class SamplePipelineWithCallbacks < Pipeline::Base
+ define_stages SampleStageWithCallback >> SampleStage
end
View
7 spec/pipeline/stage/base_spec.rb
@@ -269,6 +269,13 @@ def run
@stage.should_receive(:after_stage_callback).once
lambda {@stage.perform}.should raise_error
end
+
+ it "should run callback once for each stage" do
+ pipeline = ::SamplePipelineWithCallbacks.new
+ pipeline.perform
+ pipeline.stages[0].before_stage_executed.should == 1
+ pipeline.stages[0].after_stage_executed.should == 1
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.