Commit 04576c7e2e00f99ed88b6c828a0698a15d4e9a3e

Authored by Vitor Barbosa de Araujo
Committed by Daniela Feitosa
1 parent ad3e1722

Fix clone article behavior

Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Omar Júnior <omarroinuj@gmail.com>
Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Vítor Barbosa <vitornga15@gmail.com>
app/controllers/my_profile/cms_controller.rb
... ... @@ -118,10 +118,7 @@ class CmsController &lt; MyProfileController
118 118 end
119 119 end
120 120  
121   - unless @article.kind_of?(RssFeed)
122   - @escaped_body = CGI::escapeHTML(@article.body || '')
123   - @escaped_abstract = CGI::escapeHTML(@article.abstract || '')
124   - end
  121 + escape_fields @article
125 122 end
126 123  
127 124 def new
... ... @@ -192,6 +189,8 @@ class CmsController &lt; MyProfileController
192 189 end
193 190 end
194 191  
  192 + escape_fields @article
  193 +
195 194 render :action => 'edit'
196 195 end
197 196  
... ... @@ -541,4 +540,10 @@ class CmsController &lt; MyProfileController
541 540 end
542 541 end
543 542  
  543 + def escape_fields article
  544 + unless article.kind_of?(RssFeed)
  545 + @escaped_body = CGI::escapeHTML(article.body || '')
  546 + @escaped_abstract = CGI::escapeHTML(article.abstract || '')
  547 + end
  548 + end
544 549 end
... ...
app/views/cms/edit.html.erb
... ... @@ -5,8 +5,6 @@
5 5  
6 6 <%= hidden_field_tag("type", @type) if @type %>
7 7  
8   - <%= hidden_field_tag('parent_id', @parent_id) if @parent_id %>
9   -
10 8 <%= hidden_field_tag('back_to', @back_to) %>
11 9  
12 10 <%= hidden_field_tag('success_back_to', @success_back_to) %>
... ...
app/views/content_viewer/_article_toolbar.html.erb
... ... @@ -29,10 +29,10 @@
29 29 <%= expirable_button @page, :locale, content, url %>
30 30 <% end %>
31 31  
32   - <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) unless remove_content_button(:new, @page) %>
  32 + <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:new, @page) %>
33 33  
34 34 <% content = content_tag('span', label_for_clone_article(@page)) %>
35   - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :type => @page.class }) %>
  35 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :parent_id => (@page.folder? ? @page : @page.parent), :type => @page.class}) %>
36 36 <%= expirable_button @page, :clone, content, url %>
37 37 <% end %>
38 38  
... ...
test/functional/cms_controller_test.rb
... ... @@ -560,8 +560,17 @@ class CmsControllerTest &lt; ActionController::TestCase
560 560 end
561 561  
562 562 should 'keep informed parent_id' do
  563 + fast_create(:blog, :name=>"Sample blog", :profile_id=>@profile.id)
  564 +
  565 + profile.home_page = profile.blogs.find_by_name "Sample blog"
  566 + profile.save!
  567 +
563 568 get :new, :profile => @profile.identifier, :parent_id => profile.home_page.id, :type => 'TextileArticle'
564   - assert_tag :tag => 'input', :attributes => { :name => 'parent_id', :value => profile.home_page.id }
  569 + assert_tag :tag => 'select',
  570 + :attributes => { :id => 'article_parent_id' },
  571 + :child => {
  572 + :tag => "option", :attributes => {:value => profile.home_page.id, :selected => "selected"}
  573 + }
565 574 end
566 575  
567 576 should 'list folders before others' do
... ... @@ -1839,14 +1848,6 @@ class CmsControllerTest &lt; ActionController::TestCase
1839 1848 assert_equal 'first version', assigns(:article).name
1840 1849 end
1841 1850  
1842   - should 'clone article with its content' do
1843   - article = profile.articles.create(:name => 'first version')
1844   -
1845   - get :new, :profile => profile.identifier, :id => article.id, :clone => true, :type => 'TinyMceArticle'
1846   -
1847   - assert_match article.name, @response.body
1848   - end
1849   -
1850 1851 should 'save article with content from older version' do
1851 1852 article = profile.articles.create(:name => 'first version')
1852 1853 article.name = 'second version'; article.save
... ... @@ -1897,6 +1898,33 @@ class CmsControllerTest &lt; ActionController::TestCase
1897 1898 assert_equal '[{"label":"linux","value":"linux"}]', @response.body
1898 1899 end
1899 1900  
  1901 + should 'clone an article with its parent' do
  1902 + login_as(profile.identifier)
  1903 +
  1904 + f = Folder.new(:name => 'f')
  1905 + profile.articles << f
  1906 + f.save!
  1907 +
  1908 + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
  1909 + :article => { :name => 'Main Article', :body => 'some content' }
  1910 +
  1911 + main_article = profile.articles.find_by_name('Main Article')
  1912 + assert_not_nil main_article
  1913 +
  1914 + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
  1915 + :id => main_article.id, :clone => true
  1916 +
  1917 + cloned_main_article = profile.articles.find_by_name('Main Article')
  1918 + assert_not_nil cloned_main_article
  1919 +
  1920 + assert_equal main_article.parent_id, cloned_main_article.parent_id
  1921 +
  1922 + get :new, :profile => profile.identifier, :id => cloned_main_article.id,
  1923 + :clone => true, :type => 'TinyMceArticle'
  1924 +
  1925 + assert_match main_article.body, @response.body
  1926 + end
  1927 +
1900 1928 protected
1901 1929  
1902 1930 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
... ...
test/unit/clone_article_test.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +require_relative "../test_helper"
  2 +
  3 +class CloneArticleTest < ActiveSupport::TestCase
  4 +
  5 + should 'cloned article have its source attributes' do
  6 + community = fast_create(Community)
  7 + folder = fast_create(Folder, :profile_id => community.id)
  8 + article = fast_create(TinyMceArticle, :profile_id => community.id)
  9 + article.parent_id = folder.id
  10 + article.save!
  11 +
  12 + article.reload
  13 + cloned_article = article.copy_without_save({:parent_id => article.parent_id})
  14 +
  15 + assert_equal folder.id, cloned_article.parent_id
  16 + assert_equal article.body , cloned_article.body
  17 + assert_equal article.name, cloned_article.name
  18 + assert_equal article.setting, cloned_article.setting
  19 + end
  20 +
  21 +end
0 22 \ No newline at end of file
... ...