From 45c0df82cf8ce0fa3d49810da8f225415f7da412 Mon Sep 17 00:00:00 2001 From: Marcos da Silva Ramos Date: Fri, 27 Nov 2015 18:08:11 -0200 Subject: [PATCH] Add feature: Article Followers --- app/controllers/public/profile_controller.rb | 12 ++++++++++++ app/helpers/article_helper.rb | 26 ++++++++++++++++++++++++++ app/models/article.rb | 19 ++++++++++++++++--- app/models/article_follower.rb | 7 +++++++ app/models/comment.rb | 12 ++++++------ app/models/person.rb | 5 +++-- app/views/comment/_comment_form.html.erb | 4 ++++ app/views/content_viewer/_article_toolbar.html.erb | 2 ++ app/views/content_viewer/_publishing_info.html.erb | 18 ++++++++++++++++++ db/migrate/20151210230319_add_followers_count_to_article.rb | 13 +++++++++++++ db/schema.rb | 14 ++++++++++++++ lib/noosfero/api/entities.rb | 1 + lib/noosfero/api/v1/articles.rb | 31 +++++++++++++++++++++++++++++++ test/functional/comment_controller_test.rb | 18 +++++++++++++++++- test/functional/content_viewer_controller_test.rb | 12 ------------ test/functional/profile_controller_test.rb | 31 +++++++++++++++++++++++++++++++ test/unit/api/articles_test.rb | 35 +++++++++++++++++++++++++++++++++++ test/unit/article_test.rb | 17 ++++++++++++++++- test/unit/comment_notifier_test.rb | 2 +- test/unit/comment_test.rb | 30 ++++++++++++++---------------- test/unit/person_notifier_test.rb | 3 ++- 21 files changed, 269 insertions(+), 43 deletions(-) create mode 100644 app/models/article_follower.rb create mode 100644 db/migrate/20151210230319_add_followers_count_to_article.rb diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 29fffad..af29bc0 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -155,6 +155,18 @@ class ProfileController < PublicController end end + def follow_article + article = profile.environment.articles.find params[:article_id] + article.person_followers << user + redirect_to article.url + end + + def unfollow_article + article = profile.environment.articles.find params[:article_id] + article.person_followers.delete(user) + redirect_to article.url + end + def unblock if current_user.person.is_admin?(profile.environment) profile.unblock diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 2e4bf25..a55c553 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -155,4 +155,30 @@ module ArticleHelper _('Edit') end + def follow_button_text(article) + if article.event? + _('Attend') + else + _('Follow') + end + end + + def unfollow_button_text(article) + if article.event? + _('Unattend') + else + _('Unfollow') + end + end + + def following_button(page, user) + if !user.blank? and user != page.author + if page.is_followed_by? user + button :cancel, unfollow_button_text(page), {:controller => 'profile', :action => 'unfollow_article', :article_id => page.id} + else + button :add, follow_button_text(page), {:controller => 'profile', :action => 'follow_article', :article_id => page.id} + end + end + end + end diff --git a/app/models/article.rb b/app/models/article.rb index 7b0278b..82c3842 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -9,7 +9,7 @@ class Article < ActiveRecord::Base :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :show_to_followers, - :author, :display_preview, :published_at + :author, :display_preview, :published_at, :person_followers acts_as_having_image @@ -77,8 +77,15 @@ class Article < ActiveRecord::Base belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' +<<<<<<< 6fa2f904983046ed816efe293ba9dcad19a67a4b has_many :comments, :class_name => 'Comment', :as => 'source', :dependent => :destroy, :order => 'created_at asc' +======= + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' + has_many :article_followers, :dependent => :destroy + has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person + has_many :person_followers_emails, :class_name => 'User', :through => :person_followers, :source => :user, :select => :email +>>>>>>> Add feature: Article Followers has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } has_many :categories, :through => :article_categorizations @@ -91,7 +98,6 @@ class Article < ActiveRecord::Base settings_items :author_name, :type => :string, :default => "" settings_items :allow_members_to_edit, :type => :boolean, :default => false settings_items :moderate_comments, :type => :boolean, :default => false - settings_items :followers, :type => Array, :default => [] has_and_belongs_to_many :article_privacy_exceptions, :class_name => 'Person', :join_table => 'article_privacy_exceptions' belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' @@ -167,7 +173,6 @@ class Article < ActiveRecord::Base end end - def is_trackable? self.published? && self.notifiable? && self.advertise? && self.profile.public_profile end @@ -368,6 +373,10 @@ class Article < ActiveRecord::Base self.parent and self.parent.forum? end + def person_followers_email_list + person_followers_emails.map{|p|p.email} + end + def info_from_last_update last_comment = comments.last if last_comment @@ -407,6 +416,10 @@ class Article < ActiveRecord::Base (not self.uploaded_file? and self.mime_type != 'text/html') end + def is_followed_by?(user) + self.person_followers.include? user + end + def download_headers {} end diff --git a/app/models/article_follower.rb b/app/models/article_follower.rb new file mode 100644 index 0000000..598e070 --- /dev/null +++ b/app/models/article_follower.rb @@ -0,0 +1,7 @@ +class ArticleFollower < ActiveRecord::Base + + attr_accessible :article_id, :person_id + belongs_to :article, :counter_cache => :followers_count + belongs_to :person + +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 401c1a4..95d3654 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,13 +6,14 @@ class Comment < ActiveRecord::Base :body => {:label => _('Content'), :weight => 2}, } - attr_accessible :body, :author, :name, :email, :title, :reply_of_id, :source + attr_accessible :body, :author, :name, :email, :title, :reply_of_id, :source, :follow_article validates_presence_of :body belongs_to :source, :counter_cache => true, :polymorphic => true alias :article :source alias :article= :source= + attr_accessor :follow_article belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy @@ -100,10 +101,9 @@ class Comment < ActiveRecord::Base after_create :new_follower def new_follower - if source.kind_of?(Article) - article.followers += [author_email] - article.followers -= article.profile.notification_emails - article.followers.uniq! + if source.kind_of?(Article) and !author.nil? and @follow_article + article.person_followers += [author] + article.person_followers.uniq! article.save end end @@ -145,7 +145,7 @@ class Comment < ActiveRecord::Base if !notification_emails.empty? CommentNotifier.notification(self).deliver end - emails = article.followers - [author_email] + emails = article.person_followers_email_list - [author_email] if !emails.empty? CommentNotifier.mail_to_followers(self, emails).deliver end diff --git a/app/models/person.rb b/app/models/person.rb index 03e4d15..88c84a0 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,7 +1,7 @@ # A person is the profile of an user holding all relationships with the rest of the system class Person < Profile - attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website + attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website, :following_articles SEARCH_FILTERS = { :order => %w[more_recent more_popular more_active], @@ -84,7 +84,8 @@ class Person < Profile end has_many :comments, :foreign_key => :author_id - + has_many :article_followers, :dependent => :destroy + has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article has_many :friendships, :dependent => :destroy has_many :friends, :class_name => 'Person', :through => :friendships diff --git a/app/views/comment/_comment_form.html.erb b/app/views/comment/_comment_form.html.erb index a4ba5ce..7c628ae 100644 --- a/app/views/comment/_comment_form.html.erb +++ b/app/views/comment/_comment_form.html.erb @@ -77,6 +77,10 @@ function check_captcha(button, confirm_action) { <%= labelled_form_field(_('Title'), f.text_field(:title)) %> <%= required labelled_form_field(_('Enter your comment'), f.text_area(:body, :rows => 5)) %> + <% if logged_in? %> + <%= labelled_form_field check_box(:comment, :follow_article, {}, true, false) + _('Follow this article'), '' %> + <% end%> + <%= hidden_field_tag(:confirm, 'false') %> <%= hidden_field_tag(:view, params[:view])%> <%= f.hidden_field(:reply_of_id) %> diff --git a/app/views/content_viewer/_article_toolbar.html.erb b/app/views/content_viewer/_article_toolbar.html.erb index a5cebd1..5b532af 100644 --- a/app/views/content_viewer/_article_toolbar.html.erb +++ b/app/views/content_viewer/_article_toolbar.html.erb @@ -55,6 +55,8 @@ <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url], plugin_button[:html_options] %> <% end %> + <%= following_button @page, user %> + <%= report_abuse(profile, :link, @page) %> diff --git a/app/views/content_viewer/_publishing_info.html.erb b/app/views/content_viewer/_publishing_info.html.erb index 4ad7e71..d212203 100644 --- a/app/views/content_viewer/_publishing_info.html.erb +++ b/app/views/content_viewer/_publishing_info.html.erb @@ -10,6 +10,24 @@ <%= (" - %s") % link_to_comments(@page)%> <% end %> + + +| +<% if @page.event? %> + <% if @page.person_followers.size > 0 %> + <%= _("%s will attend this event.") % [ pluralize(@page.person_followers.size, _("person"))]%> + <% else %> + <%= _("No one attending this event yet.") %> + <% end %> +<% else %> + <% if @page.person_followers.size > 0 %> + <%= _("%s following this article.") % [ pluralize(@page.person_followers.size, _("person"))]%> + <% else %> + <%= _("No one following this article yet.") %> + <% end %> +<% end %> + + <% if @page.display_hits? || @page.license.present? %> diff --git a/db/migrate/20151210230319_add_followers_count_to_article.rb b/db/migrate/20151210230319_add_followers_count_to_article.rb new file mode 100644 index 0000000..2b3b4a1 --- /dev/null +++ b/db/migrate/20151210230319_add_followers_count_to_article.rb @@ -0,0 +1,13 @@ +class AddFollowersCountToArticle < ActiveRecord::Migration + + def self.up + add_column :articles, :followers_count, :integer, :default => 0 + + execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)" + end + + def self.down + remove_column :articles, :followers_count + end + +end diff --git a/db/schema.rb b/db/schema.rb index 9e69298..c28a240 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -51,6 +51,18 @@ ActiveRecord::Schema.define(version: 20160202142247) do add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], name: "index_action_tracker_notif_on_prof_id_act_tracker_id", unique: true, using: :btree add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree + create_table "article_followers", force: :cascade do |t| + t.integer "person_id", null: false + t.integer "article_id", null: false + t.datetime "since" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "article_followers", ["article_id"], name: "index_article_followers_on_article_id", using: :btree + add_index "article_followers", ["person_id", "article_id"], name: "index_article_followers_on_person_id_and_article_id", unique: true, using: :btree + add_index "article_followers", ["person_id"], name: "index_article_followers_on_person_id", using: :btree + create_table "article_privacy_exceptions", id: false, force: :cascade do |t| t.integer "article_id" t.integer "person_id" @@ -101,6 +113,7 @@ ActiveRecord::Schema.define(version: 20160202142247) do t.integer "spam_comments_count", default: 0 t.integer "author_id" t.integer "created_by_id" + t.integer "followers_count" end add_index "article_versions", ["article_id"], name: "index_article_versions_on_article_id", using: :btree @@ -154,6 +167,7 @@ ActiveRecord::Schema.define(version: 20160202142247) do t.integer "author_id" t.integer "created_by_id" t.boolean "show_to_followers", default: true + t.integer "followers_count", default: 0 end add_index "articles", ["comments_count"], name: "index_articles_on_comments_count", using: :btree diff --git a/lib/noosfero/api/entities.rb b/lib/noosfero/api/entities.rb index e6edf5d..9b5d180 100644 --- a/lib/noosfero/api/entities.rb +++ b/lib/noosfero/api/entities.rb @@ -148,6 +148,7 @@ module Noosfero expose :children_count expose :slug, :documentation => {:type => "String", :desc => "Trimmed and parsed name of a article"} expose :path + expose :followers_count end class Article < ArticleBase diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index c8f3e82..f7711cd 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -112,6 +112,37 @@ module Noosfero {:vote => vote.save} end + desc "Returns the total followers for the article" do + detail 'Get the followers of a specific article by id' + failure [[403, 'Forbidden']] + named 'ArticleFollowers' + end + get ':id/followers' do + article = find_article(environment.articles, params[:id]) + total = article.person_followers.count + {:total_followers => total} + end + + desc "Add a follower for the article" do + detail 'Add the current user identified by private token, like a follower of a article' + params Noosfero::API::Entities::UserLogin.documentation + failure [[401, 'Unauthorized']] + named 'ArticleFollow' + end + post ':id/follow' do + authenticate! + article = find_article(environment.articles, params[:id]) + if article.article_followers.exists?(:person_id => current_person.id) + {:success => false, :already_follow => true} + else + article_follower = ArticleFollower.new + article_follower.article = article + article_follower.person = current_person + article_follower.save! + {:success => true} + end + end + desc 'Return the children of a article identified by id' do detail 'Get all children articles of a specific article' params Noosfero::API::Entities::Article.documentation diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb index dd786a2..08d5365 100644 --- a/test/functional/comment_controller_test.rb +++ b/test/functional/comment_controller_test.rb @@ -387,10 +387,26 @@ class CommentControllerTest < ActionController::TestCase Article.record_timestamps = true login_as @profile.identifier - xhr :post, :create, :profile => profile.identifier, :id => page.id, :comment => { :title => 'crap!', :body => 'I think that this article is crap' }, :confirm => 'true' + xhr :post, :create, :profile => profile.identifier, :id => page.id, :comment => {:title => 'crap!', :body => 'I think that this article is crap' }, :confirm => 'true' assert_not_equal yesterday, page.reload.updated_at end + should 'follow article when commenting' do + page = create(Article, :profile => profile, :name => 'myarticle', :body => 'the body of the text') + login_as @profile.identifier + + xhr :post, :create, :profile => profile.identifier, :id => page.id, :comment => {:title => 'crap!', :body => 'I think that this article is crap', :follow_article => true}, :confirm => 'true' + assert_includes page.person_followers, @profile + end + + should 'not follow article when commenting' do + page = create(Article, :profile => profile, :name => 'myarticle', :body => 'the body of the text') + login_as @profile.identifier + + xhr :post, :create, :profile => profile.identifier, :id => page.id, :comment => {:title => 'crap!', :body => 'I think that this article is crap', :follow_article => false }, :confirm => 'true' + assert_not_includes page.person_followers, @profile + end + should 'be able to mark comments as spam' do login_as profile.identifier article = fast_create(Article, :profile_id => profile.id) diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 0a34c08..66b612a 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1278,18 +1278,6 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => 'This button is expired.', :class => 'button with-text icon-edit disabled' } } end - should 'remove email from article followers when unfollow' do - profile = create_user('testuser').person - follower_email = 'john@doe.br' - article = profile.articles.create(:name => 'test') - article.followers = [follower_email] - article.save - - assert_includes Article.find(article.id).followers, follower_email - post :view_page, :profile => profile.identifier, :page => [article.name], :unfollow => 'commit', :email => follower_email - assert_not_includes Article.find(article.id).followers, follower_email - end - should 'not display comments marked as spam' do article = fast_create(Article, :profile_id => profile.id) ham = fast_create(Comment, :source_id => article.id, :source_type => 'Article', :title => 'some content') diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index dde263f..a0123fc 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -18,6 +18,19 @@ class ProfileControllerTest < ActionController::TestCase assert assigns(:friends) end + should 'remove person from article followers when unfollow' do + profile = create_user('testuser').person + follower = create_user('follower').person + article = profile.articles.create(:name => 'test') + article.person_followers = [follower] + article.save + login_as('follower') + article.reload + assert_includes Article.find(article.id).person_followers, follower + post :unfollow_article, :article_id => article.id + assert_not_includes Article.find(article.id).person_followers, follower + end + should 'point to manage friends in user is seeing his own friends' do login_as('testuser') get :friends @@ -1338,6 +1351,24 @@ class ProfileControllerTest < ActionController::TestCase assert_equivalent [scrap,activity], assigns(:activities).map(&:activity) end + should "follow an article" do + article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') + login_as(@profile.identifier) + post :follow_article, :profile => profile.identifier, :article_id => article.id + assert_includes article.person_followers, @profile + end + + should "unfollow an article" do + article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') + article.person_followers << @profile + article.save! + assert_includes article.person_followers, @profile + + login_as(@profile.identifier) + post :unfollow_article, :profile => profile.identifier, :article_id => article.id + assert_not_includes article.person_followers, @profile + end + should "be logged in to leave comment on an activity" do article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') activity = ActionTracker::Record.last diff --git a/test/unit/api/articles_test.rb b/test/unit/api/articles_test.rb index 280fb8d..a85c375 100644 --- a/test/unit/api/articles_test.rb +++ b/test/unit/api/articles_test.rb @@ -39,6 +39,41 @@ class ArticlesTest < ActiveSupport::TestCase assert_equal 403, last_response.status end + should 'follow a article identified by id' do + article = fast_create(Article, :profile_id => @person.id, :name => "Some thing") + post "/api/v1/articles/#{article.id}/follow?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_not_equal 401, last_response.status + assert_equal true, json['success'] + end + + should 'return the followers count of an article' do + article = fast_create(Article, :profile_id => @person.id, :name => "Some thing") + article.person_followers << @person + + get "/api/v1/articles/#{article.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_equal 200, last_response.status + assert_equal 1, json['article']['followers_count'] + end + + should 'return the followers of a article identified by id' do + article = fast_create(Article, :profile_id => @person.id, :name => "Some thing") + + article_follower = ArticleFollower.new + article_follower.article = article + article_follower.person = @person + article_follower.save! + + get "/api/v1/articles/#{article.id}/followers?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_equal 200, last_response.status + assert_equal 1, json['total_followers'] + end + should 'list article children' do article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 13aa81b..459cb2a 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -22,6 +22,21 @@ class ArticleTest < ActiveSupport::TestCase refute a.errors[:profile_id.to_s].present? end + should 'keep unique users in list of followers' do + person1 = create_user('article_owner').person + person2 = create_user('article_follower').person + + article = fast_create(Article, :profile_id => person1.id) + + article.person_followers=[person2] + article.save + article.reload + article.person_followers=[person2] + article.save + + assert_equal 1, article.reload.person_followers.size + end + should 'require value for name' do a = Article.new a.valid? @@ -1700,7 +1715,7 @@ class ArticleTest < ActiveSupport::TestCase should 'has a empty list of followers by default' do a = Article.new - assert_equal [], a.followers + assert_equal [], a.person_followers end should 'get first image from lead' do diff --git a/test/unit/comment_notifier_test.rb b/test/unit/comment_notifier_test.rb index 00bf070..455d4bf 100644 --- a/test/unit/comment_notifier_test.rb +++ b/test/unit/comment_notifier_test.rb @@ -60,7 +60,7 @@ class CommentNotifierTest < ActiveSupport::TestCase should "deliver mail to followers" do author = create_user('follower_author').person follower = create_user('follower').person - @article.followers += [follower.email] + @article.person_followers += [follower] @article.save! create_comment_and_notify(:source => @article, :author => author, :title => 'comment title', :body => 'comment body') assert_includes ActionMailer::Base.deliveries.map(&:bcc).flatten, follower.email diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index a93cc85..409c6fa 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -328,34 +328,27 @@ class CommentTest < ActiveSupport::TestCase assert c.rejected? end - should 'subscribe user as follower of an article on new comment' do + should 'not subscribe user as follower of an article automatically on new comment' do owner = create_user('owner_of_article').person person = create_user('follower').person article = fast_create(Article, :profile_id => owner.id) - assert_not_includes article.followers, person.email + assert_not_includes article.person_followers, person create(Comment, :source => article, :author => person, :title => 'new comment', :body => 'new comment') - assert_includes article.reload.followers, person.email + assert_not_includes article.reload.person_followers, person end - should 'subscribe guest user as follower of an article on new comment' do + should 'not subscribe guest user as follower of an article on new comment' do article = fast_create(Article, :profile_id => create_user('article_owner').person.id) - assert_not_includes article.followers, 'follower@example.com' + old_num_followers = article.reload.person_followers.size create(Comment, :source => article, :name => 'follower', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment') - assert_includes article.reload.followers, 'follower@example.com' - end - - should 'keep unique emails in list of followers' do - article = fast_create(Article, :profile_id => create_user('article_owner').person.id) - create(Comment, :source => article, :name => 'follower one', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment') - create(Comment, :source => article, :name => 'follower two', :email => 'follower@example.com', :title => 'another comment', :body => 'new comment') - assert_equal 1, article.reload.followers.select{|v| v == 'follower@example.com'}.count + assert_equal old_num_followers, article.reload.person_followers.size end should 'not subscribe owner as follower of an article on new comment' do owner = create_user('owner_of_article').person article = fast_create(Article, :profile_id => owner.id) create(Comment, :source => article, :author => owner, :title => 'new comment', :body => 'new comment') - assert_not_includes article.reload.followers, owner.email + assert_not_includes article.reload.person_followers, owner end should 'not subscribe admins as follower of an article on new comment' do @@ -366,8 +359,13 @@ class CommentTest < ActiveSupport::TestCase article = fast_create(Article, :profile_id => owner.id) create(Comment, :source => article, :author => follower, :title => 'new comment', :body => 'new comment') create(Comment, :source => article, :author => admin, :title => 'new comment', :body => 'new comment') - assert_not_includes article.reload.followers, admin.email - assert_includes article.followers, follower.email + + article.person_followers += [follower] + article.save! + article.reload + + assert_not_includes article.reload.person_followers, admin + assert_includes article.reload.person_followers, follower end should 'update article activity when add a comment' do diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb index 5bf3964..0a37d1e 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -49,7 +49,8 @@ class PersonNotifierTest < ActiveSupport::TestCase should 'display author name in delivered mail' do @community.add_member(@member) User.current = @admin.user - Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) + comment = Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) + comment.save! process_delayed_job_queue notify sent = ActionMailer::Base.deliveries.last -- libgit2 0.21.2