Commit 7fe31f1a342c2ddcfd73a183816c4702085db85d
1 parent
d7eeb588
Exists in
clone_article
Fixes for merge request 579
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
6 changed files
with
38 additions
and
36 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -145,12 +145,12 @@ class CmsController < MyProfileController | @@ -145,12 +145,12 @@ class CmsController < MyProfileController | ||
145 | article_data.merge!(params[:article]) if params[:article] | 145 | article_data.merge!(params[:article]) if params[:article] |
146 | article_data.merge!(:profile => profile) if profile | 146 | article_data.merge!(:profile => profile) if profile |
147 | 147 | ||
148 | - if params[:clone] | ||
149 | - current_article = profile.articles.find(params[:id]) | ||
150 | - @article = current_article.dup | ||
151 | - else | ||
152 | - @article = klass.new(article_data) | ||
153 | - end | 148 | + @article = if params[:clone] |
149 | + current_article = profile.articles.find(params[:id]) | ||
150 | + current_article.copy_without_save | ||
151 | + else | ||
152 | + klass.new(article_data) | ||
153 | + end | ||
154 | 154 | ||
155 | parent = check_parent(params[:parent_id]) | 155 | parent = check_parent(params[:parent_id]) |
156 | if parent | 156 | if parent |
app/helpers/application_helper.rb
@@ -932,23 +932,15 @@ module ApplicationHelper | @@ -932,23 +932,15 @@ module ApplicationHelper | ||
932 | end | 932 | end |
933 | 933 | ||
934 | def label_for_clone_article(article) | 934 | def label_for_clone_article(article) |
935 | - klass = class_to_s(article.class) | ||
936 | - _("Clone #{klass}") | ||
937 | - end | 935 | + valid_type_names = ["Folder", "Blog", "Event", "Forum"] |
938 | 936 | ||
939 | - def class_to_s(article_type) | ||
940 | - classes = { | ||
941 | - Folder => _("folder"), | ||
942 | - Blog => _("blog"), | ||
943 | - Event => _("event"), | ||
944 | - Forum => _("forum"), | ||
945 | - } | 937 | + article_type = if valid_type_names.include?(article.class.to_s) |
938 | + article.class.to_s | ||
939 | + else | ||
940 | + "Article" | ||
941 | + end | ||
946 | 942 | ||
947 | - if classes.has_key?(article_type) | ||
948 | - classes[article_type] | ||
949 | - else | ||
950 | - _("article") | ||
951 | - end | 943 | + _('Clone %s') % article_type |
952 | end | 944 | end |
953 | 945 | ||
954 | def add_rss_feed_to_head(title, url) | 946 | def add_rss_feed_to_head(title, url) |
app/models/article.rb
@@ -577,25 +577,24 @@ class Article < ActiveRecord::Base | @@ -577,25 +577,24 @@ class Article < ActiveRecord::Base | ||
577 | profile.visible? && profile.public? && published? | 577 | profile.visible? && profile.public? && published? |
578 | end | 578 | end |
579 | 579 | ||
580 | - | ||
581 | - def copy(options = {}) | 580 | + def copy_without_save(options = {}) |
582 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } | 581 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } |
583 | attrs.merge!(options) | 582 | attrs.merge!(options) |
584 | object = self.class.new | 583 | object = self.class.new |
585 | attrs.each do |key, value| | 584 | attrs.each do |key, value| |
586 | object.send(key.to_s+'=', value) | 585 | object.send(key.to_s+'=', value) |
587 | end | 586 | end |
587 | + object | ||
588 | + end | ||
589 | + | ||
590 | + def copy(options = {}) | ||
591 | + object = copy_without_save(options) | ||
588 | object.save | 592 | object.save |
589 | object | 593 | object |
590 | end | 594 | end |
591 | 595 | ||
592 | def copy!(options = {}) | 596 | def copy!(options = {}) |
593 | - attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } | ||
594 | - attrs.merge!(options) | ||
595 | - object = self.class.new | ||
596 | - attrs.each do |key, value| | ||
597 | - object.send(key.to_s+'=', value) | ||
598 | - end | 597 | + object = copy_without_save(options) |
599 | object.save! | 598 | object.save! |
600 | object | 599 | object |
601 | end | 600 | end |
plugins/tolerance_time/lib/tolerance_time_plugin.rb
@@ -56,9 +56,18 @@ class ToleranceTimePlugin < Noosfero::Plugin | @@ -56,9 +56,18 @@ class ToleranceTimePlugin < Noosfero::Plugin | ||
56 | end | 56 | end |
57 | 57 | ||
58 | def content_expire_edit(content) | 58 | def content_expire_edit(content) |
59 | + content_expire_for(content, "editing") | ||
60 | + end | ||
61 | + | ||
62 | + def content_expire_clone(content) | ||
63 | + content_expire_for(content, "cloning") | ||
64 | + end | ||
65 | + | ||
66 | + private | ||
67 | + | ||
68 | + def content_expire_for(content, action) | ||
59 | if ToleranceTimePlugin.expired?(content) | 69 | if ToleranceTimePlugin.expired?(content) |
60 | - _('The tolerance time for editing this content is over.') | 70 | + _('The tolerance time for %s this content is over.') % action |
61 | end | 71 | end |
62 | end | 72 | end |
63 | - | ||
64 | end | 73 | end |
test/functional/content_viewer_controller_test.rb
@@ -1252,9 +1252,11 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -1252,9 +1252,11 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
1252 | should 'expire article actions button if any plugins says so' do | 1252 | should 'expire article actions button if any plugins says so' do |
1253 | class Plugin1 < Noosfero::Plugin | 1253 | class Plugin1 < Noosfero::Plugin |
1254 | def content_expire_edit(content); 'This button is expired.'; end | 1254 | def content_expire_edit(content); 'This button is expired.'; end |
1255 | + def content_expire_clone(content); 'This button is expired.'; end | ||
1255 | end | 1256 | end |
1256 | class Plugin2 < Noosfero::Plugin | 1257 | class Plugin2 < Noosfero::Plugin |
1257 | def content_expire_edit(content); nil; end | 1258 | def content_expire_edit(content); nil; end |
1259 | + def content_expire_clone(content); nil; end | ||
1258 | end | 1260 | end |
1259 | Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) | 1261 | Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) |
1260 | 1262 |
test/unit/application_helper_test.rb
@@ -1010,11 +1010,11 @@ class ApplicationHelperTest < ActionView::TestCase | @@ -1010,11 +1010,11 @@ class ApplicationHelperTest < ActionView::TestCase | ||
1010 | end | 1010 | end |
1011 | 1011 | ||
1012 | should "return the related class string" do | 1012 | should "return the related class string" do |
1013 | - assert_equal "Clone folder", label_for_clone_article(Folder.new) | ||
1014 | - assert_equal "Clone blog", label_for_clone_article(Blog.new) | ||
1015 | - assert_equal "Clone event", label_for_clone_article(Event.new) | ||
1016 | - assert_equal "Clone forum", label_for_clone_article(Forum.new) | ||
1017 | - assert_equal "Clone article", label_for_clone_article(TinyMceArticle.new) | 1013 | + assert_equal "Clone Folder", label_for_clone_article(Folder.new) |
1014 | + assert_equal "Clone Blog", label_for_clone_article(Blog.new) | ||
1015 | + assert_equal "Clone Event", label_for_clone_article(Event.new) | ||
1016 | + assert_equal "Clone Forum", label_for_clone_article(Forum.new) | ||
1017 | + assert_equal "Clone Article", label_for_clone_article(TinyMceArticle.new) | ||
1018 | end | 1018 | end |
1019 | 1019 | ||
1020 | protected | 1020 | protected |