Commit 622e2512484398b8879f3ef8aa1903a5a3b6fc8b
1 parent
3183c63b
Exists in
master
and in
29 other branches
creating author_id method in article class to return the author id when the author exists
Showing
3 changed files
with
16 additions
and
1 deletions
Show diff stats
app/models/approve_article.rb
... | ... | @@ -48,7 +48,7 @@ class ApproveArticle < Task |
48 | 48 | end |
49 | 49 | |
50 | 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 | 52 | end |
53 | 53 | |
54 | 54 | def title | ... | ... |
app/models/article.rb
... | ... | @@ -562,6 +562,10 @@ class Article < ActiveRecord::Base |
562 | 562 | author ? author.url : nil |
563 | 563 | end |
564 | 564 | |
565 | + def author_id | |
566 | + author ? author.id : nil | |
567 | + end | |
568 | + | |
565 | 569 | alias :active_record_cache_key :cache_key |
566 | 570 | def cache_key(params = {}, the_profile = nil, language = 'en') |
567 | 571 | active_record_cache_key+'-'+language + | ... | ... |
test/unit/article_test.rb
... | ... | @@ -1822,4 +1822,15 @@ class ArticleTest < ActiveSupport::TestCase |
1822 | 1822 | assert_equal author_name, article.author_name |
1823 | 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 | 1836 | end | ... | ... |