Commit c74b012c9ef014905d3952fe81dc90a6d33eff56
1 parent
3d1ac0e4
Exists in
master
and in
29 other branches
rails3: fix environment tests
Showing
1 changed file
with
55 additions
and
56 deletions
Show diff stats
test/unit/environment_test.rb
... | ... | @@ -5,11 +5,11 @@ class EnvironmentTest < ActiveSupport::TestCase |
5 | 5 | |
6 | 6 | def test_exists_default_and_it_is_unique |
7 | 7 | Environment.delete_all |
8 | - vc = Environment.new(:name => 'Test Community') | |
8 | + vc = build(Environment, :name => 'Test Community') | |
9 | 9 | vc.is_default = true |
10 | 10 | assert vc.save |
11 | 11 | |
12 | - vc2 = Environment.new(:name => 'Another Test Community') | |
12 | + vc2 = build(Environment, :name => 'Another Test Community') | |
13 | 13 | vc2.is_default = true |
14 | 14 | assert !vc2.valid? |
15 | 15 | assert vc2.errors[:is_default.to_s].present? |
... | ... | @@ -18,7 +18,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
18 | 18 | end |
19 | 19 | |
20 | 20 | def test_acts_as_configurable |
21 | - vc = Environment.new(:name => 'Testing Environment') | |
21 | + vc = build(Environment, :name => 'Testing Environment') | |
22 | 22 | assert_kind_of Hash, vc.settings |
23 | 23 | vc.settings[:some_setting] = 1 |
24 | 24 | assert vc.save |
... | ... | @@ -63,7 +63,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
63 | 63 | end |
64 | 64 | |
65 | 65 | def test_terms_of_use |
66 | - v = Environment.new(:name => 'My test environment') | |
66 | + v = fast_create(Environment, :name => 'My test environment') | |
67 | 67 | assert_nil v.terms_of_use |
68 | 68 | v.terms_of_use = 'To be part of this environment, you must accept the following terms: ...' |
69 | 69 | assert v.save |
... | ... | @@ -72,7 +72,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
72 | 72 | end |
73 | 73 | |
74 | 74 | should "terms of use not be an empty string" do |
75 | - v = Environment.new(:name => 'My test environment') | |
75 | + v = fast_create(Environment, :name => 'My test environment') | |
76 | 76 | assert_nil v.terms_of_use |
77 | 77 | v.terms_of_use = "" |
78 | 78 | assert v.save |
... | ... | @@ -88,7 +88,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
88 | 88 | end |
89 | 89 | |
90 | 90 | def test_terms_of_enterprise_use |
91 | - v = Environment.new(:name => 'My test environment') | |
91 | + v = fast_create(Environment, :name => 'My test environment') | |
92 | 92 | assert_nil v.terms_of_enterprise_use |
93 | 93 | v.terms_of_enterprise_use = 'To be owner of an enterprise in this environment, you must accept the following terms: ...' |
94 | 94 | assert v.save |
... | ... | @@ -133,12 +133,12 @@ class EnvironmentTest < ActiveSupport::TestCase |
133 | 133 | |
134 | 134 | def test_should_list_all_product_categories |
135 | 135 | env = fast_create(Environment) |
136 | - Category.create!(:name => 'first category', :environment_id => env.id) | |
137 | - cat = Category.create!(:name => 'second category', :environment_id => env.id) | |
138 | - Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat.id) | |
139 | - cat1 = ProductCategory.create!(:name => 'first product category', :environment_id => env.id) | |
140 | - cat2 = ProductCategory.create!(:name => 'second product category', :environment_id => env.id) | |
141 | - subcat = ProductCategory.create!(:name => 'child product category', :environment_id => env.id, :parent_id => cat2.id) | |
136 | + create(Category, :name => 'first category', :environment_id => env.id) | |
137 | + cat = create(Category, :name => 'second category', :environment_id => env.id) | |
138 | + create(Category, :name => 'child category', :environment_id => env.id, :parent_id => cat.id) | |
139 | + cat1 = create(ProductCategory, :name => 'first product category', :environment_id => env.id) | |
140 | + cat2 = create(ProductCategory, :name => 'second product category', :environment_id => env.id) | |
141 | + subcat = create(ProductCategory, :name => 'child product category', :environment_id => env.id, :parent_id => cat2.id) | |
142 | 142 | |
143 | 143 | cats = env.product_categories |
144 | 144 | assert_equal 3, cats.size |
... | ... | @@ -149,14 +149,14 @@ class EnvironmentTest < ActiveSupport::TestCase |
149 | 149 | |
150 | 150 | should 'list displayable categories' do |
151 | 151 | env = fast_create(Environment) |
152 | - cat1 = env.categories.create(:name => 'category one', :display_color => 1) | |
152 | + cat1 = create(Category, :environment => env, :name => 'category one', :display_color => 1) | |
153 | 153 | assert ! cat1.new_record? |
154 | 154 | |
155 | 155 | # subcategories should be ignored |
156 | - subcat1 = env.categories.create(:name => 'subcategory one', :parent_id => cat1.id) | |
156 | + subcat1 = create(Category, :environment => env, :name => 'subcategory one', :parent_id => cat1.id) | |
157 | 157 | assert ! subcat1.new_record? |
158 | 158 | |
159 | - cat2 = env.categories.create(:name => 'category two') | |
159 | + cat2 = create(Category, :environment => env, :name => 'category two') | |
160 | 160 | assert !cat2.new_record? |
161 | 161 | |
162 | 162 | assert_equal 1, env.display_categories.size |
... | ... | @@ -190,7 +190,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
190 | 190 | |
191 | 191 | should 'provide a default hostname' do |
192 | 192 | env = fast_create(Environment) |
193 | - env.domains << Domain.create(:name => 'example.com', :is_default => true) | |
193 | + env.domains << create(Domain, :name => 'example.com', :is_default => true) | |
194 | 194 | assert_equal 'example.com', env.default_hostname |
195 | 195 | end |
196 | 196 | |
... | ... | @@ -202,27 +202,27 @@ class EnvironmentTest < ActiveSupport::TestCase |
202 | 202 | should 'add www when told to force www' do |
203 | 203 | env = fast_create(Environment); env.force_www = true; env.save! |
204 | 204 | |
205 | - env.domains << Domain.create(:name => 'example.com', :is_default => true) | |
205 | + env.domains << create(Domain, :name => 'example.com', :is_default => true) | |
206 | 206 | assert_equal 'www.example.com', env.default_hostname |
207 | 207 | end |
208 | 208 | |
209 | 209 | should 'not add www when requesting domain for email address' do |
210 | 210 | env = fast_create(Environment) |
211 | - env.domains << Domain.create(:name => 'example.com', :is_default => true) | |
211 | + env.domains << create(Domain, :name => 'example.com', :is_default => true) | |
212 | 212 | assert_equal 'example.com', env.default_hostname(true) |
213 | 213 | end |
214 | 214 | |
215 | 215 | should 'use default domain when there is more than one' do |
216 | 216 | env = fast_create(Environment) |
217 | - env.domains << Domain.create(:name => 'example.com', :is_default => false) | |
218 | - env.domains << Domain.create(:name => 'default.com', :is_default => true) | |
217 | + env.domains << create(Domain, :name => 'example.com', :is_default => false) | |
218 | + env.domains << create(Domain, :name => 'default.com', :is_default => true) | |
219 | 219 | assert_equal 'default.com', env.default_hostname |
220 | 220 | end |
221 | 221 | |
222 | 222 | should 'use first domain when there is no default' do |
223 | 223 | env = fast_create(Environment) |
224 | - env.domains << Domain.create(:name => 'domain1.com', :is_default => false) | |
225 | - env.domains << Domain.create(:name => 'domain2.com', :is_default => false) | |
224 | + env.domains << create(Domain, :name => 'domain1.com', :is_default => false) | |
225 | + env.domains << create(Domain, :name => 'domain2.com', :is_default => false) | |
226 | 226 | assert_equal 'domain1.com', env.default_hostname |
227 | 227 | end |
228 | 228 | |
... | ... | @@ -265,19 +265,19 @@ class EnvironmentTest < ActiveSupport::TestCase |
265 | 265 | end |
266 | 266 | |
267 | 267 | should 'provide environment name in to_s' do |
268 | - env = Environment.new(:name => 'my name') | |
268 | + env = build(Environment, :name => 'my name') | |
269 | 269 | assert_equal 'my name', env.to_s |
270 | 270 | end |
271 | 271 | |
272 | 272 | should 'fallback to "?" when calling to_s with empty name' do |
273 | - env = Environment.new(:name => nil) | |
273 | + env = build(Environment, :name => nil) | |
274 | 274 | assert_nil env.name |
275 | 275 | assert_equal "?", env.to_s |
276 | 276 | end |
277 | 277 | |
278 | 278 | should 'remove boxes and blocks when removing environment' do |
279 | 279 | Environment.any_instance.stubs(:create_templates) # avoid creating templates, it's expensive |
280 | - env = Environment.create!(:name => 'test environment') | |
280 | + env = create(Environment, :name => 'test environment') | |
281 | 281 | |
282 | 282 | env_boxes = env.boxes.size |
283 | 283 | env_blocks = env.blocks.size |
... | ... | @@ -310,14 +310,14 @@ class EnvironmentTest < ActiveSupport::TestCase |
310 | 310 | |
311 | 311 | should 'have boxes and blocks upon creation' do |
312 | 312 | Environment.any_instance.stubs(:create_templates) # avoid creating templates, it's expensive |
313 | - environment = Environment.create!(:name => 'a test environment') | |
313 | + environment = create(Environment, :name => 'a test environment') | |
314 | 314 | assert environment.boxes.size > 0 |
315 | 315 | assert environment.blocks.size > 0 |
316 | 316 | end |
317 | 317 | |
318 | 318 | should 'have at least one MainBlock upon creation' do |
319 | 319 | Environment.any_instance.stubs(:create_templates) # avoid creating templates, it's expensive |
320 | - environment = Environment.create!(:name => 'a test environment') | |
320 | + environment = create(Environment, :name => 'a test environment') | |
321 | 321 | assert(environment.blocks.any? { |block| block.kind_of? MainBlock }) |
322 | 322 | end |
323 | 323 | |
... | ... | @@ -396,16 +396,16 @@ class EnvironmentTest < ActiveSupport::TestCase |
396 | 396 | env = Environment.default |
397 | 397 | e1 = fast_create(Enterprise) |
398 | 398 | category = fast_create(ProductCategory) |
399 | - p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) | |
399 | + p1 = create(Product, :enterprise => e1, :name => 'test_prod1', :product_category_id => category.id) | |
400 | 400 | products = [] |
401 | 401 | 3.times {|n| |
402 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, | |
402 | + products.push(create(Product, :name => "product #{n}", :enterprise_id => e1.id, | |
403 | 403 | :product_category_id => category.id, :highlighted => true, |
404 | 404 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
405 | 405 | )) |
406 | 406 | } |
407 | - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true) | |
408 | - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { | |
407 | + create(Product, :name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true) | |
408 | + create(Product, :name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { | |
409 | 409 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
410 | 410 | }) |
411 | 411 | assert_equal products, env.highlighted_products_with_image |
... | ... | @@ -442,15 +442,15 @@ class EnvironmentTest < ActiveSupport::TestCase |
442 | 442 | end |
443 | 443 | |
444 | 444 | should 'provide custom header' do |
445 | - assert_equal 'my header', Environment.new(:custom_header => 'my header').custom_header | |
445 | + assert_equal 'my header', build(Environment, :custom_header => 'my header').custom_header | |
446 | 446 | end |
447 | 447 | |
448 | 448 | should 'provide custom footer' do |
449 | - assert_equal 'my footer', Environment.new(:custom_footer => "my footer").custom_footer | |
449 | + assert_equal 'my footer', build(Environment, :custom_footer => "my footer").custom_footer | |
450 | 450 | end |
451 | 451 | |
452 | 452 | should 'provide theme' do |
453 | - assert_equal 'my-custom-theme', Environment.new(:theme => 'my-custom-theme').theme | |
453 | + assert_equal 'my-custom-theme', build(Environment, :theme => 'my-custom-theme').theme | |
454 | 454 | end |
455 | 455 | |
456 | 456 | should 'give default theme' do |
... | ... | @@ -496,7 +496,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
496 | 496 | end |
497 | 497 | |
498 | 498 | should 'create templates' do |
499 | - e = Environment.create!(:name => 'test_env') | |
499 | + e = create(Environment, :name => 'test_env') | |
500 | 500 | e.reload |
501 | 501 | |
502 | 502 | # the templates must be created |
... | ... | @@ -529,7 +529,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
529 | 529 | end |
530 | 530 | |
531 | 531 | should 'have a layout template' do |
532 | - e = Environment.new(:layout_template => 'mytemplate') | |
532 | + e = build(Environment, :layout_template => 'mytemplate') | |
533 | 533 | assert_equal 'mytemplate', e.layout_template |
534 | 534 | end |
535 | 535 | |
... | ... | @@ -538,7 +538,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
538 | 538 | end |
539 | 539 | |
540 | 540 | should 'set replace_enterprise_template_when_enable on environment' do |
541 | - e = Environment.new(:name => 'Enterprise test') | |
541 | + e = fast_create(Environment, :name => 'Enterprise test') | |
542 | 542 | e.replace_enterprise_template_when_enable = true |
543 | 543 | e.save |
544 | 544 | assert_equal true, e.replace_enterprise_template_when_enable |
... | ... | @@ -782,18 +782,18 @@ class EnvironmentTest < ActiveSupport::TestCase |
782 | 782 | |
783 | 783 | should 'have roles with names independent of other environments' do |
784 | 784 | e1 = fast_create(Environment) |
785 | - role1 = Role.create!(:name => 'test_role', :environment => e1) | |
785 | + role1 = create(Role, :name => 'test_role', :environment => e1) | |
786 | 786 | e2 = fast_create(Environment) |
787 | - role2 = Role.new(:name => 'test_role', :environment => e2) | |
787 | + role2 = build(Role, :name => 'test_role', :environment => e2) | |
788 | 788 | |
789 | 789 | assert role2.valid? |
790 | 790 | end |
791 | 791 | |
792 | 792 | should 'have roles with keys independent of other environments' do |
793 | 793 | e1 = fast_create(Environment) |
794 | - role1 = Role.create!(:name => 'test_role', :environment => e1, :key => 'a_member') | |
794 | + role1 = create(Role, :name => 'test_role', :environment => e1, :key => 'a_member') | |
795 | 795 | e2 = fast_create(Environment) |
796 | - role2 = Role.new(:name => 'test_role', :environment => e2, :key => 'a_member') | |
796 | + role2 = build(Role, :name => 'test_role', :environment => e2, :key => 'a_member') | |
797 | 797 | |
798 | 798 | assert role2.valid? |
799 | 799 | end |
... | ... | @@ -913,15 +913,14 @@ class EnvironmentTest < ActiveSupport::TestCase |
913 | 913 | end |
914 | 914 | |
915 | 915 | should "not crash when set nil as terms of use" do |
916 | - v = Environment.new(:name => 'My test environment') | |
916 | + v = fast_create(Environment, :name => 'My test environment') | |
917 | 917 | v.terms_of_use = nil |
918 | 918 | assert v.save! |
919 | 919 | end |
920 | 920 | |
921 | 921 | should "terms of use not be an blank string" do |
922 | - v = Environment.new(:name => 'My test environment') | |
923 | - v.terms_of_use = " " | |
924 | - assert v.save! | |
922 | + v = fast_create(Environment) | |
923 | + v.terms_of_use = ' ' | |
925 | 924 | assert !v.has_terms_of_use? |
926 | 925 | end |
927 | 926 | |
... | ... | @@ -982,7 +981,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
982 | 981 | end |
983 | 982 | |
984 | 983 | should 'store cache time for home page' do |
985 | - env = Environment.new(:home_cache_in_minutes => 99) | |
984 | + env = build(Environment, :home_cache_in_minutes => 99) | |
986 | 985 | assert_equal 99, env.home_cache_in_minutes |
987 | 986 | end |
988 | 987 | |
... | ... | @@ -1005,7 +1004,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
1005 | 1004 | end |
1006 | 1005 | |
1007 | 1006 | should 'store cache time for general content' do |
1008 | - env = Environment.new(:general_cache_in_minutes => 99) | |
1007 | + env = build(Environment, :general_cache_in_minutes => 99) | |
1009 | 1008 | assert_equal 99, env.general_cache_in_minutes |
1010 | 1009 | end |
1011 | 1010 | |
... | ... | @@ -1028,7 +1027,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
1028 | 1027 | end |
1029 | 1028 | |
1030 | 1029 | should 'store cache time for profile content' do |
1031 | - env = Environment.new(:profile_cache_in_minutes => 99) | |
1030 | + env = build(Environment, :profile_cache_in_minutes => 99) | |
1032 | 1031 | assert_equal 99, env.profile_cache_in_minutes |
1033 | 1032 | end |
1034 | 1033 | |
... | ... | @@ -1085,9 +1084,9 @@ class EnvironmentTest < ActiveSupport::TestCase |
1085 | 1084 | end |
1086 | 1085 | |
1087 | 1086 | should 'has a list of units ordered by position' do |
1088 | - litre = Unit.create!(:singular => 'Litre', :plural => 'Litres', :environment => Environment.default) | |
1089 | - meter = Unit.create!(:singular => 'Meter', :plural => 'Meters', :environment => Environment.default) | |
1090 | - kilo = Unit.create!(:singular => 'Kilo', :plural => 'Kilo', :environment => Environment.default) | |
1087 | + litre = create(Unit, :singular => 'Litre', :plural => 'Litres', :environment => Environment.default) | |
1088 | + meter = create(Unit, :singular => 'Meter', :plural => 'Meters', :environment => Environment.default) | |
1089 | + kilo = create(Unit, :singular => 'Kilo', :plural => 'Kilo', :environment => Environment.default) | |
1091 | 1090 | litre.move_to_bottom |
1092 | 1091 | assert_equal ["Meter", "Kilo", "Litre"], Environment.default.units.map(&:singular) |
1093 | 1092 | end |
... | ... | @@ -1135,8 +1134,8 @@ class EnvironmentTest < ActiveSupport::TestCase |
1135 | 1134 | title2 = "Sample Article2" |
1136 | 1135 | profile = fast_create(Profile) |
1137 | 1136 | |
1138 | - p1 = School::Project.new(:name => title1, :profile => profile) | |
1139 | - p2 = Work::Project.new(:name => title2, :profile => profile) | |
1137 | + p1 = build(School::Project, :name => title1, :profile => profile) | |
1138 | + p2 = build(Work::Project, :name => title2, :profile => profile) | |
1140 | 1139 | |
1141 | 1140 | p1.save! |
1142 | 1141 | p2.save! |
... | ... | @@ -1191,9 +1190,9 @@ class EnvironmentTest < ActiveSupport::TestCase |
1191 | 1190 | should 'be able to have many licenses' do |
1192 | 1191 | environment = Environment.default |
1193 | 1192 | another_environment = fast_create(Environment) |
1194 | - l1 = License.create!(:name => 'GPLv3', :environment => environment) | |
1195 | - l2 = License.create!(:name => 'AGPL', :environment => environment) | |
1196 | - l3 = License.create!(:name => 'Apache', :environment => another_environment) | |
1193 | + l1 = fast_create(License, :environment_id => environment.id) | |
1194 | + l2 = fast_create(License, :environment_id => environment.id) | |
1195 | + l3 = fast_create(License, :environment_id => another_environment) | |
1197 | 1196 | |
1198 | 1197 | environment.reload |
1199 | 1198 | ... | ... |