diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 96b411d..1cadb59 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -22,21 +22,6 @@ 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? @@ -1713,11 +1698,6 @@ class ArticleTest < ActiveSupport::TestCase assert post.allow_edit?(author) end - should 'has a empty list of followers by default' do - a = Article.new - assert_equal [], a.person_followers - end - should 'get first image from lead' do a = fast_create(Article, :body => '

Foo

Bar

', :abstract => '

Lead

Bar

') @@ -2269,5 +2249,44 @@ class ArticleTest < ActiveSupport::TestCase end end + should 'the owner not in followers list' 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 [person2], article.reload.person_followers + end + + should 'has a empty list of followers by default' do + a = Article.new + assert_equal [], a.person_followers + end + + should 'a follower not be duplicated' do + follower = create_user('article_follower').person + + article = fast_create(Article, :profile_id => fast_create(Person)) + + article.person_followers<< follower + assert_raises (ActiveRecord::RecordNotUnique) { article.person_followers<< follower } + end + + should 'an article be follower by many users' do + article = fast_create(Article, :profile_id => fast_create(Person)) + + 1.upto(10).map do |n| + article.person_followers<< fast_create(Person) + end + article.save + assert_equal 10, article.reload.person_followers.count + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 75873fd..9fe09c7 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1934,4 +1934,14 @@ class PersonTest < ActiveSupport::TestCase assert !person.member_relation_of(community).empty?, "Person '#{person.identifier}' is not a member of Community '#{community.identifier}'" assert person.member_since_date(community) == Date.today,"Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" end + + should 'a person follows many articles' do + person = create_user('article_follower').person + + 1.upto(10).map do |n| + person.following_articles << fast_create(Article, :profile_id => fast_create(Person)) + end + assert_equal 10, person.following_articles.count + end + end -- libgit2 0.21.2