From cfc3355bab7192578976365488ea17efce32d957 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Fri, 17 Dec 2010 09:29:51 -0300 Subject: [PATCH] The author_name should be defined by user instead of generated automatically. --- app/helpers/content_viewer_helper.rb | 2 +- app/models/article.rb | 5 +++++ app/models/suggest_article.rb | 1 + app/views/tasks/_suggest_article.rhtml | 4 ++-- test/functional/tasks_controller_test.rb | 19 +++++++++++++++---- test/unit/article_test.rb | 14 ++++++++++++++ test/unit/suggest_article_test.rb | 9 +++++++++ 7 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index b43b76d..949d2bf 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -21,7 +21,7 @@ module ContentViewerHelper title = content_tag('h1', link_to(article.name, article.url), :class => 'title') end comments = args[:no_comments] ? '' : (("- %s") % link_to_comments(article)) - title << content_tag('span', _("%s, by %s %s") % [show_date(article.published_at), link_to(article.author.name, article.author.url), comments], :class => 'created-at') + title << content_tag('span', _("%s, by %s %s") % [show_date(article.published_at), link_to(article.author_name, article.author.url), comments], :class => 'created-at') end title end diff --git a/app/models/article.rb b/app/models/article.rb index 64ceacd..43ffc10 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -25,6 +25,7 @@ class Article < ActiveRecord::Base acts_as_having_settings :field => :setting settings_items :display_hits, :type => :boolean, :default => true + settings_items :author_name, :type => :string, :default => "" belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' @@ -450,6 +451,10 @@ class Article < ActiveRecord::Base end end + def author_name + setting[:author_name].blank? ? author.name : setting[:author_name] + end + alias :active_record_cache_key :cache_key def cache_key(params = {}, the_profile = nil) active_record_cache_key + diff --git a/app/models/suggest_article.rb b/app/models/suggest_article.rb index 35dd094..afe362b 100644 --- a/app/models/suggest_article.rb +++ b/app/models/suggest_article.rb @@ -29,6 +29,7 @@ class SuggestArticle < Task TinyMceArticle.create!( :profile => target, :name => article_name, + :author_name => name, :body => article_body, :abstract => article_abstract, :parent_id => article_parent_id, diff --git a/app/views/tasks/_suggest_article.rhtml b/app/views/tasks/_suggest_article.rhtml index 3eb5917..8e32ef5 100644 --- a/app/views/tasks/_suggest_article.rhtml +++ b/app/views/tasks/_suggest_article.rhtml @@ -4,9 +4,9 @@ <% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> -

<%= label_tag(_("Sent by: %s") % task.name) %>

-

<%= label_tag(_("Email: %s") % task.email) %>

+ <%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %> +

<%= label_tag(_("Email: %s") % task.email) %>

<%= required labelled_form_field(_('Title'), f.text_field(:article_name, :size => 50)) %> <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 0b115b4..8641ae3 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -255,11 +255,22 @@ class TasksControllerTest < Test::Unit::TestCase c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) @controller.stubs(:profile).returns(c) SuggestArticle.skip_captcha! - t = SuggestArticle.create!(:article_name => 'test name', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c) - - post :close, :decision => 'finish', :id => t.id, :task => {:article_name => 'new name', :article_body => 'new body'} - assert_equal 'new name', TinyMceArticle.find(:first).name + t = SuggestArticle.new + t.article_name = 'test name' + t.article_body = 'test body' + t.name = 'some name' + t.source = 'http://test.com' + t.source_name = 'some source name' + t.email = 'test@localhost.com' + t.target = c + t.save! + + post :close, :decision => 'finish', :id => t.id, :task => {:article_name => 'new article name', :article_body => 'new body', :source => 'http://www.noosfero.com', :source_name => 'new source', :name => 'new name'} + assert_equal 'new article name', TinyMceArticle.find(:first).name + assert_equal 'new name', TinyMceArticle.find(:first).author_name assert_equal 'new body', TinyMceArticle.find(:first).body + assert_equal 'http://www.noosfero.com', TinyMceArticle.find(:first).source + assert_equal 'new source', TinyMceArticle.find(:first).source_name end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index b83940f..a41f41b 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1399,4 +1399,18 @@ class ArticleTest < Test::Unit::TestCase assert a.possible_translations.include?('pt') end + should 'have the author_name method defined' do + assert Article.method_defined?('author_name') + end + + should "the author_name returns the name od the article's author" do + author = mock() + author.expects(:name).returns('author name') + a = Article.new + a.expects(:author).returns(author) + assert_equal 'author name', a.author_name + a.author_name = 'some name' + assert_equal 'some name', a.author_name + end + end diff --git a/test/unit/suggest_article_test.rb b/test/unit/suggest_article_test.rb index 00b1995..96e99d0 100644 --- a/test/unit/suggest_article_test.rb +++ b/test/unit/suggest_article_test.rb @@ -131,4 +131,13 @@ class SuggestArticleTest < ActiveSupport::TestCase task.save end + should 'fill name into author_name created article' do + t = build(SuggestArticle, :target => @profile) + t.name = 'some name' + t.perform + + article = TinyMceArticle.last + assert_equal 'some name', article.author_name + end + end -- libgit2 0.21.2