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 | 5 | |
| 6 | 6 | def setup |
| 7 | 7 | super |
| 8 | - @profile = create_user('zezinho').person | |
| 8 | + @user = User.current = create_user('zezinho') | |
| 9 | + @profile = @user.person | |
| 9 | 10 | end |
| 10 | 11 | attr_reader :profile |
| 11 | 12 | |
| ... | ... | @@ -114,24 +115,22 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
| 114 | 115 | |
| 115 | 116 | should 'notify activity on create' do |
| 116 | 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 | 119 | assert_equal 1, ActionTracker::Record.count |
| 119 | 120 | end |
| 120 | 121 | |
| 121 | 122 | should 'not group trackers activity of article\'s creation' do |
| 122 | 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 | 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 | 128 | assert_equal 3, ActionTracker::Record.count |
| 129 | 129 | end |
| 130 | 130 | |
| 131 | 131 | should 'not update activity on update of an article' do |
| 132 | 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 | 134 | time = article.activity.updated_at |
| 136 | 135 | Time.stubs(:now).returns(time + 1.day) |
| 137 | 136 | assert_no_difference 'ActionTracker::Record.count' do |
| ... | ... | @@ -143,8 +142,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
| 143 | 142 | |
| 144 | 143 | should 'not create trackers activity when updating articles' do |
| 145 | 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 | 147 | assert_no_difference 'ActionTracker::Record.count' do |
| 149 | 148 | a1.name = 'foo';a1.save! |
| 150 | 149 | a2.name = 'another foo';a2.save! |
| ... | ... | @@ -153,34 +152,32 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
| 153 | 152 | |
| 154 | 153 | should 'remove activity when an article is destroyed' do |
| 155 | 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 | 157 | assert_difference 'ActionTracker::Record.count', -2 do |
| 159 | 158 | a1.destroy |
| 160 | 159 | a2.destroy |
| 161 | -end | |
| 160 | + end | |
| 162 | 161 | end |
| 163 | 162 | |
| 164 | 163 | should "the tracker action target be defined as the article on articles'creation in communities" do |
| 165 | 164 | ActionTracker::Record.delete_all |
| 166 | 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 | 169 | assert_equal article, ActionTracker::Record.last.target |
| 172 | 170 | end |
| 173 | 171 | |
| 174 | 172 | should "the tracker action target be defined as the article on articles'creation in profile" do |
| 175 | 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 | 175 | assert_equal article, ActionTracker::Record.last.target |
| 179 | 176 | end |
| 180 | 177 | |
| 181 | 178 | should 'not notify activity if the article is not advertise' do |
| 182 | 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 | 181 | assert_equal true, a.published? |
| 185 | 182 | assert_equal true, a.notifiable? |
| 186 | 183 | assert_equal false, a.image? | ... | ... |