Commit 8b44517e5922dda1d762d6d5d4850c290523fec6

Authored by Victor Costa
2 parents 31320be5 5b923237

Merge branch 'article-readonly' into 'master_rails3'

Article archived/readonly

This is a new feature to **freeze/archive** on specific article to avoid that a user perform some actions:

- Deny **associate** children articles to archived folders
- Not allow **vote** to a archived article and your comments
- Not allow create **new comments**
- Not count **hits (visualizations)** to a archived article

- Refactory visual aspects into **Visibility** and **Options** sections on create/edit articles

![visibilit-options](https://softwarepublico.gov.br/gitlab/uploads/noosferogov/noosfero/da89293d37/visibilit-options.png)

- Shows a warning message if a article or their parent is archived

![archived-article](https://softwarepublico.gov.br/gitlab/uploads/noosferogov/noosfero/8886c421fe/archived-article.png)

So, if you have new actions that were not described here, please give me a feedback and I will implement this :)

See merge request !2
app/helpers/article_helper.rb
... ... @@ -15,6 +15,13 @@ module ArticleHelper
15 15 topic_creation(@article) +
16 16 content_tag('h4', _('Options')) +
17 17 content_tag('div',
  18 + content_tag('div',
  19 + check_box(:article, :archived) +
  20 + content_tag('span', ' ', :class => 'access-archived-icon') +
  21 + content_tag('label', _('Read Only'), :for => 'article_archived_true') +
  22 + content_tag('span', _('Archive to avoid create comments, votes, actions in children articles...'), :class => 'access-note'),
  23 + :class => 'access-item'
  24 + ) +
18 25 (article.profile.has_members? ?
19 26 content_tag(
20 27 'div',
... ... @@ -63,13 +70,20 @@ module ArticleHelper
63 70 content_tag('div',
64 71 content_tag('div',
65 72 radio_button(:article, :published, true) +
66   - content_tag('label', _('Public (visible to other people)'), :for => 'article_published_true')
  73 + content_tag('span', ' ', :class => 'access-public-icon') +
  74 + content_tag('label', _('Public'), :for => 'article_published_true') +
  75 + content_tag('span', _('Visible to other people'), :class => 'access-note'),
  76 + :class => 'access-item'
67 77 ) +
68 78 content_tag('div',
69 79 radio_button(:article, :published, false) +
70   - content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private")
  80 + content_tag('span', ' ', :class => 'access-private-icon') +
  81 + content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") +
  82 + content_tag('span', _('Limit visibility of this article'), :class => 'access-note'),
  83 + :class => 'access-item'
71 84 ) +
72   - privacity_exceptions(article, tokenized_children)
  85 + privacity_exceptions(article, tokenized_children),
  86 + :class => 'access-itens'
73 87 )
74 88 end
75 89  
... ...
app/helpers/folder_helper.rb
... ... @@ -61,7 +61,15 @@ module FolderHelper
61 61 @article = article
62 62  
63 63 visibility_options(article,tokenized_children) +
  64 + content_tag('h4', _('Options')) +
64 65 content_tag('div',
  66 + content_tag('div',
  67 + check_box(:article, :archived) +
  68 + content_tag('span', ' ', :class => 'access-archived-icon') +
  69 + content_tag('label', _('Read Only'), :for => 'article_archived_true') +
  70 + content_tag('span', _('Archive to avoid votes and create new children articles'), :class => 'access-note'),
  71 + :class => 'access-item'
  72 + ) +
65 73 hidden_field_tag('article[accept_comments]', 0)
66 74 )
67 75 end
... ...
app/models/article.rb
... ... @@ -9,7 +9,9 @@ class Article < ActiveRecord::Base
9 9 :highlighted, :notify_comments, :display_hits, :slug,
10 10 :external_feed_builder, :display_versions, :external_link,
11 11 :image_builder, :show_to_followers,
12   - :author, :display_preview
  12 + :author, :display_preview, :archived
  13 +
  14 + attr_accessor :old_parent_id
13 15  
14 16 acts_as_having_image
15 17  
... ... @@ -154,6 +156,8 @@ class Article < ActiveRecord::Base
154 156 validate :no_self_reference
155 157 validate :no_cyclical_reference, :if => 'parent_id.present?'
156 158  
  159 + validate :parent_archived?
  160 +
157 161 def no_self_reference
158 162 errors.add(:parent_id, _('self-reference is not allowed.')) if id && parent_id == id
159 163 end
... ... @@ -484,6 +488,10 @@ class Article < ActiveRecord::Base
484 488 end
485 489 end
486 490  
  491 + def archived?
  492 + (self.parent && self.parent.archived) || self.archived
  493 + end
  494 +
487 495 def self.folder_types
488 496 ['Folder', 'Blog', 'Forum', 'Gallery']
489 497 end
... ... @@ -630,13 +638,21 @@ class Article < ActiveRecord::Base
630 638 end
631 639  
632 640 def hit
633   - self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i)
634   - 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
635 645 end
636 646  
637 647 def self.hit(articles)
638   - Article.where(:id => articles.map(&:id)).update_all('hits = hits + 1')
639   - 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?
640 656 end
641 657  
642 658 def can_display_hits?
... ... @@ -842,4 +858,10 @@ class Article &lt; ActiveRecord::Base
842 858 sanitizer.sanitize(text)
843 859 end
844 860  
  861 + def parent_archived?
  862 + if self.parent_id_changed? && self.parent && self.parent.archived?
  863 + errors.add(:parent_folder, N_('is archived!!'))
  864 + end
  865 + end
  866 +
845 867 end
... ...
app/models/comment.rb
... ... @@ -35,6 +35,8 @@ class Comment &lt; 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'
... ... @@ -210,4 +212,14 @@ class Comment &lt; ActiveRecord::Base
210 212 user.present? && user == author
211 213 end
212 214  
  215 + def archived?
  216 + self.article.archived?
  217 + end
  218 +
  219 + protected
  220 +
  221 + def article_archived?
  222 + errors.add(:article, N_('associated with this comment is achived!')) if archived?
  223 + end
  224 +
213 225 end
... ...
app/models/folder.rb
... ... @@ -65,4 +65,8 @@ class Folder &lt; Article
65 65 !self.has_posts? || self.gallery?
66 66 end
67 67  
  68 + def archived?
  69 + self.archived
  70 + end
  71 +
68 72 end
... ...
app/views/cms/_archived_warning.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<% if !article.errors.any? %>
  2 + <div class="text-warning">
  3 + <p>
  4 + <i class="icon"></i>
  5 + <%= _("Archived article! It's read-only") %>
  6 + </p>
  7 + </div>
  8 +<% end %>
... ...
app/views/cms/edit.html.erb
1 1 <%= error_messages_for 'article' %>
2 2  
  3 +<% if @article.archived? %>
  4 + <%= render :partial => 'archived_warning', :locals => {:article => @article} %>
  5 +<% end %>
3 6 <div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'>
4 7 <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
5 8  
... ... @@ -9,6 +12,7 @@
9 12  
10 13 <%= hidden_field_tag('success_back_to', @success_back_to) %>
11 14  
  15 +
12 16 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
13 17  
14 18 <% if environment.is_portal_community?(profile) %>
... ...
app/views/content_viewer/_article_toolbar.html.erb
... ... @@ -29,7 +29,9 @@
29 29 <%= expirable_button @page, :locale, content, url %>
30 30 <% end %>
31 31  
32   - <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:new, @page) %>
  32 + <% if !@page.archived? %>
  33 + <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:new, @page) %>
  34 + <% end %>
33 35  
34 36 <% content = content_tag('span', label_for_clone_article(@page)) %>
35 37 <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :parent_id => (@page.folder? ? @page : @page.parent), :type => @page.class}) %>
... ... @@ -64,6 +66,9 @@
64 66 <% end %>
65 67 <%= button_without_text(:feed, _('RSS feed'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %>
66 68 <%= @plugins.dispatch(:article_header_extra_contents, @page).collect { |content| instance_exec(&content) }.join("") %>
  69 + <% if @page.archived? %>
  70 + <%= render :partial => 'cms/archived_warning', :locals => {:article => @page} %>
  71 + <% end %>
67 72 <%= render :partial => 'article_title', :locals => {:no_link => true} %>
68 73 <%= article_translations(@page) %>
69 74 </div>
... ...
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  
... ...
app/views/content_viewer/view_page.html.erb
... ... @@ -85,7 +85,7 @@
85 85 <% end %>
86 86 </ul>
87 87  
88   - <% if @page.accept_comments? %>
  88 + <% if !@page.archived? || @page.accept_comments? %>
89 89 <div id='page-comment-form' class='page-comment-form'><%= render :partial => 'comment/comment_form', :locals =>{:url => {:controller => :comment, :action => :create}, :display_link => true, :cancel_triggers_hide => true}%></div>
90 90 <% end %>
91 91 </div><!-- end class="comments" -->
... ...
db/migrate/20151112135709_add_archived_to_articles.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddArchivedToArticles < ActiveRecord::Migration
  2 + def up
  3 + add_column :articles, :archived, :boolean, :default => false
  4 + end
  5 +
  6 + def down
  7 + remove_column :articles, :archived
  8 + end
  9 +end
... ...
plugins/vote/lib/ext/vote.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require_dependency 'models/vote'
  2 +
  3 +class Vote
  4 +
  5 + validate :verify_target_archived
  6 +
  7 + def verify_target_archived
  8 +
  9 + if voteable.kind_of?(Article) || voteable.kind_of?(Comment)
  10 + if voteable.archived?
  11 + errors.add(:base, _("The target is achived and can't accept votes"))
  12 + false
  13 + end
  14 + end
  15 +
  16 + end
  17 +
  18 +end
... ...
plugins/vote/lib/vote_plugin_helper.rb
... ... @@ -2,8 +2,10 @@ module VotePluginHelper
2 2  
3 3 def vote_partial(target, like = true, load_voters=false)
4 4 vote = like ? 1 : -1
  5 +
5 6 like_action = like ? 'like' : 'dislike'
6 7 type = target.kind_of?(Article) ? 'article' : target.kind_of?(Comment) ? 'comment' : nil
  8 + disable_vote = target.archived? ? true : false
7 9  
8 10 proc do
9 11 settings = Noosfero::Plugin::Settings.new(environment, VotePlugin)
... ... @@ -14,7 +16,7 @@ module VotePluginHelper
14 16 active = user ? (like ? user.voted_for?(target) : user.voted_against?(target)) : false
15 17 count = like ? target.votes_for : target.votes_against
16 18  
17   - render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type })
  19 + render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type, :disable_vote => disable_vote })
18 20 else
19 21 ""
20 22 end
... ...
plugins/vote/public/style.css
... ... @@ -73,3 +73,12 @@
73 73 #article .action .vote-detail img {
74 74 vertical-align: bottom;
75 75 }
  76 +
  77 +.comments-action-bar span.disabled a,
  78 +.comments-action-bar span.disabled a:hover,
  79 +.vote-actions span.disabled a,
  80 +.vote-actions span.disabled a:hover {
  81 + opacity: 0.5;
  82 + pointer-events: none;
  83 + cursor: default;
  84 +}
... ...
plugins/vote/public/vote_actions.js
... ... @@ -16,7 +16,9 @@ function openVotersDialog(div) {
16 16 clearTimeout(openEvent);
17 17 var url = $(div).data('reload_url');
18 18 hideAllVoteDetail();
19   - $.post(url);
  19 + if(url && url != '#'){
  20 + $.post(url);
  21 + }
20 22 }
21 23  
22 24 jQuery('body').live('click', function() { hideAllVoteDetail(); });
... ...
plugins/vote/test/functional/vote_plugin_profile_controller_test.rb
... ... @@ -35,6 +35,18 @@ class VotePluginProfileControllerTest &lt; ActionController::TestCase
35 35 assert profile.votes.empty?
36 36 end
37 37  
  38 + should 'not vote if a target is archived' do
  39 + article = Article.create!(:profile => profile, :name => 'Archived article', :archived => false)
  40 + comment = Comment.create!(:body => 'Comment test', :source => article, :author => profile)
  41 + xhr :post, :vote, :profile => profile.identifier, :id => article.id, :model => 'article', :vote => 1
  42 + assert !profile.votes.empty?
  43 +
  44 + article.update_attributes(:archived => true)
  45 + xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1
  46 +
  47 + assert !profile.voted_for?(comment)
  48 + end
  49 +
38 50 should 'like comment' do
39 51 xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1
40 52 assert profile.voted_for?(comment)
... ...
plugins/vote/views/vote/_vote.html.erb
1 1 <%
2   -url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote)
3   -reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote)
  2 +if disable_vote
  3 + url = reload_url = '#'
  4 + class_action = 'disabled'
  5 +else
  6 + url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote)
  7 + reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote)
  8 +end
4 9 %>
5 10  
6   -<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action">
  11 +<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action <%= class_action %>">
7 12  
8 13 <%= link_to content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), url, :class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'} require-login-popup" %>
9 14  
... ...
po/noosfero.pot
... ... @@ -5073,6 +5073,10 @@ msgid_plural &quot;Viewed %{num} times&quot;
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 &quot;Reply&quot;
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\""
... ...
public/images/icons-app/article-archived-icon.png 0 → 100644

166 Bytes

public/images/icons-app/article-private-icon.png 0 → 100644

273 Bytes

public/images/icons-app/article-public-icon.png 0 → 100644

570 Bytes

public/images/icons-app/warning-icon.png 0 → 100644

509 Bytes

public/javascripts/article.js
... ... @@ -212,4 +212,10 @@ jQuery(function($) {
212 212 $("#article_published_true").click(show_hide_privacy_options);
213 213 $(".custom_privacy_option").click(show_hide_token_input);
214 214  
  215 + //Workaround to pointer-events:none CSS3
  216 + $('a.disabled').click(function(e){
  217 + e.preventDefault();
  218 + return false;
  219 + });
  220 +
215 221 });
... ...
public/stylesheets/cms.scss
1 1 @import 'cms/fetch-external-feed';
2 2 @import 'cms/media-panel';
  3 +@import 'cms/access-options';
3 4  
4 5 table.cms-articles {
5 6 table-layout: fixed;
... ...
public/stylesheets/cms/access-options.scss 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +//Variables
  2 +$icons-size: 24px;
  3 +$warning-color: #e75e40;
  4 +$description-color: #666;
  5 +$access-types: public, private, archived;
  6 +
  7 +.text-warning {
  8 + text-align: center;
  9 + color: $warning-color;
  10 + font: {
  11 + size: 15px;
  12 + weight: bold;
  13 + }
  14 +
  15 + p i.icon {
  16 + display: inline-block;
  17 + font-size: inherit;
  18 + text-rendering: auto;
  19 + background: url('images/icons-app/warning-icon.png');
  20 + vertical-align: middle;
  21 + margin-top: -5px;
  22 + width: $icons-size;
  23 + height: $icons-size;
  24 + border: none;
  25 + }
  26 +}
  27 +
  28 +#edit-article-options {
  29 +
  30 + .access-itens .access-item {
  31 + input,label {
  32 + cursor: pointer;
  33 + }
  34 + }
  35 +
  36 + .access-item {
  37 + margin: 15px 0;
  38 + label {
  39 + font: {
  40 + size: 13px;
  41 + weight: bold;
  42 + }
  43 + }
  44 + }
  45 +
  46 + @each $access_type in $access-types {
  47 + .access-#{$access_type}-icon, .access-#{$access_type}-icon {
  48 + display: inline-block;
  49 + margin-right: 5px;
  50 + width: $icons-size;
  51 + height: $icons-size;
  52 + vertical-align: middle;
  53 + background-image: url('images/icons-app/article-#{$access_type}-icon.png');
  54 + }
  55 + }
  56 +
  57 + .access-note {
  58 + display: block;
  59 + margin: 0;
  60 + color: $description-color;
  61 + margin-left: 50px;
  62 + font: {
  63 + size: 12px;
  64 + weight: normal;
  65 + }
  66 + }
  67 +}
... ...
test/functional/cms_controller_test.rb
... ... @@ -697,6 +697,34 @@ class CmsControllerTest &lt; ActionController::TestCase
697 697 end
698 698 end
699 699  
  700 + should "marks a article like archived" do
  701 + article = create(Article, :profile => profile, :name => 'test', :published => true, :archived => false)
  702 +
  703 + post :edit, :profile => profile.identifier, :id => article.id, :article => {:archived => true}
  704 + get :edit, :profile => profile.identifier, :id => article.id
  705 + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[archived]', :id => 'article_archived', :checked => 'checked' }
  706 +
  707 + end
  708 +
  709 + should "try add children into archived folders" do
  710 + folder = create(Folder, :profile => profile, :name => 'test', :published => true, :archived => false)
  711 + article_child = create(Article, :profile => profile, :name => 'test child', :parent_id => folder.id, :published => true, :archived => false)
  712 +
  713 + get :edit, :profile => profile.identifier, :id => folder.id
  714 + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[archived]', :id => 'article_archived' }
  715 +
  716 + post :edit, :profile => profile.identifier, :id => folder.id, :article => {:archived => true}
  717 +
  718 + get :edit, :profile => profile.identifier, :id => article_child.id
  719 + assert_tag :tag => 'div', :attributes => { :class => 'text-warning'}
  720 +
  721 + err = assert_raises ActiveRecord::RecordInvalid do
  722 + another_article_child = create(Article, :profile => profile, :name => 'other test child', :parent_id => folder.id, :published => true, :archived => false)
  723 + end
  724 + assert_match 'Parent folder is archived', err.message
  725 +
  726 + end
  727 +
700 728 should 'be able to add image with alignment' do
701 729 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." }
702 730 saved = TinyMceArticle.find_by_name('image-alignment')
... ...
test/unit/article_test.rb
... ... @@ -2177,10 +2177,21 @@ class ArticleTest &lt; 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 &lt; 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 &lt; 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
... ...