Commit 3d5b46501aa593f9fa2fc0be2fe7210f63e6142b
1 parent
045fbc74
Exists in
master
and in
27 other branches
rails3: fix mass-assignment on scrap test
Also discovered that the ActionTracker::Record.current_user_from_model returning nil is a bug. So I'm removing the stubs I did before.
Showing
2 changed files
with
7 additions
and
9 deletions
Show diff stats
test/unit/scrap_test.rb
@@ -215,7 +215,7 @@ class ScrapTest < ActiveSupport::TestCase | @@ -215,7 +215,7 @@ class ScrapTest < ActiveSupport::TestCase | ||
215 | s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) | 215 | s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) |
216 | assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') | 216 | assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') |
217 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) | 217 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) |
218 | - s1 = Scrap.create(defaults_for_scrap(:scrap_id => s.id)) | 218 | + s1 = create(Scrap, defaults_for_scrap(:scrap_id => s.id)) |
219 | s.reload | 219 | s.reload |
220 | assert_not_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') | 220 | assert_not_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') |
221 | end | 221 | end |
@@ -230,20 +230,20 @@ class ScrapTest < ActiveSupport::TestCase | @@ -230,20 +230,20 @@ class ScrapTest < ActiveSupport::TestCase | ||
230 | 230 | ||
231 | should 'strip all html tags' do | 231 | should 'strip all html tags' do |
232 | s, r = fast_create(Person), fast_create(Person) | 232 | s, r = fast_create(Person), fast_create(Person) |
233 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | 233 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" |
234 | assert_equal "Test Rails", s.strip_all_html_tags | 234 | assert_equal "Test Rails", s.strip_all_html_tags |
235 | end | 235 | end |
236 | 236 | ||
237 | should 'strip html before save' do | 237 | should 'strip html before save' do |
238 | s, r = fast_create(Person), fast_create(Person) | 238 | s, r = fast_create(Person), fast_create(Person) |
239 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | 239 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" |
240 | s.save! | 240 | s.save! |
241 | assert_equal "Test Rails", s.reload.content | 241 | assert_equal "Test Rails", s.reload.content |
242 | end | 242 | end |
243 | 243 | ||
244 | should 'strip html before validate' do | 244 | should 'strip html before validate' do |
245 | s, r = fast_create(Person), fast_create(Person) | 245 | s, r = fast_create(Person), fast_create(Person) |
246 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p><b></b></p>" | 246 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p><b></b></p>" |
247 | assert !s.valid? | 247 | assert !s.valid? |
248 | s.content = "<p>Test</p>" | 248 | s.content = "<p>Test</p>" |
249 | assert s.valid? | 249 | assert s.valid? |
@@ -260,15 +260,15 @@ class ScrapTest < ActiveSupport::TestCase | @@ -260,15 +260,15 @@ class ScrapTest < ActiveSupport::TestCase | ||
260 | 260 | ||
261 | should 'scrap wall url be the root scrap receiver url if it is a reply' do | 261 | should 'scrap wall url be the root scrap receiver url if it is a reply' do |
262 | p1, p2 = fast_create(Person), fast_create(Person) | 262 | p1, p2 = fast_create(Person), fast_create(Person) |
263 | - r = Scrap.create! :sender => p1, :receiver => p2, :content => "Hello!" | ||
264 | - s = Scrap.new :sender => p2, :receiver => p1, :content => "Hi!" | 263 | + r = create Scrap, :sender => p1, :receiver => p2, :content => "Hello!" |
264 | + s = build Scrap, :sender => p2, :receiver => p1, :content => "Hi!" | ||
265 | r.replies << s; s.reload | 265 | r.replies << s; s.reload |
266 | assert_equal s.scrap_wall_url, s.root.receiver.wall_url | 266 | assert_equal s.scrap_wall_url, s.root.receiver.wall_url |
267 | end | 267 | end |
268 | 268 | ||
269 | should 'scrap wall url be the scrap receiver url if it is not a reply' do | 269 | should 'scrap wall url be the scrap receiver url if it is not a reply' do |
270 | p1, p2 = fast_create(Person), fast_create(Person) | 270 | p1, p2 = fast_create(Person), fast_create(Person) |
271 | - s = Scrap.create! :sender => p1, :receiver => p2, :content => "Hello!" | 271 | + s = create Scrap, :sender => p1, :receiver => p2, :content => "Hello!" |
272 | assert_equal s.scrap_wall_url, s.receiver.wall_url | 272 | assert_equal s.scrap_wall_url, s.receiver.wall_url |
273 | end | 273 | end |
274 | 274 |
test/unit/tiny_mce_article_test.rb
@@ -142,7 +142,6 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -142,7 +142,6 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
142 | should 'not update activity on update of an article' do | 142 | should 'not update activity on update of an article' do |
143 | ActionTracker::Record.delete_all | 143 | ActionTracker::Record.delete_all |
144 | profile = fast_create(Profile) | 144 | profile = fast_create(Profile) |
145 | - ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person)) | ||
146 | article = create(TinyMceArticle, :profile_id => profile.id) | 145 | article = create(TinyMceArticle, :profile_id => profile.id) |
147 | time = article.activity.updated_at | 146 | time = article.activity.updated_at |
148 | Time.stubs(:now).returns(time + 1.day) | 147 | Time.stubs(:now).returns(time + 1.day) |
@@ -186,7 +185,6 @@ end | @@ -186,7 +185,6 @@ end | ||
186 | should "the tracker action target be defined as the article on articles'creation in profile" do | 185 | should "the tracker action target be defined as the article on articles'creation in profile" do |
187 | ActionTracker::Record.delete_all | 186 | ActionTracker::Record.delete_all |
188 | person = Person.first | 187 | person = Person.first |
189 | - ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person)) | ||
190 | article = create TinyMceArticle, :name => 'test', :profile_id => person.id | 188 | article = create TinyMceArticle, :name => 'test', :profile_id => person.id |
191 | assert_equal article, ActionTracker::Record.last.target | 189 | assert_equal article, ActionTracker::Record.last.target |
192 | end | 190 | end |