Permalink
Browse files

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

…necessity of requiring each stage individually
  • Loading branch information...
dtsato committed Jan 26, 2010
1 parent ba4c6d8 commit 935a1f4f8ba5eaa1370352442411f14aedb26e12
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
@@ -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
@@ -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

0 comments on commit 935a1f4

Please sign in to comment.