Commit e243950f863081e00c6b6c51529d6c28a22a3002
1 parent
ec21830a
Exists in
master
and in
28 other branches
Making tests run faster
* Moved all object creation helper methods into Noosfero::Factory * Added a new and faster version of create_user. * Adjusted some test cases tests to use the new factory methods This comprised removing a lot of bad smells from the tests, involving eliminating uneeded database hits. * reviewed ProfileTest for speed as a case study. The test suite used to take ~ 40 seconds to run, now it takes ~ 14 seconds. If we do this to all test suites, we can dramatically reduce the time we need to run all the tests * Added a rake task test:smells to list potential test smells. Started with probably unecessary and/or too slow database hits * In the end, running all the tests now takes ~ 13 minutes on Colivre's development machine, instead of the ~ 30 minutes it used to. (ActionItem1279)
Showing
15 changed files
with
456 additions
and
344 deletions
Show diff stats
... | ... | @@ -0,0 +1,18 @@ |
1 | +def find_test_smells(id, title, pattern) | |
2 | + full_id = 'test:smells:' + id | |
3 | + task full_id do | |
4 | + system(" | |
5 | + ( | |
6 | + echo '########################################################' | |
7 | + echo '# #{title}' | |
8 | + echo '########################################################' | |
9 | + echo | |
10 | + ack-grep --group --color '#{pattern}' test/unit/ test/functional/ test/integration/ | |
11 | + ) | less -R | |
12 | + ") | |
13 | + end | |
14 | + task 'test:smells' => full_id | |
15 | +end | |
16 | + | |
17 | +find_test_smells 'dbhits', "Full database hits (they are probably unecessary)", '\.create' | |
18 | +find_test_smells 'constants', 'Probably unecessary contants for creating objects', "create_user.*password" | ... | ... |
test/factories.rb
1 | 1 | module Noosfero::Factory |
2 | - | |
3 | - def fast_create(name, attrs = {}) | |
4 | - obj = build(name, attrs) | |
5 | - obj.attributes.keys.each do |attr| | |
6 | - if !obj.column_for_attribute(attr).null && obj.send(attr).nil? | |
7 | - obj.send("#{attr}=", factory_num_seq) | |
8 | - end | |
2 | + | |
3 | + def fast_create(name, attrs = {}, options = {}) | |
4 | + data = defaults_for(name).merge(attrs) | |
5 | + klass = name.to_s.camelize.constantize | |
6 | + if klass.superclass != ActiveRecord::Base | |
7 | + data[:type] = klass.to_s | |
8 | + end | |
9 | + if options[:timestamps] | |
10 | + fast_insert_with_timestamps(klass, data) | |
11 | + else | |
12 | + fast_insert(klass, data) | |
9 | 13 | end |
10 | - obj.save_without_validation! | |
11 | - obj | |
14 | + return klass.last(:order => "id") | |
12 | 15 | end |
13 | 16 | |
14 | 17 | def create(name, attrs = {}) |
... | ... | @@ -23,13 +26,12 @@ module Noosfero::Factory |
23 | 26 | end |
24 | 27 | |
25 | 28 | def build(name, attrs = {}) |
26 | - data = | |
27 | - if respond_to?('defaults_for_' + name.to_s) | |
28 | - send('defaults_for_'+ name.to_s).merge(attrs) | |
29 | - else | |
30 | - attrs | |
31 | - end | |
32 | - eval(name.to_s.camelize).new(data) | |
29 | + data = defaults_for(name).merge(attrs) | |
30 | + name.to_s.camelize.constantize.new(data) | |
31 | + end | |
32 | + | |
33 | + def defaults_for(name) | |
34 | + send('defaults_for_' + name.to_s.underscore) || {} | |
33 | 35 | end |
34 | 36 | |
35 | 37 | def self.num_seq |
... | ... | @@ -38,6 +40,105 @@ module Noosfero::Factory |
38 | 40 | @num_seq |
39 | 41 | end |
40 | 42 | |
43 | + ###### old stuff to be rearranged | |
44 | + def create_admin_user(env) | |
45 | + admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) | |
46 | + admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) | |
47 | + RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) | |
48 | + admin_user.login | |
49 | + end | |
50 | + | |
51 | + def create_environment(domainname) | |
52 | + environment = fast_create(Environment) | |
53 | + fast_create(Domain, :name => domainname, :owner_type => 'Environment', :owner_id => environment.id) | |
54 | + environment | |
55 | + end | |
56 | + | |
57 | + # Old version of create user. Use it if you need to create an user for | |
58 | + # testing that passes through the actual user creation process. | |
59 | + # | |
60 | + # Be aware that this is slow, though. | |
61 | + def create_user_full(name, options = {}, person_options = {}) | |
62 | + data = { | |
63 | + :login => name, | |
64 | + :email => name + '@noosfero.org', | |
65 | + :password => name.underscore, | |
66 | + :password_confirmation => name.underscore | |
67 | + }.merge(options) | |
68 | + user = User.new(data) | |
69 | + user.save! | |
70 | + user.person.update_attributes!(person_data.merge(person_options)) | |
71 | + user | |
72 | + end | |
73 | + | |
74 | + def person_data | |
75 | + {} | |
76 | + end | |
77 | + | |
78 | + # This method knows way too much about the model. But since creating an | |
79 | + # actual user is really expensive, for tests we need a fast alternative. | |
80 | + def create_user(name, options = {}, person_options = {}) | |
81 | + environment_id = options.delete(:environment_id) || (options.delete(:environment) || Environment.default).id | |
82 | + | |
83 | + password = options.delete(:password) | |
84 | + password_confirmation = options.delete(:password_confirmation) | |
85 | + raise Exception.new("Passwords don't match") if (password && password_confirmation && password != password_confirmation) | |
86 | + crypted_password = (password || name).crypt('xy') | |
87 | + | |
88 | + data = { | |
89 | + :login => name, | |
90 | + :email => name + '@noosfero.org', | |
91 | + :crypted_password => crypted_password, | |
92 | + :password_type => 'crypt', | |
93 | + :salt => 'xy', | |
94 | + :environment_id => environment_id, | |
95 | + }.merge(options) | |
96 | + user = fast_insert_with_timestamps(User, data) | |
97 | + person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) | |
98 | + homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id }) | |
99 | + fast_update(person, {:home_page_id => homepage.id}) | |
100 | + box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) | |
101 | + block = fast_insert(Block, { :box_id => box.id, :type => 'MainBlock', :position => 0}) | |
102 | + user | |
103 | + end | |
104 | + | |
105 | + def fast_insert(klass, data) | |
106 | + names = data.keys | |
107 | + values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) } | |
108 | + sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')] | |
109 | + klass.connection.execute(sql) | |
110 | + klass.last(:order => 'id') | |
111 | + end | |
112 | + | |
113 | + def fast_insert_with_timestamps(klass, data) | |
114 | + now = Time.now | |
115 | + fast_insert(klass, { :created_at => now, :updated_at => now}.merge(data)) | |
116 | + end | |
117 | + | |
118 | + def fast_update(obj, data) | |
119 | + obj.class.connection.execute('update %s set %s where id = %d' % [obj.class.table_name, ActiveRecord::Base.send(:sanitize_sql_for_assignment, data), obj.id]) | |
120 | + end | |
121 | + | |
122 | + def give_permission(user, permission, target) | |
123 | + user = Person.find_by_identifier(user) if user.kind_of?(String) | |
124 | + target ||= user | |
125 | + i = 0 | |
126 | + while Role.find_by_name('test_role' + i.to_s) | |
127 | + i+=1 | |
128 | + end | |
129 | + | |
130 | + role = Role.create!(:name => 'test_role' + i.to_s, :permissions => [permission]) | |
131 | + assert user.add_role(role, target) | |
132 | + assert user.has_permission?(permission, target) | |
133 | + user | |
134 | + end | |
135 | + | |
136 | + def create_user_with_permission(name, permission, target= nil) | |
137 | + user = create_user(name).person | |
138 | + give_permission(user, permission, target) | |
139 | + end | |
140 | + | |
141 | + | |
41 | 142 | protected |
42 | 143 | |
43 | 144 | def factory_num_seq |
... | ... | @@ -45,6 +146,49 @@ module Noosfero::Factory |
45 | 146 | end |
46 | 147 | |
47 | 148 | ############################################### |
149 | + # Environment | |
150 | + ############################################### | |
151 | + | |
152 | + def defaults_for_environment | |
153 | + { :name => 'Environment ' + factory_num_seq.to_s } | |
154 | + end | |
155 | + | |
156 | + ############################################### | |
157 | + # Enterprise | |
158 | + ############################################### | |
159 | + | |
160 | + def defaults_for_enterprise | |
161 | + n = factory_num_seq.to_s | |
162 | + defaults_for_profile.merge({ :identifier => "enterprise-" + n, :name => 'Enterprise ' + n }) | |
163 | + end | |
164 | + | |
165 | + ############################################### | |
166 | + # Enterprise | |
167 | + ############################################### | |
168 | + | |
169 | + def defaults_for_community | |
170 | + n = factory_num_seq.to_s | |
171 | + defaults_for_profile.merge({ :identifier => "community-" + n, :name => 'Community ' + n }) | |
172 | + end | |
173 | + | |
174 | + ############################################### | |
175 | + # Profile | |
176 | + ############################################### | |
177 | + | |
178 | + def defaults_for_profile | |
179 | + n = factory_num_seq.to_s | |
180 | + { :public_profile => true, :identifier => 'profile-' + n, :name => 'Profile ' + n, :environment_id => 1 } | |
181 | + end | |
182 | + | |
183 | + ############################################### | |
184 | + # Article | |
185 | + ############################################### | |
186 | + | |
187 | + def defaults_for_article | |
188 | + { :name => 'My article ' + factory_num_seq.to_s } | |
189 | + end | |
190 | + | |
191 | + ############################################### | |
48 | 192 | # Blog |
49 | 193 | ############################################### |
50 | 194 | def create_blog |
... | ... | @@ -56,7 +200,7 @@ module Noosfero::Factory |
56 | 200 | # ExternalFeed |
57 | 201 | ############################################### |
58 | 202 | def defaults_for_external_feed |
59 | - { :address => RAILS_ROOT + '/test/fixtures/files/feed.xml' } | |
203 | + { :address => RAILS_ROOT + '/test/fixtures/files/feed.xml', :blog_id => factory_num_seq } | |
60 | 204 | end |
61 | 205 | |
62 | 206 | def create_external_feed(attrs = {}) |
... | ... | @@ -73,4 +217,22 @@ module Noosfero::Factory |
73 | 217 | { :address => RAILS_ROOT + '/test/fixtures/files/feed.xml' } |
74 | 218 | end |
75 | 219 | |
220 | + ############################################### | |
221 | + # Domain | |
222 | + ############################################### | |
223 | + def defaults_for_domain | |
224 | + { :name => 'example' + factory_num_seq.to_s + '.com' } | |
225 | + end | |
226 | + | |
227 | + ############################################### | |
228 | + # Category | |
229 | + ############################################### | |
230 | + def defaults_for_category | |
231 | + { :environment_id => Environment.default.id, :name => 'category' + factory_num_seq.to_s } | |
232 | + end | |
233 | + | |
234 | + def defaults_for_region | |
235 | + defaults_for_category | |
236 | + end | |
237 | + | |
76 | 238 | end | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -405,7 +405,7 @@ class ApplicationControllerTest < Test::Unit::TestCase |
405 | 405 | |
406 | 406 | should 'not display invisible blocks' do |
407 | 407 | @controller.expects(:uses_design_blocks?).returns(true) |
408 | - p = create_user('test_user').person | |
408 | + p = create_user_full('test_user').person | |
409 | 409 | @controller.expects(:profile).at_least_once.returns(p) |
410 | 410 | b = p.blocks[1] |
411 | 411 | b.expects(:visible).returns(false) | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -139,20 +139,6 @@ class ProfileControllerTest < Test::Unit::TestCase |
139 | 139 | assert_tag :tag => 'a', :content => /Friends/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } |
140 | 140 | end |
141 | 141 | |
142 | - should 'not show homepage and feed automatically created on recent content' do | |
143 | - person = create_user('person_1').person | |
144 | - get :index, :profile => person.identifier | |
145 | - assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => '' } | |
146 | - end | |
147 | - | |
148 | - should 'show homepage on recent content after update' do | |
149 | - person = create_user('person_1').person | |
150 | - person.home_page.name = 'Changed name' | |
151 | - assert person.home_page.save! | |
152 | - get :index, :profile => person.identifier | |
153 | - assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.home_page.name}/ } | |
154 | - end | |
155 | - | |
156 | 142 | should 'display tag for profile' do |
157 | 143 | @profile.articles.create!(:name => 'testarticle', :tag_list => 'tag1') |
158 | 144 | |
... | ... | @@ -243,14 +229,14 @@ class ProfileControllerTest < Test::Unit::TestCase |
243 | 229 | |
244 | 230 | should 'display add friend button' do |
245 | 231 | login_as(@profile.identifier) |
246 | - friend = create_user('friendtestuser').person | |
232 | + friend = create_user_full('friendtestuser').person | |
247 | 233 | get :index, :profile => friend.identifier |
248 | 234 | assert_tag :tag => 'a', :content => 'Add friend' |
249 | 235 | end |
250 | 236 | |
251 | 237 | should 'not display add friend button if user already request friendship' do |
252 | 238 | login_as(@profile.identifier) |
253 | - friend = create_user('friendtestuser').person | |
239 | + friend = create_user_full('friendtestuser').person | |
254 | 240 | AddFriend.create!(:person => @profile, :friend => friend) |
255 | 241 | get :index, :profile => friend.identifier |
256 | 242 | assert_no_tag :tag => 'a', :content => 'Add friend' |
... | ... | @@ -258,7 +244,7 @@ class ProfileControllerTest < Test::Unit::TestCase |
258 | 244 | |
259 | 245 | should 'not display add friend button if user already friend' do |
260 | 246 | login_as(@profile.identifier) |
261 | - friend = create_user('friendtestuser').person | |
247 | + friend = create_user_full('friendtestuser').person | |
262 | 248 | @profile.add_friend(friend) |
263 | 249 | @profile.friends.reload |
264 | 250 | assert @profile.is_a_friend?(friend) |
... | ... | @@ -369,7 +355,7 @@ class ProfileControllerTest < Test::Unit::TestCase |
369 | 355 | end |
370 | 356 | |
371 | 357 | should 'display contact button only if friends' do |
372 | - friend = create_user('friend_user').person | |
358 | + friend = create_user_full('friend_user').person | |
373 | 359 | @profile.add_friend(friend) |
374 | 360 | env = Environment.default |
375 | 361 | env.disable('disable_contact_person') |
... | ... | @@ -380,14 +366,14 @@ class ProfileControllerTest < Test::Unit::TestCase |
380 | 366 | end |
381 | 367 | |
382 | 368 | should 'not display contact button if no friends' do |
383 | - nofriend = create_user('no_friend').person | |
369 | + nofriend = create_user_full('no_friend').person | |
384 | 370 | login_as(@profile.identifier) |
385 | 371 | get :index, :profile => nofriend.identifier |
386 | 372 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{nofriend.identifier}/new" } |
387 | 373 | end |
388 | 374 | |
389 | 375 | should 'display contact button only if friends and its enable in environment' do |
390 | - friend = create_user('friend_user').person | |
376 | + friend = create_user_full('friend_user').person | |
391 | 377 | env = Environment.default |
392 | 378 | env.disable('disable_contact_person') |
393 | 379 | env.save! |
... | ... | @@ -398,7 +384,7 @@ class ProfileControllerTest < Test::Unit::TestCase |
398 | 384 | end |
399 | 385 | |
400 | 386 | should 'not display contact button if friends and its disable in environment' do |
401 | - friend = create_user('friend_user').person | |
387 | + friend = create_user_full('friend_user').person | |
402 | 388 | env = Environment.default |
403 | 389 | env.enable('disable_contact_person') |
404 | 390 | env.save! |
... | ... | @@ -409,7 +395,6 @@ class ProfileControllerTest < Test::Unit::TestCase |
409 | 395 | end |
410 | 396 | |
411 | 397 | should 'display contact button for community if its enable in environment' do |
412 | - friend = create_user('friend_user').person | |
413 | 398 | env = Environment.default |
414 | 399 | community = Community.create!(:name => 'my test community', :environment => env) |
415 | 400 | env.disable('disable_contact_community') | ... | ... |
test/functional/profile_members_controller_test.rb
... | ... | @@ -220,7 +220,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase |
220 | 220 | |
221 | 221 | should 'find users' do |
222 | 222 | ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') |
223 | - user = create_user('test_user').person | |
223 | + user = create_user_full('test_user').person | |
224 | 224 | u = create_user_with_permission('ent_user', 'manage_memberships', ent) |
225 | 225 | login_as :ent_user |
226 | 226 | |
... | ... | @@ -240,8 +240,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase |
240 | 240 | end |
241 | 241 | |
242 | 242 | should 'return users with <query> as a prefix' do |
243 | - daniel = create_user('daniel').person | |
244 | - daniela = create_user('daniela').person | |
243 | + daniel = create_user_full('daniel').person | |
244 | + daniela = create_user_full('daniela').person | |
245 | 245 | |
246 | 246 | ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') |
247 | 247 | p = create_user_with_permission('test_user', 'manage_memberships', ent) | ... | ... |
test/test_helper.rb
... | ... | @@ -68,56 +68,6 @@ class Test::Unit::TestCase |
68 | 68 | |
69 | 69 | end |
70 | 70 | |
71 | - def create_admin_user(env) | |
72 | - admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) | |
73 | - admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) | |
74 | - RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) | |
75 | - admin_user.login | |
76 | - end | |
77 | - | |
78 | - def create_environment(domainname) | |
79 | - env = Environment.create!(:name => domainname) | |
80 | - env.domains << Domain.new(:name => domainname) | |
81 | - env.save! | |
82 | - env | |
83 | - end | |
84 | - | |
85 | - def create_user(name, options = {}, person_options = {}) | |
86 | - data = { | |
87 | - :login => name, | |
88 | - :email => name + '@noosfero.org', | |
89 | - :password => name.underscore, | |
90 | - :password_confirmation => name.underscore | |
91 | - }.merge(options) | |
92 | - user = User.new(data) | |
93 | - user.save! | |
94 | - user.person.update_attributes!(person_data.merge(person_options)) | |
95 | - user | |
96 | - end | |
97 | - | |
98 | - def person_data | |
99 | - {} | |
100 | - end | |
101 | - | |
102 | - def give_permission(user, permission, target) | |
103 | - user = Person.find_by_identifier(user) if user.kind_of?(String) | |
104 | - target ||= user | |
105 | - i = 0 | |
106 | - while Role.find_by_name('test_role' + i.to_s) | |
107 | - i+=1 | |
108 | - end | |
109 | - | |
110 | - role = Role.create!(:name => 'test_role' + i.to_s, :permissions => [permission]) | |
111 | - assert user.add_role(role, target) | |
112 | - assert user.has_permission?(permission, target) | |
113 | - user | |
114 | - end | |
115 | - | |
116 | - def create_user_with_permission(name, permission, target= nil) | |
117 | - user = create_user(name).person | |
118 | - give_permission(user, permission, target) | |
119 | - end | |
120 | - | |
121 | 71 | alias :ok :assert_block |
122 | 72 | |
123 | 73 | def assert_equivalent(enum1, enum2) |
... | ... | @@ -247,7 +197,6 @@ class ActionController::IntegrationTest |
247 | 197 | assert_tag :tag => 'a', :attributes => { :href => '/account/logout' } |
248 | 198 | end |
249 | 199 | |
250 | - | |
251 | 200 | def login(username, password) |
252 | 201 | ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) |
253 | 202 | ... | ... |
test/unit/article_test.rb
... | ... | @@ -735,15 +735,17 @@ class ArticleTest < Test::Unit::TestCase |
735 | 735 | end |
736 | 736 | |
737 | 737 | should 'not get tagged with tag from other environment' do |
738 | - a1 = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') | |
739 | - e = Environment.create!(:name => 'other env') | |
740 | - p = create_user('other_user', :environment => e).person | |
741 | - a2 = Article.create!(:name => 'Published at', :profile => p, :tag_list => 'bli') | |
742 | - t = a2.tags[0] | |
743 | - as = e.articles.find_tagged_with(t) | |
744 | - | |
745 | - assert_includes as, a2 | |
746 | - assert_not_includes as, a1 | |
738 | + article_from_this_environment = create(Article, :profile => profile, :tag_list => 'bli') | |
739 | + | |
740 | + other_environment = fast_create(Environment) | |
741 | + user_from_other_environment = create_user('other_user', :environment => other_environment).person | |
742 | + article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') | |
743 | + | |
744 | + tag = article_from_other_enviroment.tags.first | |
745 | + tagged_articles_in_other_environment = other_environment.articles.find_tagged_with(tag) | |
746 | + | |
747 | + assert_includes tagged_articles_in_other_environment, article_from_other_enviroment | |
748 | + assert_not_includes tagged_articles_in_other_environment, article_from_this_environment | |
747 | 749 | end |
748 | 750 | |
749 | 751 | should 'ignore category with zero as id' do | ... | ... |
test/unit/boxes_helper_test.rb
... | ... | @@ -23,8 +23,15 @@ class BoxesHelperTest < Test::Unit::TestCase |
23 | 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' |
24 | 24 | end |
25 | 25 | |
26 | - should 'display invisible block for editing' do | |
26 | + def create_user_with_blocks | |
27 | 27 | p = create_user('test_user').person |
28 | + LinkListBlock.create!(:box => p.boxes.first) | |
29 | + p | |
30 | + end | |
31 | + | |
32 | + should 'display invisible block for editing' do | |
33 | + p = create_user_with_blocks | |
34 | + | |
28 | 35 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] |
29 | 36 | b.visible = false; b.save! |
30 | 37 | box = b.box |
... | ... | @@ -37,7 +44,8 @@ class BoxesHelperTest < Test::Unit::TestCase |
37 | 44 | end |
38 | 45 | |
39 | 46 | should 'not display invisible block' do |
40 | - p = create_user('test_user').person | |
47 | + p = create_user_with_blocks | |
48 | + | |
41 | 49 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] |
42 | 50 | b.visible = false; b.save! |
43 | 51 | box = b.box | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -28,7 +28,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
28 | 28 | task.valid? |
29 | 29 | |
30 | 30 | assert task.errors.invalid?(:requestor_id) |
31 | - task.requestor = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person | |
31 | + task.requestor = create_user('testuser').person | |
32 | 32 | task.valid? |
33 | 33 | assert !task.errors.invalid?(:requestor_id) |
34 | 34 | end |
... | ... | @@ -98,7 +98,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
98 | 98 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
99 | 99 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
100 | 100 | region.validators << validator |
101 | - person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person | |
101 | + person = create_user('testuser').person | |
102 | 102 | |
103 | 103 | task = CreateEnterprise.create!({ |
104 | 104 | :name => 'My new enterprise', |
... | ... | @@ -132,7 +132,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
132 | 132 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
133 | 133 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
134 | 134 | region.validators << validator |
135 | - person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person | |
135 | + person = create_user('testuser').person | |
136 | 136 | |
137 | 137 | task = CreateEnterprise.create!({ |
138 | 138 | :name => 'My new enterprise', |
... | ... | @@ -175,7 +175,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
175 | 175 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
176 | 176 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
177 | 177 | region.validators << validator |
178 | - person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person | |
178 | + person = create_user('testuser').person | |
179 | 179 | task = CreateEnterprise.new({ |
180 | 180 | :name => 'My new enterprise', |
181 | 181 | :identifier => 'mynewenterprise', | ... | ... |
test/unit/environment_statistics_block_test.rb
... | ... | @@ -20,36 +20,35 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase |
20 | 20 | end |
21 | 21 | |
22 | 22 | should 'generate statistics' do |
23 | - env = Environment.create!(:name => "My test environment") | |
23 | + env = create(Environment) | |
24 | 24 | user1 = create_user('testuser1', :environment_id => env.id) |
25 | 25 | user2 = create_user('testuser2', :environment_id => env.id) |
26 | 26 | |
27 | - env.enterprises.build(:identifier => 'mytestenterprise', :name => 'My test enterprise').save! | |
28 | - | |
29 | - env.communities.build(:identifier => 'mytestcommunity', :name => 'mytestcommunity').save! | |
27 | + fast_create(Enterprise, :environment_id => env.id) | |
28 | + fast_create(Community, :environment_id => env.id) | |
30 | 29 | |
31 | 30 | block = EnvironmentStatisticsBlock.new |
32 | 31 | env.boxes.first.blocks << block |
33 | 32 | |
34 | 33 | content = block.content |
35 | 34 | |
36 | - assert_match /One enterprise/, content | |
37 | - assert_match /2 users/, content | |
38 | - assert_match /One community/, content | |
35 | + assert_match(/One enterprise/, content) | |
36 | + assert_match(/2 users/, content) | |
37 | + assert_match(/One community/, content) | |
39 | 38 | end |
40 | 39 | |
41 | 40 | should 'generate statistics but not for private profiles' do |
42 | - env = Environment.create!(:name => "My test environment") | |
41 | + env = create(Environment) | |
43 | 42 | user1 = create_user('testuser1', :environment_id => env.id) |
44 | 43 | user2 = create_user('testuser2', :environment_id => env.id) |
45 | 44 | user3 = create_user('testuser3', :environment_id => env.id) |
46 | 45 | p = user3.person; p.public_profile = false; p.save! |
47 | 46 | |
48 | - env.enterprises.build(:identifier => 'mytestenterprise', :name => 'My test enterprise').save! | |
49 | - env.enterprises.build(:identifier => 'mytestenterprise2', :name => 'My test enterprise 2', :public_profile => false).save! | |
47 | + fast_create(Enterprise, :environment_id => env.id) | |
48 | + fast_create(Enterprise, :environment_id => env.id, :public_profile => false) | |
50 | 49 | |
51 | - env.communities.build(:identifier => 'mytestcommunity', :name => 'mytestcommunity').save! | |
52 | - env.communities.build(:identifier => 'mytestcommunity2', :name => 'mytestcommunity 2', :public_profile => false).save! | |
50 | + fast_create(Community, :environment_id => env.id) | |
51 | + fast_create(Community, :environment_id => env.id, :public_profile => false) | |
53 | 52 | |
54 | 53 | block = EnvironmentStatisticsBlock.new |
55 | 54 | env.boxes.first.blocks << block | ... | ... |
test/unit/external_feed_test.rb
... | ... | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class ExternalFeedTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | should 'require blog' do |
6 | - e = build(:external_feed, :blog => nil) | |
6 | + e = ExternalFeed.new | |
7 | 7 | e.valid? |
8 | 8 | assert e.errors[:blog_id] |
9 | 9 | e.blog = create_blog | ... | ... |
test/unit/feed_handler_test.rb
... | ... | @@ -8,7 +8,7 @@ class FeedHandlerTest < Test::Unit::TestCase |
8 | 8 | end |
9 | 9 | attr_reader :handler |
10 | 10 | def container |
11 | - @container ||= fast_create(:feed_reader_block) | |
11 | + @container ||= create(:feed_reader_block) | |
12 | 12 | end |
13 | 13 | |
14 | 14 | should 'fetch feed content' do |
... | ... | @@ -90,7 +90,7 @@ class FeedHandlerTest < Test::Unit::TestCase |
90 | 90 | [:external_feed, :feed_reader_block].each do |container_class| |
91 | 91 | |
92 | 92 | should "reset the errors count after a successfull run (#{container_class})" do |
93 | - container = fast_create(container_class, :update_errors => 1, :address => RAILS_ROOT + '/test/fixtures/files/feed.xml') | |
93 | + container = build(container_class, :update_errors => 1, :address => RAILS_ROOT + '/test/fixtures/files/feed.xml') | |
94 | 94 | handler.expects(:actually_process_container).with(container) |
95 | 95 | handler.process(container) |
96 | 96 | assert_equal 0, container.update_errors |
... | ... | @@ -99,7 +99,7 @@ class FeedHandlerTest < Test::Unit::TestCase |
99 | 99 | should "set error message and disable in case of errors (#{container_class})" do |
100 | 100 | FeedHandler.stubs(:max_errors).returns(4) |
101 | 101 | |
102 | - container = fast_create(container_class) | |
102 | + container = create(container_class) | |
103 | 103 | handler.stubs(:actually_process_container).with(container).raises(Exception.new("crash")) |
104 | 104 | |
105 | 105 | # in the first 4 errors, we are ok | ... | ... |
test/unit/feed_reader_block_test.rb
test/unit/person_test.rb
... | ... | @@ -163,14 +163,14 @@ class PersonTest < Test::Unit::TestCase |
163 | 163 | end |
164 | 164 | |
165 | 165 | should 'get a default home page and a RSS feed' do |
166 | - person = create_user('mytestuser').person | |
166 | + person = create_user_full('mytestuser').person | |
167 | 167 | |
168 | 168 | assert_kind_of Article, person.home_page |
169 | 169 | assert_kind_of RssFeed, person.articles.find_by_path('feed') |
170 | 170 | end |
171 | 171 | |
172 | 172 | should 'create default set of blocks' do |
173 | - p = create_user('testingblocks').person | |
173 | + p = create_user_full('testingblocks').person | |
174 | 174 | |
175 | 175 | assert p.boxes[0].blocks.map(&:class).include?(MainBlock), 'person must have a MainBlock upon creation' |
176 | 176 | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -39,19 +39,19 @@ class ProfileTest < Test::Unit::TestCase |
39 | 39 | end |
40 | 40 | |
41 | 41 | should 'be assigned to default environment if no environment is informed' do |
42 | - assert_equal Environment.default, Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile').environment | |
42 | + assert_equal Environment.default, create(Profile).environment | |
43 | 43 | end |
44 | 44 | |
45 | 45 | should 'not override environment informed before creation' do |
46 | - env = Environment.create!(:name => 'My test environment') | |
47 | - p = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment_id => env.id) | |
46 | + env = fast_create(Environment) | |
47 | + p = create(Profile, :environment_id => env.id) | |
48 | 48 | |
49 | 49 | assert_equal env, p.environment |
50 | 50 | end |
51 | 51 | |
52 | 52 | should 'be able to set environment after instantiation and before creating' do |
53 | - env = Environment.create!(:name => 'My test environment') | |
54 | - p = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile') | |
53 | + env = fast_create(Environment) | |
54 | + p = create(Profile) | |
55 | 55 | p.environment = env |
56 | 56 | p.save! |
57 | 57 | |
... | ... | @@ -73,7 +73,7 @@ class ProfileTest < Test::Unit::TestCase |
73 | 73 | end |
74 | 74 | |
75 | 75 | should 'provide access to home page' do |
76 | - profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') | |
76 | + profile = create(Profile) | |
77 | 77 | assert_kind_of Article, profile.home_page |
78 | 78 | end |
79 | 79 | |
... | ... | @@ -87,7 +87,7 @@ class ProfileTest < Test::Unit::TestCase |
87 | 87 | end |
88 | 88 | |
89 | 89 | def test_can_have_affiliated_people |
90 | - pr = Profile.create(:name => 'composite_profile', :identifier => 'composite') | |
90 | + pr = fast_create(Profile) | |
91 | 91 | pe = create_user('aff', :email => 'aff@pr.coop', :password => 'blih', :password_confirmation => 'blih').person |
92 | 92 | |
93 | 93 | member_role = Role.new(:name => 'new_member_role') |
... | ... | @@ -98,17 +98,17 @@ class ProfileTest < Test::Unit::TestCase |
98 | 98 | end |
99 | 99 | |
100 | 100 | def test_find_by_contents |
101 | - p = Profile.create(:name => 'wanted', :identifier => 'wanted') | |
101 | + p = create(Profile, :name => 'wanted') | |
102 | 102 | |
103 | 103 | assert Profile.find_by_contents('wanted').include?(p) |
104 | 104 | assert ! Profile.find_by_contents('not_wanted').include?(p) |
105 | 105 | end |
106 | 106 | |
107 | 107 | should 'remove pages when removing profile' do |
108 | - profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') | |
109 | - first = profile.articles.build(:name => 'first'); first.save! | |
110 | - second = profile.articles.build(:name => 'second'); second.save! | |
111 | - third = profile.articles.build(:name => 'third'); third.save! | |
108 | + profile = fast_create(Profile) | |
109 | + first = fast_create(Article, :profile_id => profile.id) | |
110 | + second = fast_create(Article, :profile_id => profile.id) | |
111 | + third = fast_create(Article, :profile_id => profile.id) | |
112 | 112 | |
113 | 113 | total = Article.count |
114 | 114 | mine = profile.articles.count |
... | ... | @@ -133,19 +133,19 @@ class ProfileTest < Test::Unit::TestCase |
133 | 133 | end |
134 | 134 | |
135 | 135 | should 'provide recent documents' do |
136 | - profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') | |
136 | + profile = fast_create(Profile) | |
137 | 137 | profile.articles.destroy_all |
138 | 138 | |
139 | - first = profile.articles.build(:name => 'first'); first.save! | |
140 | - second = profile.articles.build(:name => 'second'); second.save! | |
141 | - third = profile.articles.build(:name => 'third'); third.save! | |
139 | + first = fast_create(Article, { :profile_id => profile.id }, :timestamps => true) | |
140 | + second = fast_create(Article, { :profile_id => profile.id }, :timestamps => true) | |
141 | + third = fast_create(Article, { :profile_id => profile.id }, :timestamps => true) | |
142 | 142 | |
143 | 143 | assert_equal [third, second], profile.recent_documents(2) |
144 | 144 | assert_equal [third, second, first], profile.recent_documents |
145 | 145 | end |
146 | 146 | |
147 | 147 | should 'affiliate and provide a list of the affiliated users' do |
148 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') | |
148 | + profile = fast_create(Profile) | |
149 | 149 | person = create_user('test_user').person |
150 | 150 | role = Role.create!(:name => 'just_another_test_role') |
151 | 151 | assert profile.affiliate(person, role) |
... | ... | @@ -153,8 +153,8 @@ class ProfileTest < Test::Unit::TestCase |
153 | 153 | end |
154 | 154 | |
155 | 155 | should 'authorize users that have permission on the environment' do |
156 | - env = Environment.create!(:name => 'test_env') | |
157 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :environment => env) | |
156 | + env = fast_create(Environment) | |
157 | + profile = fast_create(Profile, :environment_id => env.id) | |
158 | 158 | person = create_user('test_user').person |
159 | 159 | role = Role.create!(:name => 'just_another_test_role', :permissions => ['edit_profile']) |
160 | 160 | assert env.affiliate(person, role) |
... | ... | @@ -162,29 +162,24 @@ class ProfileTest < Test::Unit::TestCase |
162 | 162 | end |
163 | 163 | |
164 | 164 | should 'have articles' do |
165 | - env = Environment.create!(:name => 'test_env') | |
166 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :environment => env) | |
165 | + profile = build(Profile) | |
167 | 166 | |
168 | 167 | assert_raise ActiveRecord::AssociationTypeMismatch do |
169 | 168 | profile.articles << 1 |
170 | 169 | end |
171 | 170 | |
172 | 171 | assert_nothing_raised do |
173 | - profile.articles << Article.new(:name => 'testing article') | |
172 | + profile.articles << build(Article) | |
174 | 173 | end |
175 | 174 | end |
176 | 175 | |
177 | 176 | should 'list top-level articles' do |
178 | - env = Environment.create!(:name => 'test_env') | |
179 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :environment => env) | |
177 | + profile = fast_create(Profile) | |
180 | 178 | |
181 | - p1 = profile.articles.build(:name => 'parent1') | |
182 | - p1.save! | |
183 | - p2 = profile.articles.build(:name => 'parent2') | |
184 | - p2.save! | |
179 | + p1 = create(Article, :profile_id => profile.id) | |
180 | + p2 = create(Article, :profile_id => profile.id) | |
185 | 181 | |
186 | - child = profile.articles.build(:name => 'parent2', :parent_id => p1.id) | |
187 | - child.save! | |
182 | + child = create(Article, :profile_id => profile.id, :parent_id => p1.id) | |
188 | 183 | |
189 | 184 | top = profile.top_level_articles |
190 | 185 | assert top.include?(p1) |
... | ... | @@ -193,8 +188,7 @@ class ProfileTest < Test::Unit::TestCase |
193 | 188 | end |
194 | 189 | |
195 | 190 | should 'be able to optionally reload the list of top level articles' do |
196 | - env = Environment.create!(:name => 'test_env') | |
197 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :environment => env) | |
191 | + profile = fast_create(Profile) | |
198 | 192 | |
199 | 193 | list = profile.top_level_articles |
200 | 194 | same_list = profile.top_level_articles |
... | ... | @@ -205,8 +199,8 @@ class ProfileTest < Test::Unit::TestCase |
205 | 199 | end |
206 | 200 | |
207 | 201 | should 'be able to find profiles by their names with ferret' do |
208 | - small = Profile.create!(:name => 'A small profile for testing ', :identifier => 'smallprofilefortesting') | |
209 | - big = Profile.create!(:name => 'A big profile for testing', :identifier => 'bigprofilefortesting') | |
202 | + small = create(Profile, :name => 'A small profile for testing') | |
203 | + big = create(Profile, :name => 'A big profile for testing') | |
210 | 204 | |
211 | 205 | assert Profile.find_by_contents('small').include?(small) |
212 | 206 | assert Profile.find_by_contents('big').include?(big) |
... | ... | @@ -217,13 +211,12 @@ class ProfileTest < Test::Unit::TestCase |
217 | 211 | end |
218 | 212 | |
219 | 213 | should 'provide a shortcut for picking a profile by its identifier' do |
220 | - profile = Profile.create!(:name => 'bla', :identifier => 'testprofile') | |
214 | + profile = fast_create(Profile, :identifier => 'testprofile') | |
221 | 215 | assert_equal profile, Profile['testprofile'] |
222 | 216 | end |
223 | 217 | |
224 | 218 | should 'have boxes upon creation' do |
225 | - profile = Profile.create!(:name => 'test profile', :identifier => 'testprofile') | |
226 | - | |
219 | + profile = create(Profile) | |
227 | 220 | assert profile.boxes.size > 0 |
228 | 221 | end |
229 | 222 | |
... | ... | @@ -247,66 +240,71 @@ class ProfileTest < Test::Unit::TestCase |
247 | 240 | end |
248 | 241 | |
249 | 242 | should 'provide url to itself' do |
250 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
243 | + environment = create_environment('mycolivre.net') | |
244 | + profile = build(Profile, :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
251 | 245 | |
252 | 246 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) |
253 | 247 | end |
254 | 248 | |
255 | 249 | should 'provide URL to admin area' do |
256 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
250 | + environment = create_environment('mycolivre.net') | |
251 | + profile = build(Profile, :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
252 | + | |
257 | 253 | assert_equal({ :profile => 'testprofile', :controller => 'profile_editor', :action => 'index'}, profile.admin_url) |
258 | 254 | end |
259 | 255 | |
260 | 256 | should 'provide URL to public profile' do |
261 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
257 | + environment = create_environment('mycolivre.net') | |
258 | + profile = build(Profile, :identifier => 'testprofile', :environment_id => environment.id) | |
259 | + | |
262 | 260 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) |
263 | 261 | end |
264 | 262 | |
265 | 263 | should "use own domain name instead of environment's for home page url" do |
266 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
264 | + profile = build(Profile, :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
267 | 265 | profile.domains << Domain.new(:name => 'micojones.net') |
266 | + | |
268 | 267 | assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) |
269 | 268 | end |
270 | 269 | |
271 | 270 | should 'help developers by adding a suitable port to url' do |
272 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
271 | + profile = build(Profile) | |
273 | 272 | |
274 | 273 | Noosfero.expects(:url_options).returns({ :port => 9999 }) |
275 | 274 | |
276 | - ok('Profile#url_options must include port option when running in development mode') { profile.url[:port] == 9999 } | |
275 | + assert profile.url[:port] == 9999, 'Profile#url_options must include port option when running in development mode' | |
277 | 276 | end |
278 | 277 | |
279 | 278 | should 'help developers by adding a suitable port to url options for own domain urls' do |
280 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
281 | - profile.domains << Domain.new(:name => 'micojones.net') | |
279 | + environment = create_environment('mycolivre.net') | |
280 | + profile = build(Profile, :environment_id => environment.id) | |
281 | + profile.domains << build(Domain) | |
282 | 282 | |
283 | 283 | Noosfero.expects(:url_options).returns({ :port => 9999 }) |
284 | 284 | |
285 | - ok('Profile#url must include port options when running in developers mode') { profile.url[:port] == 9999 } | |
285 | + assert profile.url[:port] == 9999, 'Profile#url must include port options when running in developers mode' | |
286 | 286 | end |
287 | 287 | |
288 | 288 | should 'list article tags for profile' do |
289 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
290 | - profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! | |
291 | - profile.articles.build(:name => 'second', :tag_list => 'first-tag, second-tag').save! | |
292 | - profile.articles.build(:name => 'third', :tag_list => 'first-tag, second-tag, third-tag').save! | |
289 | + profile = fast_create(Profile) | |
290 | + create(Article, :profile => profile, :tag_list => 'first-tag') | |
291 | + create(Article, :profile => profile, :tag_list => 'first-tag, second-tag') | |
292 | + create(Article, :profile => profile, :tag_list => 'first-tag, second-tag, third-tag') | |
293 | 293 | |
294 | 294 | assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, profile.article_tags) |
295 | - | |
296 | 295 | end |
297 | 296 | |
298 | 297 | should 'list tags for profile' do |
299 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :tag_list => 'first-tag, second-tag') | |
298 | + profile = create(Profile, :tag_list => 'first-tag, second-tag') | |
300 | 299 | |
301 | 300 | assert_equal(['first-tag', 'second-tag'], profile.tags.map(&:name)) |
302 | 301 | end |
303 | 302 | |
304 | 303 | should 'find content tagged with given tag' do |
305 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
306 | - first = profile.articles.build(:name => 'first', :tag_list => 'first-tag'); first.save! | |
307 | - second = profile.articles.build(:name => 'second', :tag_list => 'first-tag, second-tag'); second.save! | |
308 | - third = profile.articles.build(:name => 'third', :tag_list => 'first-tag, second-tag, third-tag'); third.save! | |
309 | - profile.reload | |
304 | + profile = fast_create(Profile) | |
305 | + first = create(Article, :profile => profile, :tag_list => 'first-tag') | |
306 | + second = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag') | |
307 | + third = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag, third-tag') | |
310 | 308 | |
311 | 309 | assert_equivalent [ first, second, third], profile.find_tagged_with('first-tag') |
312 | 310 | assert_equivalent [ second, third ], profile.find_tagged_with('second-tag') |
... | ... | @@ -337,14 +335,14 @@ class ProfileTest < Test::Unit::TestCase |
337 | 335 | end |
338 | 336 | |
339 | 337 | should 'create a homepage and a feed on creation' do |
340 | - profile = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
338 | + profile = create(Profile) | |
341 | 339 | |
342 | 340 | assert_kind_of Article, profile.home_page |
343 | 341 | assert_kind_of RssFeed, profile.articles.find_by_path('feed') |
344 | 342 | end |
345 | 343 | |
346 | 344 | should 'not allow to add members' do |
347 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
345 | + c = fast_create(Profile) | |
348 | 346 | p = create_user('mytestuser').person |
349 | 347 | assert_raise RuntimeError do |
350 | 348 | c.add_member(p) |
... | ... | @@ -352,7 +350,7 @@ class ProfileTest < Test::Unit::TestCase |
352 | 350 | end |
353 | 351 | |
354 | 352 | should 'allow to add administrators' do |
355 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
353 | + c = fast_create(Profile) | |
356 | 354 | p = create_user('mytestuser').person |
357 | 355 | |
358 | 356 | c.add_admin(p) |
... | ... | @@ -361,7 +359,7 @@ class ProfileTest < Test::Unit::TestCase |
361 | 359 | end |
362 | 360 | |
363 | 361 | should 'not allow to add moderators' do |
364 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
362 | + c = fast_create(Profile) | |
365 | 363 | p = create_user('mytestuser').person |
366 | 364 | assert_raise RuntimeError do |
367 | 365 | c.add_moderator(p) |
... | ... | @@ -369,7 +367,7 @@ class ProfileTest < Test::Unit::TestCase |
369 | 367 | end |
370 | 368 | |
371 | 369 | should 'have tasks' do |
372 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
370 | + c = fast_create(Profile) | |
373 | 371 | t1 = c.tasks.build |
374 | 372 | t1.save! |
375 | 373 | |
... | ... | @@ -380,7 +378,7 @@ class ProfileTest < Test::Unit::TestCase |
380 | 378 | end |
381 | 379 | |
382 | 380 | should 'have pending tasks' do |
383 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
381 | + c = fast_create(Profile) | |
384 | 382 | t1 = c.tasks.build; t1.save! |
385 | 383 | t2 = c.tasks.build; t2.save!; t2.finish |
386 | 384 | t3 = c.tasks.build; t3.save! |
... | ... | @@ -389,7 +387,7 @@ class ProfileTest < Test::Unit::TestCase |
389 | 387 | end |
390 | 388 | |
391 | 389 | should 'have finished tasks' do |
392 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
390 | + c = fast_create(Profile) | |
393 | 391 | t1 = c.tasks.build; t1.save! |
394 | 392 | t2 = c.tasks.build; t2.save!; t2.finish |
395 | 393 | t3 = c.tasks.build; t3.save!; t3.finish |
... | ... | @@ -398,12 +396,12 @@ class ProfileTest < Test::Unit::TestCase |
398 | 396 | end |
399 | 397 | |
400 | 398 | should 'responds to categories' do |
401 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
399 | + c = fast_create(Profile) | |
402 | 400 | assert_respond_to c, :categories |
403 | 401 | end |
404 | 402 | |
405 | 403 | should 'have categories' do |
406 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
404 | + c = fast_create(Profile) | |
407 | 405 | cat = Environment.default.categories.build(:name => 'a category'); cat.save! |
408 | 406 | c.add_category cat |
409 | 407 | c.save! |
... | ... | @@ -431,13 +429,13 @@ class ProfileTest < Test::Unit::TestCase |
431 | 429 | end |
432 | 430 | |
433 | 431 | should 'advertise false to homepage and feed on creation' do |
434 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
432 | + profile = create(Profile) | |
435 | 433 | assert !profile.home_page.advertise? |
436 | 434 | assert !profile.articles.find_by_path('feed').advertise? |
437 | 435 | end |
438 | 436 | |
439 | 437 | should 'advertise true to homepage after update' do |
440 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
438 | + profile = create(Profile) | |
441 | 439 | assert !profile.home_page.advertise? |
442 | 440 | profile.home_page.name = 'Changed name' |
443 | 441 | assert profile.home_page.save! |
... | ... | @@ -445,7 +443,7 @@ class ProfileTest < Test::Unit::TestCase |
445 | 443 | end |
446 | 444 | |
447 | 445 | should 'advertise true to feed after update' do |
448 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
446 | + profile = create(Profile) | |
449 | 447 | assert !profile.articles.find_by_path('feed').advertise? |
450 | 448 | profile.articles.find_by_path('feed').name = 'Changed name' |
451 | 449 | assert profile.articles.find_by_path('feed').save! |
... | ... | @@ -453,15 +451,13 @@ class ProfileTest < Test::Unit::TestCase |
453 | 451 | end |
454 | 452 | |
455 | 453 | should 'have latitude and longitude' do |
456 | - e = Enterprise.create!(:name => 'test1', :identifier => 'test1') | |
457 | - e.lat, e.lng = 45, 45 ; e.save! | |
454 | + e = fast_create(Enterprise, :lat => 45, :lng => 45) | |
458 | 455 | |
459 | 456 | assert_includes Enterprise.find_within(2, :origin => [45, 45]), e |
460 | 457 | end |
461 | 458 | |
462 | 459 | should 'have latitude and longitude and find' do |
463 | - e = Enterprise.create!(:name => 'test1', :identifier => 'test1') | |
464 | - e.lat, e.lng = 45, 45 ; e.save! | |
460 | + e = fast_create(Enterprise, :lat => 45, :lng => 45) | |
465 | 461 | |
466 | 462 | assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e |
467 | 463 | end |
... | ... | @@ -477,8 +473,8 @@ class ProfileTest < Test::Unit::TestCase |
477 | 473 | end |
478 | 474 | |
479 | 475 | should 'be able to find the public profiles but not private ones' do |
480 | - p1 = Profile.create!(:name => 'test1', :identifier => 'test1', :public_profile => true) | |
481 | - p2 = Profile.create!(:name => 'test2', :identifier => 'test2', :public_profile => false) | |
476 | + p1 = create(Profile, :public_profile => true) | |
477 | + p2 = create(Profile, :public_profile => false) | |
482 | 478 | |
483 | 479 | result = Profile.find(:all, :conditions => {:public_profile => true}) |
484 | 480 | assert_includes result, p1 |
... | ... | @@ -548,24 +544,24 @@ class ProfileTest < Test::Unit::TestCase |
548 | 544 | |
549 | 545 | should 'index profile identifier for searching' do |
550 | 546 | Profile.destroy_all |
551 | - p = Profile.create!(:identifier => 'lalala', :name => 'Interesting Profile') | |
547 | + p = create(Profile, :identifier => 'lalala') | |
552 | 548 | assert_includes Profile.find_by_contents('lalala'), p |
553 | 549 | end |
554 | 550 | |
555 | 551 | should 'index profile name for searching' do |
556 | - p = Profile.create!(:identifier => 'testprofile', :name => 'Interesting Profile') | |
552 | + p = create(Profile, :name => 'Interesting Profile') | |
557 | 553 | assert_includes Profile.find_by_contents('interesting'), p |
558 | 554 | end |
559 | 555 | |
560 | 556 | should 'enabled by default on creation' do |
561 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
557 | + profile = fast_create(Profile) | |
562 | 558 | assert profile.enabled? |
563 | 559 | end |
564 | 560 | |
565 | 561 | should 'categorize in the entire category hierarchy' do |
566 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
567 | - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') | |
568 | - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3') | |
562 | + c1 = fast_create(Category) | |
563 | + c2 = fast_create(Category, :parent_id => c1.id) | |
564 | + c3 = fast_create(Category, :parent_id => c2.id) | |
569 | 565 | |
570 | 566 | profile = create_user('testuser').person |
571 | 567 | profile.add_category(c3) |
... | ... | @@ -580,11 +576,11 @@ class ProfileTest < Test::Unit::TestCase |
580 | 576 | end |
581 | 577 | |
582 | 578 | should 'redefine the entire category set at once' do |
583 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
584 | - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') | |
585 | - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3') | |
586 | - c4 = c1.children.create!(:environment => Environment.default, :name => 'c4') | |
587 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
579 | + c1 = fast_create(Category) | |
580 | + c2 = fast_create(Category, :parent_id => c1.id) | |
581 | + c3 = fast_create(Category, :parent_id => c2.id) | |
582 | + c4 = fast_create(Category, :parent_id => c1.id) | |
583 | + profile = fast_create(Profile) | |
588 | 584 | |
589 | 585 | profile.add_category(c4) |
590 | 586 | |
... | ... | @@ -594,33 +590,33 @@ class ProfileTest < Test::Unit::TestCase |
594 | 590 | end |
595 | 591 | |
596 | 592 | should 'be able to create an profile already with categories' do |
597 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
598 | - c2 = Category.create!(:environment => Environment.default, :name => 'c2') | |
593 | + c1 = create(Category) | |
594 | + c2 = create(Category) | |
599 | 595 | |
600 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile', :category_ids => [c1.id, c2.id]) | |
596 | + profile = create(Profile, :category_ids => [c1.id, c2.id]) | |
601 | 597 | |
602 | 598 | assert_equivalent [c1, c2], profile.categories(true) |
603 | 599 | end |
604 | 600 | |
605 | 601 | should 'be associated with a region' do |
606 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
607 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region) | |
602 | + region = fast_create(Region) | |
603 | + profile = fast_create(Profile, :region_id => region.id) | |
608 | 604 | |
609 | 605 | assert_equal region, profile.region |
610 | 606 | end |
611 | 607 | |
612 | 608 | should 'categorized automatically in its region' do |
613 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
614 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region) | |
609 | + region = fast_create(Region) | |
610 | + profile = create(Profile, :region => region) | |
615 | 611 | |
616 | 612 | assert_equal [region], profile.categories(true) |
617 | 613 | end |
618 | 614 | |
619 | 615 | should 'change categorization when changing region' do |
620 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
621 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region) | |
616 | + region = fast_create(Region) | |
617 | + region2 = fast_create(Region) | |
622 | 618 | |
623 | - region2 = Region.create!(:name => "Feira de Santana", :environment => Environment.default) | |
619 | + profile = fast_create(Profile, :region_id => region.id) | |
624 | 620 | |
625 | 621 | profile.region = region2 |
626 | 622 | profile.save! |
... | ... | @@ -629,8 +625,8 @@ class ProfileTest < Test::Unit::TestCase |
629 | 625 | end |
630 | 626 | |
631 | 627 | should 'remove categorization when removing region' do |
632 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
633 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region) | |
628 | + region = fast_create(Region) | |
629 | + profile = fast_create(Profile, :region_id => region.id) | |
634 | 630 | |
635 | 631 | profile.region = nil |
636 | 632 | profile.save! |
... | ... | @@ -639,8 +635,8 @@ class ProfileTest < Test::Unit::TestCase |
639 | 635 | end |
640 | 636 | |
641 | 637 | should 'not remove region, only dissasociate from it' do |
642 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
643 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region) | |
638 | + region = fast_create(Region) | |
639 | + profile = fast_create(Profile, :region_id => region.id) | |
644 | 640 | |
645 | 641 | profile.region = nil |
646 | 642 | profile.save! |
... | ... | @@ -651,19 +647,18 @@ class ProfileTest < Test::Unit::TestCase |
651 | 647 | end |
652 | 648 | |
653 | 649 | should 'be able to create with categories and region at the same time' do |
654 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
655 | - category = Category.create!(:name => 'test category', :environment => Environment.default) | |
656 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region, :category_ids => [category.id]) | |
650 | + region = fast_create(Region) | |
651 | + category = fast_create(Category) | |
652 | + profile = create(Profile, :region => region, :category_ids => [category.id]) | |
657 | 653 | |
658 | 654 | assert_equivalent [region, category], profile.categories(true) |
659 | 655 | end |
660 | 656 | |
661 | 657 | should 'be able to update categories and not get regions removed' do |
662 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
663 | - category = Category.create!(:name => 'test category', :environment => Environment.default) | |
664 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region, :category_ids => [category.id]) | |
665 | - | |
666 | - category2 = Category.create!(:name => 'test category 2', :environment => Environment.default) | |
658 | + region = fast_create(Region) | |
659 | + category = fast_create(Category) | |
660 | + category2 = fast_create(Category) | |
661 | + profile = create(Profile, :region => region, :category_ids => [category.id]) | |
667 | 662 | |
668 | 663 | profile.update_attributes!(:category_ids => [category2.id]) |
669 | 664 | |
... | ... | @@ -671,11 +666,10 @@ class ProfileTest < Test::Unit::TestCase |
671 | 666 | end |
672 | 667 | |
673 | 668 | should 'be able to update region and not get categories removed' do |
674 | - region = Region.create!(:name => "Salvador", :environment => Environment.default) | |
675 | - category = Category.create!(:name => 'test category', :environment => Environment.default) | |
676 | - profile = Profile.create!(:name => 'testprofile', :identifier => 'testprofile', :region => region, :category_ids => [category.id]) | |
677 | - | |
678 | - region2 = Region.create!(:name => "Aracaju", :environment => Environment.default) | |
669 | + region = fast_create(Region) | |
670 | + region2 = fast_create(Region) | |
671 | + category = fast_create(Category) | |
672 | + profile = create(Profile, :region => region, :category_ids => [category.id]) | |
679 | 673 | |
680 | 674 | profile.update_attributes!(:region => region2) |
681 | 675 | |
... | ... | @@ -691,16 +685,16 @@ class ProfileTest < Test::Unit::TestCase |
691 | 685 | end |
692 | 686 | |
693 | 687 | should 'query region for location' do |
694 | - region = Region.new(:name => 'Some ackwrad region name') | |
695 | - p = Profile.new(:region => region) | |
696 | - assert_equal 'Some ackwrad region name', p.location | |
688 | + region = build(Region, :name => 'Some ackward region name') | |
689 | + p = build(Profile, :region => region) | |
690 | + assert_equal 'Some ackward region name', p.location | |
697 | 691 | end |
698 | 692 | |
699 | 693 | should 'query region hierarchy for location up to 2 levels' do |
700 | - country = Region.new(:name => "Brazil") | |
701 | - state = Region.new(:name => "Bahia", :parent => country) | |
702 | - city = Region.new(:name => "Salvador", :parent => state) | |
703 | - p = Profile.new(:region => city) | |
694 | + country = build(Region, :name => "Brazil") | |
695 | + state = build(Region, :name => "Bahia", :parent => country) | |
696 | + city = build(Region, :name => "Salvador", :parent => state) | |
697 | + p = build(Profile, :region => city) | |
704 | 698 | assert_equal 'Salvador - Bahia', p.location |
705 | 699 | end |
706 | 700 | |
... | ... | @@ -735,21 +729,21 @@ class ProfileTest < Test::Unit::TestCase |
735 | 729 | end |
736 | 730 | |
737 | 731 | should 'default home page is a TinyMceArticle' do |
738 | - profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') | |
732 | + profile = create(Profile) | |
739 | 733 | assert_kind_of TinyMceArticle, profile.home_page |
740 | 734 | end |
741 | 735 | |
742 | 736 | should 'not add a category twice to profile' do |
743 | - c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
744 | - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') | |
745 | - c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') | |
746 | - profile = create_user('testuser').person | |
737 | + c1 = fast_create(Category) | |
738 | + c2 = fast_create(Category, :parent_id => c1.id) | |
739 | + c3 = fast_create(Category, :parent_id => c1.id) | |
740 | + profile = fast_create(Profile) | |
747 | 741 | profile.category_ids = [c2,c3,c3].map(&:id) |
748 | 742 | assert_equal [c2, c3], profile.categories(true) |
749 | 743 | end |
750 | 744 | |
751 | 745 | should 'not return nil members when a member is removed from system' do |
752 | - p = Community.create!(:name => 'test community', :identifier => 'test_comm') | |
746 | + p = fast_create(Community) | |
753 | 747 | member = create_user('test_user').person |
754 | 748 | p.add_member(member) |
755 | 749 | |
... | ... | @@ -880,16 +874,16 @@ class ProfileTest < Test::Unit::TestCase |
880 | 874 | end |
881 | 875 | |
882 | 876 | should 'respond to public? as public_profile' do |
883 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | |
884 | - p2 = Profile.create!(:name => 'test profile 2', :identifier => 'test_profile2', :public_profile => false) | |
877 | + p1 = fast_create(Profile) | |
878 | + p2 = fast_create(Profile, :public_profile => false) | |
885 | 879 | |
886 | 880 | assert p1.public? |
887 | 881 | assert !p2.public? |
888 | 882 | end |
889 | 883 | |
890 | 884 | should 'create a initial private folder when a public profile is created' do |
891 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | |
892 | - p2 = Profile.create!(:name => 'test profile 2', :identifier => 'test_profile2', :public_profile => false) | |
885 | + p1 = create(Profile) | |
886 | + p2 = create(Profile, :public_profile => false) | |
893 | 887 | |
894 | 888 | assert p1.articles.find(:first, :conditions => {:public_article => false}) |
895 | 889 | assert !p2.articles.find(:first, :conditions => {:public_article => false}) |
... | ... | @@ -897,7 +891,7 @@ class ProfileTest < Test::Unit::TestCase |
897 | 891 | |
898 | 892 | should 'remove member with many roles' do |
899 | 893 | person = create_user('test_user').person |
900 | - community = Community.create!(:name => 'Boca do Siri', :identifier => 'boca_do_siri') | |
894 | + community = fast_create(Community) | |
901 | 895 | community.affiliate(person, Profile::Roles.all_roles(community.environment.id)) |
902 | 896 | |
903 | 897 | community.remove_member(person) |
... | ... | @@ -908,12 +902,12 @@ class ProfileTest < Test::Unit::TestCase |
908 | 902 | should 'copy set of articles from a template' do |
909 | 903 | template = create_user('test_template').person |
910 | 904 | template.articles.destroy_all |
911 | - a1 = template.articles.create(:name => 'some xyz article') | |
912 | - a2 = template.articles.create(:name => 'some child article', :parent => a1) | |
905 | + a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | |
906 | + a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id) | |
913 | 907 | |
914 | 908 | Profile.any_instance.stubs(:template).returns(template) |
915 | 909 | |
916 | - p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | |
910 | + p = create(Profile) | |
917 | 911 | |
918 | 912 | assert_equal 1, p.top_level_articles.size |
919 | 913 | top_art = p.top_level_articles[0] |
... | ... | @@ -926,14 +920,13 @@ class ProfileTest < Test::Unit::TestCase |
926 | 920 | should 'copy homepage from template' do |
927 | 921 | template = create_user('test_template').person |
928 | 922 | template.articles.destroy_all |
929 | - a1 = template.articles.create(:name => 'some xyz article') | |
923 | + a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | |
930 | 924 | template.home_page = a1 |
931 | 925 | template.save! |
932 | 926 | |
933 | 927 | Profile.any_instance.stubs(:template).returns(template) |
934 | 928 | |
935 | - p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | |
936 | - p.reload | |
929 | + p = create(Profile) | |
937 | 930 | |
938 | 931 | assert_not_nil p.home_page |
939 | 932 | assert_equal 'some xyz article', p.home_page.name |
... | ... | @@ -942,12 +935,11 @@ class ProfileTest < Test::Unit::TestCase |
942 | 935 | should 'not advertise the articles copied from templates' do |
943 | 936 | template = create_user('test_template').person |
944 | 937 | template.articles.destroy_all |
945 | - a = template.articles.create(:name => 'some xyz article') | |
938 | + a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | |
946 | 939 | |
947 | 940 | Profile.any_instance.stubs(:template).returns(template) |
948 | 941 | |
949 | - p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | |
950 | - p.reload | |
942 | + p = create(Profile) | |
951 | 943 | |
952 | 944 | a_copy = p.articles[0] |
953 | 945 | |
... | ... | @@ -955,7 +947,7 @@ class ProfileTest < Test::Unit::TestCase |
955 | 947 | end |
956 | 948 | |
957 | 949 | should 'copy set of boxes from profile template' do |
958 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
950 | + template = fast_create(Profile) | |
959 | 951 | template.boxes.destroy_all |
960 | 952 | template.boxes << Box.new |
961 | 953 | template.boxes[0].blocks << Block.new |
... | ... | @@ -963,18 +955,18 @@ class ProfileTest < Test::Unit::TestCase |
963 | 955 | |
964 | 956 | Profile.any_instance.stubs(:template).returns(template) |
965 | 957 | |
966 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
958 | + p = create(Profile) | |
967 | 959 | |
968 | 960 | assert_equal 1, p.boxes.size |
969 | 961 | assert_equal 1, p.boxes[0].blocks.size |
970 | 962 | end |
971 | 963 | |
972 | 964 | should 'copy layout template when applying template' do |
973 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
965 | + template = fast_create(Profile) | |
974 | 966 | template.layout_template = 'leftbar' |
975 | 967 | template.save! |
976 | 968 | |
977 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
969 | + p = create(Profile) | |
978 | 970 | |
979 | 971 | p.apply_template(template) |
980 | 972 | |
... | ... | @@ -982,7 +974,7 @@ class ProfileTest < Test::Unit::TestCase |
982 | 974 | end |
983 | 975 | |
984 | 976 | should 'copy blocks when applying template' do |
985 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
977 | + template = fast_create(Profile) | |
986 | 978 | template.boxes.destroy_all |
987 | 979 | template.boxes << Box.new |
988 | 980 | template.boxes[0].blocks << Block.new |
... | ... | @@ -997,7 +989,7 @@ class ProfileTest < Test::Unit::TestCase |
997 | 989 | end |
998 | 990 | |
999 | 991 | should 'copy articles when applying template' do |
1000 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
992 | + template = fast_create(Profile) | |
1001 | 993 | template.articles.create(:name => 'template article') |
1002 | 994 | template.save! |
1003 | 995 | |
... | ... | @@ -1009,14 +1001,14 @@ class ProfileTest < Test::Unit::TestCase |
1009 | 1001 | end |
1010 | 1002 | |
1011 | 1003 | should 'rename existing articles when applying template' do |
1012 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
1004 | + template = fast_create(Profile) | |
1013 | 1005 | template.boxes.destroy_all |
1014 | 1006 | template.boxes << Box.new |
1015 | 1007 | template.boxes[0].blocks << Block.new |
1016 | 1008 | template.articles.create(:name => 'some article') |
1017 | 1009 | template.save! |
1018 | 1010 | |
1019 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
1011 | + p = create(Profile) | |
1020 | 1012 | p.articles.create(:name => 'some article') |
1021 | 1013 | |
1022 | 1014 | p.apply_template(template) |
... | ... | @@ -1026,11 +1018,11 @@ class ProfileTest < Test::Unit::TestCase |
1026 | 1018 | end |
1027 | 1019 | |
1028 | 1020 | should 'copy header when applying template' do |
1029 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
1021 | + template = fast_create(Profile) | |
1030 | 1022 | template[:custom_header] = '{name}' |
1031 | 1023 | template.save! |
1032 | 1024 | |
1033 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
1025 | + p = create(Profile, :name => 'test prof') | |
1034 | 1026 | |
1035 | 1027 | p.apply_template(template) |
1036 | 1028 | |
... | ... | @@ -1040,11 +1032,9 @@ class ProfileTest < Test::Unit::TestCase |
1040 | 1032 | end |
1041 | 1033 | |
1042 | 1034 | should 'copy footer when applying template' do |
1043 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address') | |
1044 | - template[:custom_footer] = '{address}' | |
1045 | - template.save! | |
1035 | + template = create(Profile, :address => 'Template address', :custom_footer => '{address}') | |
1046 | 1036 | |
1047 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof', :address => 'Profile address') | |
1037 | + p = create(Profile, :address => 'Profile address') | |
1048 | 1038 | p.apply_template(template) |
1049 | 1039 | |
1050 | 1040 | assert_equal '{address}', p[:custom_footer] |
... | ... | @@ -1053,10 +1043,9 @@ class ProfileTest < Test::Unit::TestCase |
1053 | 1043 | end |
1054 | 1044 | |
1055 | 1045 | should 'ignore failing validation when applying template' do |
1056 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address', :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header') | |
1057 | - template.save! | |
1046 | + template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header') | |
1058 | 1047 | |
1059 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof', :address => 'Profile address') | |
1048 | + p = create(Profile) | |
1060 | 1049 | def p.validate |
1061 | 1050 | self.errors.add('identifier', 'is invalid') |
1062 | 1051 | end |
... | ... | @@ -1070,26 +1059,26 @@ class ProfileTest < Test::Unit::TestCase |
1070 | 1059 | end |
1071 | 1060 | |
1072 | 1061 | should 'copy homepage when applying template' do |
1073 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address') | |
1074 | - template.articles.destroy_all | |
1075 | - a1 = template.articles.create(:name => 'some xyz article') | |
1062 | + template = fast_create(Profile) | |
1063 | + a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | |
1076 | 1064 | template.home_page = a1 |
1077 | 1065 | template.save! |
1078 | 1066 | |
1079 | - p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | |
1067 | + p = fast_create(Profile) | |
1080 | 1068 | p.apply_template(template) |
1081 | 1069 | |
1082 | 1070 | assert_not_nil p.home_page |
1083 | - assert_equal 'some xyz article', Profile['test_profile'].home_page.name | |
1071 | + assert_equal 'some xyz article', p.home_page.name | |
1084 | 1072 | end |
1085 | 1073 | |
1086 | 1074 | should 'not copy blocks default_title when applying template' do |
1087 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
1075 | + template = fast_create(Profile) | |
1088 | 1076 | template.boxes.destroy_all |
1089 | 1077 | template.boxes << Box.new |
1090 | 1078 | b = Block.new() |
1091 | 1079 | template.boxes[0].blocks << b |
1092 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
1080 | + | |
1081 | + p = create(Profile) | |
1093 | 1082 | assert b[:title].blank? |
1094 | 1083 | |
1095 | 1084 | p.copy_blocks_from(template) |
... | ... | @@ -1098,12 +1087,13 @@ class ProfileTest < Test::Unit::TestCase |
1098 | 1087 | end |
1099 | 1088 | |
1100 | 1089 | should 'copy blocks title when applying template' do |
1101 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | |
1090 | + template = fast_create(Profile) | |
1102 | 1091 | template.boxes.destroy_all |
1103 | 1092 | template.boxes << Box.new |
1104 | 1093 | b = Block.new(:title => 'default title') |
1105 | 1094 | template.boxes[0].blocks << b |
1106 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | |
1095 | + | |
1096 | + p = create(Profile) | |
1107 | 1097 | assert !b[:title].blank? |
1108 | 1098 | |
1109 | 1099 | p.copy_blocks_from(template) |
... | ... | @@ -1116,7 +1106,7 @@ class ProfileTest < Test::Unit::TestCase |
1116 | 1106 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) |
1117 | 1107 | |
1118 | 1108 | begin |
1119 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | |
1109 | + p1 = fast_create(Profile) | |
1120 | 1110 | t = Theme.new('test_theme'); t.owner = p1; t.save |
1121 | 1111 | |
1122 | 1112 | assert_equal [t], p1.themes |
... | ... | @@ -1129,7 +1119,7 @@ class ProfileTest < Test::Unit::TestCase |
1129 | 1119 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) |
1130 | 1120 | |
1131 | 1121 | begin |
1132 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | |
1122 | + p1 = fast_create(Profile) | |
1133 | 1123 | t = Theme.new('test_theme'); t.owner = p1; t.save |
1134 | 1124 | |
1135 | 1125 | assert_equal t, p1.find_theme('test_theme') |
... | ... | @@ -1139,12 +1129,12 @@ class ProfileTest < Test::Unit::TestCase |
1139 | 1129 | end |
1140 | 1130 | |
1141 | 1131 | should 'have a layout template' do |
1142 | - p = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => Environment.default) | |
1132 | + p = Profile.new | |
1143 | 1133 | assert_equal 'default', p.layout_template |
1144 | 1134 | end |
1145 | 1135 | |
1146 | 1136 | should 'get boxes limit from template' do |
1147 | - p = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => Environment.default) | |
1137 | + p = create(Profile) | |
1148 | 1138 | |
1149 | 1139 | layout = mock |
1150 | 1140 | layout.expects(:number_of_boxes).returns(6) |
... | ... | @@ -1165,11 +1155,11 @@ class ProfileTest < Test::Unit::TestCase |
1165 | 1155 | end |
1166 | 1156 | |
1167 | 1157 | should 'not be possible to have different profiles with the same identifier in the same environment' do |
1168 | - env = Environment.create!(:name => 'My test environment') | |
1158 | + env = fast_create(Environment) | |
1169 | 1159 | |
1170 | - p1 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
1160 | + p1 = fast_create(Profile, :identifier => 'mytestprofile', :environment_id => env.id) | |
1171 | 1161 | |
1172 | - p2 = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
1162 | + p2 = Profile.new(:identifier => 'mytestprofile', :environment => env) | |
1173 | 1163 | assert !p2.valid? |
1174 | 1164 | |
1175 | 1165 | assert p2.errors.on(:identifier) |
... | ... | @@ -1177,32 +1167,32 @@ class ProfileTest < Test::Unit::TestCase |
1177 | 1167 | end |
1178 | 1168 | |
1179 | 1169 | should 'be possible to have different profiles with the same identifier in different environments' do |
1180 | - p1 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile') | |
1170 | + p1 = fast_create(Profile, :identifier => 'mytestprofile') | |
1181 | 1171 | |
1182 | - env = Environment.create!(:name => 'My test environment') | |
1183 | - p2 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
1172 | + env = fast_create(Environment) | |
1173 | + p2 = create(Profile, :identifier => 'mytestprofile', :environment => env) | |
1184 | 1174 | |
1185 | 1175 | assert_not_equal p1.environment, p2.environment |
1186 | 1176 | end |
1187 | 1177 | |
1188 | 1178 | should 'has blog' do |
1189 | - p = create_user('testuser').person | |
1179 | + p = fast_create(Profile) | |
1190 | 1180 | p.articles << Blog.new(:profile => p, :name => 'blog_feed_test') |
1191 | 1181 | assert p.has_blog? |
1192 | 1182 | end |
1193 | 1183 | |
1194 | 1184 | should 'not has blog' do |
1195 | - p = create_user('testuser').person | |
1185 | + p = fast_create(Profile) | |
1196 | 1186 | assert !p.has_blog? |
1197 | 1187 | end |
1198 | 1188 | |
1199 | 1189 | should 'get nil when no blog' do |
1200 | - p = create_user('testuser').person | |
1190 | + p = fast_create(Profile) | |
1201 | 1191 | assert_nil p.blog |
1202 | 1192 | end |
1203 | 1193 | |
1204 | 1194 | should 'list admins' do |
1205 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
1195 | + c = fast_create(Profile) | |
1206 | 1196 | p = create_user('mytestuser').person |
1207 | 1197 | c.add_admin(p) |
1208 | 1198 | |
... | ... | @@ -1255,7 +1245,7 @@ class ProfileTest < Test::Unit::TestCase |
1255 | 1245 | |
1256 | 1246 | should 'find task from all environment if is admin' do |
1257 | 1247 | env = Environment.default |
1258 | - another = Environment.create!(:name => 'another_env') | |
1248 | + another = fast_create(Environment) | |
1259 | 1249 | person = Person['ze'] |
1260 | 1250 | task1 = Task.create!(:requestor => person, :target => env) |
1261 | 1251 | task2 = Task.create!(:requestor => person, :target => another) |
... | ... | @@ -1269,15 +1259,15 @@ class ProfileTest < Test::Unit::TestCase |
1269 | 1259 | end |
1270 | 1260 | |
1271 | 1261 | should 'find task by id on all environments' do |
1272 | - env = Environment.create!(:name => 'other_env') | |
1273 | - another = Environment.create!(:name => 'another_env') | |
1274 | - person = Person['ze'] | |
1262 | + other = fast_create(Environment) | |
1263 | + another = fast_create(Environment) | |
1264 | + person = Person['ze'] | |
1275 | 1265 | |
1276 | - task1 = Task.create!(:requestor => person, :target => env) | |
1266 | + task1 = Task.create!(:requestor => person, :target => other) | |
1277 | 1267 | task2 = Task.create!(:requestor => person, :target => another) |
1278 | 1268 | |
1279 | - person.stubs(:is_admin?).with(env).returns(true) | |
1280 | - Environment.find(:all).select{|i| i.name != 'other_env'}.each do |env| | |
1269 | + person.stubs(:is_admin?).with(other).returns(true) | |
1270 | + Environment.find(:all).select{|i| i != other }.each do |env| | |
1281 | 1271 | person.stubs(:is_admin?).with(env).returns(false) |
1282 | 1272 | end |
1283 | 1273 | |
... | ... | @@ -1294,18 +1284,18 @@ class ProfileTest < Test::Unit::TestCase |
1294 | 1284 | end |
1295 | 1285 | |
1296 | 1286 | should 'use its first domain hostname name if available' do |
1297 | - profile = create_user('testuser').person | |
1287 | + profile = fast_create(Profile) | |
1298 | 1288 | profile.domains << Domain.new(:name => 'myowndomain.net') |
1299 | 1289 | assert_equal 'myowndomain.net', profile.default_hostname |
1300 | 1290 | end |
1301 | 1291 | |
1302 | 1292 | should 'have a preferred domain name' do |
1303 | - person = create_user('testuser').person | |
1304 | - domain = Domain.create!(:name => 'myowndomain.net', :owner => person) | |
1305 | - person.preferred_domain = domain | |
1306 | - person.save! | |
1293 | + profile = fast_create(Profile) | |
1294 | + domain = create(Domain, :owner => profile) | |
1295 | + profile.preferred_domain = domain | |
1296 | + profile.save! | |
1307 | 1297 | |
1308 | - assert_equal domain, Person.find(person.id).preferred_domain(true) | |
1298 | + assert_equal domain, Profile.find(profile.id).preferred_domain(true) | |
1309 | 1299 | end |
1310 | 1300 | |
1311 | 1301 | should 'use preferred domain for hostname' do |
... | ... | @@ -1316,16 +1306,16 @@ class ProfileTest < Test::Unit::TestCase |
1316 | 1306 | end |
1317 | 1307 | |
1318 | 1308 | should 'provide a list of possible preferred domain names' do |
1319 | - profile = create_user('testuser').person | |
1320 | - domain1 = Domain.create!(:name => 'envdomain.net', :owner => profile.environment) | |
1321 | - domain2 = Domain.create!(:name => 'profiledomain.net', :owner => profile) | |
1309 | + profile = fast_create(Profile) | |
1310 | + domain1 = create(Domain, :owner => profile.environment) | |
1311 | + domain2 = create(Domain, :owner => profile) | |
1322 | 1312 | |
1323 | 1313 | assert_includes profile.possible_domains, domain1 |
1324 | 1314 | assert_includes profile.possible_domains, domain2 |
1325 | 1315 | end |
1326 | 1316 | |
1327 | 1317 | should 'list folder articles' do |
1328 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') | |
1318 | + profile = fast_create(Profile) | |
1329 | 1319 | Article.destroy_all |
1330 | 1320 | p1 = Folder.create!(:name => 'parent1', :profile => profile) |
1331 | 1321 | p2 = Blog.create!(:name => 'parent2', :profile => profile) |
... | ... | @@ -1340,13 +1330,13 @@ class ProfileTest < Test::Unit::TestCase |
1340 | 1330 | end |
1341 | 1331 | |
1342 | 1332 | should 'validates profile image when save' do |
1343 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
1333 | + profile = build(Profile, :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
1344 | 1334 | profile.image.expects(:valid?).returns(false).at_least_once |
1345 | 1335 | assert !profile.valid? |
1346 | 1336 | end |
1347 | 1337 | |
1348 | 1338 | should 'profile is invalid when image not valid' do |
1349 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
1339 | + profile = build(Profile, :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
1350 | 1340 | profile.image.expects(:valid?).returns(false).at_least_once |
1351 | 1341 | profile.image.errors.add(:size, "fake error") |
1352 | 1342 | assert !profile.valid? |
... | ... | @@ -1365,36 +1355,36 @@ class ProfileTest < Test::Unit::TestCase |
1365 | 1355 | end |
1366 | 1356 | |
1367 | 1357 | should 'copy header and footer after create a person' do |
1368 | - template = create_user('template').person | |
1358 | + template = fast_create(Profile) | |
1369 | 1359 | template.custom_footer = "footer customized" |
1370 | 1360 | template.custom_header = "header customized" |
1371 | 1361 | Environment.any_instance.stubs(:person_template).returns(template) |
1372 | 1362 | |
1373 | - person = create_user('mytestuser').person | |
1363 | + person = create_user_full('mytestuser').person | |
1374 | 1364 | assert_equal "footer customized", person.custom_footer |
1375 | 1365 | assert_equal "header customized", person.custom_header |
1376 | 1366 | end |
1377 | 1367 | |
1378 | 1368 | should 'provide URL to leave' do |
1379 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
1369 | + profile = build(Profile, :identifier => 'testprofile') | |
1380 | 1370 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave'}, profile.leave_url) |
1381 | 1371 | end |
1382 | 1372 | |
1383 | 1373 | should 'provide URL to join' do |
1384 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
1374 | + profile = build(Profile, :identifier => 'testprofile') | |
1385 | 1375 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'join'}, profile.join_url) |
1386 | 1376 | end |
1387 | 1377 | |
1388 | - should 'ignore categgory with id zero' do | |
1389 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
1390 | - c = Category.create!(:name => 'test cat', :environment => profile.environment) | |
1378 | + should 'ignore category with id zero' do | |
1379 | + profile = fast_create(Profile) | |
1380 | + c = fast_create(Category) | |
1391 | 1381 | profile.category_ids = ['0', c.id, nil] |
1392 | 1382 | |
1393 | 1383 | assert_equal [c], profile.categories |
1394 | 1384 | end |
1395 | 1385 | |
1396 | 1386 | should 'get first blog when has multiple blogs' do |
1397 | - p = create_user('testuser').person | |
1387 | + p = fast_create(Profile) | |
1398 | 1388 | p.blogs << Blog.new(:profile => p, :name => 'Blog one') |
1399 | 1389 | p.blogs << Blog.new(:profile => p, :name => 'Blog two') |
1400 | 1390 | p.blogs << Blog.new(:profile => p, :name => 'Blog three') |
... | ... | @@ -1403,7 +1393,7 @@ class ProfileTest < Test::Unit::TestCase |
1403 | 1393 | end |
1404 | 1394 | |
1405 | 1395 | should 'list all events' do |
1406 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
1396 | + profile = fast_create(Profile) | |
1407 | 1397 | event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today) |
1408 | 1398 | event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1) |
1409 | 1399 | profile.events << [event1, event2] |
... | ... | @@ -1412,7 +1402,7 @@ class ProfileTest < Test::Unit::TestCase |
1412 | 1402 | end |
1413 | 1403 | |
1414 | 1404 | should 'list events by day' do |
1415 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
1405 | + profile = fast_create(Profile) | |
1416 | 1406 | |
1417 | 1407 | today = Date.today |
1418 | 1408 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) |
... | ... | @@ -1425,7 +1415,7 @@ class ProfileTest < Test::Unit::TestCase |
1425 | 1415 | end |
1426 | 1416 | |
1427 | 1417 | should 'list events in a range' do |
1428 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
1418 | + profile = fast_create(Profile) | |
1429 | 1419 | |
1430 | 1420 | today = Date.today |
1431 | 1421 | event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
... | ... | @@ -1439,7 +1429,7 @@ class ProfileTest < Test::Unit::TestCase |
1439 | 1429 | end |
1440 | 1430 | |
1441 | 1431 | should 'not list events out of range' do |
1442 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
1432 | + profile = fast_create(Profile) | |
1443 | 1433 | |
1444 | 1434 | today = Date.today |
1445 | 1435 | event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
... | ... | @@ -1454,7 +1444,7 @@ class ProfileTest < Test::Unit::TestCase |
1454 | 1444 | end |
1455 | 1445 | |
1456 | 1446 | should 'sort events by name' do |
1457 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | |
1447 | + profile = fast_create(Profile) | |
1458 | 1448 | event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => Date.today) |
1459 | 1449 | event2 = Event.new(:name => 'Debian Day', :start_date => Date.today) |
1460 | 1450 | event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today) |
... | ... | @@ -1463,15 +1453,14 @@ class ProfileTest < Test::Unit::TestCase |
1463 | 1453 | end |
1464 | 1454 | |
1465 | 1455 | should 'be available if identifier doesnt exist on environment' do |
1466 | - p = create_user('identifier-test').person | |
1467 | - | |
1468 | - env = Environment.create(:name => 'Environment test') | |
1456 | + p = fast_create(Profile, :identifier => 'identifier-test') | |
1457 | + env = fast_create(Environment) | |
1469 | 1458 | assert_equal true, Profile.is_available?('identifier-test', env) |
1470 | 1459 | end |
1471 | 1460 | |
1472 | 1461 | should 'not be available if identifier exists on environment' do |
1473 | 1462 | p = create_user('identifier-test').person |
1474 | - | |
1463 | + p = fast_create(Profile, :identifier => 'identifier-test') | |
1475 | 1464 | assert_equal false, Profile.is_available?('identifier-test', Environment.default) |
1476 | 1465 | end |
1477 | 1466 | ... | ... |