Commit 86ef31c1e968ce7521b34c74034901b71c1eb6a4

Authored by Victor Costa
1 parent 00c030b0

Handle steps childrend activation

plugins/community_track/lib/ext/article.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + before_create do |article|
  6 + if article.parent.kind_of?(CommunityTrackPlugin::Step)
  7 + article.accept_comments = article.parent.accept_comments
  8 + end
  9 + true
  10 + end
  11 +
  12 +end
... ...
plugins/community_track/test/unit/article_test.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ArticleTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Community)
  7 + @track = create_track('track', @profile)
  8 + @step = CommunityTrackPlugin::Step.create!(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
  9 + end
  10 +
  11 + should 'inherit accept_comments from parent if it is a step' do
  12 + @step.accept_comments = true
  13 + @step.save!
  14 + article = Article.create!(:parent => @step, :profile => @profile, :accept_comments => false, :name => "article")
  15 + assert article.accept_comments
  16 + end
  17 +
  18 + should 'do nothing if parent is not a step' do
  19 + folder = fast_create(Folder, :profile_id => @profile.id)
  20 + article = Article.create!(:parent => folder, :profile => @profile, :accept_comments => false, :name => "article")
  21 + assert !article.accept_comments
  22 + end
  23 +
  24 +end
... ...