Commit cfc3355bab7192578976365488ea17efce32d957
Committed by
Antonio Terceiro
1 parent
9c287ade
Exists in
master
and in
22 other branches
The author_name should be defined by user instead of generated automatically.
(ActionItem1732)
Showing
7 changed files
with
47 additions
and
7 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
| ... | ... | @@ -21,7 +21,7 @@ module ContentViewerHelper |
| 21 | 21 | title = content_tag('h1', link_to(article.name, article.url), :class => 'title') |
| 22 | 22 | end |
| 23 | 23 | comments = args[:no_comments] ? '' : (("- %s") % link_to_comments(article)) |
| 24 | - 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') | |
| 24 | + 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') | |
| 25 | 25 | end |
| 26 | 26 | title |
| 27 | 27 | end | ... | ... |
app/models/article.rb
| ... | ... | @@ -25,6 +25,7 @@ class Article < ActiveRecord::Base |
| 25 | 25 | acts_as_having_settings :field => :setting |
| 26 | 26 | |
| 27 | 27 | settings_items :display_hits, :type => :boolean, :default => true |
| 28 | + settings_items :author_name, :type => :string, :default => "" | |
| 28 | 29 | |
| 29 | 30 | belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' |
| 30 | 31 | |
| ... | ... | @@ -450,6 +451,10 @@ class Article < ActiveRecord::Base |
| 450 | 451 | end |
| 451 | 452 | end |
| 452 | 453 | |
| 454 | + def author_name | |
| 455 | + setting[:author_name].blank? ? author.name : setting[:author_name] | |
| 456 | + end | |
| 457 | + | |
| 453 | 458 | alias :active_record_cache_key :cache_key |
| 454 | 459 | def cache_key(params = {}, the_profile = nil) |
| 455 | 460 | active_record_cache_key + | ... | ... |
app/models/suggest_article.rb
app/views/tasks/_suggest_article.rhtml
| ... | ... | @@ -4,9 +4,9 @@ |
| 4 | 4 | |
| 5 | 5 | <% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> |
| 6 | 6 | |
| 7 | - <p><%= label_tag(_("Sent by: %s") % task.name) %> </p> | |
| 8 | - <p><%= label_tag(_("Email: %s") % task.email) %> </p> | |
| 9 | 7 | |
| 8 | + <%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %> | |
| 9 | + <p><%= label_tag(_("Email: %s") % task.email) %> </p> | |
| 10 | 10 | <%= required labelled_form_field(_('Title'), f.text_field(:article_name, :size => 50)) %> |
| 11 | 11 | <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> |
| 12 | 12 | <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -255,11 +255,22 @@ class TasksControllerTest < Test::Unit::TestCase |
| 255 | 255 | c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) |
| 256 | 256 | @controller.stubs(:profile).returns(c) |
| 257 | 257 | SuggestArticle.skip_captcha! |
| 258 | - t = SuggestArticle.create!(:article_name => 'test name', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c) | |
| 259 | - | |
| 260 | - post :close, :decision => 'finish', :id => t.id, :task => {:article_name => 'new name', :article_body => 'new body'} | |
| 261 | - assert_equal 'new name', TinyMceArticle.find(:first).name | |
| 258 | + t = SuggestArticle.new | |
| 259 | + t.article_name = 'test name' | |
| 260 | + t.article_body = 'test body' | |
| 261 | + t.name = 'some name' | |
| 262 | + t.source = 'http://test.com' | |
| 263 | + t.source_name = 'some source name' | |
| 264 | + t.email = 'test@localhost.com' | |
| 265 | + t.target = c | |
| 266 | + t.save! | |
| 267 | + | |
| 268 | + 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'} | |
| 269 | + assert_equal 'new article name', TinyMceArticle.find(:first).name | |
| 270 | + assert_equal 'new name', TinyMceArticle.find(:first).author_name | |
| 262 | 271 | assert_equal 'new body', TinyMceArticle.find(:first).body |
| 272 | + assert_equal 'http://www.noosfero.com', TinyMceArticle.find(:first).source | |
| 273 | + assert_equal 'new source', TinyMceArticle.find(:first).source_name | |
| 263 | 274 | end |
| 264 | 275 | |
| 265 | 276 | end | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -1399,4 +1399,18 @@ class ArticleTest < Test::Unit::TestCase |
| 1399 | 1399 | assert a.possible_translations.include?('pt') |
| 1400 | 1400 | end |
| 1401 | 1401 | |
| 1402 | + should 'have the author_name method defined' do | |
| 1403 | + assert Article.method_defined?('author_name') | |
| 1404 | + end | |
| 1405 | + | |
| 1406 | + should "the author_name returns the name od the article's author" do | |
| 1407 | + author = mock() | |
| 1408 | + author.expects(:name).returns('author name') | |
| 1409 | + a = Article.new | |
| 1410 | + a.expects(:author).returns(author) | |
| 1411 | + assert_equal 'author name', a.author_name | |
| 1412 | + a.author_name = 'some name' | |
| 1413 | + assert_equal 'some name', a.author_name | |
| 1414 | + end | |
| 1415 | + | |
| 1402 | 1416 | end | ... | ... |
test/unit/suggest_article_test.rb
| ... | ... | @@ -131,4 +131,13 @@ class SuggestArticleTest < ActiveSupport::TestCase |
| 131 | 131 | task.save |
| 132 | 132 | end |
| 133 | 133 | |
| 134 | + should 'fill name into author_name created article' do | |
| 135 | + t = build(SuggestArticle, :target => @profile) | |
| 136 | + t.name = 'some name' | |
| 137 | + t.perform | |
| 138 | + | |
| 139 | + article = TinyMceArticle.last | |
| 140 | + assert_equal 'some name', article.author_name | |
| 141 | + end | |
| 142 | + | |
| 134 | 143 | end | ... | ... |