Commit ccc53a309872248683ad35cb48d3afe35b6e4c1f
1 parent
dd30815a
Exists in
web_steps_improvements
and in
9 other branches
creating new tests for followers stuff
Showing
2 changed files
with
49 additions
and
20 deletions
Show diff stats
test/unit/article_test.rb
@@ -22,21 +22,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -22,21 +22,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
22 | refute a.errors[:profile_id.to_s].present? | 22 | refute a.errors[:profile_id.to_s].present? |
23 | end | 23 | end |
24 | 24 | ||
25 | - should 'keep unique users in list of followers' do | ||
26 | - person1 = create_user('article_owner').person | ||
27 | - person2 = create_user('article_follower').person | ||
28 | - | ||
29 | - article = fast_create(Article, :profile_id => person1.id) | ||
30 | - | ||
31 | - article.person_followers=[person2] | ||
32 | - article.save | ||
33 | - article.reload | ||
34 | - article.person_followers=[person2] | ||
35 | - article.save | ||
36 | - | ||
37 | - assert_equal 1, article.reload.person_followers.size | ||
38 | - end | ||
39 | - | ||
40 | should 'require value for name' do | 25 | should 'require value for name' do |
41 | a = Article.new | 26 | a = Article.new |
42 | a.valid? | 27 | a.valid? |
@@ -1713,11 +1698,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1713,11 +1698,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
1713 | assert post.allow_edit?(author) | 1698 | assert post.allow_edit?(author) |
1714 | end | 1699 | end |
1715 | 1700 | ||
1716 | - should 'has a empty list of followers by default' do | ||
1717 | - a = Article.new | ||
1718 | - assert_equal [], a.person_followers | ||
1719 | - end | ||
1720 | - | ||
1721 | should 'get first image from lead' do | 1701 | should 'get first image from lead' do |
1722 | a = fast_create(Article, :body => '<p>Foo</p><p><img src="bar.png" />Bar<img src="foo.png" /></p>', | 1702 | a = fast_create(Article, :body => '<p>Foo</p><p><img src="bar.png" />Bar<img src="foo.png" /></p>', |
1723 | :abstract => '<p>Lead</p><p><img src="leadbar.png" />Bar<img src="leadfoo.png" /></p>') | 1703 | :abstract => '<p>Lead</p><p><img src="leadbar.png" />Bar<img src="leadfoo.png" /></p>') |
@@ -2269,5 +2249,44 @@ class ArticleTest < ActiveSupport::TestCase | @@ -2269,5 +2249,44 @@ class ArticleTest < ActiveSupport::TestCase | ||
2269 | end | 2249 | end |
2270 | end | 2250 | end |
2271 | 2251 | ||
2252 | + should 'the owner not in followers list' do | ||
2253 | + person1 = create_user('article_owner').person | ||
2254 | + person2 = create_user('article_follower').person | ||
2255 | + | ||
2256 | + article = fast_create(Article, :profile_id => person1.id) | ||
2257 | + | ||
2258 | + article.person_followers=[person2] | ||
2259 | + article.save | ||
2260 | + article.reload | ||
2261 | + article.person_followers=[person2] | ||
2262 | + article.save | ||
2263 | + | ||
2264 | + assert_equal [person2], article.reload.person_followers | ||
2265 | + end | ||
2266 | + | ||
2267 | + should 'has a empty list of followers by default' do | ||
2268 | + a = Article.new | ||
2269 | + assert_equal [], a.person_followers | ||
2270 | + end | ||
2271 | + | ||
2272 | + should 'a follower not be duplicated' do | ||
2273 | + follower = create_user('article_follower').person | ||
2274 | + | ||
2275 | + article = fast_create(Article, :profile_id => fast_create(Person)) | ||
2276 | + | ||
2277 | + article.person_followers<< follower | ||
2278 | + assert_raises (ActiveRecord::RecordNotUnique) { article.person_followers<< follower } | ||
2279 | + end | ||
2280 | + | ||
2281 | + should 'an article be follower by many users' do | ||
2282 | + article = fast_create(Article, :profile_id => fast_create(Person)) | ||
2283 | + | ||
2284 | + 1.upto(10).map do |n| | ||
2285 | + article.person_followers<< fast_create(Person) | ||
2286 | + end | ||
2287 | + article.save | ||
2288 | + assert_equal 10, article.reload.person_followers.count | ||
2289 | + end | ||
2290 | + | ||
2272 | 2291 | ||
2273 | end | 2292 | end |
test/unit/person_test.rb
@@ -1934,4 +1934,14 @@ class PersonTest < ActiveSupport::TestCase | @@ -1934,4 +1934,14 @@ class PersonTest < ActiveSupport::TestCase | ||
1934 | assert !person.member_relation_of(community).empty?, "Person '#{person.identifier}' is not a member of Community '#{community.identifier}'" | 1934 | assert !person.member_relation_of(community).empty?, "Person '#{person.identifier}' is not a member of Community '#{community.identifier}'" |
1935 | assert person.member_since_date(community) == Date.today,"Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" | 1935 | assert person.member_since_date(community) == Date.today,"Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" |
1936 | end | 1936 | end |
1937 | + | ||
1938 | + should 'a person follows many articles' do | ||
1939 | + person = create_user('article_follower').person | ||
1940 | + | ||
1941 | + 1.upto(10).map do |n| | ||
1942 | + person.following_articles << fast_create(Article, :profile_id => fast_create(Person)) | ||
1943 | + end | ||
1944 | + assert_equal 10, person.following_articles.count | ||
1945 | + end | ||
1946 | + | ||
1937 | end | 1947 | end |