Commit 622e2512484398b8879f3ef8aa1903a5a3b6fc8b

Authored by Leandro Nunes dos Santos
1 parent 3183c63b

creating author_id method in article class to return the author id when the author exists

app/models/approve_article.rb
@@ -48,7 +48,7 @@ class ApproveArticle < Task @@ -48,7 +48,7 @@ class ApproveArticle < Task
48 end 48 end
49 49
50 def perform 50 def perform
51 - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author.id) 51 + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author_id)
52 end 52 end
53 53
54 def title 54 def title
app/models/article.rb
@@ -562,6 +562,10 @@ class Article < ActiveRecord::Base @@ -562,6 +562,10 @@ class Article < ActiveRecord::Base
562 author ? author.url : nil 562 author ? author.url : nil
563 end 563 end
564 564
  565 + def author_id
  566 + author ? author.id : nil
  567 + end
  568 +
565 alias :active_record_cache_key :cache_key 569 alias :active_record_cache_key :cache_key
566 def cache_key(params = {}, the_profile = nil, language = 'en') 570 def cache_key(params = {}, the_profile = nil, language = 'en')
567 active_record_cache_key+'-'+language + 571 active_record_cache_key+'-'+language +
test/unit/article_test.rb
@@ -1822,4 +1822,15 @@ class ArticleTest < ActiveSupport::TestCase @@ -1822,4 +1822,15 @@ class ArticleTest < ActiveSupport::TestCase
1822 assert_equal author_name, article.author_name 1822 assert_equal author_name, article.author_name
1823 end 1823 end
1824 1824
  1825 + should "author_id return the author id of the article's author" do
  1826 + author = fast_create(Person)
  1827 + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => author)
  1828 + assert_equal author.id, article.author_id
  1829 + end
  1830 +
  1831 + should "author_id return nil if there is no article's author" do
  1832 + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil)
  1833 + assert_nil article.author_id
  1834 + end
  1835 +
1825 end 1836 end