Commit 381cca8f612df8d34b64b2f862567c5606262bdd
1 parent
36ad1dcf
Exists in
master
and in
22 other branches
Making unit tests run more faster
Showing
40 changed files
with
369 additions
and
390 deletions
Show diff stats
test/factories.rb
... | ... | @@ -220,6 +220,11 @@ module Noosfero::Factory |
220 | 220 | { :name => name, :slug => name.to_slug, :path => name.to_slug } |
221 | 221 | end |
222 | 222 | |
223 | + alias :defaults_for_text_article :defaults_for_article | |
224 | + alias :defaults_for_textile_article :defaults_for_article | |
225 | + alias :defaults_for_tiny_mce_article :defaults_for_article | |
226 | + alias :defaults_for_rss_feed :defaults_for_article | |
227 | + | |
223 | 228 | ############################################### |
224 | 229 | # Folder |
225 | 230 | ############################################### |
... | ... | @@ -249,7 +254,8 @@ module Noosfero::Factory |
249 | 254 | # Blog |
250 | 255 | ############################################### |
251 | 256 | def defaults_for_blog |
252 | - { :name => 'My blog ' + factory_num_seq.to_s } | |
257 | + name = 'My blog ' + factory_num_seq.to_s | |
258 | + { :name => name, :slug => name.to_slug } | |
253 | 259 | end |
254 | 260 | |
255 | 261 | def create_blog |
... | ... | @@ -289,12 +295,11 @@ module Noosfero::Factory |
289 | 295 | # Category |
290 | 296 | ############################################### |
291 | 297 | def defaults_for_category |
292 | - { :environment_id => Environment.default.id, :name => 'category' + factory_num_seq.to_s } | |
298 | + name = 'category' + factory_num_seq.to_s | |
299 | + { :environment_id => 1, :name => name, :slug => name.to_slug, :path => name.to_slug } | |
293 | 300 | end |
294 | 301 | |
295 | - def defaults_for_region | |
296 | - defaults_for_category | |
297 | - end | |
302 | + alias :defaults_for_region :defaults_for_category | |
298 | 303 | |
299 | 304 | ############################################### |
300 | 305 | # Box |
... | ... | @@ -303,4 +308,23 @@ module Noosfero::Factory |
303 | 308 | { } |
304 | 309 | end |
305 | 310 | |
311 | + ############################################### | |
312 | + # Block | |
313 | + ############################################### | |
314 | + def defaults_for_block | |
315 | + { } | |
316 | + end | |
317 | + | |
318 | + ############################################### | |
319 | + # Task | |
320 | + ############################################### | |
321 | + def defaults_for_task | |
322 | + { :code => "task_for_test_#{factory_num_seq.to_s}" } | |
323 | + end | |
324 | + | |
325 | + alias :defaults_for_add_friend :defaults_for_task | |
326 | + alias :defaults_for_add_member :defaults_for_task | |
327 | + alias :defaults_for_create_community :defaults_for_task | |
328 | + alias :defaults_for_email_activation :defaults_for_task | |
329 | + | |
306 | 330 | end | ... | ... |
test/unit/acts_as_filesystem_test.rb
... | ... | @@ -75,9 +75,9 @@ class ActsAsFilesystemTest < Test::Unit::TestCase |
75 | 75 | |
76 | 76 | should 'be able to list text articles that are children of a folder' do |
77 | 77 | profile = create_user('testinguser').person |
78 | - folder = Folder.create!(:name => 'folder', :profile => profile) | |
79 | - article1 = Article.create(:name => 'article 1', :profile => profile, :parent => folder) | |
80 | - article2 = Article.create(:name => 'article 2', :profile => profile, :parent => folder) | |
78 | + folder = fast_create(Folder, :name => 'folder', :profile_id => profile.id) | |
79 | + article1 = Article.create!(:name => 'article 1', :profile => profile, :parent => folder) | |
80 | + article2 = Article.create!(:name => 'article 2', :profile => profile, :parent => folder) | |
81 | 81 | folder.reload |
82 | 82 | |
83 | 83 | assert_equal [folder, article1, article2], folder.map_traversal | ... | ... |
test/unit/acts_as_having_boxes.rb
... | ... | @@ -1,16 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | - | |
3 | -class ActsAsHavingBoxesTest < Test::Unit::TestCase | |
4 | - | |
5 | - should 'be able to find blocks by id' do | |
6 | - env = Environment.create!(:name => 'my test environment') | |
7 | - env.boxes.destroy_all | |
8 | - | |
9 | - env.boxes << Box.new | |
10 | - block = Block.new | |
11 | - env.boxes.first.blocks << block | |
12 | - | |
13 | - assert_equal block, env.blocks.find(block.id) | |
14 | - end | |
15 | - | |
16 | -end |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ActsAsHavingBoxesTest < Test::Unit::TestCase | |
4 | + | |
5 | + should 'be able to find blocks by id' do | |
6 | + env = fast_create(Environment, :name => 'An environment without blocks') | |
7 | + | |
8 | + env.boxes << Box.new | |
9 | + block = Block.new | |
10 | + env.boxes.first.blocks << block | |
11 | + | |
12 | + assert_equal block, env.blocks.find(block.id) | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |
test/unit/add_friend_test.rb
... | ... | @@ -10,7 +10,7 @@ class AddFriendTest < ActiveSupport::TestCase |
10 | 10 | p1 = create_user('testuser1').person |
11 | 11 | p2 = create_user('testuser2').person |
12 | 12 | |
13 | - task = AddFriend.create!(:person => p1, :friend => p2) | |
13 | + task = fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id, :target_type => 'Person') | |
14 | 14 | |
15 | 15 | assert_difference Friendship, :count, 2 do |
16 | 16 | task.finish |
... | ... | @@ -26,7 +26,10 @@ class AddFriendTest < ActiveSupport::TestCase |
26 | 26 | p1 = create_user('testuser1').person |
27 | 27 | p2 = create_user('testuser2').person |
28 | 28 | |
29 | - task = AddFriend.create!(:person => p1, :group_for_person => 'friend1', :friend => p2, :group_for_friend => 'friend2') | |
29 | + task = fast_create(AddFriend, :requestor_id => p1, :target_id => p2.id, :target_type => 'Person') | |
30 | + task.group_for_person = 'friend1' | |
31 | + task.group_for_friend = 'friend2' | |
32 | + assert task.save | |
30 | 33 | |
31 | 34 | assert_difference Friendship, :count, 2 do |
32 | 35 | task.finish |
... | ... | @@ -72,7 +75,7 @@ class AddFriendTest < ActiveSupport::TestCase |
72 | 75 | p1 = create_user('testuser1').person |
73 | 76 | p2 = create_user('testuser2').person |
74 | 77 | |
75 | - task = AddFriend.create!(:person => p1, :friend => p2) | |
78 | + task = fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id) | |
76 | 79 | |
77 | 80 | assert_equal 'testuser1 wants to be your friend.', task.description |
78 | 81 | end |
... | ... | @@ -85,7 +88,7 @@ class AddFriendTest < ActiveSupport::TestCase |
85 | 88 | should 'not add friend twice' do |
86 | 89 | p1 = create_user('testuser1').person |
87 | 90 | p2 = create_user('testuser2').person |
88 | - AddFriend.create!(:person => p1, :friend => p2) | |
91 | + fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id) | |
89 | 92 | assert_raise ActiveRecord::RecordInvalid do |
90 | 93 | AddFriend.create!(:person => p1, :friend => p2) |
91 | 94 | end | ... | ... |
test/unit/add_member_test.rb
... | ... | @@ -8,9 +8,10 @@ class AddMemberTest < ActiveSupport::TestCase |
8 | 8 | |
9 | 9 | should 'actually add memberships when confirmed' do |
10 | 10 | p = create_user('testuser1').person |
11 | - c = Community.create!(:name => 'closed community', :closed => true) | |
11 | + c = fast_create(Community, :name => 'closed community') | |
12 | + c.update_attribute(:closed, true) | |
12 | 13 | TaskMailer.stubs(:deliver_target_notification) |
13 | - task = AddMember.create!(:person => p, :organization => c) | |
14 | + task = fast_create(AddMember, :requestor_id => p.id, :target_id => c.id, :target_type => 'Community') | |
14 | 15 | assert_difference c, :members, [p] do |
15 | 16 | task.finish |
16 | 17 | c.reload |
... | ... | @@ -41,7 +42,8 @@ class AddMemberTest < ActiveSupport::TestCase |
41 | 42 | |
42 | 43 | should 'send e-mails' do |
43 | 44 | p = create_user('testuser1').person |
44 | - c = Community.create!(:name => 'closed community', :closed => true) | |
45 | + c = fast_create(Community, :name => 'closed community') | |
46 | + c.update_attribute(:closed, true) | |
45 | 47 | |
46 | 48 | TaskMailer.expects(:deliver_target_notification).at_least_once |
47 | 49 | |
... | ... | @@ -50,11 +52,12 @@ class AddMemberTest < ActiveSupport::TestCase |
50 | 52 | |
51 | 53 | should 'provide proper description' do |
52 | 54 | p = create_user('testuser1').person |
53 | - c = Community.create!(:name => 'closed community', :closed => true) | |
55 | + c = fast_create(Community, :name => 'closed community') | |
56 | + c.update_attribute(:closed, true) | |
54 | 57 | |
55 | 58 | TaskMailer.stubs(:deliver_target_notification) |
56 | 59 | |
57 | - task = AddMember.create!(:person => p, :organization => c) | |
60 | + task = fast_create(AddMember, :requestor_id => p.id, :target_id => c.id, :target_type => 'Community') | |
58 | 61 | |
59 | 62 | assert_equal 'testuser1 wants to be a member of "closed community".', task.description |
60 | 63 | end |
... | ... | @@ -66,7 +69,7 @@ class AddMemberTest < ActiveSupport::TestCase |
66 | 69 | |
67 | 70 | should 'have roles' do |
68 | 71 | p = create_user('testuser1').person |
69 | - c = Community.create!(:name => 'community_test') | |
72 | + c = fast_create(Community, :name => 'community_test') | |
70 | 73 | TaskMailer.stubs(:deliver_target_notification) |
71 | 74 | task = AddMember.create!(:roles => [1,2,3], :person => p, :organization => c) |
72 | 75 | assert_equal [1,2,3], task.roles |
... | ... | @@ -74,7 +77,7 @@ class AddMemberTest < ActiveSupport::TestCase |
74 | 77 | |
75 | 78 | should 'put member with the right roles' do |
76 | 79 | p = create_user('testuser1').person |
77 | - c = Community.create!(:name => 'community_test') | |
80 | + c = fast_create(Community, :name => 'community_test') | |
78 | 81 | |
79 | 82 | roles = [Profile::Roles.member(c.environment.id), Profile::Roles.admin(c.environment.id)] |
80 | 83 | TaskMailer.stubs(:deliver_target_notification) |
... | ... | @@ -97,7 +100,7 @@ class AddMemberTest < ActiveSupport::TestCase |
97 | 100 | |
98 | 101 | should 'ignore roles with id zero' do |
99 | 102 | p = create_user('testuser1').person |
100 | - c = Community.create!(:name => 'community_test') | |
103 | + c = fast_create(Community, :name => 'community_test') | |
101 | 104 | |
102 | 105 | role = Profile::Roles.member(c.environment.id) |
103 | 106 | TaskMailer.stubs(:deliver_target_notification) | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -98,36 +98,11 @@ class ApplicationHelperTest < Test::Unit::TestCase |
98 | 98 | |
99 | 99 | should 'rolename for' do |
100 | 100 | person = create_user('usertest').person |
101 | - community = Community.create!(:name => 'new community', :identifier => 'new-community', :environment => Environment.default) | |
101 | + community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) | |
102 | 102 | community.add_member(person) |
103 | 103 | assert_equal 'Profile Member', rolename_for(person, community) |
104 | 104 | end |
105 | 105 | |
106 | - should 'display categories' do | |
107 | - # FIXME implement this test!!! | |
108 | - assert true | |
109 | - #category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default) | |
110 | - #child = Category.create!(:name => 'child category for testing', :environment => Environment.default, :display_in_menu => true, :parent => category) | |
111 | - #owner = create_user('testuser').person | |
112 | - #@article = owner.articles.create!(:name => 'ytest') | |
113 | - #@article.add_category(category) | |
114 | - #expects(:environment).returns(Environment.default) | |
115 | - #result = select_categories(:article) | |
116 | - #assert_match /parent category/, result | |
117 | - end | |
118 | - | |
119 | - should 'not display categories if has no child' do | |
120 | - # FIXME implement this test!!! | |
121 | - assert true | |
122 | - #category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default) | |
123 | - #owner = create_user('testuser').person | |
124 | - #@article = owner.articles.create!(:name => 'ytest') | |
125 | - #@article.add_category(category) | |
126 | - #expects(:environment).returns(Environment.default) | |
127 | - #result = select_categories(:article) | |
128 | - #assert_no_match /parent category/, result | |
129 | - end | |
130 | - | |
131 | 106 | should 'get theme from environment by default' do |
132 | 107 | @environment = mock |
133 | 108 | @environment.stubs(:theme).returns('my-environment-theme') |
... | ... | @@ -229,7 +204,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
229 | 204 | end |
230 | 205 | |
231 | 206 | should 'return nil if disable_categories is enabled' do |
232 | - env = Environment.create!(:name => 'env test') | |
207 | + env = fast_create(Environment, :name => 'env test') | |
233 | 208 | stubs(:environment).returns(env) |
234 | 209 | assert_not_nil env |
235 | 210 | env.enable(:disable_categories) |
... | ... | @@ -263,14 +238,14 @@ class ApplicationHelperTest < Test::Unit::TestCase |
263 | 238 | end |
264 | 239 | |
265 | 240 | should 'not draw sex icon when disabled in the environment' do |
266 | - env = Environment.create!(:name => 'env test') | |
241 | + env = fast_create(Environment, :name => 'env test') | |
267 | 242 | env.expects(:enabled?).with('disable_gender_icon').returns(true) |
268 | 243 | stubs(:environment).returns(env) |
269 | 244 | assert_equal '', profile_sex_icon(Person.new(:sex => 'male')) |
270 | 245 | end |
271 | 246 | |
272 | 247 | should 'display field on signup' do |
273 | - env = Environment.create!(:name => 'env test') | |
248 | + env = fast_create(Environment, :name => 'env test') | |
274 | 249 | stubs(:environment).returns(env) |
275 | 250 | |
276 | 251 | controller = mock |
... | ... | @@ -283,7 +258,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
283 | 258 | end |
284 | 259 | |
285 | 260 | should 'not display field on signup' do |
286 | - env = Environment.create!(:name => 'env test') | |
261 | + env = fast_create(Environment, :name => 'env test') | |
287 | 262 | stubs(:environment).returns(env) |
288 | 263 | |
289 | 264 | controller = mock |
... | ... | @@ -296,7 +271,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
296 | 271 | end |
297 | 272 | |
298 | 273 | should 'display active fields' do |
299 | - env = Environment.create!(:name => 'env test') | |
274 | + env = fast_create(Environment, :name => 'env test') | |
300 | 275 | stubs(:environment).returns(env) |
301 | 276 | |
302 | 277 | controller = mock |
... | ... | @@ -309,7 +284,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
309 | 284 | end |
310 | 285 | |
311 | 286 | should 'not display active fields' do |
312 | - env = Environment.create!(:name => 'env test') | |
287 | + env = fast_create(Environment, :name => 'env test') | |
313 | 288 | stubs(:environment).returns(env) |
314 | 289 | |
315 | 290 | controller = mock |
... | ... | @@ -322,7 +297,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
322 | 297 | end |
323 | 298 | |
324 | 299 | should 'display required fields' do |
325 | - env = Environment.create!(:name => 'env test') | |
300 | + env = fast_create(Environment, :name => 'env test') | |
326 | 301 | stubs(:environment).returns(env) |
327 | 302 | |
328 | 303 | controller = mock |
... | ... | @@ -380,7 +355,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
380 | 355 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
381 | 356 | stubs(:environment).returns(e) |
382 | 357 | |
383 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
358 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
384 | 359 | stubs(:profile).returns(c) |
385 | 360 | stubs(:logged_in?).returns(false) |
386 | 361 | assert ! ask_to_join? |
... | ... | @@ -393,7 +368,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
393 | 368 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
394 | 369 | stubs(:environment).returns(e) |
395 | 370 | |
396 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
371 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
397 | 372 | stubs(:profile).returns(c) |
398 | 373 | stubs(:logged_in?).returns(false) |
399 | 374 | assert ask_to_join? |
... | ... | @@ -406,7 +381,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
406 | 381 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
407 | 382 | stubs(:environment).returns(e) |
408 | 383 | |
409 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
384 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
410 | 385 | stubs(:profile).returns(c) |
411 | 386 | stubs(:logged_in?).returns(true) |
412 | 387 | p = create_user('test_user').person |
... | ... | @@ -422,7 +397,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
422 | 397 | e = Environment.default |
423 | 398 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
424 | 399 | stubs(:environment).returns(e) |
425 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
400 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
426 | 401 | stubs(:profile).returns(c) |
427 | 402 | stubs(:logged_in?).returns(true) |
428 | 403 | p = create_user('test_user').person |
... | ... | @@ -438,7 +413,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
438 | 413 | e = Environment.default |
439 | 414 | e.stubs(:enabled?).with(:join_community_popup).returns(false) |
440 | 415 | stubs(:environment).returns(e) |
441 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
416 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
442 | 417 | stubs(:profile).returns(c) |
443 | 418 | stubs(:logged_in?).returns(false) |
444 | 419 | assert !ask_to_join? |
... | ... | @@ -450,7 +425,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
450 | 425 | e = Environment.default |
451 | 426 | e.stubs(:enabled?).with(:join_community_popup).returns(false) |
452 | 427 | stubs(:environment).returns(e) |
453 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
428 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
454 | 429 | stubs(:profile).returns(c) |
455 | 430 | stubs(:logged_in?).returns(true) |
456 | 431 | p = create_user('test_user').person |
... | ... | @@ -467,7 +442,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
467 | 442 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
468 | 443 | stubs(:environment).returns(e) |
469 | 444 | |
470 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
445 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
471 | 446 | stubs(:profile).returns(c) |
472 | 447 | stubs(:logged_in?).returns(false) |
473 | 448 | stubs(:session).returns({:no_asking => [c.id]}) |
... | ... | @@ -482,7 +457,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
482 | 457 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
483 | 458 | stubs(:environment).returns(e) |
484 | 459 | |
485 | - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
460 | + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') | |
486 | 461 | stubs(:profile).returns(c) |
487 | 462 | stubs(:logged_in?).returns(true) |
488 | 463 | stubs(:session).returns({:no_asking => [c.id]}) |
... | ... | @@ -507,7 +482,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
507 | 482 | should 'display name on page title if profile doesnt have nickname' do |
508 | 483 | stubs(:environment).returns(Environment.default) |
509 | 484 | |
510 | - c = Community.create(:name => 'Comm name', :identifier => 'test_comm') | |
485 | + c = fast_create(Community, :name => 'Comm name', :identifier => 'test_comm') | |
511 | 486 | stubs(:profile).returns(c) |
512 | 487 | assert_match(/Comm name/, page_title) |
513 | 488 | end |
... | ... | @@ -515,7 +490,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
515 | 490 | should 'display nickname on page title if profile has nickname' do |
516 | 491 | stubs(:environment).returns(Environment.default) |
517 | 492 | |
518 | - c = Community.create(:name => 'Community for tests', :nickname => 'Community nickname', :identifier => 'test_comm') | |
493 | + c = fast_create(Community, :name => 'Community for tests', :nickname => 'Community nickname', :identifier => 'test_comm') | |
519 | 494 | stubs(:profile).returns(c) |
520 | 495 | assert_match(/Community nickname/, page_title) |
521 | 496 | end | ... | ... |
test/unit/approve_article_test.rb
... | ... | @@ -11,7 +11,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
11 | 11 | attr_reader :profile |
12 | 12 | |
13 | 13 | should 'have name, reference article and profile' do |
14 | - article = profile.articles.create!(:name => 'test article') | |
14 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
15 | 15 | |
16 | 16 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
17 | 17 | |
... | ... | @@ -21,7 +21,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
21 | 21 | end |
22 | 22 | |
23 | 23 | should 'create published article when finished' do |
24 | - article = profile.articles.create!(:name => 'test article') | |
24 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
25 | 25 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
26 | 26 | |
27 | 27 | assert_difference PublishedArticle, :count do |
... | ... | @@ -39,7 +39,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
39 | 39 | end |
40 | 40 | |
41 | 41 | should 'have parent if defined' do |
42 | - article = profile.articles.create!(:name => 'test article') | |
42 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
43 | 43 | folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') |
44 | 44 | |
45 | 45 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id) |
... | ... | @@ -48,7 +48,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
48 | 48 | end |
49 | 49 | |
50 | 50 | should 'not have parent if not defined' do |
51 | - article = profile.articles.create!(:name => 'test article') | |
51 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
52 | 52 | |
53 | 53 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
54 | 54 | |
... | ... | @@ -75,7 +75,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
75 | 75 | |
76 | 76 | should 'handle blank names' do |
77 | 77 | article = profile.articles.create!(:name => 'test article') |
78 | - community = Community.create!(:name => 'test comm') | |
78 | + community = fast_create(Community, :name => 'test comm') | |
79 | 79 | a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) |
80 | 80 | |
81 | 81 | assert_difference PublishedArticle, :count do |
... | ... | @@ -84,14 +84,14 @@ class ApproveArticleTest < ActiveSupport::TestCase |
84 | 84 | end |
85 | 85 | |
86 | 86 | should 'notify target if group is moderated' do |
87 | - article = profile.articles.create!(:name => 'test article') | |
87 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
88 | 88 | community = Community.create!(:name => 'test comm', :moderated_articles => true) |
89 | 89 | a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) |
90 | 90 | assert !ActionMailer::Base.deliveries.empty? |
91 | 91 | end |
92 | 92 | |
93 | 93 | should 'not notify target if group is not moderated' do |
94 | - article = profile.articles.create!(:name => 'test article') | |
94 | + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') | |
95 | 95 | community = Community.create!(:name => 'test comm', :moderated_articles => false) |
96 | 96 | a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) |
97 | 97 | assert ActionMailer::Base.deliveries.empty? | ... | ... |
test/unit/article_block_test.rb
... | ... | @@ -71,7 +71,7 @@ class ArticleBlockTest < Test::Unit::TestCase |
71 | 71 | env.articles.destroy_all |
72 | 72 | assert_equal [], env.articles |
73 | 73 | community = fast_create(Community) |
74 | - a = community.articles.create!(:name => 'test') | |
74 | + a = fast_create(TextArticle, :profile_id => community.id, :name => 'test') | |
75 | 75 | env.portal_community=community |
76 | 76 | env.save |
77 | 77 | block = ArticleBlock.create(:article => a) | ... | ... |
test/unit/article_test.rb
... | ... | @@ -76,7 +76,7 @@ class ArticleTest < Test::Unit::TestCase |
76 | 76 | |
77 | 77 | should 'provide HTML version' do |
78 | 78 | profile = create_user('testinguser').person |
79 | - a = Article.create!(:name => 'my article', :profile_id => profile.id) | |
79 | + a = fast_create(Article, :name => 'my article', :profile_id => profile.id) | |
80 | 80 | a.expects(:body).returns('the body of the article') |
81 | 81 | assert_equal 'the body of the article', a.to_html |
82 | 82 | end |
... | ... | @@ -88,7 +88,7 @@ class ArticleTest < Test::Unit::TestCase |
88 | 88 | |
89 | 89 | should 'provide first paragraph of HTML version' do |
90 | 90 | profile = create_user('testinguser').person |
91 | - a = Article.create!(:name => 'my article', :profile_id => profile.id) | |
91 | + a = fast_create(Article, :name => 'my article', :profile_id => profile.id) | |
92 | 92 | a.expects(:body).returns('<p>the first paragraph of the article</p> The second paragraph') |
93 | 93 | assert_equal '<p>the first paragraph of the article</p>', a.first_paragraph |
94 | 94 | end |
... | ... | @@ -149,11 +149,11 @@ class ArticleTest < Test::Unit::TestCase |
149 | 149 | |
150 | 150 | Article.destroy_all |
151 | 151 | |
152 | - first = profile.articles.build(:name => 'first'); first.save! | |
153 | - second = profile.articles.build(:name => 'second'); second.save! | |
154 | - third = profile.articles.build(:name => 'third'); third.save! | |
155 | - fourth = profile.articles.build(:name => 'fourth'); fourth.save! | |
156 | - fifth = profile.articles.build(:name => 'fifth'); fifth.save! | |
152 | + first = fast_create(TextArticle, :profile_id => profile.id, :name => 'first') | |
153 | + second = fast_create(TextArticle, :profile_id => profile.id, :name => 'second') | |
154 | + third = fast_create(TextArticle, :profile_id => profile.id, :name => 'third') | |
155 | + fourth = fast_create(TextArticle, :profile_id => profile.id, :name => 'fourth') | |
156 | + fifth = fast_create(TextArticle, :profile_id => profile.id, :name => 'fifth') | |
157 | 157 | |
158 | 158 | other_first = other_profile.articles.build(:name => 'first'); other_first.save! |
159 | 159 | |
... | ... | @@ -165,8 +165,8 @@ class ArticleTest < Test::Unit::TestCase |
165 | 165 | p = create_user('usr1').person |
166 | 166 | Article.destroy_all |
167 | 167 | |
168 | - first = p.articles.build(:name => 'first', :published => true); first.save! | |
169 | - second = p.articles.build(:name => 'second', :published => false); second.save! | |
168 | + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) | |
169 | + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) | |
170 | 170 | |
171 | 171 | assert_equal [ first ], Article.recent(nil) |
172 | 172 | end |
... | ... | @@ -175,8 +175,8 @@ class ArticleTest < Test::Unit::TestCase |
175 | 175 | p = create_user('usr1').person |
176 | 176 | Article.destroy_all |
177 | 177 | |
178 | - first = p.articles.build(:name => 'first', :published => true); first.save! | |
179 | - second = p.articles.build(:name => 'second', :published => false); second.save! | |
178 | + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) | |
179 | + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) | |
180 | 180 | |
181 | 181 | assert_equal [ first ], Article.recent(nil) |
182 | 182 | end |
... | ... | @@ -185,8 +185,8 @@ class ArticleTest < Test::Unit::TestCase |
185 | 185 | p = fast_create(Person, :public_profile => false) |
186 | 186 | Article.destroy_all |
187 | 187 | |
188 | - first = p.articles.build(:name => 'first', :published => true); first.save! | |
189 | - second = p.articles.build(:name => 'second', :published => false); second.save! | |
188 | + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) | |
189 | + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) | |
190 | 190 | |
191 | 191 | assert_equal [ ], Article.recent(nil) |
192 | 192 | end |
... | ... | @@ -195,8 +195,8 @@ class ArticleTest < Test::Unit::TestCase |
195 | 195 | p = fast_create(Person, :visible => false) |
196 | 196 | Article.destroy_all |
197 | 197 | |
198 | - first = p.articles.build(:name => 'first', :published => true); first.save! | |
199 | - second = p.articles.build(:name => 'second', :published => false); second.save! | |
198 | + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) | |
199 | + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) | |
200 | 200 | |
201 | 201 | assert_equal [ ], Article.recent(nil) |
202 | 202 | end |
... | ... | @@ -224,7 +224,7 @@ class ArticleTest < Test::Unit::TestCase |
224 | 224 | Article.destroy_all |
225 | 225 | |
226 | 226 | first = UploadedFile.new(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! |
227 | - second = p.articles.build(:name => 'second'); second.save! | |
227 | + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second') | |
228 | 228 | |
229 | 229 | assert_equal [ second ], Article.recent(nil) |
230 | 230 | end |
... | ... | @@ -232,7 +232,7 @@ class ArticleTest < Test::Unit::TestCase |
232 | 232 | should 'not show RssFeed as recent' do |
233 | 233 | p = create_user('usr1').person |
234 | 234 | Article.destroy_all |
235 | - first = RssFeed.create!(:profile => p, :name => 'my feed', :advertise => true) | |
235 | + first = fast_create(RssFeed, :profile_id => p.id, :name => 'my feed', :advertise => true) | |
236 | 236 | first.limit = 10; first.save! |
237 | 237 | second = p.articles.build(:name => 'second'); second.save! |
238 | 238 | |
... | ... | @@ -242,7 +242,7 @@ class ArticleTest < Test::Unit::TestCase |
242 | 242 | should 'not show blog as recent' do |
243 | 243 | p = create_user('usr1').person |
244 | 244 | Article.destroy_all |
245 | - first = Blog.create!(:profile => p, :name => 'my blog', :advertise => true) | |
245 | + first = fast_create(Blog, :profile_id => p.id, :name => 'my blog', :advertise => true) | |
246 | 246 | second = p.articles.build(:name => 'second'); second.save! |
247 | 247 | |
248 | 248 | assert_equal [ second ], Article.recent(nil) |
... | ... | @@ -425,8 +425,8 @@ class ArticleTest < Test::Unit::TestCase |
425 | 425 | end |
426 | 426 | |
427 | 427 | should 'be able to create an article already with categories' do |
428 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
429 | - c2 = Category.create!(:environment => Environment.default, :name => 'c2') | |
428 | + c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') | |
429 | + c2 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c2') | |
430 | 430 | |
431 | 431 | p = create_user('testinguser').person |
432 | 432 | a = p.articles.create!(:name => 'test', :category_ids => [c1.id, c2.id]) |
... | ... | @@ -435,7 +435,7 @@ class ArticleTest < Test::Unit::TestCase |
435 | 435 | end |
436 | 436 | |
437 | 437 | should 'not add a category twice to article' do |
438 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
438 | + c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') | |
439 | 439 | c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') |
440 | 440 | c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') |
441 | 441 | owner = create_user('testuser').person |
... | ... | @@ -454,23 +454,23 @@ class ArticleTest < Test::Unit::TestCase |
454 | 454 | end |
455 | 455 | |
456 | 456 | should 'say that logged off user cannot see private article' do |
457 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
458 | - article = Article.create!(:name => 'test article', :profile => profile, :published => false) | |
457 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
458 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | |
459 | 459 | |
460 | 460 | assert !article.display_to?(nil) |
461 | 461 | end |
462 | 462 | |
463 | 463 | should 'say that not member of profile cannot see private article' do |
464 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
465 | - article = Article.create!(:name => 'test article', :profile => profile, :published => false) | |
464 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
465 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | |
466 | 466 | person = create_user('test_user').person |
467 | 467 | |
468 | 468 | assert !article.display_to?(person) |
469 | 469 | end |
470 | 470 | |
471 | 471 | should 'say that member user can not see private article' do |
472 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
473 | - article = Article.create!(:name => 'test article', :profile => profile, :published => false) | |
472 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
473 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | |
474 | 474 | person = create_user('test_user').person |
475 | 475 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
476 | 476 | |
... | ... | @@ -478,8 +478,8 @@ class ArticleTest < Test::Unit::TestCase |
478 | 478 | end |
479 | 479 | |
480 | 480 | should 'say that profile admin can see private article' do |
481 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
482 | - article = Article.create!(:name => 'test article', :profile => profile, :published => false) | |
481 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
482 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | |
483 | 483 | person = create_user('test_user').person |
484 | 484 | profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) |
485 | 485 | |
... | ... | @@ -487,8 +487,8 @@ class ArticleTest < Test::Unit::TestCase |
487 | 487 | end |
488 | 488 | |
489 | 489 | should 'say that profile moderator can see private article' do |
490 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
491 | - article = Article.create!(:name => 'test article', :profile => profile, :published => false) | |
490 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
491 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | |
492 | 492 | person = create_user('test_user').person |
493 | 493 | profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) |
494 | 494 | |
... | ... | @@ -496,8 +496,8 @@ class ArticleTest < Test::Unit::TestCase |
496 | 496 | end |
497 | 497 | |
498 | 498 | should 'not show article to non member if article public but profile private' do |
499 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) | |
500 | - article = Article.create!(:name => 'test article', :profile => profile, :published => true) | |
499 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile', :public_profile => false) | |
500 | + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) | |
501 | 501 | person1 = create_user('test_user1').person |
502 | 502 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) |
503 | 503 | person2 = create_user('test_user2').person |
... | ... | @@ -508,17 +508,17 @@ class ArticleTest < Test::Unit::TestCase |
508 | 508 | end |
509 | 509 | |
510 | 510 | should 'make new article private if created inside a private folder' do |
511 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
512 | - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) | |
513 | - article = Article.create!(:name => 'my private article', :profile => profile, :parent => folder) | |
511 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
512 | + folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) | |
513 | + article = fast_create(Article, :name => 'my private article', :profile_id => profile.id, :parent_id => folder.id) | |
514 | 514 | |
515 | 515 | assert !article.published? |
516 | 516 | end |
517 | 517 | |
518 | 518 | should 'save as private' do |
519 | - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | |
520 | - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) | |
521 | - article = TextileArticle.new(:name => 'my private article') | |
519 | + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
520 | + folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) | |
521 | + article = fast_create(Article, :name => 'my private article') | |
522 | 522 | article.profile = profile |
523 | 523 | article.parent = folder |
524 | 524 | article.save! |
... | ... | @@ -540,7 +540,7 @@ class ArticleTest < Test::Unit::TestCase |
540 | 540 | |
541 | 541 | should 'display private articles to people who can view private content' do |
542 | 542 | person = create_user('test_user').person |
543 | - article = Article.create!(:name => 'test article', :profile => person, :published => false) | |
543 | + article = fast_create(Article, :name => 'test article', :profile_id => person.id, :published => false) | |
544 | 544 | |
545 | 545 | admin_user = create_user('admin_user').person |
546 | 546 | admin_user.stubs(:has_permission?).with('view_private_content', article.profile).returns('true') |
... | ... | @@ -570,7 +570,7 @@ class ArticleTest < Test::Unit::TestCase |
570 | 570 | |
571 | 571 | should 'mantain the type in a copy' do |
572 | 572 | p = create_user('test_user').person |
573 | - a = Folder.create!(:name => 'test folder', :profile => p) | |
573 | + a = fast_create(Folder, :name => 'test folder', :profile_id => p.id) | |
574 | 574 | b = a.copy(:parent => a, :profile => p) |
575 | 575 | |
576 | 576 | assert_kind_of Folder, b |
... | ... | @@ -638,15 +638,15 @@ class ArticleTest < Test::Unit::TestCase |
638 | 638 | |
639 | 639 | should 'identify if belongs to blog' do |
640 | 640 | p = create_user('user_blog_test').person |
641 | - blog = Blog.create!(:name => 'Blog test', :profile => p) | |
642 | - post = TextileArticle.create!(:name => 'First post', :profile => p, :parent => blog) | |
641 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => p.id) | |
642 | + post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => blog.id) | |
643 | 643 | assert post.belongs_to_blog? |
644 | 644 | end |
645 | 645 | |
646 | 646 | should 'not belongs to blog' do |
647 | 647 | p = create_user('user_blog_test').person |
648 | - folder = Folder.create!(:name => 'Not Blog', :profile => p) | |
649 | - a = TextileArticle.create!(:name => 'Not blog post', :profile => p, :parent => folder) | |
648 | + folder = fast_create(Folder, :name => 'Not Blog', :profile_id => p.id) | |
649 | + a = fast_create(TextileArticle, :name => 'Not blog post', :profile_id => p.id, :parent_id => folder.id) | |
650 | 650 | assert !a.belongs_to_blog? |
651 | 651 | end |
652 | 652 | |
... | ... | @@ -656,7 +656,7 @@ class ArticleTest < Test::Unit::TestCase |
656 | 656 | end |
657 | 657 | |
658 | 658 | should 'hold hits count' do |
659 | - a = Article.create!(:name => 'Test article', :profile => profile) | |
659 | + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) | |
660 | 660 | a.hits = 10 |
661 | 661 | a.save! |
662 | 662 | a.reload |
... | ... | @@ -664,7 +664,7 @@ class ArticleTest < Test::Unit::TestCase |
664 | 664 | end |
665 | 665 | |
666 | 666 | should 'increment hit counter when hitted' do |
667 | - a = Article.create!(:name => 'Test article', :profile => profile, :hits => 10) | |
667 | + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id, :hits => 10) | |
668 | 668 | a.hit |
669 | 669 | assert_equal 11, a.hits |
670 | 670 | a.reload |
... | ... | @@ -672,13 +672,13 @@ class ArticleTest < Test::Unit::TestCase |
672 | 672 | end |
673 | 673 | |
674 | 674 | should 'have display_hits setting with default true' do |
675 | - a = Article.create!(:name => 'Test article', :profile => profile) | |
675 | + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) | |
676 | 676 | assert_respond_to a, :display_hits |
677 | 677 | assert_equal true, a.display_hits |
678 | 678 | end |
679 | 679 | |
680 | 680 | should 'can display hits' do |
681 | - a = Article.create!(:name => 'Test article', :profile => profile) | |
681 | + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) | |
682 | 682 | assert_respond_to a, :can_display_hits? |
683 | 683 | assert_equal true, a.can_display_hits? |
684 | 684 | end |
... | ... | @@ -690,7 +690,7 @@ class ArticleTest < Test::Unit::TestCase |
690 | 690 | end |
691 | 691 | |
692 | 692 | should 'not return a view url when common article' do |
693 | - a = Article.create!(:name => 'Test article', :profile => profile) | |
693 | + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) | |
694 | 694 | |
695 | 695 | assert_equal a.url, a.view_url |
696 | 696 | end |
... | ... | @@ -708,17 +708,17 @@ class ArticleTest < Test::Unit::TestCase |
708 | 708 | end |
709 | 709 | |
710 | 710 | should 'published_at is same as created_at if not set' do |
711 | - a = Article.create!(:name => 'Published at', :profile => profile) | |
711 | + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) | |
712 | 712 | assert_equal a.created_at, a.published_at |
713 | 713 | end |
714 | 714 | |
715 | 715 | should 'use npage to compose cache key' do |
716 | - a = Article.create!(:name => 'Published at', :profile => profile) | |
716 | + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) | |
717 | 717 | assert_match(/-npage-2/,a.cache_key(:npage => 2)) |
718 | 718 | end |
719 | 719 | |
720 | 720 | should 'use year and month to compose cache key' do |
721 | - a = Article.create!(:name => 'Published at', :profile => profile) | |
721 | + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) | |
722 | 722 | assert_match(/-year-2009-month-04/, a.cache_key(:year => '2009', :month => '04')) |
723 | 723 | end |
724 | 724 | |
... | ... | @@ -728,7 +728,7 @@ class ArticleTest < Test::Unit::TestCase |
728 | 728 | end |
729 | 729 | |
730 | 730 | should 'get tagged with tag' do |
731 | - a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') | |
731 | + a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli') | |
732 | 732 | as = Article.find_tagged_with('bli') |
733 | 733 | |
734 | 734 | assert_includes as, a |
... | ... | @@ -749,7 +749,7 @@ class ArticleTest < Test::Unit::TestCase |
749 | 749 | |
750 | 750 | should 'ignore category with zero as id' do |
751 | 751 | a = profile.articles.create!(:name => 'a test article') |
752 | - c = Category.create!(:name => 'test category', :environment => profile.environment) | |
752 | + c = fast_create(Category, :name => 'test category', :environment_id => profile.environment.id) | |
753 | 753 | a.category_ids = ['0', c.id, nil] |
754 | 754 | assert a.save |
755 | 755 | assert_equal [c], a.categories |
... | ... | @@ -766,13 +766,13 @@ class ArticleTest < Test::Unit::TestCase |
766 | 766 | end |
767 | 767 | |
768 | 768 | should 'add owner on cache_key when profile is community' do |
769 | - c = Community.create!(:name => 'new_comm') | |
769 | + c = fast_create(Community) | |
770 | 770 | a = c.articles.create!(:name => 'a test article') |
771 | 771 | assert_match(/-owner/, a.cache_key({}, c)) |
772 | 772 | end |
773 | 773 | |
774 | 774 | should 'have a creator method' do |
775 | - c = Community.create!(:name => 'new_comm') | |
775 | + c = fast_create(Community) | |
776 | 776 | a = c.articles.create!(:name => 'a test article', :last_changed_by => profile) |
777 | 777 | p = create_user('other_user').person |
778 | 778 | a.update_attributes(:body => 'some content', :last_changed_by => p); a.save! |
... | ... | @@ -780,7 +780,7 @@ class ArticleTest < Test::Unit::TestCase |
780 | 780 | end |
781 | 781 | |
782 | 782 | should 'allow creator to edit if is publisher' do |
783 | - c = Community.create!(:name => 'new_comm') | |
783 | + c = fast_create(Community) | |
784 | 784 | p = create_user_with_permission('test_user', 'publish_content', c) |
785 | 785 | a = c.articles.create!(:name => 'a test article', :last_changed_by => p) |
786 | 786 | |
... | ... | @@ -788,7 +788,7 @@ class ArticleTest < Test::Unit::TestCase |
788 | 788 | end |
789 | 789 | |
790 | 790 | should 'allow user with "Manage content" permissions to edit' do |
791 | - c = Community.create!(:name => 'new_comm') | |
791 | + c = fast_create(Community) | |
792 | 792 | p = create_user_with_permission('test_user', 'post_content', c) |
793 | 793 | a = c.articles.create!(:name => 'a test article') |
794 | 794 | |
... | ... | @@ -796,7 +796,7 @@ class ArticleTest < Test::Unit::TestCase |
796 | 796 | end |
797 | 797 | |
798 | 798 | should 'update slug from name' do |
799 | - article = Article.create!(:name => 'A test article', :profile => profile) | |
799 | + article = create(Article, :name => 'A test article', :profile_id => profile.id) | |
800 | 800 | assert_equal 'a-test-article', article.slug |
801 | 801 | article.name = 'Changed name' |
802 | 802 | assert_equal 'changed-name', article.slug | ... | ... |
test/unit/block_test.rb
... | ... | @@ -9,7 +9,7 @@ class BlockTest < Test::Unit::TestCase |
9 | 9 | should 'access owner through box' do |
10 | 10 | user = create_user('testinguser').person |
11 | 11 | |
12 | - box = Box.create!(:owner => user) | |
12 | + box = fast_create(Box, :owner_id => user, :owner_type => 'Person') | |
13 | 13 | |
14 | 14 | block = Block.new |
15 | 15 | block.box = box |
... | ... | @@ -54,14 +54,14 @@ class BlockTest < Test::Unit::TestCase |
54 | 54 | should 'provide chache keys' do |
55 | 55 | p = create_user('test_user').person |
56 | 56 | box = p.boxes[0] |
57 | - b = Block.create!(:box => box) | |
57 | + b = fast_create(Block, :box_id => box.id) | |
58 | 58 | |
59 | 59 | assert_equal( "block-id-#{b.id}", b.cache_keys) |
60 | 60 | end |
61 | 61 | |
62 | 62 | should 'list enabled blocks' do |
63 | - block1 = Block.create!(:title => 'test 1') | |
64 | - block2 = Block.create!(:title => 'test 2', :enabled => false) | |
63 | + block1 = fast_create(Block, :title => 'test 1') | |
64 | + block2 = fast_create(Block, :title => 'test 2', :enabled => false) | |
65 | 65 | assert_includes Block.enabled, block1 |
66 | 66 | assert_not_includes Block.enabled, block2 |
67 | 67 | end |
... | ... | @@ -89,7 +89,7 @@ class BlockTest < Test::Unit::TestCase |
89 | 89 | should 'be able to save display setting' do |
90 | 90 | user = create_user('testinguser').person |
91 | 91 | box = fast_create(Box, :owner_id => user.id) |
92 | - block = Block.create!(:display => 'never', :box => box) | |
92 | + block = create(Block, :display => 'never', :box_id => box.id) | |
93 | 93 | block.reload |
94 | 94 | assert_equal 'never', block.display |
95 | 95 | end |
... | ... | @@ -97,7 +97,7 @@ class BlockTest < Test::Unit::TestCase |
97 | 97 | should 'be able to update display setting' do |
98 | 98 | user = create_user('testinguser').person |
99 | 99 | box = fast_create(Box, :owner_id => user.id) |
100 | - block = Block.create!(:display => 'never', :box => box) | |
100 | + block = create(Block, :display => 'never', :box_id => box.id) | |
101 | 101 | assert block.update_attributes!(:display => 'always') |
102 | 102 | block.reload |
103 | 103 | assert_equal 'always', block.display | ... | ... |
test/unit/blog_archives_block_test.rb
... | ... | @@ -21,7 +21,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
21 | 21 | date = DateTime.parse('2008-01-01') |
22 | 22 | blog = profile.blog |
23 | 23 | for i in 1..10 do |
24 | - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) | |
24 | + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) | |
25 | 25 | post.update_attribute(:published_at, date) |
26 | 26 | end |
27 | 27 | block = BlogArchivesBlock.new |
... | ... | @@ -33,7 +33,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
33 | 33 | date = DateTime.parse('2008-01-01') |
34 | 34 | blog = profile.blog |
35 | 35 | for i in 1..10 do |
36 | - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) | |
36 | + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) | |
37 | 37 | assert post.update_attribute(:published_at, date) |
38 | 38 | end |
39 | 39 | block = BlogArchivesBlock.new |
... | ... | @@ -44,7 +44,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
44 | 44 | should 'order list of amount posts' do |
45 | 45 | blog = profile.blog |
46 | 46 | for i in 1..10 do |
47 | - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) | |
47 | + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) | |
48 | 48 | post.update_attribute(:published_at, DateTime.parse("2008-#{i}-01")) |
49 | 49 | end |
50 | 50 | block = BlogArchivesBlock.new |
... | ... | @@ -90,11 +90,11 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
90 | 90 | end |
91 | 91 | |
92 | 92 | should 'show posts from first blog' do |
93 | - (blog_one, blog_two) = profile.blogs | |
94 | 93 | profile.articles << Blog.new(:name => 'Blog Two', :profile => profile) |
94 | + (blog_one, blog_two) = profile.blogs | |
95 | 95 | for month in 1..3 |
96 | - TextileArticle.create!(:name => "blog one - post #{month}", :profile => profile, :parent => blog_one) | |
97 | - TextileArticle.create!(:name => "blog two - post #{month}", :profile => profile, :parent => blog_two) | |
96 | + create(TextileArticle, :name => "blog one - post #{month}", :profile_id => profile.id, :parent_id => blog_one.id) | |
97 | + create(TextileArticle, :name => "blog two - post #{month}", :profile_id => profile.id, :parent_id => blog_two.id) | |
98 | 98 | end |
99 | 99 | block = BlogArchivesBlock.new |
100 | 100 | block.stubs(:owner).returns(profile) | ... | ... |
test/unit/blog_helper_test.rb
... | ... | @@ -11,7 +11,7 @@ class BlogHelperTest < Test::Unit::TestCase |
11 | 11 | stubs(:show_date).returns('') |
12 | 12 | @environment = Environment.default |
13 | 13 | @profile = create_user('blog_helper_test').person |
14 | - @blog = Blog.create!(:profile => profile, :name => 'Blog test') | |
14 | + @blog = fast_create(Blog, :profile_id => profile.id, :name => 'Blog test') | |
15 | 15 | end |
16 | 16 | |
17 | 17 | attr :profile | ... | ... |
test/unit/blog_test.rb
... | ... | @@ -28,7 +28,7 @@ class BlogTest < ActiveSupport::TestCase |
28 | 28 | |
29 | 29 | should 'create rss feed automatically' do |
30 | 30 | p = create_user('testuser').person |
31 | - b = Blog.create!(:profile => p, :name => 'blog_feed_test') | |
31 | + b = create(Blog, :profile_id => p.id, :name => 'blog_feed_test') | |
32 | 32 | assert_kind_of RssFeed, b.feed |
33 | 33 | end |
34 | 34 | |
... | ... | @@ -61,37 +61,37 @@ class BlogTest < ActiveSupport::TestCase |
61 | 61 | |
62 | 62 | should 'has posts' do |
63 | 63 | p = create_user('testuser').person |
64 | - blog = Blog.create!(:profile => p, :name => 'Blog test') | |
65 | - post = TextileArticle.create!(:name => 'First post', :profile => p, :parent => blog) | |
64 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
65 | + post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => blog.id) | |
66 | 66 | blog.children << post |
67 | 67 | assert_includes blog.posts, post |
68 | 68 | end |
69 | 69 | |
70 | 70 | should 'not includes rss feed in posts' do |
71 | 71 | p = create_user('testuser').person |
72 | - blog = Blog.create!(:profile => p, :name => 'Blog test') | |
72 | + blog = create(Blog, :profile_id => p.id, :name => 'Blog test') | |
73 | 73 | assert_includes blog.children, blog.feed |
74 | 74 | assert_not_includes blog.posts, blog.feed |
75 | 75 | end |
76 | 76 | |
77 | 77 | should 'list posts ordered by published at' do |
78 | 78 | p = create_user('testuser').person |
79 | - blog = Blog.create!(:profile => p, :name => 'Blog test') | |
80 | - newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p) | |
81 | - older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :published_at => Time.now - 1.month) | |
79 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
80 | + newer = create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p) | |
81 | + older = create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => Time.now - 1.month) | |
82 | 82 | assert_equal [newer, older], blog.posts |
83 | 83 | end |
84 | 84 | |
85 | 85 | should 'has filter' do |
86 | 86 | p = create_user('testuser').person |
87 | - blog = Blog.create!(:profile => p, :name => 'Blog test') | |
87 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
88 | 88 | blog.filter = {:param => 'value'} |
89 | 89 | assert_equal 'value', blog.filter[:param] |
90 | 90 | end |
91 | 91 | |
92 | 92 | should 'has one external feed' do |
93 | 93 | p = create_user('testuser').person |
94 | - blog = Blog.create!(:profile => p, :name => 'Blog test') | |
94 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
95 | 95 | efeed = blog.create_external_feed(:address => 'http://invalid.url') |
96 | 96 | assert_equal efeed, blog.external_feed |
97 | 97 | end |
... | ... | @@ -135,7 +135,7 @@ class BlogTest < ActiveSupport::TestCase |
135 | 135 | |
136 | 136 | should 'profile has more then one blog' do |
137 | 137 | p = create_user('testuser').person |
138 | - Blog.create!(:name => 'Blog test', :profile => p) | |
138 | + fast_create(Blog, :name => 'Blog test', :profile_id => p.id) | |
139 | 139 | assert_nothing_raised ActiveRecord::RecordInvalid do |
140 | 140 | Blog.create!(:name => 'Another Blog', :profile => p) |
141 | 141 | end | ... | ... |
test/unit/comment_notifier_test.rb
... | ... | @@ -8,47 +8,39 @@ class CommentNotifierTest < Test::Unit::TestCase |
8 | 8 | ActionMailer::Base.delivery_method = :test |
9 | 9 | ActionMailer::Base.perform_deliveries = true |
10 | 10 | ActionMailer::Base.deliveries = [] |
11 | - | |
11 | + @profile = create_user('user_comment_test').person | |
12 | + @article = fast_create(Article, :name => 'Article test', :profile_id => @profile.id, :notify_comments => true) | |
12 | 13 | end |
13 | 14 | |
14 | 15 | should 'deliver mail after make aarticle commment' do |
15 | - p = create_user('user_comment_test').person | |
16 | - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) | |
17 | 16 | assert_difference ActionMailer::Base.deliveries, :size do |
18 | - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') | |
17 | + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') | |
19 | 18 | end |
20 | 19 | end |
21 | 20 | |
22 | 21 | should 'deliver mail to owner of article' do |
23 | - p = create_user('user_comment_test').person | |
24 | - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) | |
25 | - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') | |
22 | + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') | |
26 | 23 | sent = ActionMailer::Base.deliveries.first |
27 | - assert_equal [p.email], sent.to | |
24 | + assert_equal [@profile.email], sent.to | |
28 | 25 | end |
29 | 26 | |
30 | 27 | should 'display author name in delivered mail' do |
31 | - p = create_user('user_comment_test').person | |
32 | - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) | |
33 | - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') | |
28 | + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') | |
34 | 29 | sent = ActionMailer::Base.deliveries.first |
35 | 30 | assert_match /user_comment_test/, sent.body |
36 | 31 | end |
37 | 32 | |
38 | 33 | should 'display unauthenticated author name and email in delivered mail' do |
39 | - p = create_user('user_comment_test').person | |
40 | - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) | |
41 | - a.comments << Comment.new(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!') | |
34 | + @article.comments << Comment.new(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!') | |
42 | 35 | sent = ActionMailer::Base.deliveries.first |
43 | 36 | assert_match /flatline/, sent.body |
44 | 37 | assert_match /flatline@invalid.com/, sent.body |
45 | 38 | end |
46 | 39 | |
47 | 40 | should 'not deliver mail if notify comments is false' do |
48 | - p = create_user('user_comment_test').person | |
49 | - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => false) | |
41 | + @article.update_attribute(:notify_comments, false) | |
50 | 42 | assert_no_difference ActionMailer::Base.deliveries, :size do |
51 | - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') | |
43 | + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') | |
52 | 44 | end |
53 | 45 | end |
54 | 46 | ... | ... |
test/unit/communities_block_test.rb
... | ... | @@ -121,7 +121,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase |
121 | 121 | community_public = fast_create(Community, :environment_id => Environment.default.id, :public_profile => true) |
122 | 122 | community_public.add_member(user) |
123 | 123 | |
124 | - community_private = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false) | |
124 | + community_private = fast_create(Community, :public_profile => false) | |
125 | 125 | community_private.add_member(user) |
126 | 126 | |
127 | 127 | block = CommunitiesBlock.new |
... | ... | @@ -133,10 +133,10 @@ class CommunitiesBlockTest < Test::Unit::TestCase |
133 | 133 | should 'not count non-visible profile communities' do |
134 | 134 | user = create_user('testuser').person |
135 | 135 | |
136 | - visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true) | |
136 | + visible_community = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :visible => true) | |
137 | 137 | visible_community.add_member(user) |
138 | 138 | |
139 | - not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false) | |
139 | + not_visible_community = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :visible => false) | |
140 | 140 | not_visible_community.add_member(user) |
141 | 141 | |
142 | 142 | block = CommunitiesBlock.new |
... | ... | @@ -146,9 +146,9 @@ class CommunitiesBlockTest < Test::Unit::TestCase |
146 | 146 | end |
147 | 147 | |
148 | 148 | should 'count non-public environment communities' do |
149 | - community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) | |
149 | + community_public = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :public_profile => true) | |
150 | 150 | |
151 | - community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) | |
151 | + community_private = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :public_profile => false) | |
152 | 152 | |
153 | 153 | block = CommunitiesBlock.new |
154 | 154 | block.expects(:owner).at_least_once.returns(Environment.default) |
... | ... | @@ -157,9 +157,9 @@ class CommunitiesBlockTest < Test::Unit::TestCase |
157 | 157 | end |
158 | 158 | |
159 | 159 | should 'not count non-visible environment communities' do |
160 | - visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true) | |
160 | + visible_community = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :visible => true) | |
161 | 161 | |
162 | - not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false) | |
162 | + not_visible_community = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :visible => false) | |
163 | 163 | |
164 | 164 | block = CommunitiesBlock.new |
165 | 165 | block.expects(:owner).at_least_once.returns(Environment.default) | ... | ... |
test/unit/community_test.rb
... | ... | @@ -51,7 +51,7 @@ class CommunityTest < Test::Unit::TestCase |
51 | 51 | end |
52 | 52 | |
53 | 53 | should 'allow to add new members' do |
54 | - c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') | |
54 | + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | |
55 | 55 | p = create_user('mytestuser').person |
56 | 56 | |
57 | 57 | c.add_member(p) |
... | ... | @@ -60,7 +60,7 @@ class CommunityTest < Test::Unit::TestCase |
60 | 60 | end |
61 | 61 | |
62 | 62 | should 'allow to remove members' do |
63 | - c = Community.create!(:environment => Environment.default, :name => 'my other test profile', :identifier => 'myothertestprofile') | |
63 | + c = fast_create(Community, :name => 'my other test profile', :identifier => 'myothertestprofile') | |
64 | 64 | p = create_user('myothertestuser').person |
65 | 65 | |
66 | 66 | c.add_member(p) |
... | ... | @@ -71,7 +71,7 @@ class CommunityTest < Test::Unit::TestCase |
71 | 71 | end |
72 | 72 | |
73 | 73 | should 'clear relationships after destroy' do |
74 | - c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') | |
74 | + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | |
75 | 75 | member = create_user('memberuser').person |
76 | 76 | admin = create_user('adminuser').person |
77 | 77 | moderator = create_user('moderatoruser').person |
... | ... | @@ -91,7 +91,7 @@ class CommunityTest < Test::Unit::TestCase |
91 | 91 | |
92 | 92 | should 'have a community template' do |
93 | 93 | env = Environment.create!(:name => 'test env') |
94 | - p = Community.create!(:environment => Environment.default, :name => 'test_com', :identifier => 'test_com', :environment => env) | |
94 | + p = Community.create!(:name => 'test_com', :identifier => 'test_com', :environment => env) | |
95 | 95 | assert_kind_of Community, p.template |
96 | 96 | end |
97 | 97 | |
... | ... | @@ -124,28 +124,28 @@ class CommunityTest < Test::Unit::TestCase |
124 | 124 | end |
125 | 125 | |
126 | 126 | should 'return newest text articles as news' do |
127 | - c = Community.create!(:name => 'test_com') | |
128 | - f = Folder.create!(:name => 'folder', :profile => c) | |
127 | + c = fast_create(Community, :name => 'test_com') | |
128 | + f = fast_create(Folder, :name => 'folder', :profile_id => c.id) | |
129 | 129 | u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
130 | - older_t = TinyMceArticle.create!(:name => 'old news', :profile => c) | |
131 | - t = TinyMceArticle.create!(:name => 'news', :profile => c) | |
132 | - t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) | |
130 | + older_t = fast_create(TinyMceArticle, :name => 'old news', :profile_id => c.id) | |
131 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) | |
132 | + t_in_f = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => f.id) | |
133 | 133 | |
134 | 134 | assert_equal [t_in_f, t], c.news(2) |
135 | 135 | end |
136 | 136 | |
137 | 137 | should 'not return highlighted news when not asked' do |
138 | - c = Community.create!(:name => 'test_com') | |
139 | - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) | |
140 | - t = TinyMceArticle.create!(:name => 'news', :profile => c) | |
138 | + c = fast_create(Community, :name => 'test_com') | |
139 | + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true) | |
140 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) | |
141 | 141 | |
142 | 142 | assert_equal [t].map(&:slug), c.news(2).map(&:slug) |
143 | 143 | end |
144 | 144 | |
145 | 145 | should 'return highlighted news when asked' do |
146 | - c = Community.create!(:name => 'test_com') | |
147 | - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) | |
148 | - t = TinyMceArticle.create!(:name => 'news', :profile => c) | |
146 | + c = fast_create(Community, :name => 'test_com') | |
147 | + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true) | |
148 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) | |
149 | 149 | |
150 | 150 | assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug) |
151 | 151 | end | ... | ... |
test/unit/contact_test.rb
... | ... | @@ -32,13 +32,13 @@ class ContactTest < ActiveSupport::TestCase |
32 | 32 | end |
33 | 33 | |
34 | 34 | should 'deliver message' do |
35 | - ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) | |
35 | + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') | |
36 | 36 | c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent) |
37 | 37 | assert c.deliver |
38 | 38 | end |
39 | 39 | |
40 | 40 | should 'not deliver message if contact is invalid' do |
41 | - ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) | |
41 | + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') | |
42 | 42 | c = Contact.new(:name => 'john', :subject => 'hi', :message => 'hi, all', :dest => ent) |
43 | 43 | assert !c.valid? |
44 | 44 | assert !c.deliver | ... | ... |
test/unit/content_viewer_helper_test.rb
... | ... | @@ -13,7 +13,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase |
13 | 13 | attr :profile |
14 | 14 | |
15 | 15 | should 'display published-at for blog posts' do |
16 | - blog = Blog.create!(:name => 'Blog test', :profile => profile) | |
16 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | |
17 | 17 | post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) |
18 | 18 | result = article_title(post) |
19 | 19 | assert_match /#{show_date(post.published_at)}, by .*#{profile.identifier}/, result |
... | ... | @@ -26,22 +26,22 @@ class ContentViewerHelperTest < Test::Unit::TestCase |
26 | 26 | end |
27 | 27 | |
28 | 28 | should 'create link on title of blog posts' do |
29 | - blog = Blog.create!(:name => 'Blog test', :profile => profile) | |
30 | - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) | |
29 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | |
30 | + post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) | |
31 | 31 | assert post.belongs_to_blog? |
32 | 32 | result = article_title(post) |
33 | 33 | assert_match /a href='#{post.url}'>#{post.name}</, result |
34 | 34 | end |
35 | 35 | |
36 | 36 | should 'not create link on title if pass no_link option' do |
37 | - blog = Blog.create!(:name => 'Blog test', :profile => profile) | |
38 | - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) | |
37 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | |
38 | + post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) | |
39 | 39 | result = article_title(post, :no_link => :true) |
40 | 40 | assert_no_match /a href='#{post.url}'>#{post.name}</, result |
41 | 41 | end |
42 | 42 | |
43 | 43 | should 'not create link on title if non-blog post' do |
44 | - article = TextileArticle.create!(:name => 'art test', :profile => profile) | |
44 | + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id) | |
45 | 45 | result = article_title(article) |
46 | 46 | assert_no_match /a href='#{article.url}'>#{article.name}</, result |
47 | 47 | end | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -46,8 +46,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
46 | 46 | |
47 | 47 | should 'require that the informed target (validator organization) actually validates for the chosen region' do |
48 | 48 | environment = fast_create(Environment) |
49 | - region = Region.create!(:name => 'My region', :environment_id => environment.id) | |
50 | - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
49 | + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) | |
50 | + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
51 | 51 | |
52 | 52 | task = CreateEnterprise.new |
53 | 53 | |
... | ... | @@ -94,8 +94,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
94 | 94 | should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association' do |
95 | 95 | |
96 | 96 | environment = fast_create(Environment) |
97 | - region = Region.create!(:name => 'My region', :environment_id => environment.id) | |
98 | - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
97 | + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) | |
98 | + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
99 | 99 | region.validators << validator |
100 | 100 | person = create_user('testuser').person |
101 | 101 | |
... | ... | @@ -128,8 +128,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
128 | 128 | should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association even when environment is not default' do |
129 | 129 | |
130 | 130 | environment = fast_create(Environment) |
131 | - region = Region.create!(:name => 'My region', :environment_id => environment.id) | |
132 | - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
131 | + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) | |
132 | + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
133 | 133 | region.validators << validator |
134 | 134 | person = create_user('testuser').person |
135 | 135 | |
... | ... | @@ -170,8 +170,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
170 | 170 | |
171 | 171 | should 'validate that eveything is ok but the validator (target)' do |
172 | 172 | environment = fast_create(Environment) |
173 | - region = Region.create!(:name => 'My region', :environment_id => environment.id) | |
174 | - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
173 | + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) | |
174 | + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
175 | 175 | region.validators << validator |
176 | 176 | person = create_user('testuser').person |
177 | 177 | task = CreateEnterprise.new({ | ... | ... |
test/unit/disabled_enterprise_message_block_test.rb
... | ... | @@ -7,7 +7,7 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase |
7 | 7 | end |
8 | 8 | |
9 | 9 | should 'display message for disabled enterprise' do |
10 | - e = Environment.create(:name => 'test_env') | |
10 | + e = Environment.default | |
11 | 11 | e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises') |
12 | 12 | block = DisabledEnterpriseMessageBlock.new |
13 | 13 | p = Profile.new |
... | ... | @@ -19,7 +19,7 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase |
19 | 19 | end |
20 | 20 | |
21 | 21 | should 'display nothing if environment has no message' do |
22 | - e = Environment.create(:name => 'test_env') | |
22 | + e = fast_create(Environment) | |
23 | 23 | block = DisabledEnterpriseMessageBlock.new |
24 | 24 | p = Profile.new |
25 | 25 | block.expects(:owner).returns(p) | ... | ... |
test/unit/domain_test.rb
... | ... | @@ -51,7 +51,7 @@ class DomainTest < Test::Unit::TestCase |
51 | 51 | |
52 | 52 | def test_find_by_name |
53 | 53 | Domain.delete_all |
54 | - Domain.create(:name => 'example.net') | |
54 | + fast_create(Domain, :name => 'example.net') | |
55 | 55 | d1 = Domain.find_by_name('example.net') |
56 | 56 | d2 = Domain.find_by_name('www.example.net') |
57 | 57 | assert !d1.nil? | ... | ... |
test/unit/email_activation_test.rb
... | ... | @@ -25,7 +25,7 @@ class EmailActivationTest < Test::Unit::TestCase |
25 | 25 | should 'enable user email when finish' do |
26 | 26 | ze = create_user('zezinho', :environment_id => Environment.default.id) |
27 | 27 | assert !ze.enable_email |
28 | - task = EmailActivation.create!(:requestor => ze.person, :target => Environment.default) | |
28 | + task = fast_create(EmailActivation, :requestor_id => ze.person.id, :target_id => Environment.default.id) | |
29 | 29 | task.finish |
30 | 30 | ze.reload |
31 | 31 | assert ze.enable_email | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -46,7 +46,7 @@ class EnterpriseTest < Test::Unit::TestCase |
46 | 46 | end |
47 | 47 | |
48 | 48 | should 'remove products when removing enterprise' do |
49 | - e = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise') | |
49 | + e = fast_create(Enterprise) | |
50 | 50 | e.products.build(:name => 'One product').save! |
51 | 51 | e.products.build(:name => 'Another product').save! |
52 | 52 | |
... | ... | @@ -77,7 +77,7 @@ class EnterpriseTest < Test::Unit::TestCase |
77 | 77 | end |
78 | 78 | |
79 | 79 | should 'be found in search for its product categories' do |
80 | - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') | |
80 | + ent1 = fast_create(Enterprise) | |
81 | 81 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
82 | 82 | prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) |
83 | 83 | |
... | ... | @@ -90,7 +90,7 @@ class EnterpriseTest < Test::Unit::TestCase |
90 | 90 | end |
91 | 91 | |
92 | 92 | should 'be found in search for its product categories hierarchy' do |
93 | - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') | |
93 | + ent1 = fast_create(Enterprise) | |
94 | 94 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
95 | 95 | prod_child = ProductCategory.create!(:name => 'pchild', :environment => Environment.default, :parent => prod_cat) |
96 | 96 | prod = ent1.products.create!(:name => 'teste', :product_category => prod_child) |
... | ... | @@ -104,7 +104,7 @@ class EnterpriseTest < Test::Unit::TestCase |
104 | 104 | end |
105 | 105 | |
106 | 106 | should 'not allow to add new members' do |
107 | - o = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
107 | + o = fast_create(Enterprise) | |
108 | 108 | p = create_user('mytestuser').person |
109 | 109 | |
110 | 110 | o.add_member(p) |
... | ... | @@ -114,7 +114,7 @@ class EnterpriseTest < Test::Unit::TestCase |
114 | 114 | end |
115 | 115 | |
116 | 116 | should 'allow to remove members' do |
117 | - c = Enterprise.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | |
117 | + c = fast_create(Enterprise) | |
118 | 118 | c.expects(:closed?).returns(false) |
119 | 119 | p = create_user('myothertestuser').person |
120 | 120 | |
... | ... | @@ -126,27 +126,27 @@ class EnterpriseTest < Test::Unit::TestCase |
126 | 126 | end |
127 | 127 | |
128 | 128 | should 'have foudation_year' do |
129 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') | |
129 | + ent = fast_create(Enterprise) | |
130 | 130 | |
131 | 131 | assert_respond_to ent, 'foundation_year' |
132 | 132 | assert_respond_to ent, 'foundation_year=' |
133 | 133 | end |
134 | 134 | |
135 | 135 | should 'have cnpj' do |
136 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') | |
136 | + ent = fast_create(Enterprise) | |
137 | 137 | |
138 | 138 | assert_respond_to ent, 'cnpj' |
139 | 139 | assert_respond_to ent, 'cnpj=' |
140 | 140 | end |
141 | 141 | |
142 | 142 | should 'block' do |
143 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') | |
143 | + ent = fast_create(Enterprise) | |
144 | 144 | ent.block |
145 | 145 | assert Enterprise.find(ent.id).blocked? |
146 | 146 | end |
147 | 147 | |
148 | 148 | should 'unblock' do |
149 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') | |
149 | + ent = fast_create(Enterprise) | |
150 | 150 | ent.data[:blocked] = true |
151 | 151 | ent.save |
152 | 152 | ent.unblock |
... | ... | @@ -154,7 +154,7 @@ class EnterpriseTest < Test::Unit::TestCase |
154 | 154 | end |
155 | 155 | |
156 | 156 | should 'enable and make user admin' do |
157 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | |
157 | + ent = fast_create(Enterprise, :enabled => false) | |
158 | 158 | p = create_user('test_user').person |
159 | 159 | |
160 | 160 | assert ent.enable(p) | ... | ... |
test/unit/enterprises_block_test.rb
... | ... | @@ -125,11 +125,11 @@ class EnterprisesBlockTest < Test::Unit::TestCase |
125 | 125 | should 'count number of owner enterprises' do |
126 | 126 | user = create_user('testuser').person |
127 | 127 | |
128 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default) | |
128 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1') | |
129 | 129 | ent1.expects(:closed?).returns(false) |
130 | 130 | ent1.add_member(user) |
131 | 131 | |
132 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default) | |
132 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2') | |
133 | 133 | ent2.expects(:closed?).returns(false) |
134 | 134 | ent2.add_member(user) |
135 | 135 | |
... | ... | @@ -186,9 +186,9 @@ class EnterprisesBlockTest < Test::Unit::TestCase |
186 | 186 | end |
187 | 187 | |
188 | 188 | should 'not count non-visible environment enterprises' do |
189 | - env = Environment.create!(:name => 'test_env') | |
190 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :visible => true) | |
191 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :visible => false) | |
189 | + env = fast_create(Environment) | |
190 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1', :environment_id => env.id, :visible => true) | |
191 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2', :environment_id => env.id, :visible => false) | |
192 | 192 | |
193 | 193 | block = EnterprisesBlock.new |
194 | 194 | block.expects(:owner).at_least_once.returns(env) | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -107,9 +107,9 @@ class EnvironmentTest < Test::Unit::TestCase |
107 | 107 | |
108 | 108 | def test_should_list_top_level_categories |
109 | 109 | env = fast_create(Environment) |
110 | - cat1 = Category.create!(:name => 'first category', :environment_id => env.id) | |
111 | - cat2 = Category.create!(:name => 'second category', :environment_id => env.id) | |
112 | - subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id) | |
110 | + cat1 = fast_create(Category, :name => 'first category', :environment_id => env.id) | |
111 | + cat2 = fast_create(Category, :name => 'second category', :environment_id => env.id) | |
112 | + subcat = fast_create(Category, :name => 'child category', :environment_id => env.id, :parent_id => cat2.id) | |
113 | 113 | |
114 | 114 | cats = env.top_level_categories |
115 | 115 | assert_equal 2, cats.size |
... | ... | @@ -120,9 +120,9 @@ class EnvironmentTest < Test::Unit::TestCase |
120 | 120 | |
121 | 121 | def test_should_list_all_categories |
122 | 122 | env = fast_create(Environment) |
123 | - cat1 = Category.create!(:name => 'first category', :environment_id => env.id) | |
124 | - cat2 = Category.create!(:name => 'second category', :environment_id => env.id) | |
125 | - subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id) | |
123 | + cat1 = fast_create(Category, :name => 'first category', :environment_id => env.id) | |
124 | + cat2 = fast_create(Category, :name => 'second category', :environment_id => env.id) | |
125 | + subcat = fast_create(Category, :name => 'child category', :environment_id => env.id, :parent_id => cat2.id) | |
126 | 126 | |
127 | 127 | cats = env.categories |
128 | 128 | assert_equal 3, cats.size |
... | ... | @@ -315,21 +315,21 @@ class EnvironmentTest < Test::Unit::TestCase |
315 | 315 | should 'provide recent_documents' do |
316 | 316 | environment = fast_create(Environment) |
317 | 317 | |
318 | - p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1'); p1.save! | |
319 | - p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2'); p2.save! | |
318 | + p1 = fast_create(Profile, :environment_id => environment.id) | |
319 | + p2 = fast_create(Profile, :environment_id => environment.id) | |
320 | 320 | |
321 | 321 | # clear the articles |
322 | 322 | Article.destroy_all |
323 | 323 | |
324 | 324 | # p1 creates one article |
325 | - doc1 = p1.articles.build(:name => 'text 1'); doc1.save! | |
325 | + doc1 = fast_create(Article, :profile_id => p1.id) | |
326 | 326 | |
327 | 327 | # p2 creates two articles |
328 | - doc2 = p2.articles.build(:name => 'text 2'); doc2.save! | |
329 | - doc3 = p2.articles.build(:name => 'text 3'); doc3.save! | |
328 | + doc2 = fast_create(Article, :profile_id => p2.id) | |
329 | + doc3 = fast_create(Article, :profile_id => p2.id) | |
330 | 330 | |
331 | 331 | # p1 creates another article |
332 | - doc4 = p1.articles.build(:name => 'text 4'); doc4.save! | |
332 | + doc4 = fast_create(Article, :profile_id => p1.id) | |
333 | 333 | |
334 | 334 | all_recent = environment.recent_documents |
335 | 335 | [doc1,doc2,doc3,doc4].each do |item| |
... | ... | @@ -404,34 +404,10 @@ class EnvironmentTest < Test::Unit::TestCase |
404 | 404 | assert_equal 'this enterprise was disabled', env.message_for_disabled_enterprise |
405 | 405 | end |
406 | 406 | |
407 | - should 'have articles and text_articles' do | |
408 | - # FIXME | |
409 | - assert true | |
410 | - #environment = Environment.create(:name => 'a test environment') | |
411 | - | |
412 | - ## creates profile | |
413 | - #profile = environment.profiles.create!(:identifier => 'testprofile1', :name => 'test profile 1') | |
414 | - | |
415 | - ## profile creates one article | |
416 | - #article = profile.articles.create!(:name => 'text article') | |
417 | - | |
418 | - ## profile creates one textile article | |
419 | - #textile = TextileArticle.create!(:name => 'textile article', :profile => profile) | |
420 | - #profile.articles << textile | |
421 | - | |
422 | - #assert_includes environment.articles, article | |
423 | - #assert_includes environment.articles, textile | |
424 | - | |
425 | - #assert_includes environment.text_articles, textile | |
426 | - #assert_not_includes environment.text_articles, article | |
427 | - end | |
428 | - | |
429 | 407 | should 'find by contents from articles' do |
430 | 408 | environment = fast_create(Environment) |
431 | 409 | assert_nothing_raised do |
432 | 410 | environment.articles.find_by_contents('') |
433 | - # FIXME | |
434 | - #environment.text_articles.find_by_contents('') | |
435 | 411 | end |
436 | 412 | end |
437 | 413 | |
... | ... | @@ -768,7 +744,7 @@ class EnvironmentTest < Test::Unit::TestCase |
768 | 744 | e = Environment.default |
769 | 745 | |
770 | 746 | c = e.portal_community = fast_create(Community) |
771 | - news_folder = Folder.create!(:name => 'news folder', :profile => c) | |
747 | + news_folder = fast_create(Folder, :name => 'news folder', :profile_id => c.id) | |
772 | 748 | |
773 | 749 | e.portal_folders = [news_folder] |
774 | 750 | e.save!; e.reload |
... | ... | @@ -848,9 +824,9 @@ class EnvironmentTest < Test::Unit::TestCase |
848 | 824 | |
849 | 825 | should 'list tags with their counts' do |
850 | 826 | person = fast_create(Person) |
851 | - person.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! | |
852 | - person.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! | |
853 | - person.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! | |
827 | + person.articles.create!(:name => 'article 1', :tag_list => 'first-tag') | |
828 | + person.articles.create!(:name => 'article 2', :tag_list => 'first-tag, second-tag') | |
829 | + person.articles.create!(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag') | |
854 | 830 | |
855 | 831 | assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, Environment.default.tag_counts) |
856 | 832 | end | ... | ... |
test/unit/event_test.rb
... | ... | @@ -172,7 +172,7 @@ class EventTest < ActiveSupport::TestCase |
172 | 172 | end |
173 | 173 | |
174 | 174 | should 'list all events' do |
175 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
175 | + profile = fast_create(Profile) | |
176 | 176 | event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today) |
177 | 177 | event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1) |
178 | 178 | profile.events << [event1, event2] |
... | ... | @@ -181,7 +181,7 @@ class EventTest < ActiveSupport::TestCase |
181 | 181 | end |
182 | 182 | |
183 | 183 | should 'list events by day' do |
184 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
184 | + profile = fast_create(Profile) | |
185 | 185 | |
186 | 186 | today = Date.today |
187 | 187 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) |
... | ... | @@ -194,7 +194,7 @@ class EventTest < ActiveSupport::TestCase |
194 | 194 | end |
195 | 195 | |
196 | 196 | should 'list events in a range' do |
197 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
197 | + profile = fast_create(Profile) | |
198 | 198 | |
199 | 199 | today = Date.today |
200 | 200 | event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
... | ... | @@ -208,7 +208,7 @@ class EventTest < ActiveSupport::TestCase |
208 | 208 | end |
209 | 209 | |
210 | 210 | should 'not list events out of range' do |
211 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
211 | + profile = fast_create(Profile) | |
212 | 212 | |
213 | 213 | today = Date.today |
214 | 214 | event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) | ... | ... |
test/unit/favorite_enterprises_block_test.rb
... | ... | @@ -63,9 +63,9 @@ class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase |
63 | 63 | should 'count number of owner favorite enterprises' do |
64 | 64 | user = create_user('testuser').person |
65 | 65 | |
66 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default) | |
66 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1') | |
67 | 67 | |
68 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default) | |
68 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2') | |
69 | 69 | |
70 | 70 | user.favorite_enterprises << [ent1, ent2] |
71 | 71 | ... | ... |
test/unit/folder_test.rb
... | ... | @@ -24,13 +24,13 @@ class FolderTest < ActiveSupport::TestCase |
24 | 24 | |
25 | 25 | should 'can display hits' do |
26 | 26 | profile = create_user('testuser').person |
27 | - a = Folder.create!(:name => 'Test article', :profile => profile) | |
27 | + a = fast_create(Folder, :profile_id => profile.id) | |
28 | 28 | assert_equal false, a.can_display_hits? |
29 | 29 | end |
30 | 30 | |
31 | 31 | should 'be viewed as image gallery' do |
32 | 32 | p = create_user('test_user').person |
33 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
33 | + f = fast_create(Folder, :profile_id => p.id) | |
34 | 34 | f.view_as = 'image_gallery'; f.save! |
35 | 35 | f.reload |
36 | 36 | |
... | ... | @@ -39,14 +39,14 @@ class FolderTest < ActiveSupport::TestCase |
39 | 39 | |
40 | 40 | should 'not allow view as bogus' do |
41 | 41 | p = create_user('test_user').person |
42 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
42 | + f = fast_create(Folder, :profile_id => p.id) | |
43 | 43 | f.view_as = 'bogus' |
44 | 44 | assert !f.save |
45 | 45 | end |
46 | 46 | |
47 | 47 | should 'view as folder by default' do |
48 | 48 | p = create_user('test_user').person |
49 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
49 | + f = fast_create(Folder, :profile_id => p.id) | |
50 | 50 | f.expects(:folder) |
51 | 51 | f.to_html |
52 | 52 | |
... | ... | @@ -55,60 +55,60 @@ class FolderTest < ActiveSupport::TestCase |
55 | 55 | |
56 | 56 | should 'have images that are only images or other folders' do |
57 | 57 | p = create_user('test_user').person |
58 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
58 | + f = fast_create(Folder, :profile_id => p.id) | |
59 | 59 | file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => f, :profile => p) |
60 | 60 | image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) |
61 | - folder = Folder.create!(:name => 'child test folder', :parent => f, :profile => p) | |
61 | + folder = fast_create(Folder, :profile_id => p.id, :parent_id => f.id) | |
62 | 62 | |
63 | 63 | assert_equivalent [folder, image], f.images |
64 | 64 | end |
65 | 65 | |
66 | 66 | should 'bring folders first in alpha order in images listing' do |
67 | 67 | p = create_user('test_user').person |
68 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
69 | - folder1 = Folder.create!(:name => 'child test folder 1', :parent => f, :profile => p) | |
68 | + f = fast_create(Folder, :profile_id => p.id) | |
69 | + folder1 = fast_create(Folder, :name => 'b', :profile_id => p.id, :parent_id => f.id) | |
70 | 70 | image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) |
71 | - folder2 = Folder.create!(:name => 'child test folder 2', :parent => f, :profile => p) | |
72 | - folder3 = Folder.create!(:name => 'another child test folder', :parent => f, :profile => p) | |
71 | + folder2 = fast_create(Folder, :name => 'c', :profile_id => p.id, :parent_id => f.id) | |
72 | + folder3 = fast_create(Folder, :name => 'a', :profile_id => p.id, :parent_id => f.id) | |
73 | 73 | |
74 | 74 | assert_equal [folder3.id, folder1.id, folder2.id, image.id], f.images.map(&:id) |
75 | 75 | end |
76 | 76 | |
77 | 77 | should 'images support pagination' do |
78 | 78 | p = create_user('test_user').person |
79 | - f = Folder.create!(:name => 'Test folder', :profile => p) | |
80 | - folder = Folder.create!(:name => 'child test folder', :parent => f, :profile => p) | |
79 | + f = fast_create(Folder, :profile_id => p.id) | |
80 | + folder = fast_create(Folder, :profile_id => p.id, :parent_id => f.id) | |
81 | 81 | image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) |
82 | 82 | |
83 | 83 | assert_equal [image], f.images.paginate(:page => 2, :per_page => 1) |
84 | 84 | end |
85 | 85 | |
86 | 86 | should 'return newest text articles as news' do |
87 | - c = Community.create!(:name => 'test_com') | |
88 | - folder = Folder.create!(:name => 'folder', :profile => c) | |
89 | - f = Folder.create!(:name => 'folder', :profile => c, :parent => folder) | |
87 | + c = fast_create(Community) | |
88 | + folder = fast_create(Folder, :profile_id => c.id) | |
89 | + f = fast_create(Folder, :name => 'folder', :profile_id => c.id, :parent_id => folder.id) | |
90 | 90 | u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => folder) |
91 | - older_t = TinyMceArticle.create!(:name => 'old news', :profile => c, :parent => folder) | |
92 | - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) | |
93 | - t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) | |
91 | + older_t = fast_create(TinyMceArticle, :name => 'old news', :profile_id => c.id, :parent_id => folder.id) | |
92 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) | |
93 | + t_in_f = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => f.id) | |
94 | 94 | |
95 | 95 | assert_equal [t], folder.news(1) |
96 | 96 | end |
97 | 97 | |
98 | 98 | should 'not return highlighted news when not asked' do |
99 | - c = Community.create!(:name => 'test_com') | |
100 | - folder = Folder.create!(:name => 'folder', :profile => c) | |
101 | - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) | |
102 | - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) | |
99 | + c = fast_create(Community) | |
100 | + folder = fast_create(Folder, :profile_id => c.id) | |
101 | + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true, :parent_id => folder.id) | |
102 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) | |
103 | 103 | |
104 | 104 | assert_equal [t].map(&:slug), folder.news(2).map(&:slug) |
105 | 105 | end |
106 | 106 | |
107 | 107 | should 'return highlighted news when asked' do |
108 | - c = Community.create!(:name => 'test_com') | |
109 | - folder = Folder.create!(:name => 'folder', :profile => c) | |
110 | - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) | |
111 | - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) | |
108 | + c = fast_create(Community) | |
109 | + folder = fast_create(Folder, :profile_id => c.id) | |
110 | + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true, :parent_id => folder.id) | |
111 | + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) | |
112 | 112 | |
113 | 113 | assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug) |
114 | 114 | end |
... | ... | @@ -117,8 +117,8 @@ class FolderTest < ActiveSupport::TestCase |
117 | 117 | p = create_user('test_user').person |
118 | 118 | i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
119 | 119 | |
120 | - c = Community.create!(:name => 'test_com') | |
121 | - folder = Folder.create!(:name => 'folder', :profile => c) | |
120 | + c = fast_create(Community) | |
121 | + folder = fast_create(Folder, :profile_id => c.id) | |
122 | 122 | pi = PublishedArticle.create!(:profile => c, :reference_article => i, :parent => folder) |
123 | 123 | |
124 | 124 | assert_includes folder.images(true), pi | ... | ... |
test/unit/organization_test.rb
... | ... | @@ -4,7 +4,7 @@ class OrganizationTest < Test::Unit::TestCase |
4 | 4 | fixtures :profiles |
5 | 5 | |
6 | 6 | def create_create_enterprise(org) |
7 | - region = Region.create!(:name => 'some region', :environment => Environment.default) | |
7 | + region = fast_create(Region, :name => 'some region') | |
8 | 8 | region.validators << org |
9 | 9 | |
10 | 10 | requestor = create_user('testreq').person |
... | ... | @@ -130,7 +130,7 @@ class OrganizationTest < Test::Unit::TestCase |
130 | 130 | end |
131 | 131 | |
132 | 132 | should 'be able to find a pending validation by its code' do |
133 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
133 | + org = fast_create(Organization) | |
134 | 134 | |
135 | 135 | validation = create_create_enterprise(org) |
136 | 136 | |
... | ... | @@ -148,7 +148,7 @@ class OrganizationTest < Test::Unit::TestCase |
148 | 148 | end |
149 | 149 | |
150 | 150 | should 'be able to find an already processed validation by its code' do |
151 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
151 | + org = fast_create(Organization) | |
152 | 152 | validation = create_create_enterprise(org) |
153 | 153 | validation.finish |
154 | 154 | |
... | ... | @@ -167,7 +167,7 @@ class OrganizationTest < Test::Unit::TestCase |
167 | 167 | end |
168 | 168 | |
169 | 169 | should 'update contact_person' do |
170 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
170 | + org = fast_create(Organization) | |
171 | 171 | assert_nil org.contact_person |
172 | 172 | org.contact_person = 'person' |
173 | 173 | assert_not_nil org.contact_person |
... | ... | @@ -197,7 +197,7 @@ class OrganizationTest < Test::Unit::TestCase |
197 | 197 | end |
198 | 198 | |
199 | 199 | should 'allow to add new member' do |
200 | - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
200 | + o = fast_create(Organization) | |
201 | 201 | p = create_user('mytestuser').person |
202 | 202 | |
203 | 203 | o.add_member(p) |
... | ... | @@ -206,7 +206,7 @@ class OrganizationTest < Test::Unit::TestCase |
206 | 206 | end |
207 | 207 | |
208 | 208 | should 'allow to remove members' do |
209 | - c = Organization.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | |
209 | + c = fast_create(Organization) | |
210 | 210 | p = create_user('myothertestuser').person |
211 | 211 | |
212 | 212 | c.add_member(p) |
... | ... | @@ -217,7 +217,7 @@ class OrganizationTest < Test::Unit::TestCase |
217 | 217 | end |
218 | 218 | |
219 | 219 | should 'allow to add new moderator' do |
220 | - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
220 | + o = fast_create(Organization) | |
221 | 221 | p = create_user('myanothertestuser').person |
222 | 222 | |
223 | 223 | o.add_moderator(p) |
... | ... | @@ -226,14 +226,14 @@ class OrganizationTest < Test::Unit::TestCase |
226 | 226 | end |
227 | 227 | |
228 | 228 | should 'moderator has moderate_comments permission' do |
229 | - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
229 | + o = fast_create(Organization) | |
230 | 230 | p = create_user('myanothertestuser').person |
231 | 231 | o.add_moderator(p) |
232 | 232 | assert p.has_permission?(:moderate_comments, o) |
233 | 233 | end |
234 | 234 | |
235 | 235 | should 'be able to change identifier' do |
236 | - o = Organization.create!(:name => 'Test Org', :identifier => 'test_org') | |
236 | + o = fast_create(Organization) | |
237 | 237 | assert_nothing_raised do |
238 | 238 | o.identifier = 'test_org_new_url' |
239 | 239 | end | ... | ... |
test/unit/pending_task_notifier_test.rb
... | ... | @@ -21,7 +21,7 @@ class PendingTaskNotifierTest < Test::Unit::TestCase |
21 | 21 | |
22 | 22 | should 'list organization pending tasks' do |
23 | 23 | p = create_user('maelcum').person |
24 | - c = Community.create!(:name => 'my test community') | |
24 | + c = fast_create(Community) | |
25 | 25 | c.add_admin(p) |
26 | 26 | c.tasks << Task.new |
27 | 27 | ... | ... |
test/unit/people_block_test.rb
... | ... | @@ -24,7 +24,7 @@ class PeopleBlockTest < ActiveSupport::TestCase |
24 | 24 | end |
25 | 25 | |
26 | 26 | should 'list people' do |
27 | - owner = Environment.create!(:name => 'test environment') | |
27 | + owner = fast_create(Environment) | |
28 | 28 | block = PeopleBlock.new |
29 | 29 | block.expects(:owner).returns(owner).at_least_once |
30 | 30 | person1 = fast_create(Person, :environment_id => owner.id) | ... | ... |
test/unit/person_test.rb
... | ... | @@ -36,7 +36,7 @@ class PersonTest < Test::Unit::TestCase |
36 | 36 | end |
37 | 37 | |
38 | 38 | should 'belong to communities' do |
39 | - c = Community.create!(:name => 'my test community') | |
39 | + c = fast_create(Community) | |
40 | 40 | p = create_user('mytestuser').person |
41 | 41 | |
42 | 42 | c.add_member(p) |
... | ... | @@ -78,7 +78,7 @@ class PersonTest < Test::Unit::TestCase |
78 | 78 | |
79 | 79 | should 'change the roles of the user' do |
80 | 80 | p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person |
81 | - e = Enterprise.create(:identifier => 'enter', :name => 'Enter') | |
81 | + e = fast_create(Enterprise) | |
82 | 82 | r1 = Role.create(:name => 'associate') |
83 | 83 | assert e.affiliate(p, r1) |
84 | 84 | r2 = Role.create(:name => 'partner') |
... | ... | @@ -91,7 +91,7 @@ class PersonTest < Test::Unit::TestCase |
91 | 91 | should 'report that the user has the permission' do |
92 | 92 | p = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person |
93 | 93 | r = Role.create(:name => 'associate', :permissions => ['edit_profile']) |
94 | - e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri') | |
94 | + e = fast_create(Enterprise) | |
95 | 95 | assert e.affiliate(p, r) |
96 | 96 | p = Person.find(p.id) |
97 | 97 | assert e.reload |
... | ... | @@ -147,7 +147,7 @@ class PersonTest < Test::Unit::TestCase |
147 | 147 | |
148 | 148 | should 'be an admin if have permission of environment administration' do |
149 | 149 | role = Role.create!(:name => 'just_another_admin_role') |
150 | - env = Environment.create!(:name => 'blah') | |
150 | + env = fast_create(Environment) | |
151 | 151 | person = create_user('just_another_person').person |
152 | 152 | env.affiliate(person, role) |
153 | 153 | assert ! person.is_admin?(env) |
... | ... | @@ -157,8 +157,8 @@ class PersonTest < Test::Unit::TestCase |
157 | 157 | end |
158 | 158 | |
159 | 159 | should 'separate admins of different environments' do |
160 | - env1 = Environment.create!(:name => 'blah1') | |
161 | - env2 = Environment.create!(:name => 'blah2') | |
160 | + env1 = fast_create(Environment) | |
161 | + env2 = fast_create(Environment) | |
162 | 162 | |
163 | 163 | # role is an admin role |
164 | 164 | role = Role.create!(:name => 'just_another_admin_role') |
... | ... | @@ -290,7 +290,7 @@ class PersonTest < Test::Unit::TestCase |
290 | 290 | |
291 | 291 | should 'have favorite enterprises' do |
292 | 292 | p = create_user('test_person').person |
293 | - e = Enterprise.create!(:name => 'test_ent', :identifier => 'test_ent') | |
293 | + e = fast_create(Enterprise) | |
294 | 294 | |
295 | 295 | p.favorite_enterprises << e |
296 | 296 | |
... | ... | @@ -325,7 +325,8 @@ class PersonTest < Test::Unit::TestCase |
325 | 325 | end |
326 | 326 | |
327 | 327 | should 'have e-mail addresses' do |
328 | - env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) | |
328 | + env = fast_create(Environment) | |
329 | + env.domains << Domain.new(:name => 'somedomain.com') | |
329 | 330 | person = Person.new(:environment => env, :identifier => 'testuser') |
330 | 331 | person.expects(:environment).returns(env) |
331 | 332 | |
... | ... | @@ -333,9 +334,9 @@ class PersonTest < Test::Unit::TestCase |
333 | 334 | end |
334 | 335 | |
335 | 336 | should 'not show www in e-mail addresses when force_www=true' do |
336 | - env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) | |
337 | - env.force_www = true | |
338 | - env.save | |
337 | + env = fast_create(Environment) | |
338 | + env.domains << Domain.new(:name => 'somedomain.com') | |
339 | + env.update_attribute(:force_www, true) | |
339 | 340 | person = Person.new(:environment => env, :identifier => 'testuser') |
340 | 341 | person.expects(:environment).returns(env) |
341 | 342 | |
... | ... | @@ -377,12 +378,12 @@ class PersonTest < Test::Unit::TestCase |
377 | 378 | |
378 | 379 | should 'person has group with pending tasks' do |
379 | 380 | p1 = create_user('user_with_tasks').person |
380 | - c1 = Community.create!(:name => 'my test community') | |
381 | + c1 = fast_create(Community) | |
381 | 382 | c1.tasks << Task.new |
382 | 383 | assert !c1.tasks.pending.empty? |
383 | 384 | c1.add_admin(p1) |
384 | 385 | |
385 | - c2 = Community.create!(:name => 'my other test community') | |
386 | + c2 = fast_create(Community) | |
386 | 387 | p2 = create_user('user_without_tasks').person |
387 | 388 | c2.add_admin(p2) |
388 | 389 | |
... | ... | @@ -391,7 +392,7 @@ class PersonTest < Test::Unit::TestCase |
391 | 392 | end |
392 | 393 | |
393 | 394 | should 'not allow simple member to view group pending tasks' do |
394 | - c = Community.create!(:name => 'my test community') | |
395 | + c = fast_create(Community) | |
395 | 396 | c.tasks << Task.new |
396 | 397 | p = create_user('user_without_tasks').person |
397 | 398 | c.add_member(p) |
... | ... | @@ -400,7 +401,7 @@ class PersonTest < Test::Unit::TestCase |
400 | 401 | end |
401 | 402 | |
402 | 403 | should 'person has organization pending tasks' do |
403 | - c = Community.create!(:name => 'my test community') | |
404 | + c = fast_create(Community) | |
404 | 405 | c.tasks << Task.new |
405 | 406 | p = create_user('user_with_tasks').person |
406 | 407 | c.add_admin(p) |
... | ... | @@ -409,7 +410,7 @@ class PersonTest < Test::Unit::TestCase |
409 | 410 | end |
410 | 411 | |
411 | 412 | should 'select organization pending tasks' do |
412 | - c = Community.create!(:name => 'my test community') | |
413 | + c = fast_create(Community) | |
413 | 414 | c.tasks << Task.new |
414 | 415 | p = create_user('user_with_tasks').person |
415 | 416 | c.add_admin(p) |
... | ... | @@ -505,7 +506,7 @@ class PersonTest < Test::Unit::TestCase |
505 | 506 | |
506 | 507 | should 'refuse join community' do |
507 | 508 | p = create_user('test_user').person |
508 | - c = Community.create!(:name => 'Test community', :identifier => 'test_community') | |
509 | + c = fast_create(Community) | |
509 | 510 | |
510 | 511 | assert p.ask_to_join?(c) |
511 | 512 | p.refuse_join(c) |
... | ... | @@ -514,7 +515,7 @@ class PersonTest < Test::Unit::TestCase |
514 | 515 | |
515 | 516 | should 'not ask to join for a member' do |
516 | 517 | p = create_user('test_user').person |
517 | - c = Community.create!(:name => 'Test community', :identifier => 'test_community') | |
518 | + c = fast_create(Community) | |
518 | 519 | c.add_member(p) |
519 | 520 | |
520 | 521 | assert !p.ask_to_join?(c) |
... | ... | @@ -522,7 +523,7 @@ class PersonTest < Test::Unit::TestCase |
522 | 523 | |
523 | 524 | should 'not ask to join if already asked' do |
524 | 525 | p = create_user('test_user').person |
525 | - c = Community.create!(:name => 'Test community', :identifier => 'test_community') | |
526 | + c = fast_create(Community) | |
526 | 527 | AddMember.create!(:person => p, :organization => c) |
527 | 528 | |
528 | 529 | assert !p.ask_to_join?(c) | ... | ... |
test/unit/profile_list_block_test.rb
... | ... | @@ -24,7 +24,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
24 | 24 | person2 = create_user('testperson2').person |
25 | 25 | person3 = create_user('testperson3').person |
26 | 26 | |
27 | - owner = Environment.create!(:name => 'test env') | |
27 | + owner = fast_create(Environment) | |
28 | + owner.boxes << Box.new | |
28 | 29 | block = ProfileListBlock.new |
29 | 30 | owner.boxes.first.blocks << block |
30 | 31 | block.save! |
... | ... | @@ -43,7 +44,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
43 | 44 | end |
44 | 45 | |
45 | 46 | should 'list private profiles' do |
46 | - env = Environment.create!(:name => 'test env') | |
47 | + env = fast_create(Environment) | |
48 | + env.boxes << Box.new | |
47 | 49 | profile1 = fast_create(Profile, :environment_id => env.id) |
48 | 50 | profile2 = fast_create(Profile, :environment_id => env.id, :public_profile => false) # private profile |
49 | 51 | block = ProfileListBlock.new |
... | ... | @@ -56,7 +58,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
56 | 58 | end |
57 | 59 | |
58 | 60 | should 'not list invisible profiles' do |
59 | - env = Environment.create!(:name => 'test env') | |
61 | + env = fast_create(Environment) | |
62 | + env.boxes << Box.new | |
60 | 63 | profile1 = fast_create(Profile, :environment_id => env.id) |
61 | 64 | profile2 = fast_create(Profile, :environment_id => env.id, :visible => false) # not visible profile |
62 | 65 | block = ProfileListBlock.new |
... | ... | @@ -81,7 +84,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
81 | 84 | end |
82 | 85 | |
83 | 86 | should 'provide view_title' do |
84 | - env = Environment.create!(:name => 'test env') | |
87 | + env = fast_create(Environment) | |
88 | + env.boxes << Box.new | |
85 | 89 | block = ProfileListBlock.new(:title => 'Title from block') |
86 | 90 | env.boxes.first.blocks << block |
87 | 91 | block.save! |
... | ... | @@ -89,7 +93,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
89 | 93 | end |
90 | 94 | |
91 | 95 | should 'provide view title with variables' do |
92 | - env = Environment.create!(:name => 'test env') | |
96 | + env = fast_create(Environment) | |
97 | + env.boxes << Box.new | |
93 | 98 | block = ProfileListBlock.new(:title => '{#} members') |
94 | 99 | env.boxes.first.blocks << block |
95 | 100 | block.save! |
... | ... | @@ -97,7 +102,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
97 | 102 | end |
98 | 103 | |
99 | 104 | should 'count number of public and private profiles' do |
100 | - env = Environment.create!(:name => 'test env') | |
105 | + env = fast_create(Environment) | |
106 | + env.boxes << Box.new | |
101 | 107 | block = ProfileListBlock.new |
102 | 108 | env.boxes.first.blocks << block |
103 | 109 | block.save! |
... | ... | @@ -115,7 +121,8 @@ class ProfileListBlockTest < Test::Unit::TestCase |
115 | 121 | end |
116 | 122 | |
117 | 123 | should 'only count number of visible profiles' do |
118 | - env = Environment.create!(:name => 'test env') | |
124 | + env = fast_create(Environment) | |
125 | + env.boxes << Box.new | |
119 | 126 | block = ProfileListBlock.new |
120 | 127 | env.boxes.first.blocks << block |
121 | 128 | block.save! | ... | ... |
test/unit/published_article_test.rb
... | ... | @@ -4,12 +4,11 @@ class PublishedArticleTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @profile = create_user('test_user').person |
7 | - @article = @profile.articles.create!(:name => 'test_article', :body => 'some trivial body') | |
7 | + @article = fast_create(Article, :profile_id => @profile.id, :name => 'test_article', :body => 'some trivial body') | |
8 | 8 | end |
9 | 9 | |
10 | - | |
11 | 10 | should 'have a reference article and profile' do |
12 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
11 | + prof = fast_create(Community) | |
13 | 12 | p = PublishedArticle.create(:reference_article => @article, :profile => prof) |
14 | 13 | |
15 | 14 | assert p |
... | ... | @@ -18,7 +17,7 @@ class PublishedArticleTest < ActiveSupport::TestCase |
18 | 17 | end |
19 | 18 | |
20 | 19 | should 'have a different name than reference article' do |
21 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
20 | + prof = fast_create(Community) | |
22 | 21 | p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') |
23 | 22 | |
24 | 23 | assert_equal 'other title', p.name |
... | ... | @@ -27,7 +26,7 @@ class PublishedArticleTest < ActiveSupport::TestCase |
27 | 26 | end |
28 | 27 | |
29 | 28 | should 'use name of reference article a default name' do |
30 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
29 | + prof = fast_create(Community) | |
31 | 30 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof) |
32 | 31 | |
33 | 32 | assert_equal @article.name, p.name |
... | ... | @@ -37,7 +36,7 @@ class PublishedArticleTest < ActiveSupport::TestCase |
37 | 36 | parent = mock |
38 | 37 | @article.expects(:parent).returns(parent) |
39 | 38 | parent.expects(:blog?).returns(true) |
40 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
39 | + prof = fast_create(Community) | |
41 | 40 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof) |
42 | 41 | |
43 | 42 | assert !prof.has_blog? |
... | ... | @@ -48,7 +47,7 @@ class PublishedArticleTest < ActiveSupport::TestCase |
48 | 47 | parent = mock |
49 | 48 | @article.expects(:parent).returns(parent) |
50 | 49 | parent.expects(:blog?).returns(true) |
51 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
50 | + prof = fast_create(Community) | |
52 | 51 | prof.articles << Blog.new(:profile => prof, :name => 'Blog test') |
53 | 52 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof) |
54 | 53 | |
... | ... | @@ -59,8 +58,8 @@ class PublishedArticleTest < ActiveSupport::TestCase |
59 | 58 | parent = mock |
60 | 59 | @article.expects(:parent).returns(parent) |
61 | 60 | parent.expects(:blog?).returns(false) |
62 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
63 | - blog = Blog.create!(:profile => prof, :name => 'Blog test') | |
61 | + prof = fast_create(Community) | |
62 | + blog = fast_create(Blog, :profile_id => prof.id, :name => 'Blog test') | |
64 | 63 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof) |
65 | 64 | |
66 | 65 | assert_nil p.parent |
... | ... | @@ -78,8 +77,8 @@ class PublishedArticleTest < ActiveSupport::TestCase |
78 | 77 | end |
79 | 78 | |
80 | 79 | should 'have parent if defined' do |
81 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
82 | - folder = Folder.create(:name => 'folder test', :profile => prof) | |
80 | + prof = fast_create(Community) | |
81 | + folder = fast_create(Folder, :name => 'folder test', :profile_id => prof.id) | |
83 | 82 | p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder) |
84 | 83 | |
85 | 84 | assert p |
... | ... | @@ -87,23 +86,23 @@ class PublishedArticleTest < ActiveSupport::TestCase |
87 | 86 | end |
88 | 87 | |
89 | 88 | should 'use to_html from reference_article' do |
90 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
89 | + prof = fast_create(Community) | |
91 | 90 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof) |
92 | 91 | |
93 | 92 | assert_equal @article.to_html, p.to_html |
94 | 93 | end |
95 | 94 | |
96 | 95 | should 'use to_html from reference_article when is Textile' do |
97 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
98 | - textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof) | |
96 | + prof = fast_create(Community) | |
97 | + textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id) | |
99 | 98 | p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof) |
100 | 99 | |
101 | 100 | assert_equal textile_article.to_html, p.to_html |
102 | 101 | end |
103 | 102 | |
104 | 103 | should 'display message when reference_article does not exist' do |
105 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
106 | - textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof) | |
104 | + prof = fast_create(Community) | |
105 | + textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id) | |
107 | 106 | p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof) |
108 | 107 | textile_article.destroy |
109 | 108 | p.reload |
... | ... | @@ -115,17 +114,17 @@ class PublishedArticleTest < ActiveSupport::TestCase |
115 | 114 | parent = mock |
116 | 115 | @article.stubs(:parent).returns(parent) |
117 | 116 | parent.stubs(:blog?).returns(true) |
118 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
117 | + prof = fast_create(Community) | |
119 | 118 | prof.articles << Blog.new(:profile => prof, :name => 'Blog test') |
120 | - new_parent = Folder.create!(:profile => prof, :name => 'Folder test') | |
119 | + new_parent = fast_create(Folder, :profile_id => prof.id, :name => 'Folder test') | |
121 | 120 | p = PublishedArticle.create!(:reference_article => @article, :profile => prof, :parent => new_parent) |
122 | 121 | |
123 | 122 | assert_equal p.parent, new_parent |
124 | 123 | end |
125 | 124 | |
126 | 125 | should 'provide first paragraph of HTML version' do |
127 | - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | |
128 | - a = Article.create!(:name => 'my article', :profile_id => prof.id) | |
126 | + prof = fast_create(Community) | |
127 | + a = fast_create(Article, :name => 'my article', :profile_id => prof.id) | |
129 | 128 | a.expects(:body).returns('<p>the first paragraph of the article</p> The second paragraph') |
130 | 129 | p = PublishedArticle.create(:reference_article => a, :profile => prof) |
131 | 130 | assert_equal '<p>the first paragraph of the article</p>', p.first_paragraph | ... | ... |
test/unit/region_test.rb
... | ... | @@ -17,8 +17,8 @@ class RegionTest < Test::Unit::TestCase |
17 | 17 | end |
18 | 18 | |
19 | 19 | should 'be able to search for possible validators by name' do |
20 | - env = Environment.create!(:name => "my test environment") | |
21 | - region = Region.create!(:environment_id => env.id, :name => 'My Region') | |
20 | + env = fast_create(Environment) | |
21 | + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
22 | 22 | org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) |
23 | 23 | org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) |
24 | 24 | |
... | ... | @@ -29,10 +29,10 @@ class RegionTest < Test::Unit::TestCase |
29 | 29 | end |
30 | 30 | |
31 | 31 | should 'return search results without validators that are already associated to the current region' do |
32 | - env = Environment.create!(:name => "my test environment") | |
33 | - region = Region.create!(:environment_id => env.id, :name => 'My Region') | |
34 | - org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) | |
35 | - org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) | |
32 | + env = fast_create(Environment) | |
33 | + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
34 | + org1 = fast_create(Organization, :name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) | |
35 | + org2 = fast_create(Organization, :name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) | |
36 | 36 | region.validators << org1 |
37 | 37 | |
38 | 38 | possible = region.search_possible_validators('organization') |
... | ... | @@ -41,15 +41,15 @@ class RegionTest < Test::Unit::TestCase |
41 | 41 | end |
42 | 42 | |
43 | 43 | should 'has validator' do |
44 | - env = Environment.create!(:name => "my test environment") | |
45 | - region = Region.create!(:environment_id => env.id, :name => 'My Region') | |
44 | + env = fast_create(Environment) | |
45 | + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
46 | 46 | region.validators.create!(:name => 'Validator entity', :identifier => 'validator-entity') |
47 | 47 | assert region.has_validator? |
48 | 48 | end |
49 | 49 | |
50 | 50 | should 'has no validator' do |
51 | - env = Environment.create!(:name => "my test environment") | |
52 | - region = Region.create!(:environment_id => env.id, :name => 'My Region') | |
51 | + env = fast_create(Environment) | |
52 | + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
53 | 53 | assert !region.has_validator? |
54 | 54 | end |
55 | 55 | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -94,7 +94,7 @@ class RssFeedTest < Test::Unit::TestCase |
94 | 94 | blog = Blog.create!(:name => 'blog-test', :profile => profile) |
95 | 95 | posts = [] |
96 | 96 | 6.times do |i| |
97 | - posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) | |
97 | + posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) | |
98 | 98 | end |
99 | 99 | feed = blog.feed |
100 | 100 | feed.limit = 5 |
... | ... | @@ -108,7 +108,7 @@ class RssFeedTest < Test::Unit::TestCase |
108 | 108 | blog = Blog.create!(:name => 'blog-test', :profile => profile) |
109 | 109 | posts = [] |
110 | 110 | 5.times do |i| |
111 | - posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) | |
111 | + posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) | |
112 | 112 | end |
113 | 113 | posts[0].published = false |
114 | 114 | posts[0].save! | ... | ... |
test/unit/text_article_test.rb
... | ... | @@ -10,7 +10,7 @@ class TextArticleTest < Test::Unit::TestCase |
10 | 10 | |
11 | 11 | should 'found TextileArticle by TextArticle class' do |
12 | 12 | person = create_user('testuser').person |
13 | - article = TextileArticle.create!(:name => 'textile article test', :profile => person) | |
13 | + article = fast_create(TextileArticle, :name => 'textile article test', :profile_id => person.id) | |
14 | 14 | assert_includes TextArticle.find(:all), article |
15 | 15 | end |
16 | 16 | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -87,7 +87,7 @@ class UploadedFileTest < Test::Unit::TestCase |
87 | 87 | |
88 | 88 | should 'create icon when created in folder' do |
89 | 89 | p = create_user('test_user').person |
90 | - f = Folder.create!(:name => 'test_folder', :profile => p) | |
90 | + f = fast_create(Folder, :name => 'test_folder', :profile_id => p.id) | |
91 | 91 | file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent_id => f.id, :profile => p) |
92 | 92 | |
93 | 93 | assert File.exists?(file.public_filename(:icon)) | ... | ... |
test/unit/user_test.rb
... | ... | @@ -153,7 +153,7 @@ class UserTest < Test::Unit::TestCase |
153 | 153 | end |
154 | 154 | |
155 | 155 | should 'set the same environment for user and person objects' do |
156 | - env = Environment.create!(:name => 'my test environment') | |
156 | + env = fast_create(Environment) | |
157 | 157 | user = new_user(:environment_id => env.id) |
158 | 158 | assert_equal env, user.environment |
159 | 159 | assert_equal env, user.person.environment | ... | ... |