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