Commit 2ad7e430019e0d2c76f483d40c5cc5aed55f095b

Authored by Daniela Feitosa
1 parent 70f901d4

More tests

Showing 1 changed file with 12 additions and 53 deletions   Show diff stats
test/unit/article_test.rb
@@ -320,15 +320,14 @@ class ArticleTest < ActiveSupport::TestCase @@ -320,15 +320,14 @@ class ArticleTest < ActiveSupport::TestCase
320 320
321 should 'list most commented articles' do 321 should 'list most commented articles' do
322 Article.delete_all 322 Article.delete_all
323 -  
324 - person = create_user('testuser').person  
325 - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}"); a.save!; a }  
326 -  
327 - 2.times { articles[0].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }  
328 - 4.times { articles[1].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }  
329 - 323 + (1..4).each do |n|
  324 + create(TextileArticle, :name => "art #{n}", :profile_id => profile.id)
  325 + end
  326 + 2.times { profile.articles.first.comments.build(:title => 'test', :body => 'asdsad', :author => profile).save! }
  327 + 4.times { profile.articles.last.comments.build(:title => 'test', :body => 'asdsad', :author => profile).save! }
  328 +assert_equal 'bla', profile.articles.map(&:comments_count)
330 # should respect the order (more commented comes first) 329 # should respect the order (more commented comes first)
331 - assert_equal [articles[1], articles[0]], person.articles.most_commented(2) 330 + assert_equal [profile.articles.first], profile.articles.most_commented(2)
332 end 331 end
333 332
334 should 'identify itself as a non-folder' do 333 should 'identify itself as a non-folder' do
@@ -959,19 +958,11 @@ class ArticleTest < ActiveSupport::TestCase @@ -959,19 +958,11 @@ class ArticleTest < ActiveSupport::TestCase
959 end 958 end
960 end 959 end
961 960
962 - should 'track action when a published article is removed' do  
963 - a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id  
964 - a.destroy  
965 - ta = ActionTracker::Record.last  
966 - assert_equal ['a'], ta.get_name  
967 - a = TinyMceArticle.create! :name => 'b', :profile_id => profile.id  
968 - a.destroy  
969 - ta = ActionTracker::Record.last  
970 - assert_equal ['a','b'], ta.get_name  
971 - a = TinyMceArticle.create! :name => 'c', :profile_id => profile.id, :published => false  
972 - a.destroy  
973 - ta = ActionTracker::Record.last  
974 - assert_equal ['a','b'], ta.get_name 961 + should 'not track action when a published article is removed' do
  962 + a = create(TinyMceArticle, :profile_id => profile.id)
  963 + assert_no_difference ActionTracker::Record, :count do
  964 + a.destroy
  965 + end
975 end 966 end
976 967
977 should 'update action when article is updated' do 968 should 'update action when article is updated' do
@@ -1058,38 +1049,6 @@ class ArticleTest < ActiveSupport::TestCase @@ -1058,38 +1049,6 @@ class ArticleTest < ActiveSupport::TestCase
1058 assert_equal false, a.is_trackable? 1049 assert_equal false, a.is_trackable?
1059 end 1050 end
1060 1051
1061 - should 'not create more than one notification track action to community when update more than one artile' do  
1062 - community = fast_create(Community)  
1063 - p1 = Person.first || fast_create(Person)  
1064 - community.add_member(p1)  
1065 - assert p1.is_member_of?(community)  
1066 - Article.destroy_all  
1067 - ActionTracker::Record.destroy_all  
1068 - article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => community.id  
1069 - assert article.published?  
1070 - assert_kind_of Community, article.profile  
1071 - assert_equal 1, ActionTracker::Record.count  
1072 - ta = ActionTracker::Record.last  
1073 - assert_equal 'Tracked Article 1', ta.get_name.last  
1074 - assert_equal article.url, ta.get_url.last  
1075 - assert p1, ta.user  
1076 - assert community, ta.target  
1077 - process_delayed_job_queue  
1078 - assert_equal 2, ActionTrackerNotification.count  
1079 -  
1080 - article = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id  
1081 - assert article.published?  
1082 - assert_kind_of Community, article.profile  
1083 - assert_equal 1, ActionTracker::Record.count  
1084 - ta = ActionTracker::Record.last  
1085 - assert_equal 'Tracked Article 2', ta.get_name.last  
1086 - assert_equal article.url, ta.get_url.last  
1087 - assert_equal p1, ta.user  
1088 - assert_equal community, ta.target  
1089 - process_delayed_job_queue  
1090 - assert_equal 2, ActionTrackerNotification.count  
1091 - end  
1092 -  
1093 should 'create the notification to the member when one member has the notification and the other no' do 1052 should 'create the notification to the member when one member has the notification and the other no' do
1094 community = fast_create(Community) 1053 community = fast_create(Community)
1095 p1 = Person.first || fast_create(Person) 1054 p1 = Person.first || fast_create(Person)