Commit b942e7fe9fc40d08b02cc19a8209bf4bade6c8b8

Authored by Victor Costa
1 parent d870ebf0

Put activation_job in a separate file for community track

plugins/community_track/lib/community_track_plugin/activation_job.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)
  2 +
  3 + def self.find(step_id)
  4 + Delayed::Job.where(:handler => "--- !ruby/struct:CommunityTrackPlugin::ActivationJob \nstep_id: #{step_id}\n")
  5 + end
  6 +
  7 + def perform
  8 + step = CommunityTrackPlugin::Step.find(step_id)
  9 + step.publish
  10 + end
  11 +
  12 +end
... ...
plugins/community_track/lib/community_track_plugin/step.rb
... ... @@ -104,17 +104,4 @@ class CommunityTrackPlugin::Step &lt; Folder
104 104 tools.find(:first, :conditions => {:type => tool_type })
105 105 end
106 106  
107   - class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)
108   -
109   - def self.find(step_id)
110   - Delayed::Job.where(:handler => "--- !ruby/struct:CommunityTrackPlugin::ActivationJob \nstep_id: #{step_id}\n")
111   - end
112   -
113   - def perform
114   - step = CommunityTrackPlugin::Step.find(step_id)
115   - step.publish
116   - end
117   -
118   - end
119   -
120 107 end
... ...
plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +require File.dirname(__FILE__) + '/../../test_helper'
  2 +
  3 +class ActivationJobTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Community)
  7 + @track = create_track('track', @profile)
  8 + @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
  9 + Delayed::Job.destroy_all
  10 + end
  11 +
  12 + should 'return delayed job created with a specific step_id' do
  13 + step_id = 0
  14 + CommunityTrackPlugin::ActivationJob.new(step_id)
  15 + assert CommunityTrackPlugin::ActivationJob.find(step_id)
  16 + end
  17 +
  18 + should 'change publish to true on perform delayed job in a active step' do
  19 + @step.start_date = Date.today
  20 + @step.end_date = Date.today + 2.days
  21 + @step.published = false
  22 + @step.save!
  23 + CommunityTrackPlugin::ActivationJob.new(@step.id).perform
  24 + @step.reload
  25 + assert @step.published
  26 + end
  27 +
  28 + should 'reschedule delayed job after change publish to true' do
  29 + @step.start_date = Date.today
  30 + @step.end_date = Date.today + 2.days
  31 + @step.published = false
  32 + @step.save!
  33 + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
  34 + process_delayed_job_queue
  35 + assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
  36 + end
  37 +
  38 +end
... ...
plugins/community_track/test/unit/community_track_plugin/step_test.rb
... ... @@ -140,26 +140,6 @@ class StepTest &lt; ActiveSupport::TestCase
140 140 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
141 141 end
142 142  
143   - should 'change publish to true on perform delayed job in a active step' do
144   - @step.start_date = Date.today
145   - @step.end_date = Date.today + 2.days
146   - @step.published = false
147   - @step.save!
148   - CommunityTrackPlugin::ActivationJob.new(@step.id).perform
149   - @step.reload
150   - assert @step.published
151   - end
152   -
153   - should 'reschedule delayed job after change publish to true' do
154   - @step.start_date = Date.today
155   - @step.end_date = Date.today + 2.days
156   - @step.published = false
157   - @step.save!
158   - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
159   - process_delayed_job_queue
160   - assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
161   - end
162   -
163 143 should 'do not schedule delayed job if save but do not modify date fields and published status' do
164 144 @step.start_date = Date.today
165 145 @step.end_date = Date.today
... ...