Commit 60b07c1ca347204a17d7ac467074baacc7dd579a

Authored by Victor Costa
1 parent 27b7acbc

comment_paragraph: permit the new content type to enable this plugin

plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb
... ... @@ -23,4 +23,8 @@ class CommentParagraphPlugin::Discussion < Event
23 23 environment.plugin_enabled?(CommentParagraphPlugin)
24 24 end
25 25  
  26 + def comment_paragraph_plugin_activation_mode
  27 + "auto"
  28 + end
  29 +
26 30 end
... ...
plugins/comment_paragraph/lib/ext/article.rb
... ... @@ -12,7 +12,7 @@ class Article
12 12 settings_items :comment_paragraph_plugin_activate, :type => :boolean, :default => false
13 13  
14 14 def comment_paragraph_plugin_enabled?
15   - environment.plugin_enabled?(CommentParagraphPlugin) && self.kind_of?(TextArticle)
  15 + environment.plugin_enabled?(CommentParagraphPlugin) && (self.kind_of?(TextArticle) || self.kind_of?(CommentParagraphPlugin::Discussion))
16 16 end
17 17  
18 18 def comment_paragraph_plugin_activated?
... ... @@ -55,7 +55,11 @@ class Article
55 55  
56 56 def comment_paragraph_plugin_set_initial_value
57 57 self.comment_paragraph_plugin_activate = comment_paragraph_plugin_enabled? &&
58   - comment_paragraph_plugin_settings.activation_mode == 'auto'
  58 + comment_paragraph_plugin_activation_mode == 'auto'
  59 + end
  60 +
  61 + def comment_paragraph_plugin_activation_mode
  62 + comment_paragraph_plugin_settings.activation_mode
59 63 end
60 64  
61 65 def comment_paragraph_plugin_settings
... ...
plugins/comment_paragraph/test/unit/api_test.rb
... ... @@ -81,4 +81,13 @@ class APITest < ActiveSupport::TestCase
81 81 json = JSON.parse(last_response.body)
82 82 assert_equivalent [comment1.id], json['comments'].map {|c| c['id']}
83 83 end
  84 +
  85 + should "create discussion article" do
  86 + article = fast_create(Article, :profile_id => person.id)
  87 + params[:article] = {name: "Title", type: "CommentParagraphPlugin::Discussion"}
  88 + post "/api/v1/articles/#{article.id}/children?#{params.to_query}"
  89 + json = JSON.parse(last_response.body)
  90 + assert_equal "CommentParagraphPlugin::Discussion", json["article"]["type"]
  91 + assert json["article"]["setting"]["comment_paragraph_plugin_activate"]
  92 + end
84 93 end
... ...
plugins/comment_paragraph/test/unit/article_test.rb
... ... @@ -170,4 +170,7 @@ class ArticleTest < ActiveSupport::TestCase
170 170 assert_equal nil, article.comment_paragraph_plugin_paragraph_content(1)
171 171 end
172 172  
  173 + should 'be enabled if plugin is enabled and article is a kind of Discussion' do
  174 + assert fast_create(CommentParagraphPlugin::Discussion, profile_id: profile.id).comment_paragraph_plugin_enabled?
  175 + end
173 176 end
... ...
plugins/comment_paragraph/test/unit/discussion_test.rb
... ... @@ -15,6 +15,7 @@ class DiscussionTest < ActiveSupport::TestCase
15 15 discussion = CommentParagraphPlugin::Discussion.new(profile: profile, name: "discussion", start_date: Time.now, end_date: Time.now + 1.day)
16 16 discussion.body = '<ul><li class="custom_class">item1</li><li>item2</li></ul>'
17 17 discussion.save!
  18 + assert discussion.comment_paragraph_plugin_activate
18 19 assert_mark_paragraph discussion.body, 'li', 'item1'
19 20 assert_mark_paragraph discussion.body, 'li', 'item2'
20 21 end
... ...