[noosfero/noosfero][next] 2 commits: Validate article type in SuggestArticle

Victor Costa gitlab at gitlab.com
Mon Apr 27 19:51:12 BRT 2015


Victor Costa pushed to branch next at Noosfero / noosfero


Commits:
3c2de986 by Victor Costa at 2015-04-27T19:04:56Z
Validate article type in SuggestArticle

- - - - -
fecb92d5 by Victor Costa at 2015-04-27T19:22:56Z
Fix type and parent_id selection for suggest article view

- - - - -


4 changed files:

- app/models/suggest_article.rb
- app/views/tasks/_suggest_article_accept_details.html.erb
- test/functional/tasks_controller_test.rb
- test/unit/suggest_article_test.rb


Changes:

=====================================
app/models/suggest_article.rb
=====================================
--- a/app/models/suggest_article.rb
+++ b/app/models/suggest_article.rb
@@ -36,7 +36,11 @@ class SuggestArticle < Task
   end
 
   def article_type
-    (article[:type] || 'TinyMceArticle').constantize
+    if article[:type].present?
+      type = article[:type].constantize
+      return type if type < Article
+    end
+    TinyMceArticle
   end
 
   def perform


=====================================
app/views/tasks/_suggest_article_accept_details.html.erb
=====================================
--- a/app/views/tasks/_suggest_article_accept_details.html.erb
+++ b/app/views/tasks/_suggest_article_accept_details.html.erb
@@ -10,8 +10,10 @@
   <%= labelled_form_field(_('Source'), a.text_field(:source_name)) %>
   <%= labelled_form_field(_("Source URL"), a.text_field(:source)) %>
 
-  <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article][parent_id]", task.target) %>
+  <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article][parent_id]", task.target, task.article[:parent_id]) %>
   <%= labelled_form_field(_('Highlight this article'), a.check_box(:highlighted)) %>
 
+  <%= a.hidden_field(:type) %>
+
   <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => a, :lead_id => task.id} %>
 <% end %>


=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -313,6 +313,29 @@ class TasksControllerTest < ActionController::TestCase
     assert_select "#tasks_#{t.id}_task_name"
   end
 
+  should "append hidden tag with type value from article suggestion" do
+    Task.destroy_all
+    c = fast_create(Community)
+    c.add_admin profile
+    @controller.stubs(:profile).returns(c)
+    t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body', :type => 'TextArticle'}, :name => 'some name', :email => 'test at localhost.com', :target => c)
+
+    get :index
+    assert_select "#tasks_#{t.id}_task_article_type[value=TextArticle]"
+  end
+
+  should "display parent_id selection from article suggestion with predefined value" do
+    Task.destroy_all
+    c = fast_create(Community)
+    c.add_admin profile
+    @controller.stubs(:profile).returns(c)
+    parent = fast_create(Folder, :profile_id => c.id)
+    t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body', :parent_id => parent.id}, :name => 'some name', :email => 'test at localhost.com', :target => c)
+
+    get :index
+    assert_select "#tasks_#{t.id}_task_article_parent_id option[value=#{parent.id}]"
+  end
+
   should "not display name from article suggestion when requestor was setted" do
     Task.destroy_all
     c = fast_create(Community)


=====================================
test/unit/suggest_article_test.rb
=====================================
--- a/test/unit/suggest_article_test.rb
+++ b/test/unit/suggest_article_test.rb
@@ -230,4 +230,16 @@ class SuggestArticleTest < ActiveSupport::TestCase
     end
   end
 
+  should 'accept article type parameter' do
+    t = SuggestArticle.new
+    t.article = {:name => 'name', :body => 'body', :type => 'TextArticle'}
+    t.article_type == TextArticle
+  end
+
+  should 'fallback to tinymce when type parameter is invalid' do
+    t = SuggestArticle.new
+    t.article = {:name => 'name', :body => 'body', :type => 'Comment'}
+    t.article_type == TinyMceArticle
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/356ed1a35203e1fabc2e1762759c28090de75c15...fecb92d5a3839232e367c6195b64ef9334cc294a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150427/9fb66561/attachment.html>


More information about the Noosfero-dev mailing list