diff --git a/plugins/community_track/lib/ext/article.rb b/plugins/community_track/lib/ext/article.rb new file mode 100644 index 0000000..a7783dc --- /dev/null +++ b/plugins/community_track/lib/ext/article.rb @@ -0,0 +1,12 @@ +require_dependency 'article' + +class Article + + before_create do |article| + if article.parent.kind_of?(CommunityTrackPlugin::Step) + article.accept_comments = article.parent.accept_comments + end + true + end + +end diff --git a/plugins/community_track/test/unit/article_test.rb b/plugins/community_track/test/unit/article_test.rb new file mode 100644 index 0000000..6e47b30 --- /dev/null +++ b/plugins/community_track/test/unit/article_test.rb @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ArticleTest < ActiveSupport::TestCase + + def setup + @profile = fast_create(Community) + @track = create_track('track', @profile) + @step = CommunityTrackPlugin::Step.create!(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + end + + should 'inherit accept_comments from parent if it is a step' do + @step.accept_comments = true + @step.save! + article = Article.create!(:parent => @step, :profile => @profile, :accept_comments => false, :name => "article") + assert article.accept_comments + end + + should 'do nothing if parent is not a step' do + folder = fast_create(Folder, :profile_id => @profile.id) + article = Article.create!(:parent => folder, :profile => @profile, :accept_comments => false, :name => "article") + assert !article.accept_comments + end + +end -- libgit2 0.21.2