Commit 5b9232378ea22313997d4a22626c17226da12f90
1 parent
4edfee6d
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Avoid count hits and add comments in archived articles. Added to new unit tests and translated msg
Showing
9 changed files
with
79 additions
and
11 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -99,7 +99,6 @@ class CmsController < MyProfileController |
99 | 99 | @article.image.save! |
100 | 100 | end |
101 | 101 | @article.last_changed_by = user |
102 | - @article.old_parent_id = @article.parent_id | |
103 | 102 | if @article.update_attributes(params[:article]) |
104 | 103 | if !continue |
105 | 104 | if @article.content_type.nil? || @article.image? | ... | ... |
app/models/article.rb
... | ... | @@ -638,13 +638,21 @@ class Article < ActiveRecord::Base |
638 | 638 | end |
639 | 639 | |
640 | 640 | def hit |
641 | - self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
642 | - self.hits += 1 | |
641 | + if !archived? | |
642 | + self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
643 | + self.hits += 1 | |
644 | + end | |
643 | 645 | end |
644 | 646 | |
645 | 647 | def self.hit(articles) |
646 | - Article.where(:id => articles.map(&:id)).update_all('hits = hits + 1') | |
647 | - articles.each { |a| a.hits += 1 } | |
648 | + ids = [] | |
649 | + articles.each do |article| | |
650 | + if !article.archived? | |
651 | + ids << article.id | |
652 | + article.hits += 1 | |
653 | + end | |
654 | + end | |
655 | + Article.where(:id => ids).update_all('hits = hits + 1') if !ids.empty? | |
648 | 656 | end |
649 | 657 | |
650 | 658 | def can_display_hits? |
... | ... | @@ -851,7 +859,7 @@ class Article < ActiveRecord::Base |
851 | 859 | end |
852 | 860 | |
853 | 861 | def parent_archived? |
854 | - if (self.old_parent_id != self.parent_id) && self.parent && self.parent.archived? | |
862 | + if self.parent_id_changed? && self.parent && self.parent.archived? | |
855 | 863 | errors.add(:parent_folder, N_('is archived!!')) |
856 | 864 | end |
857 | 865 | end | ... | ... |
app/models/comment.rb
... | ... | @@ -35,6 +35,8 @@ class Comment < ActiveRecord::Base |
35 | 35 | end |
36 | 36 | end |
37 | 37 | |
38 | + validate :article_archived? | |
39 | + | |
38 | 40 | acts_as_having_settings |
39 | 41 | |
40 | 42 | xss_terminate :only => [ :body, :title, :name ], :on => 'validation' |
... | ... | @@ -214,4 +216,10 @@ class Comment < ActiveRecord::Base |
214 | 216 | self.article.archived? |
215 | 217 | end |
216 | 218 | |
219 | + protected | |
220 | + | |
221 | + def article_archived? | |
222 | + errors.add(:article, N_('associated with this comment is achived!')) if archived? | |
223 | + end | |
224 | + | |
217 | 225 | end | ... | ... |
app/views/content_viewer/_publishing_info.html.erb
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | <div id='article-sub-header'> |
17 | 17 | <% if @page.display_hits? %> |
18 | 18 | <div id="article-hits"> |
19 | - <%= n_('Viewed one time', 'Viewed %{num} times', @page.hits) % { :num => @page.hits } %> | |
19 | + <%= n_('Viewed one time %{desc}', 'Viewed %{num} times %{desc}', @page.hits) % { :num => @page.hits, :desc => @page.archived? ? '<b>'+_('(Not countable anymore)')+'</b>' : '' } %> | |
20 | 20 | </div> |
21 | 21 | <% end %> |
22 | 22 | ... | ... |
plugins/vote/test/functional/vote_plugin_profile_controller_test.rb
... | ... | @@ -36,12 +36,14 @@ class VotePluginProfileControllerTest < ActionController::TestCase |
36 | 36 | end |
37 | 37 | |
38 | 38 | should 'not vote if a target is archived' do |
39 | - article = Article.create!(:profile => profile, :name => 'Archived article', :archived => true) | |
39 | + article = Article.create!(:profile => profile, :name => 'Archived article', :archived => false) | |
40 | 40 | comment = Comment.create!(:body => 'Comment test', :source => article, :author => profile) |
41 | 41 | xhr :post, :vote, :profile => profile.identifier, :id => article.id, :model => 'article', :vote => 1 |
42 | - assert profile.votes.empty? | |
42 | + assert !profile.votes.empty? | |
43 | 43 | |
44 | + article.update_attributes(:archived => true) | |
44 | 45 | xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1 |
46 | + | |
45 | 47 | assert !profile.voted_for?(comment) |
46 | 48 | end |
47 | 49 | ... | ... |
po/noosfero.pot
... | ... | @@ -5073,6 +5073,10 @@ msgid_plural "Viewed %{num} times" |
5073 | 5073 | msgstr[0] "" |
5074 | 5074 | msgstr[1] "" |
5075 | 5075 | |
5076 | +#: app/views/content_viewer/_publishing_info.html.erb:19 | |
5077 | +msgid "(Not countable anymore)" | |
5078 | +msgstr "" | |
5079 | + | |
5076 | 5080 | #: app/views/content_viewer/versions_diff.html.erb:5 |
5077 | 5081 | msgid "Changes on \"%s\"" |
5078 | 5082 | msgstr "" | ... | ... |
po/pt/noosfero.po
... | ... | @@ -5231,11 +5231,15 @@ msgid "Reply" |
5231 | 5231 | msgstr "Responder" |
5232 | 5232 | |
5233 | 5233 | #: app/views/content_viewer/_publishing_info.html.erb:19 |
5234 | -msgid "Viewed one time" | |
5235 | -msgid_plural "Viewed %{num} times" | |
5234 | +msgid "Viewed one time %{desc}" | |
5235 | +msgid_plural "Viewed %{num} times %{desc}" | |
5236 | 5236 | msgstr[0] "Visualizado uma vez" |
5237 | 5237 | msgstr[1] "Visualizado %{num} vezes" |
5238 | 5238 | |
5239 | +#: app/views/content_viewer/_publishing_info.html.erb:19 | |
5240 | +msgid "(Not countable anymore)" | |
5241 | +msgstr "(Não mais contabilizado)" | |
5242 | + | |
5239 | 5243 | #: app/views/content_viewer/versions_diff.html.erb:5 |
5240 | 5244 | msgid "Changes on \"%s\"" |
5241 | 5245 | msgstr "Mudanças em \"%s\"" | ... | ... |
test/unit/article_test.rb
... | ... | @@ -2177,10 +2177,21 @@ class ArticleTest < ActiveSupport::TestCase |
2177 | 2177 | a3 = fast_create(Article) |
2178 | 2178 | Article.hit([a1, a2, a3]) |
2179 | 2179 | Article.hit([a2, a3]) |
2180 | + | |
2180 | 2181 | assert_equal [1, 2, 2], [a1.hits, a2.hits, a3.hits] |
2181 | 2182 | assert_equal [1, 2, 2], [a1.reload.hits, a2.reload.hits, a3.reload.hits] |
2182 | 2183 | end |
2183 | 2184 | |
2185 | + should 'not update hit attribute of archiveds articles' do | |
2186 | + a1 = fast_create(Article) | |
2187 | + a2 = fast_create(Article, :archived => true) | |
2188 | + a3 = fast_create(Article, :archived => true) | |
2189 | + Article.hit([a1, a2, a3]) | |
2190 | + | |
2191 | + assert_equal [1, 0, 0], [a1.hits, a2.hits, a3.hits] | |
2192 | + assert_equal [1, 0, 0], [a1.reload.hits, a2.reload.hits, a3.reload.hits] | |
2193 | + end | |
2194 | + | |
2184 | 2195 | should 'vote in a article' do |
2185 | 2196 | article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) |
2186 | 2197 | profile.vote(article, 5) |
... | ... | @@ -2222,4 +2233,25 @@ class ArticleTest < ActiveSupport::TestCase |
2222 | 2233 | assert !a.display_preview? |
2223 | 2234 | end |
2224 | 2235 | |
2236 | + should 'check if a article is archived' do | |
2237 | + folder = Folder.create!(:name => 'Parent Archived', :profile => profile) | |
2238 | + a1 = Article.create!(:name => 'Test', :profile => profile, :parent_id => folder.id, :archived => false) | |
2239 | + a2 = Article.create!(:name => 'Test 2', :profile => profile, :archived => true) | |
2240 | + folder.update_attributes(:archived => true) | |
2241 | + a1.reload | |
2242 | + | |
2243 | + assert a1.archived? | |
2244 | + assert a2.archived? | |
2245 | + end | |
2246 | + | |
2247 | + should 'try add a child article to a archived folder' do | |
2248 | + folder = Folder.create!(:name => 'Parent Archived', :profile => profile, :archived => true) | |
2249 | + | |
2250 | + err = assert_raises ActiveRecord::RecordInvalid do | |
2251 | + a1 = Article.create!(:name => 'Test', :profile => profile, :parent_id => folder.id, :archived => false) | |
2252 | + end | |
2253 | + | |
2254 | + assert_match 'Parent folder is archived', err.message | |
2255 | + end | |
2256 | + | |
2225 | 2257 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -94,6 +94,17 @@ class CommentTest < ActiveSupport::TestCase |
94 | 94 | assert_equal cc + 1, ActionTracker::Record.find(activity.id).comments_count |
95 | 95 | end |
96 | 96 | |
97 | + should 'try add a comment to a archived article' do | |
98 | + person = fast_create(Person) | |
99 | + article = Article.create!(:name => 'Test', :profile => person, :archived => true) | |
100 | + | |
101 | + err = assert_raises ActiveRecord::RecordInvalid do | |
102 | + comment = create(Comment, :source => article, :author_id => person.id) | |
103 | + end | |
104 | + | |
105 | + assert_match 'Article associated with this comment is achived', err.message | |
106 | + end | |
107 | + | |
97 | 108 | should 'provide author name for authenticated authors' do |
98 | 109 | owner = create_user('testuser').person |
99 | 110 | assert_equal 'testuser', build(Comment, :author => owner).author_name | ... | ... |