Commit 46549f7006a07523a02c130c063de603015a2a50
Exists in
theme-brasil-digital-from-staging
and in
6 other branches
Merge branch 'master_rails3' into staging
Conflicts: app/models/article.rb app/models/comment.rb
Showing
29 changed files
with
305 additions
and
19 deletions
Show diff stats
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
| 1 | + | |
| 1 | 2 | class Article < ActiveRecord::Base |
| 2 | 3 | |
| 3 | 4 | attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, |
| ... | ... | @@ -8,7 +9,7 @@ class Article < ActiveRecord::Base |
| 8 | 9 | :highlighted, :notify_comments, :display_hits, :slug, |
| 9 | 10 | :external_feed_builder, :display_versions, :external_link, |
| 10 | 11 | :author, :published_at, :person_followers, :show_to_followers, |
| 11 | - :image_builder, :display_preview | |
| 12 | + :image_builder, :display_preview, :archived | |
| 12 | 13 | |
| 13 | 14 | acts_as_having_image |
| 14 | 15 | |
| ... | ... | @@ -157,6 +158,8 @@ class Article < ActiveRecord::Base |
| 157 | 158 | validate :no_self_reference |
| 158 | 159 | validate :no_cyclical_reference, :if => 'parent_id.present?' |
| 159 | 160 | |
| 161 | + validate :parent_archived? | |
| 162 | + | |
| 160 | 163 | def no_self_reference |
| 161 | 164 | errors.add(:parent_id, _('self-reference is not allowed.')) if id && parent_id == id |
| 162 | 165 | end |
| ... | ... | @@ -487,6 +490,10 @@ class Article < ActiveRecord::Base |
| 487 | 490 | end |
| 488 | 491 | end |
| 489 | 492 | |
| 493 | + def archived? | |
| 494 | + (self.parent && self.parent.archived) || self.archived | |
| 495 | + end | |
| 496 | + | |
| 490 | 497 | def self.folder_types |
| 491 | 498 | ['Folder', 'Blog', 'Forum', 'Gallery'] |
| 492 | 499 | end |
| ... | ... | @@ -633,13 +640,21 @@ class Article < ActiveRecord::Base |
| 633 | 640 | end |
| 634 | 641 | |
| 635 | 642 | def hit |
| 636 | - self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
| 637 | - self.hits += 1 | |
| 643 | + if !archived? | |
| 644 | + self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
| 645 | + self.hits += 1 | |
| 646 | + end | |
| 638 | 647 | end |
| 639 | 648 | |
| 640 | 649 | def self.hit(articles) |
| 641 | - Article.where(:id => articles.map(&:id)).update_all('hits = hits + 1') | |
| 642 | - articles.each { |a| a.hits += 1 } | |
| 650 | + ids = [] | |
| 651 | + articles.each do |article| | |
| 652 | + if !article.archived? | |
| 653 | + ids << article.id | |
| 654 | + article.hits += 1 | |
| 655 | + end | |
| 656 | + end | |
| 657 | + Article.where(:id => ids).update_all('hits = hits + 1') if !ids.empty? | |
| 643 | 658 | end |
| 644 | 659 | |
| 645 | 660 | def can_display_hits? |
| ... | ... | @@ -853,4 +868,10 @@ class Article < ActiveRecord::Base |
| 853 | 868 | sanitizer.sanitize(text) |
| 854 | 869 | end |
| 855 | 870 | |
| 871 | + def parent_archived? | |
| 872 | + if self.parent_id_changed? && self.parent && self.parent.archived? | |
| 873 | + errors.add(:parent_folder, N_('is archived!!')) | |
| 874 | + end | |
| 875 | + end | |
| 876 | + | |
| 856 | 877 | end | ... | ... |
app/models/comment.rb
| ... | ... | @@ -34,7 +34,9 @@ class Comment < ActiveRecord::Base |
| 34 | 34 | rec.errors.add(:name, _('{fn} can only be informed for unauthenticated authors').fix_i18n) |
| 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 < 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
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" --> | ... | ... |
| ... | ... | @@ -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 < 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 "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\"" | ... | ... |
166 Bytes
273 Bytes
570 Bytes
509 Bytes
public/javascripts/article.js
| ... | ... | @@ -200,4 +200,10 @@ jQuery(function($) { |
| 200 | 200 | |
| 201 | 201 | $(".custom_privacy_option").click(show_hide_token_input); |
| 202 | 202 | |
| 203 | + //Workaround to pointer-events:none CSS3 | |
| 204 | + $('a.disabled').click(function(e){ | |
| 205 | + e.preventDefault(); | |
| 206 | + return false; | |
| 207 | + }); | |
| 208 | + | |
| 203 | 209 | }); | ... | ... |
public/stylesheets/cms.scss
| ... | ... | @@ -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 < 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 < 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) |
| ... | ... | @@ -2239,4 +2250,25 @@ class ArticleTest < ActiveSupport::TestCase |
| 2239 | 2250 | assert !a.display_preview? |
| 2240 | 2251 | end |
| 2241 | 2252 | |
| 2253 | + should 'check if a article is archived' do | |
| 2254 | + folder = Folder.create!(:name => 'Parent Archived', :profile => profile) | |
| 2255 | + a1 = Article.create!(:name => 'Test', :profile => profile, :parent_id => folder.id, :archived => false) | |
| 2256 | + a2 = Article.create!(:name => 'Test 2', :profile => profile, :archived => true) | |
| 2257 | + folder.update_attributes(:archived => true) | |
| 2258 | + a1.reload | |
| 2259 | + | |
| 2260 | + assert a1.archived? | |
| 2261 | + assert a2.archived? | |
| 2262 | + end | |
| 2263 | + | |
| 2264 | + should 'try add a child article to a archived folder' do | |
| 2265 | + folder = Folder.create!(:name => 'Parent Archived', :profile => profile, :archived => true) | |
| 2266 | + | |
| 2267 | + err = assert_raises ActiveRecord::RecordInvalid do | |
| 2268 | + a1 = Article.create!(:name => 'Test', :profile => profile, :parent_id => folder.id, :archived => false) | |
| 2269 | + end | |
| 2270 | + | |
| 2271 | + assert_match 'Parent folder is archived', err.message | |
| 2272 | + end | |
| 2273 | + | |
| 2242 | 2274 | 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 | ... | ... |