From e168cf92fee529d1091604b632159e3f815c2c0b Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 6 Dec 2013 14:53:14 -0300 Subject: [PATCH] Change community track to allow visualization of inactive steps --- plugins/community_track/lib/community_track_plugin/activation_job.rb | 2 +- plugins/community_track/lib/community_track_plugin/step.rb | 23 ++++++++++++++--------- plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb | 16 +++------------- plugins/community_track/test/unit/community_track_plugin/step_test.rb | 65 +++++++++++++++++++++++++++++++++++++++-------------------------- 4 files changed, 57 insertions(+), 49 deletions(-) diff --git a/plugins/community_track/lib/community_track_plugin/activation_job.rb b/plugins/community_track/lib/community_track_plugin/activation_job.rb index 9fc0b87..abae756 100644 --- a/plugins/community_track/lib/community_track_plugin/activation_job.rb +++ b/plugins/community_track/lib/community_track_plugin/activation_job.rb @@ -6,7 +6,7 @@ class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) def perform step = CommunityTrackPlugin::Step.find(step_id) - step.publish + step.toggle_activation end end diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb index 6ffa00b..e697e26 100644 --- a/plugins/community_track/lib/community_track_plugin/step.rb +++ b/plugins/community_track/lib/community_track_plugin/step.rb @@ -18,7 +18,7 @@ class CommunityTrackPlugin::Step < Folder after_save :schedule_activation before_create do |step| - step.published = false + step.accept_comments = false true end @@ -55,7 +55,7 @@ class CommunityTrackPlugin::Step < Folder end def accept_comments? - true + accept_comments end def self.enabled_tools @@ -82,18 +82,23 @@ class CommunityTrackPlugin::Step < Folder end def schedule_activation - return if !changes['start_date'] && !changes['end_date'] && !changes['published'] - today = Date.today - if today <= end_date || published - schedule_date = !published ? start_date : end_date + 1.day + return if !changes['start_date'] && !changes['end_date'] + if Date.today <= end_date || accept_comments + schedule_date = !accept_comments ? start_date : end_date + 1.day CommunityTrackPlugin::ActivationJob.find(id).destroy_all Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) end end - def publish - self[:published] = active? && !hidden - save! + def toggle_activation + accept_comments = active? + # set accept_comments = true on all children + self.class.toggle_activation(self, accept_comments) + end + + def self.toggle_activation(article, accept_comments) + article.update_attribute(:accept_comments, accept_comments) + article.children.each {|a| toggle_activation(a, accept_comments)} end def tool_class diff --git a/plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb b/plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb index ef68432..049096a 100644 --- a/plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb @@ -15,24 +15,14 @@ class ActivationJobTest < ActiveSupport::TestCase assert CommunityTrackPlugin::ActivationJob.find(step_id) end - should 'change publish to true on perform delayed job in a active step' do + should 'change accept_comments to true on perform delayed job in a active step' do @step.start_date = Date.today @step.end_date = Date.today + 2.days - @step.published = false + @step.accept_comments = false @step.save! CommunityTrackPlugin::ActivationJob.new(@step.id).perform @step.reload - assert @step.published - end - - should 'reschedule delayed job after change publish to true' do - @step.start_date = Date.today - @step.end_date = Date.today + 2.days - @step.published = false - @step.save! - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date - process_delayed_job_queue - assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date + assert @step.accept_comments end end diff --git a/plugins/community_track/test/unit/community_track_plugin/step_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_test.rb index d9145d2..7f545ea 100644 --- a/plugins/community_track/test/unit/community_track_plugin/step_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/step_test.rb @@ -21,10 +21,10 @@ class StepTest < ActiveSupport::TestCase assert CommunityTrackPlugin::Step.short_description end - should 'set published to false on create' do + should 'set accept_comments to false on create' do today = Date.today step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) - assert !step.published + assert !step.accept_comments end should 'do not allow step creation with a parent that is not a track' do @@ -97,6 +97,7 @@ class StepTest < ActiveSupport::TestCase should 'create delayed job' do @step.start_date = Date.today @step.end_date = Date.today + @step.accept_comments = false @step.schedule_activation assert_equal 1, Delayed::Job.count assert_equal @step.start_date, Delayed::Job.first.run_at.to_date @@ -106,6 +107,7 @@ class StepTest < ActiveSupport::TestCase @step.start_date = Date.today @step.end_date = Date.today @step.schedule_activation + assert_equal 1, Delayed::Job.count @step.schedule_activation assert_equal 1, Delayed::Job.count end @@ -120,30 +122,21 @@ class StepTest < ActiveSupport::TestCase should 'create delayed job even if start date has passed' do @step.start_date = Date.today - 2.days @step.end_date = Date.today + @step.accept_comments = false @step.schedule_activation assert_equal @step.start_date, Delayed::Job.first.run_at.to_date end - should 'do not create delayed job if end date has passed and step is not published' do + should 'create delayed job if end date has passed' do @step.start_date = Date.today - 5.days @step.end_date = Date.today - 2.days - @step.published = false - @step.schedule_activation - assert_equal 0, Delayed::Job.count - end - - should 'create delayed job if end date has passed and step is published' do - @step.start_date = Date.today - 5.days - @step.end_date = Date.today - 2.days - @step.published = true @step.schedule_activation assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date end - should 'do not schedule delayed job if save but do not modify date fields and published status' do + should 'do not schedule delayed job if save but do not modify date fields' do @step.start_date = Date.today @step.end_date = Date.today - @step.published = false @step.save! assert_equal 1, Delayed::Job.count Delayed::Job.destroy_all @@ -161,38 +154,38 @@ class StepTest < ActiveSupport::TestCase assert_equal 2, step2.position end - should 'publish step if it is active' do + should 'accept comments if step is active' do @step.start_date = Date.today @step.save! - assert !@step.published - @step.publish + assert !@step.accept_comments + @step.toggle_activation @step.reload - assert @step.published + assert @step.accept_comments end - should 'do not publish step if it is not active' do + should 'do not accept comments if step is not active' do @step.start_date = Date.today + 2.days @step.end_date = Date.today + 3.days @step.save! assert !@step.published - @step.publish + @step.toggle_activation @step.reload assert !@step.published end - should 'unpublish step if it is not active anymore' do + should 'do not accept comments if step is not active anymore' do @step.start_date = Date.today @step.save! - @step.publish + @step.toggle_activation @step.reload - assert @step.published + assert @step.accept_comments @step.start_date = Date.today - 2.days @step.end_date = Date.today - 1.day @step.save! - @step.publish + @step.toggle_activation @step.reload - assert !@step.published + assert !@step.accept_comments end should 'set position to zero if step is hidden' do @@ -236,7 +229,7 @@ class StepTest < ActiveSupport::TestCase @step.hidden = true @step.save! assert !@step.published - @step.publish + @step.toggle_activation @step.reload assert !@step.published end @@ -272,4 +265,24 @@ class StepTest < ActiveSupport::TestCase assert step.end_date end + should 'enable comments on children when step is activated' do + @step.start_date = Date.today + @step.save! + assert !@step.accept_comments + article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) + assert !article.accept_comments + @step.toggle_activation + assert article.reload.accept_comments + end + + should 'enable comments on children when step is active' do + @step.start_date = Date.today + @step.start_date = Date.today + @step.save! + assert !@step.accept_comments + @step.toggle_activation + article = Article.create!(:parent => @step, :profile => @step.profile, :accept_comments => false, :name => "article") + assert article.reload.accept_comments + end + end -- libgit2 0.21.2