Commit 2f142b415df2b0573225f4b928fae998b7384c38
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'next' into api
Showing
4 changed files
with
43 additions
and
2 deletions
Show diff stats
app/models/suggest_article.rb
... | ... | @@ -36,7 +36,11 @@ class SuggestArticle < Task |
36 | 36 | end |
37 | 37 | |
38 | 38 | def article_type |
39 | - (article[:type] || 'TinyMceArticle').constantize | |
39 | + if article[:type].present? | |
40 | + type = article[:type].constantize | |
41 | + return type if type < Article | |
42 | + end | |
43 | + TinyMceArticle | |
40 | 44 | end |
41 | 45 | |
42 | 46 | def perform | ... | ... |
app/views/tasks/_suggest_article_accept_details.html.erb
... | ... | @@ -10,8 +10,10 @@ |
10 | 10 | <%= labelled_form_field(_('Source'), a.text_field(:source_name)) %> |
11 | 11 | <%= labelled_form_field(_("Source URL"), a.text_field(:source)) %> |
12 | 12 | |
13 | - <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article][parent_id]", task.target) %> | |
13 | + <%= 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]) %> | |
14 | 14 | <%= labelled_form_field(_('Highlight this article'), a.check_box(:highlighted)) %> |
15 | 15 | |
16 | + <%= a.hidden_field(:type) %> | |
17 | + | |
16 | 18 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => a, :lead_id => task.id} %> |
17 | 19 | <% end %> | ... | ... |
test/functional/tasks_controller_test.rb
... | ... | @@ -313,6 +313,29 @@ class TasksControllerTest < ActionController::TestCase |
313 | 313 | assert_select "#tasks_#{t.id}_task_name" |
314 | 314 | end |
315 | 315 | |
316 | + should "append hidden tag with type value from article suggestion" do | |
317 | + Task.destroy_all | |
318 | + c = fast_create(Community) | |
319 | + c.add_admin profile | |
320 | + @controller.stubs(:profile).returns(c) | |
321 | + t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body', :type => 'TextArticle'}, :name => 'some name', :email => 'test@localhost.com', :target => c) | |
322 | + | |
323 | + get :index | |
324 | + assert_select "#tasks_#{t.id}_task_article_type[value=TextArticle]" | |
325 | + end | |
326 | + | |
327 | + should "display parent_id selection from article suggestion with predefined value" do | |
328 | + Task.destroy_all | |
329 | + c = fast_create(Community) | |
330 | + c.add_admin profile | |
331 | + @controller.stubs(:profile).returns(c) | |
332 | + parent = fast_create(Folder, :profile_id => c.id) | |
333 | + t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body', :parent_id => parent.id}, :name => 'some name', :email => 'test@localhost.com', :target => c) | |
334 | + | |
335 | + get :index | |
336 | + assert_select "#tasks_#{t.id}_task_article_parent_id option[value=#{parent.id}]" | |
337 | + end | |
338 | + | |
316 | 339 | should "not display name from article suggestion when requestor was setted" do |
317 | 340 | Task.destroy_all |
318 | 341 | c = fast_create(Community) | ... | ... |
test/unit/suggest_article_test.rb
... | ... | @@ -230,4 +230,16 @@ class SuggestArticleTest < ActiveSupport::TestCase |
230 | 230 | end |
231 | 231 | end |
232 | 232 | |
233 | + should 'accept article type parameter' do | |
234 | + t = SuggestArticle.new | |
235 | + t.article = {:name => 'name', :body => 'body', :type => 'TextArticle'} | |
236 | + t.article_type == TextArticle | |
237 | + end | |
238 | + | |
239 | + should 'fallback to tinymce when type parameter is invalid' do | |
240 | + t = SuggestArticle.new | |
241 | + t.article = {:name => 'name', :body => 'body', :type => 'Comment'} | |
242 | + t.article_type == TinyMceArticle | |
243 | + end | |
244 | + | |
233 | 245 | end | ... | ... |