[Git][noosfero/noosfero][master] save body content of comment paragraph plugin

Leandro Nunes gitlab at mg.gitlab.com
Fri Sep 9 18:16:27 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
f4d6132d by Leandro Nunes dos Santos at 2016-09-09T18:15:55-03:00
save body content of comment paragraph plugin

- - - - -


5 changed files:

- + plugins/comment_paragraph/features/cms.feature
- plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
- plugins/comment_paragraph/lib/ext/article.rb
- plugins/comment_paragraph/test/unit/discussion_block_test.rb
- plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb


Changes:

=====================================
plugins/comment_paragraph/features/cms.feature
=====================================
--- /dev/null
+++ b/plugins/comment_paragraph/features/cms.feature
@@ -0,0 +1,23 @@
+Feature: Create a new Discussion Article
+  As a noosfero user
+  I want to create a discusssion article
+
+  Background:
+    Given Noosfero is configured to use English as default
+    Given plugin CommentParagraph is enabled on environment
+    Given I am on the homepage
+    And the following users
+      | login     | name       |
+      | joaosilva | Joao Silva |
+    And I am logged in as "joaosilva"
+
+  @selenium
+  Scenario: discussion article should save content body
+  Given I am on joaosilva's control panel
+  And I follow "Manage Content"
+  And I follow "New content"
+  When I follow "Comments Discussion"
+  And I fill in "Title" with "My discussion"
+  And I fill in tinyMCE "article_body" with "My discussion body!!!"
+  And I press "Save"
+  Then I should see "My discussion body!!!"


=====================================
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
=====================================
--- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
+++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
@@ -22,7 +22,7 @@ class CommentParagraphPlugin::DiscussionBlock < Block
 
   def discussions
     current_time = Time.now
-    discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date DESC, created_at DESC').limit(self.total_items)
+    discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date ASC, created_at DESC').limit(self.total_items)
     case discussion_status
     when STATUS_NOT_OPENED
       discussions = discussions.where("start_date > ?", current_time)


=====================================
plugins/comment_paragraph/lib/ext/article.rb
=====================================
--- a/plugins/comment_paragraph/lib/ext/article.rb
+++ b/plugins/comment_paragraph/lib/ext/article.rb
@@ -49,7 +49,8 @@ class Article
         commentable.inner_html = paragraph.inner_html
         paragraph.inner_html = commentable
       end
-      self.body = doc.at('body').inner_html
+      doc_body =  doc.at('body')
+      self.body = doc_body.inner_html if doc_body
     end
   end
 


=====================================
plugins/comment_paragraph/test/unit/discussion_block_test.rb
=====================================
--- a/plugins/comment_paragraph/test/unit/discussion_block_test.rb
+++ b/plugins/comment_paragraph/test/unit/discussion_block_test.rb
@@ -79,6 +79,21 @@ class DiscussionBlockTest < ActiveSupport::TestCase
     assert_equivalent [a1, a2], b.discussions
   end
 
+  should 'return only not opened discussions if discussion status is not opened odered by end_date' do
+    community = fast_create(Community)
+    community.boxes << Box.new
+    b = CommentParagraphPlugin::DiscussionBlock.new
+    b.box = community.boxes.last
+    b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_NOT_OPENED
+    b.save
+    current_date = DateTime.now + 1
+    a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 7.day)
+    a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 3.day)
+    a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 1.day)
+    a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 4.day)
+    assert_equal [a3, a2, a4, a1], b.discussions
+  end
+
   should 'return only not opened discussions if discussion status is not opened' do
     community = fast_create(Community)
     community.boxes << Box.new
@@ -108,6 +123,21 @@ class DiscussionBlockTest < ActiveSupport::TestCase
     assert_equivalent [a2, a3, a5], b.discussions
   end
 
+  should 'return only available discussions if discussion status is available odered by end_date' do
+    community = fast_create(Community)
+    community.boxes << Box.new
+    b = CommentParagraphPlugin::DiscussionBlock.new
+    b.box = community.boxes.last
+    b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_AVAILABLE
+    b.save
+    current_date = DateTime.now
+    a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 7.day)
+    a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 3.day)
+    a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 1.day)
+    a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now + 4.day)
+    assert_equal [a3, a2, a4, a1], b.discussions
+  end
+
   should 'return only closed discussions if discussion status is closed' do
     community = fast_create(Community)
     community.boxes << Box.new
@@ -122,6 +152,21 @@ class DiscussionBlockTest < ActiveSupport::TestCase
     assert_equivalent [a4], b.discussions
   end
 
+  should 'return only closed discussions if discussion status is closed odered by end_date' do
+    community = fast_create(Community)
+    community.boxes << Box.new
+    b = CommentParagraphPlugin::DiscussionBlock.new
+    b.box = community.boxes.last
+    b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_CLOSED
+    b.save
+    current_date = DateTime.now - 10
+    a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now - 7.day)
+    a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now - 3.day)
+    a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now - 1.day)
+    a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => current_date, :end_date => DateTime.now - 4.day)
+    assert_equal [a1, a4, a2, a3], b.discussions
+  end
+
 end
 
 require 'boxes_helper'


=====================================
plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb
=====================================
--- a/plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb
+++ b/plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb
@@ -1,7 +1,5 @@
 <%= required_fields_message %>
 
-<%= render :file => 'shared/tiny_mce' %>
-
 <div>
   <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
 
@@ -9,5 +7,5 @@
   <%= render :partial => 'general_fields' %>
   <%= render :partial => 'translatable' %>
   <%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %>
-  <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %>
+  <%= render :partial => 'shared/lead_and_body' %>
 </div>



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/f4d6132d899f1087c3623020977f59a7b1e30777
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160909/f978466f/attachment-0001.html>


More information about the Noosfero-dev mailing list