Commit 4ddc6025 authored by Vitor Barbosa's avatar Vitor Barbosa Committed by Thiago Ribeiro
Browse files
parent 492c3d63
......@@ -118,10 +118,7 @@ class CmsController < MyProfileController
end
end
unless @article.kind_of?(RssFeed)
@escaped_body = CGI::escapeHTML(@article.body || '')
@escaped_abstract = CGI::escapeHTML(@article.abstract || '')
end
escape_fields @article
end
def new
......@@ -192,6 +189,8 @@ class CmsController < MyProfileController
end
end
escape_fields @article
render :action => 'edit'
end
......@@ -541,4 +540,10 @@ class CmsController < MyProfileController
end
end
def escape_fields article
unless article.kind_of?(RssFeed)
@escaped_body = CGI::escapeHTML(article.body || '')
@escaped_abstract = CGI::escapeHTML(article.abstract || '')
end
end
end
......@@ -5,8 +5,6 @@
<%= hidden_field_tag("type", @type) if @type %>
<%= hidden_field_tag('parent_id', @parent_id) if @parent_id %>
<%= hidden_field_tag('back_to', @back_to) %>
<%= hidden_field_tag('success_back_to', @success_back_to) %>
......
......@@ -29,10 +29,10 @@
<%= expirable_button @page, :locale, content, url %>
<% end %>
<%= 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) %>
<%= 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) %>
<% content = content_tag('span', label_for_clone_article(@page)) %>
<% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :type => @page.class }) %>
<% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :parent_id => (@page.folder? ? @page : @page.parent), :type => @page.class}) %>
<%= expirable_button @page, :clone, content, url %>
<% end %>
......
......@@ -560,8 +560,17 @@ class CmsControllerTest < ActionController::TestCase
end
should 'keep informed parent_id' do
fast_create(:blog, :name=>"Sample blog", :profile_id=>@profile.id)
profile.home_page = profile.blogs.find_by_name "Sample blog"
profile.save!
get :new, :profile => @profile.identifier, :parent_id => profile.home_page.id, :type => 'TextileArticle'
assert_tag :tag => 'input', :attributes => { :name => 'parent_id', :value => profile.home_page.id }
assert_tag :tag => 'select',
:attributes => { :id => 'article_parent_id' },
:child => {
:tag => "option", :attributes => {:value => profile.home_page.id, :selected => "selected"}
}
end
should 'list folders before others' do
......@@ -1839,14 +1848,6 @@ class CmsControllerTest < ActionController::TestCase
assert_equal 'first version', assigns(:article).name
end
should 'clone article with its content' do
article = profile.articles.create(:name => 'first version')
get :new, :profile => profile.identifier, :id => article.id, :clone => true, :type => 'TinyMceArticle'
assert_match article.name, @response.body
end
should 'save article with content from older version' do
article = profile.articles.create(:name => 'first version')
article.name = 'second version'; article.save
......@@ -1897,6 +1898,33 @@ class CmsControllerTest < ActionController::TestCase
assert_equal '[{"label":"linux","value":"linux"}]', @response.body
end
should 'clone an article with its parent' do
login_as(profile.identifier)
f = Folder.new(:name => 'f')
profile.articles << f
f.save!
post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
:article => { :name => 'Main Article', :body => 'some content' }
main_article = profile.articles.find_by_name('Main Article')
assert_not_nil main_article
post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
:id => main_article.id, :clone => true
cloned_main_article = profile.articles.find_by_name('Main Article')
assert_not_nil cloned_main_article
assert_equal main_article.parent_id, cloned_main_article.parent_id
get :new, :profile => profile.identifier, :id => cloned_main_article.id,
:clone => true, :type => 'TinyMceArticle'
assert_match main_article.body, @response.body
end
protected
# FIXME this is to avoid adding an extra dependency for a proper JSON parser.
......
require_relative "../test_helper"
class CloneArticleTest < ActiveSupport::TestCase
should 'cloned article have its source attributes' do
community = fast_create(Community)
folder = fast_create(Folder, :profile_id => community.id)
article = fast_create(TinyMceArticle, :profile_id => community.id)
article.parent_id = folder.id
article.save!
article.reload
cloned_article = article.copy_without_save({:parent_id => article.parent_id})
assert_equal folder.id, cloned_article.parent_id
assert_equal article.body , cloned_article.body
assert_equal article.name, cloned_article.name
assert_equal article.setting, cloned_article.setting
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment