Commit 936b15e687d59a51543a321e56e07808827cec49
1 parent
0588c69e
Exists in
web_steps_improvements
and in
8 other branches
tiny_mce: fix random failures with action tracker
Showing
1 changed file
with
17 additions
and
20 deletions
Show diff stats
test/unit/tiny_mce_article_test.rb
| @@ -5,7 +5,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -5,7 +5,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
| 5 | 5 | ||
| 6 | def setup | 6 | def setup |
| 7 | super | 7 | super |
| 8 | - @profile = create_user('zezinho').person | 8 | + @user = User.current = create_user('zezinho') |
| 9 | + @profile = @user.person | ||
| 9 | end | 10 | end |
| 10 | attr_reader :profile | 11 | attr_reader :profile |
| 11 | 12 | ||
| @@ -114,24 +115,22 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -114,24 +115,22 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
| 114 | 115 | ||
| 115 | should 'notify activity on create' do | 116 | should 'notify activity on create' do |
| 116 | ActionTracker::Record.delete_all | 117 | ActionTracker::Record.delete_all |
| 117 | - create TinyMceArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true | 118 | + create TinyMceArticle, name: 'test', profile_id: profile.id, published: true |
| 118 | assert_equal 1, ActionTracker::Record.count | 119 | assert_equal 1, ActionTracker::Record.count |
| 119 | end | 120 | end |
| 120 | 121 | ||
| 121 | should 'not group trackers activity of article\'s creation' do | 122 | should 'not group trackers activity of article\'s creation' do |
| 122 | ActionTracker::Record.delete_all | 123 | ActionTracker::Record.delete_all |
| 123 | - profile = fast_create(Profile) | ||
| 124 | - create TinyMceArticle, :name => 'bar', :profile_id => profile.id, :published => true | ||
| 125 | - create TinyMceArticle, :name => 'another bar', :profile_id => profile.id, :published => true | 124 | + create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true |
| 125 | + create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | ||
| 126 | assert_equal 2, ActionTracker::Record.count | 126 | assert_equal 2, ActionTracker::Record.count |
| 127 | - create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 127 | + create TinyMceArticle, name: 'another bar 2', profile_id: profile.id, published: true |
| 128 | assert_equal 3, ActionTracker::Record.count | 128 | assert_equal 3, ActionTracker::Record.count |
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | should 'not update activity on update of an article' do | 131 | should 'not update activity on update of an article' do |
| 132 | ActionTracker::Record.delete_all | 132 | ActionTracker::Record.delete_all |
| 133 | - profile = fast_create(Profile) | ||
| 134 | - article = create(TinyMceArticle, :profile_id => profile.id) | 133 | + article = create TinyMceArticle, profile_id: profile.id |
| 135 | time = article.activity.updated_at | 134 | time = article.activity.updated_at |
| 136 | Time.stubs(:now).returns(time + 1.day) | 135 | Time.stubs(:now).returns(time + 1.day) |
| 137 | assert_no_difference 'ActionTracker::Record.count' do | 136 | assert_no_difference 'ActionTracker::Record.count' do |
| @@ -143,8 +142,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -143,8 +142,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
| 143 | 142 | ||
| 144 | should 'not create trackers activity when updating articles' do | 143 | should 'not create trackers activity when updating articles' do |
| 145 | ActionTracker::Record.delete_all | 144 | ActionTracker::Record.delete_all |
| 146 | - a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | ||
| 147 | - a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 145 | + a1 = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true |
| 146 | + a2 = create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | ||
| 148 | assert_no_difference 'ActionTracker::Record.count' do | 147 | assert_no_difference 'ActionTracker::Record.count' do |
| 149 | a1.name = 'foo';a1.save! | 148 | a1.name = 'foo';a1.save! |
| 150 | a2.name = 'another foo';a2.save! | 149 | a2.name = 'another foo';a2.save! |
| @@ -153,34 +152,32 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -153,34 +152,32 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
| 153 | 152 | ||
| 154 | should 'remove activity when an article is destroyed' do | 153 | should 'remove activity when an article is destroyed' do |
| 155 | ActionTracker::Record.delete_all | 154 | ActionTracker::Record.delete_all |
| 156 | - a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | ||
| 157 | - a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 155 | + a1 = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true |
| 156 | + a2 = create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | ||
| 158 | assert_difference 'ActionTracker::Record.count', -2 do | 157 | assert_difference 'ActionTracker::Record.count', -2 do |
| 159 | a1.destroy | 158 | a1.destroy |
| 160 | a2.destroy | 159 | a2.destroy |
| 161 | -end | 160 | + end |
| 162 | end | 161 | end |
| 163 | 162 | ||
| 164 | should "the tracker action target be defined as the article on articles'creation in communities" do | 163 | should "the tracker action target be defined as the article on articles'creation in communities" do |
| 165 | ActionTracker::Record.delete_all | 164 | ActionTracker::Record.delete_all |
| 166 | community = fast_create(Community) | 165 | community = fast_create(Community) |
| 167 | - p1 = Person.first | ||
| 168 | - community.add_member(p1) | ||
| 169 | - assert p1.is_member_of?(community) | ||
| 170 | - article = create TinyMceArticle, :name => 'test', :profile_id => community.id | 166 | + community.add_member profile |
| 167 | + assert profile.is_member_of?(community) | ||
| 168 | + article = create TinyMceArticle, name: 'test', profile_id: community.id | ||
| 171 | assert_equal article, ActionTracker::Record.last.target | 169 | assert_equal article, ActionTracker::Record.last.target |
| 172 | end | 170 | end |
| 173 | 171 | ||
| 174 | should "the tracker action target be defined as the article on articles'creation in profile" do | 172 | should "the tracker action target be defined as the article on articles'creation in profile" do |
| 175 | ActionTracker::Record.delete_all | 173 | ActionTracker::Record.delete_all |
| 176 | - person = Person.first | ||
| 177 | - article = create TinyMceArticle, :name => 'test', :profile_id => person.id | 174 | + article = create TinyMceArticle, name: 'test', profile_id: profile.id |
| 178 | assert_equal article, ActionTracker::Record.last.target | 175 | assert_equal article, ActionTracker::Record.last.target |
| 179 | end | 176 | end |
| 180 | 177 | ||
| 181 | should 'not notify activity if the article is not advertise' do | 178 | should 'not notify activity if the article is not advertise' do |
| 182 | ActionTracker::Record.delete_all | 179 | ActionTracker::Record.delete_all |
| 183 | - a = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false | 180 | + a = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true, advertise: false |
| 184 | assert_equal true, a.published? | 181 | assert_equal true, a.published? |
| 185 | assert_equal true, a.notifiable? | 182 | assert_equal true, a.notifiable? |
| 186 | assert_equal false, a.image? | 183 | assert_equal false, a.image? |