Commit e243950f863081e00c6b6c51529d6c28a22a3002
1 parent
ec21830a
Exists in
master
and in
23 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 @@ | @@ -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 | module Noosfero::Factory | 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 | end | 13 | end |
| 10 | - obj.save_without_validation! | ||
| 11 | - obj | 14 | + return klass.last(:order => "id") |
| 12 | end | 15 | end |
| 13 | 16 | ||
| 14 | def create(name, attrs = {}) | 17 | def create(name, attrs = {}) |
| @@ -23,13 +26,12 @@ module Noosfero::Factory | @@ -23,13 +26,12 @@ module Noosfero::Factory | ||
| 23 | end | 26 | end |
| 24 | 27 | ||
| 25 | def build(name, attrs = {}) | 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 | end | 35 | end |
| 34 | 36 | ||
| 35 | def self.num_seq | 37 | def self.num_seq |
| @@ -38,6 +40,105 @@ module Noosfero::Factory | @@ -38,6 +40,105 @@ module Noosfero::Factory | ||
| 38 | @num_seq | 40 | @num_seq |
| 39 | end | 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 | protected | 142 | protected |
| 42 | 143 | ||
| 43 | def factory_num_seq | 144 | def factory_num_seq |
| @@ -45,6 +146,49 @@ module Noosfero::Factory | @@ -45,6 +146,49 @@ module Noosfero::Factory | ||
| 45 | end | 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 | # Blog | 192 | # Blog |
| 49 | ############################################### | 193 | ############################################### |
| 50 | def create_blog | 194 | def create_blog |
| @@ -56,7 +200,7 @@ module Noosfero::Factory | @@ -56,7 +200,7 @@ module Noosfero::Factory | ||
| 56 | # ExternalFeed | 200 | # ExternalFeed |
| 57 | ############################################### | 201 | ############################################### |
| 58 | def defaults_for_external_feed | 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 | end | 204 | end |
| 61 | 205 | ||
| 62 | def create_external_feed(attrs = {}) | 206 | def create_external_feed(attrs = {}) |
| @@ -73,4 +217,22 @@ module Noosfero::Factory | @@ -73,4 +217,22 @@ module Noosfero::Factory | ||
| 73 | { :address => RAILS_ROOT + '/test/fixtures/files/feed.xml' } | 217 | { :address => RAILS_ROOT + '/test/fixtures/files/feed.xml' } |
| 74 | end | 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 | end | 238 | end |
test/functional/application_controller_test.rb
| @@ -405,7 +405,7 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -405,7 +405,7 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
| 405 | 405 | ||
| 406 | should 'not display invisible blocks' do | 406 | should 'not display invisible blocks' do |
| 407 | @controller.expects(:uses_design_blocks?).returns(true) | 407 | @controller.expects(:uses_design_blocks?).returns(true) |
| 408 | - p = create_user('test_user').person | 408 | + p = create_user_full('test_user').person |
| 409 | @controller.expects(:profile).at_least_once.returns(p) | 409 | @controller.expects(:profile).at_least_once.returns(p) |
| 410 | b = p.blocks[1] | 410 | b = p.blocks[1] |
| 411 | b.expects(:visible).returns(false) | 411 | b.expects(:visible).returns(false) |
test/functional/profile_controller_test.rb
| @@ -139,20 +139,6 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -139,20 +139,6 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 139 | assert_tag :tag => 'a', :content => /Friends/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } | 139 | assert_tag :tag => 'a', :content => /Friends/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } |
| 140 | end | 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 | should 'display tag for profile' do | 142 | should 'display tag for profile' do |
| 157 | @profile.articles.create!(:name => 'testarticle', :tag_list => 'tag1') | 143 | @profile.articles.create!(:name => 'testarticle', :tag_list => 'tag1') |
| 158 | 144 | ||
| @@ -243,14 +229,14 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -243,14 +229,14 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 243 | 229 | ||
| 244 | should 'display add friend button' do | 230 | should 'display add friend button' do |
| 245 | login_as(@profile.identifier) | 231 | login_as(@profile.identifier) |
| 246 | - friend = create_user('friendtestuser').person | 232 | + friend = create_user_full('friendtestuser').person |
| 247 | get :index, :profile => friend.identifier | 233 | get :index, :profile => friend.identifier |
| 248 | assert_tag :tag => 'a', :content => 'Add friend' | 234 | assert_tag :tag => 'a', :content => 'Add friend' |
| 249 | end | 235 | end |
| 250 | 236 | ||
| 251 | should 'not display add friend button if user already request friendship' do | 237 | should 'not display add friend button if user already request friendship' do |
| 252 | login_as(@profile.identifier) | 238 | login_as(@profile.identifier) |
| 253 | - friend = create_user('friendtestuser').person | 239 | + friend = create_user_full('friendtestuser').person |
| 254 | AddFriend.create!(:person => @profile, :friend => friend) | 240 | AddFriend.create!(:person => @profile, :friend => friend) |
| 255 | get :index, :profile => friend.identifier | 241 | get :index, :profile => friend.identifier |
| 256 | assert_no_tag :tag => 'a', :content => 'Add friend' | 242 | assert_no_tag :tag => 'a', :content => 'Add friend' |
| @@ -258,7 +244,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -258,7 +244,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 258 | 244 | ||
| 259 | should 'not display add friend button if user already friend' do | 245 | should 'not display add friend button if user already friend' do |
| 260 | login_as(@profile.identifier) | 246 | login_as(@profile.identifier) |
| 261 | - friend = create_user('friendtestuser').person | 247 | + friend = create_user_full('friendtestuser').person |
| 262 | @profile.add_friend(friend) | 248 | @profile.add_friend(friend) |
| 263 | @profile.friends.reload | 249 | @profile.friends.reload |
| 264 | assert @profile.is_a_friend?(friend) | 250 | assert @profile.is_a_friend?(friend) |
| @@ -369,7 +355,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -369,7 +355,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 369 | end | 355 | end |
| 370 | 356 | ||
| 371 | should 'display contact button only if friends' do | 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 | @profile.add_friend(friend) | 359 | @profile.add_friend(friend) |
| 374 | env = Environment.default | 360 | env = Environment.default |
| 375 | env.disable('disable_contact_person') | 361 | env.disable('disable_contact_person') |
| @@ -380,14 +366,14 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -380,14 +366,14 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 380 | end | 366 | end |
| 381 | 367 | ||
| 382 | should 'not display contact button if no friends' do | 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 | login_as(@profile.identifier) | 370 | login_as(@profile.identifier) |
| 385 | get :index, :profile => nofriend.identifier | 371 | get :index, :profile => nofriend.identifier |
| 386 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{nofriend.identifier}/new" } | 372 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{nofriend.identifier}/new" } |
| 387 | end | 373 | end |
| 388 | 374 | ||
| 389 | should 'display contact button only if friends and its enable in environment' do | 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 | env = Environment.default | 377 | env = Environment.default |
| 392 | env.disable('disable_contact_person') | 378 | env.disable('disable_contact_person') |
| 393 | env.save! | 379 | env.save! |
| @@ -398,7 +384,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -398,7 +384,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 398 | end | 384 | end |
| 399 | 385 | ||
| 400 | should 'not display contact button if friends and its disable in environment' do | 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 | env = Environment.default | 388 | env = Environment.default |
| 403 | env.enable('disable_contact_person') | 389 | env.enable('disable_contact_person') |
| 404 | env.save! | 390 | env.save! |
| @@ -409,7 +395,6 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -409,7 +395,6 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 409 | end | 395 | end |
| 410 | 396 | ||
| 411 | should 'display contact button for community if its enable in environment' do | 397 | should 'display contact button for community if its enable in environment' do |
| 412 | - friend = create_user('friend_user').person | ||
| 413 | env = Environment.default | 398 | env = Environment.default |
| 414 | community = Community.create!(:name => 'my test community', :environment => env) | 399 | community = Community.create!(:name => 'my test community', :environment => env) |
| 415 | env.disable('disable_contact_community') | 400 | env.disable('disable_contact_community') |
test/functional/profile_members_controller_test.rb
| @@ -220,7 +220,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -220,7 +220,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
| 220 | 220 | ||
| 221 | should 'find users' do | 221 | should 'find users' do |
| 222 | ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') | 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 | u = create_user_with_permission('ent_user', 'manage_memberships', ent) | 224 | u = create_user_with_permission('ent_user', 'manage_memberships', ent) |
| 225 | login_as :ent_user | 225 | login_as :ent_user |
| 226 | 226 | ||
| @@ -240,8 +240,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -240,8 +240,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
| 240 | end | 240 | end |
| 241 | 241 | ||
| 242 | should 'return users with <query> as a prefix' do | 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 | ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') | 246 | ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') |
| 247 | p = create_user_with_permission('test_user', 'manage_memberships', ent) | 247 | p = create_user_with_permission('test_user', 'manage_memberships', ent) |
test/test_helper.rb
| @@ -68,56 +68,6 @@ class Test::Unit::TestCase | @@ -68,56 +68,6 @@ class Test::Unit::TestCase | ||
| 68 | 68 | ||
| 69 | end | 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 | alias :ok :assert_block | 71 | alias :ok :assert_block |
| 122 | 72 | ||
| 123 | def assert_equivalent(enum1, enum2) | 73 | def assert_equivalent(enum1, enum2) |
| @@ -247,7 +197,6 @@ class ActionController::IntegrationTest | @@ -247,7 +197,6 @@ class ActionController::IntegrationTest | ||
| 247 | assert_tag :tag => 'a', :attributes => { :href => '/account/logout' } | 197 | assert_tag :tag => 'a', :attributes => { :href => '/account/logout' } |
| 248 | end | 198 | end |
| 249 | 199 | ||
| 250 | - | ||
| 251 | def login(username, password) | 200 | def login(username, password) |
| 252 | ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | 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,15 +735,17 @@ class ArticleTest < Test::Unit::TestCase | ||
| 735 | end | 735 | end |
| 736 | 736 | ||
| 737 | should 'not get tagged with tag from other environment' do | 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 | end | 749 | end |
| 748 | 750 | ||
| 749 | should 'ignore category with zero as id' do | 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,8 +23,15 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
| 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' | 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' |
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | - should 'display invisible block for editing' do | 26 | + def create_user_with_blocks |
| 27 | p = create_user('test_user').person | 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 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] | 35 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] |
| 29 | b.visible = false; b.save! | 36 | b.visible = false; b.save! |
| 30 | box = b.box | 37 | box = b.box |
| @@ -37,7 +44,8 @@ class BoxesHelperTest < Test::Unit::TestCase | @@ -37,7 +44,8 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
| 37 | end | 44 | end |
| 38 | 45 | ||
| 39 | should 'not display invisible block' do | 46 | should 'not display invisible block' do |
| 40 | - p = create_user('test_user').person | 47 | + p = create_user_with_blocks |
| 48 | + | ||
| 41 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] | 49 | b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] |
| 42 | b.visible = false; b.save! | 50 | b.visible = false; b.save! |
| 43 | box = b.box | 51 | box = b.box |
test/unit/create_enterprise_test.rb
| @@ -28,7 +28,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -28,7 +28,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
| 28 | task.valid? | 28 | task.valid? |
| 29 | 29 | ||
| 30 | assert task.errors.invalid?(:requestor_id) | 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 | task.valid? | 32 | task.valid? |
| 33 | assert !task.errors.invalid?(:requestor_id) | 33 | assert !task.errors.invalid?(:requestor_id) |
| 34 | end | 34 | end |
| @@ -98,7 +98,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -98,7 +98,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
| 98 | region = Region.create!(:name => 'My region', :environment_id => environment.id) | 98 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
| 99 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | 99 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
| 100 | region.validators << validator | 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 | task = CreateEnterprise.create!({ | 103 | task = CreateEnterprise.create!({ |
| 104 | :name => 'My new enterprise', | 104 | :name => 'My new enterprise', |
| @@ -132,7 +132,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -132,7 +132,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
| 132 | region = Region.create!(:name => 'My region', :environment_id => environment.id) | 132 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
| 133 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | 133 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
| 134 | region.validators << validator | 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 | task = CreateEnterprise.create!({ | 137 | task = CreateEnterprise.create!({ |
| 138 | :name => 'My new enterprise', | 138 | :name => 'My new enterprise', |
| @@ -175,7 +175,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -175,7 +175,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
| 175 | region = Region.create!(:name => 'My region', :environment_id => environment.id) | 175 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
| 176 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | 176 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
| 177 | region.validators << validator | 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 | task = CreateEnterprise.new({ | 179 | task = CreateEnterprise.new({ |
| 180 | :name => 'My new enterprise', | 180 | :name => 'My new enterprise', |
| 181 | :identifier => 'mynewenterprise', | 181 | :identifier => 'mynewenterprise', |
test/unit/environment_statistics_block_test.rb
| @@ -20,36 +20,35 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase | @@ -20,36 +20,35 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase | ||
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | should 'generate statistics' do | 22 | should 'generate statistics' do |
| 23 | - env = Environment.create!(:name => "My test environment") | 23 | + env = create(Environment) |
| 24 | user1 = create_user('testuser1', :environment_id => env.id) | 24 | user1 = create_user('testuser1', :environment_id => env.id) |
| 25 | user2 = create_user('testuser2', :environment_id => env.id) | 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 | block = EnvironmentStatisticsBlock.new | 30 | block = EnvironmentStatisticsBlock.new |
| 32 | env.boxes.first.blocks << block | 31 | env.boxes.first.blocks << block |
| 33 | 32 | ||
| 34 | content = block.content | 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 | end | 38 | end |
| 40 | 39 | ||
| 41 | should 'generate statistics but not for private profiles' do | 40 | should 'generate statistics but not for private profiles' do |
| 42 | - env = Environment.create!(:name => "My test environment") | 41 | + env = create(Environment) |
| 43 | user1 = create_user('testuser1', :environment_id => env.id) | 42 | user1 = create_user('testuser1', :environment_id => env.id) |
| 44 | user2 = create_user('testuser2', :environment_id => env.id) | 43 | user2 = create_user('testuser2', :environment_id => env.id) |
| 45 | user3 = create_user('testuser3', :environment_id => env.id) | 44 | user3 = create_user('testuser3', :environment_id => env.id) |
| 46 | p = user3.person; p.public_profile = false; p.save! | 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 | block = EnvironmentStatisticsBlock.new | 53 | block = EnvironmentStatisticsBlock.new |
| 55 | env.boxes.first.blocks << block | 54 | env.boxes.first.blocks << block |
test/unit/external_feed_test.rb
| @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
| 3 | class ExternalFeedTest < ActiveSupport::TestCase | 3 | class ExternalFeedTest < ActiveSupport::TestCase |
| 4 | 4 | ||
| 5 | should 'require blog' do | 5 | should 'require blog' do |
| 6 | - e = build(:external_feed, :blog => nil) | 6 | + e = ExternalFeed.new |
| 7 | e.valid? | 7 | e.valid? |
| 8 | assert e.errors[:blog_id] | 8 | assert e.errors[:blog_id] |
| 9 | e.blog = create_blog | 9 | e.blog = create_blog |
test/unit/feed_handler_test.rb
| @@ -8,7 +8,7 @@ class FeedHandlerTest < Test::Unit::TestCase | @@ -8,7 +8,7 @@ class FeedHandlerTest < Test::Unit::TestCase | ||
| 8 | end | 8 | end |
| 9 | attr_reader :handler | 9 | attr_reader :handler |
| 10 | def container | 10 | def container |
| 11 | - @container ||= fast_create(:feed_reader_block) | 11 | + @container ||= create(:feed_reader_block) |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | should 'fetch feed content' do | 14 | should 'fetch feed content' do |
| @@ -90,7 +90,7 @@ class FeedHandlerTest < Test::Unit::TestCase | @@ -90,7 +90,7 @@ class FeedHandlerTest < Test::Unit::TestCase | ||
| 90 | [:external_feed, :feed_reader_block].each do |container_class| | 90 | [:external_feed, :feed_reader_block].each do |container_class| |
| 91 | 91 | ||
| 92 | should "reset the errors count after a successfull run (#{container_class})" do | 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 | handler.expects(:actually_process_container).with(container) | 94 | handler.expects(:actually_process_container).with(container) |
| 95 | handler.process(container) | 95 | handler.process(container) |
| 96 | assert_equal 0, container.update_errors | 96 | assert_equal 0, container.update_errors |
| @@ -99,7 +99,7 @@ class FeedHandlerTest < Test::Unit::TestCase | @@ -99,7 +99,7 @@ class FeedHandlerTest < Test::Unit::TestCase | ||
| 99 | should "set error message and disable in case of errors (#{container_class})" do | 99 | should "set error message and disable in case of errors (#{container_class})" do |
| 100 | FeedHandler.stubs(:max_errors).returns(4) | 100 | FeedHandler.stubs(:max_errors).returns(4) |
| 101 | 101 | ||
| 102 | - container = fast_create(container_class) | 102 | + container = create(container_class) |
| 103 | handler.stubs(:actually_process_container).with(container).raises(Exception.new("crash")) | 103 | handler.stubs(:actually_process_container).with(container).raises(Exception.new("crash")) |
| 104 | 104 | ||
| 105 | # in the first 4 errors, we are ok | 105 | # in the first 4 errors, we are ok |
test/unit/feed_reader_block_test.rb
| @@ -5,7 +5,7 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | @@ -5,7 +5,7 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | ||
| 5 | include DatesHelper | 5 | include DatesHelper |
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | - @feed = fast_create(:feed_reader_block) | 8 | + @feed = create(:feed_reader_block) |
| 9 | end | 9 | end |
| 10 | attr_reader :feed | 10 | attr_reader :feed |
| 11 | 11 |
test/unit/person_test.rb
| @@ -163,14 +163,14 @@ class PersonTest < Test::Unit::TestCase | @@ -163,14 +163,14 @@ class PersonTest < Test::Unit::TestCase | ||
| 163 | end | 163 | end |
| 164 | 164 | ||
| 165 | should 'get a default home page and a RSS feed' do | 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 | assert_kind_of Article, person.home_page | 168 | assert_kind_of Article, person.home_page |
| 169 | assert_kind_of RssFeed, person.articles.find_by_path('feed') | 169 | assert_kind_of RssFeed, person.articles.find_by_path('feed') |
| 170 | end | 170 | end |
| 171 | 171 | ||
| 172 | should 'create default set of blocks' do | 172 | should 'create default set of blocks' do |
| 173 | - p = create_user('testingblocks').person | 173 | + p = create_user_full('testingblocks').person |
| 174 | 174 | ||
| 175 | assert p.boxes[0].blocks.map(&:class).include?(MainBlock), 'person must have a MainBlock upon creation' | 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,19 +39,19 @@ class ProfileTest < Test::Unit::TestCase | ||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | should 'be assigned to default environment if no environment is informed' do | 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 | end | 43 | end |
| 44 | 44 | ||
| 45 | should 'not override environment informed before creation' do | 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 | assert_equal env, p.environment | 49 | assert_equal env, p.environment |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | should 'be able to set environment after instantiation and before creating' do | 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 | p.environment = env | 55 | p.environment = env |
| 56 | p.save! | 56 | p.save! |
| 57 | 57 | ||
| @@ -73,7 +73,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -73,7 +73,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 73 | end | 73 | end |
| 74 | 74 | ||
| 75 | should 'provide access to home page' do | 75 | should 'provide access to home page' do |
| 76 | - profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') | 76 | + profile = create(Profile) |
| 77 | assert_kind_of Article, profile.home_page | 77 | assert_kind_of Article, profile.home_page |
| 78 | end | 78 | end |
| 79 | 79 | ||
| @@ -87,7 +87,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -87,7 +87,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 87 | end | 87 | end |
| 88 | 88 | ||
| 89 | def test_can_have_affiliated_people | 89 | def test_can_have_affiliated_people |
| 90 | - pr = Profile.create(:name => 'composite_profile', :identifier => 'composite') | 90 | + pr = fast_create(Profile) |
| 91 | pe = create_user('aff', :email => 'aff@pr.coop', :password => 'blih', :password_confirmation => 'blih').person | 91 | pe = create_user('aff', :email => 'aff@pr.coop', :password => 'blih', :password_confirmation => 'blih').person |
| 92 | 92 | ||
| 93 | member_role = Role.new(:name => 'new_member_role') | 93 | member_role = Role.new(:name => 'new_member_role') |
| @@ -98,17 +98,17 @@ class ProfileTest < Test::Unit::TestCase | @@ -98,17 +98,17 @@ class ProfileTest < Test::Unit::TestCase | ||
| 98 | end | 98 | end |
| 99 | 99 | ||
| 100 | def test_find_by_contents | 100 | def test_find_by_contents |
| 101 | - p = Profile.create(:name => 'wanted', :identifier => 'wanted') | 101 | + p = create(Profile, :name => 'wanted') |
| 102 | 102 | ||
| 103 | assert Profile.find_by_contents('wanted').include?(p) | 103 | assert Profile.find_by_contents('wanted').include?(p) |
| 104 | assert ! Profile.find_by_contents('not_wanted').include?(p) | 104 | assert ! Profile.find_by_contents('not_wanted').include?(p) |
| 105 | end | 105 | end |
| 106 | 106 | ||
| 107 | should 'remove pages when removing profile' do | 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 | total = Article.count | 113 | total = Article.count |
| 114 | mine = profile.articles.count | 114 | mine = profile.articles.count |
| @@ -133,19 +133,19 @@ class ProfileTest < Test::Unit::TestCase | @@ -133,19 +133,19 @@ class ProfileTest < Test::Unit::TestCase | ||
| 133 | end | 133 | end |
| 134 | 134 | ||
| 135 | should 'provide recent documents' do | 135 | should 'provide recent documents' do |
| 136 | - profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') | 136 | + profile = fast_create(Profile) |
| 137 | profile.articles.destroy_all | 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 | assert_equal [third, second], profile.recent_documents(2) | 143 | assert_equal [third, second], profile.recent_documents(2) |
| 144 | assert_equal [third, second, first], profile.recent_documents | 144 | assert_equal [third, second, first], profile.recent_documents |
| 145 | end | 145 | end |
| 146 | 146 | ||
| 147 | should 'affiliate and provide a list of the affiliated users' do | 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 | person = create_user('test_user').person | 149 | person = create_user('test_user').person |
| 150 | role = Role.create!(:name => 'just_another_test_role') | 150 | role = Role.create!(:name => 'just_another_test_role') |
| 151 | assert profile.affiliate(person, role) | 151 | assert profile.affiliate(person, role) |
| @@ -153,8 +153,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -153,8 +153,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 153 | end | 153 | end |
| 154 | 154 | ||
| 155 | should 'authorize users that have permission on the environment' do | 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 | person = create_user('test_user').person | 158 | person = create_user('test_user').person |
| 159 | role = Role.create!(:name => 'just_another_test_role', :permissions => ['edit_profile']) | 159 | role = Role.create!(:name => 'just_another_test_role', :permissions => ['edit_profile']) |
| 160 | assert env.affiliate(person, role) | 160 | assert env.affiliate(person, role) |
| @@ -162,29 +162,24 @@ class ProfileTest < Test::Unit::TestCase | @@ -162,29 +162,24 @@ class ProfileTest < Test::Unit::TestCase | ||
| 162 | end | 162 | end |
| 163 | 163 | ||
| 164 | should 'have articles' do | 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 | assert_raise ActiveRecord::AssociationTypeMismatch do | 167 | assert_raise ActiveRecord::AssociationTypeMismatch do |
| 169 | profile.articles << 1 | 168 | profile.articles << 1 |
| 170 | end | 169 | end |
| 171 | 170 | ||
| 172 | assert_nothing_raised do | 171 | assert_nothing_raised do |
| 173 | - profile.articles << Article.new(:name => 'testing article') | 172 | + profile.articles << build(Article) |
| 174 | end | 173 | end |
| 175 | end | 174 | end |
| 176 | 175 | ||
| 177 | should 'list top-level articles' do | 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 | top = profile.top_level_articles | 184 | top = profile.top_level_articles |
| 190 | assert top.include?(p1) | 185 | assert top.include?(p1) |
| @@ -193,8 +188,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -193,8 +188,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 193 | end | 188 | end |
| 194 | 189 | ||
| 195 | should 'be able to optionally reload the list of top level articles' do | 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 | list = profile.top_level_articles | 193 | list = profile.top_level_articles |
| 200 | same_list = profile.top_level_articles | 194 | same_list = profile.top_level_articles |
| @@ -205,8 +199,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -205,8 +199,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 205 | end | 199 | end |
| 206 | 200 | ||
| 207 | should 'be able to find profiles by their names with ferret' do | 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 | assert Profile.find_by_contents('small').include?(small) | 205 | assert Profile.find_by_contents('small').include?(small) |
| 212 | assert Profile.find_by_contents('big').include?(big) | 206 | assert Profile.find_by_contents('big').include?(big) |
| @@ -217,13 +211,12 @@ class ProfileTest < Test::Unit::TestCase | @@ -217,13 +211,12 @@ class ProfileTest < Test::Unit::TestCase | ||
| 217 | end | 211 | end |
| 218 | 212 | ||
| 219 | should 'provide a shortcut for picking a profile by its identifier' do | 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 | assert_equal profile, Profile['testprofile'] | 215 | assert_equal profile, Profile['testprofile'] |
| 222 | end | 216 | end |
| 223 | 217 | ||
| 224 | should 'have boxes upon creation' do | 218 | should 'have boxes upon creation' do |
| 225 | - profile = Profile.create!(:name => 'test profile', :identifier => 'testprofile') | ||
| 226 | - | 219 | + profile = create(Profile) |
| 227 | assert profile.boxes.size > 0 | 220 | assert profile.boxes.size > 0 |
| 228 | end | 221 | end |
| 229 | 222 | ||
| @@ -247,66 +240,71 @@ class ProfileTest < Test::Unit::TestCase | @@ -247,66 +240,71 @@ class ProfileTest < Test::Unit::TestCase | ||
| 247 | end | 240 | end |
| 248 | 241 | ||
| 249 | should 'provide url to itself' do | 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 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) | 246 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) |
| 253 | end | 247 | end |
| 254 | 248 | ||
| 255 | should 'provide URL to admin area' do | 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 | assert_equal({ :profile => 'testprofile', :controller => 'profile_editor', :action => 'index'}, profile.admin_url) | 253 | assert_equal({ :profile => 'testprofile', :controller => 'profile_editor', :action => 'index'}, profile.admin_url) |
| 258 | end | 254 | end |
| 259 | 255 | ||
| 260 | should 'provide URL to public profile' do | 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 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) | 260 | assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) |
| 263 | end | 261 | end |
| 264 | 262 | ||
| 265 | should "use own domain name instead of environment's for home page url" do | 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 | profile.domains << Domain.new(:name => 'micojones.net') | 265 | profile.domains << Domain.new(:name => 'micojones.net') |
| 266 | + | ||
| 268 | assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) | 267 | assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) |
| 269 | end | 268 | end |
| 270 | 269 | ||
| 271 | should 'help developers by adding a suitable port to url' do | 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 | Noosfero.expects(:url_options).returns({ :port => 9999 }) | 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 | end | 276 | end |
| 278 | 277 | ||
| 279 | should 'help developers by adding a suitable port to url options for own domain urls' do | 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 | Noosfero.expects(:url_options).returns({ :port => 9999 }) | 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 | end | 286 | end |
| 287 | 287 | ||
| 288 | should 'list article tags for profile' do | 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 | assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, profile.article_tags) | 294 | assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, profile.article_tags) |
| 295 | - | ||
| 296 | end | 295 | end |
| 297 | 296 | ||
| 298 | should 'list tags for profile' do | 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 | assert_equal(['first-tag', 'second-tag'], profile.tags.map(&:name)) | 300 | assert_equal(['first-tag', 'second-tag'], profile.tags.map(&:name)) |
| 302 | end | 301 | end |
| 303 | 302 | ||
| 304 | should 'find content tagged with given tag' do | 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 | assert_equivalent [ first, second, third], profile.find_tagged_with('first-tag') | 309 | assert_equivalent [ first, second, third], profile.find_tagged_with('first-tag') |
| 312 | assert_equivalent [ second, third ], profile.find_tagged_with('second-tag') | 310 | assert_equivalent [ second, third ], profile.find_tagged_with('second-tag') |
| @@ -337,14 +335,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -337,14 +335,14 @@ class ProfileTest < Test::Unit::TestCase | ||
| 337 | end | 335 | end |
| 338 | 336 | ||
| 339 | should 'create a homepage and a feed on creation' do | 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 | assert_kind_of Article, profile.home_page | 340 | assert_kind_of Article, profile.home_page |
| 343 | assert_kind_of RssFeed, profile.articles.find_by_path('feed') | 341 | assert_kind_of RssFeed, profile.articles.find_by_path('feed') |
| 344 | end | 342 | end |
| 345 | 343 | ||
| 346 | should 'not allow to add members' do | 344 | should 'not allow to add members' do |
| 347 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 345 | + c = fast_create(Profile) |
| 348 | p = create_user('mytestuser').person | 346 | p = create_user('mytestuser').person |
| 349 | assert_raise RuntimeError do | 347 | assert_raise RuntimeError do |
| 350 | c.add_member(p) | 348 | c.add_member(p) |
| @@ -352,7 +350,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -352,7 +350,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 352 | end | 350 | end |
| 353 | 351 | ||
| 354 | should 'allow to add administrators' do | 352 | should 'allow to add administrators' do |
| 355 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 353 | + c = fast_create(Profile) |
| 356 | p = create_user('mytestuser').person | 354 | p = create_user('mytestuser').person |
| 357 | 355 | ||
| 358 | c.add_admin(p) | 356 | c.add_admin(p) |
| @@ -361,7 +359,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -361,7 +359,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 361 | end | 359 | end |
| 362 | 360 | ||
| 363 | should 'not allow to add moderators' do | 361 | should 'not allow to add moderators' do |
| 364 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 362 | + c = fast_create(Profile) |
| 365 | p = create_user('mytestuser').person | 363 | p = create_user('mytestuser').person |
| 366 | assert_raise RuntimeError do | 364 | assert_raise RuntimeError do |
| 367 | c.add_moderator(p) | 365 | c.add_moderator(p) |
| @@ -369,7 +367,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -369,7 +367,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 369 | end | 367 | end |
| 370 | 368 | ||
| 371 | should 'have tasks' do | 369 | should 'have tasks' do |
| 372 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 370 | + c = fast_create(Profile) |
| 373 | t1 = c.tasks.build | 371 | t1 = c.tasks.build |
| 374 | t1.save! | 372 | t1.save! |
| 375 | 373 | ||
| @@ -380,7 +378,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -380,7 +378,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 380 | end | 378 | end |
| 381 | 379 | ||
| 382 | should 'have pending tasks' do | 380 | should 'have pending tasks' do |
| 383 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 381 | + c = fast_create(Profile) |
| 384 | t1 = c.tasks.build; t1.save! | 382 | t1 = c.tasks.build; t1.save! |
| 385 | t2 = c.tasks.build; t2.save!; t2.finish | 383 | t2 = c.tasks.build; t2.save!; t2.finish |
| 386 | t3 = c.tasks.build; t3.save! | 384 | t3 = c.tasks.build; t3.save! |
| @@ -389,7 +387,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -389,7 +387,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 389 | end | 387 | end |
| 390 | 388 | ||
| 391 | should 'have finished tasks' do | 389 | should 'have finished tasks' do |
| 392 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 390 | + c = fast_create(Profile) |
| 393 | t1 = c.tasks.build; t1.save! | 391 | t1 = c.tasks.build; t1.save! |
| 394 | t2 = c.tasks.build; t2.save!; t2.finish | 392 | t2 = c.tasks.build; t2.save!; t2.finish |
| 395 | t3 = c.tasks.build; t3.save!; t3.finish | 393 | t3 = c.tasks.build; t3.save!; t3.finish |
| @@ -398,12 +396,12 @@ class ProfileTest < Test::Unit::TestCase | @@ -398,12 +396,12 @@ class ProfileTest < Test::Unit::TestCase | ||
| 398 | end | 396 | end |
| 399 | 397 | ||
| 400 | should 'responds to categories' do | 398 | should 'responds to categories' do |
| 401 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 399 | + c = fast_create(Profile) |
| 402 | assert_respond_to c, :categories | 400 | assert_respond_to c, :categories |
| 403 | end | 401 | end |
| 404 | 402 | ||
| 405 | should 'have categories' do | 403 | should 'have categories' do |
| 406 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 404 | + c = fast_create(Profile) |
| 407 | cat = Environment.default.categories.build(:name => 'a category'); cat.save! | 405 | cat = Environment.default.categories.build(:name => 'a category'); cat.save! |
| 408 | c.add_category cat | 406 | c.add_category cat |
| 409 | c.save! | 407 | c.save! |
| @@ -431,13 +429,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -431,13 +429,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 431 | end | 429 | end |
| 432 | 430 | ||
| 433 | should 'advertise false to homepage and feed on creation' do | 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 | assert !profile.home_page.advertise? | 433 | assert !profile.home_page.advertise? |
| 436 | assert !profile.articles.find_by_path('feed').advertise? | 434 | assert !profile.articles.find_by_path('feed').advertise? |
| 437 | end | 435 | end |
| 438 | 436 | ||
| 439 | should 'advertise true to homepage after update' do | 437 | should 'advertise true to homepage after update' do |
| 440 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 438 | + profile = create(Profile) |
| 441 | assert !profile.home_page.advertise? | 439 | assert !profile.home_page.advertise? |
| 442 | profile.home_page.name = 'Changed name' | 440 | profile.home_page.name = 'Changed name' |
| 443 | assert profile.home_page.save! | 441 | assert profile.home_page.save! |
| @@ -445,7 +443,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -445,7 +443,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 445 | end | 443 | end |
| 446 | 444 | ||
| 447 | should 'advertise true to feed after update' do | 445 | should 'advertise true to feed after update' do |
| 448 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 446 | + profile = create(Profile) |
| 449 | assert !profile.articles.find_by_path('feed').advertise? | 447 | assert !profile.articles.find_by_path('feed').advertise? |
| 450 | profile.articles.find_by_path('feed').name = 'Changed name' | 448 | profile.articles.find_by_path('feed').name = 'Changed name' |
| 451 | assert profile.articles.find_by_path('feed').save! | 449 | assert profile.articles.find_by_path('feed').save! |
| @@ -453,15 +451,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -453,15 +451,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 453 | end | 451 | end |
| 454 | 452 | ||
| 455 | should 'have latitude and longitude' do | 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 | assert_includes Enterprise.find_within(2, :origin => [45, 45]), e | 456 | assert_includes Enterprise.find_within(2, :origin => [45, 45]), e |
| 460 | end | 457 | end |
| 461 | 458 | ||
| 462 | should 'have latitude and longitude and find' do | 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 | assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e | 462 | assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e |
| 467 | end | 463 | end |
| @@ -477,8 +473,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -477,8 +473,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 477 | end | 473 | end |
| 478 | 474 | ||
| 479 | should 'be able to find the public profiles but not private ones' do | 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 | result = Profile.find(:all, :conditions => {:public_profile => true}) | 479 | result = Profile.find(:all, :conditions => {:public_profile => true}) |
| 484 | assert_includes result, p1 | 480 | assert_includes result, p1 |
| @@ -548,24 +544,24 @@ class ProfileTest < Test::Unit::TestCase | @@ -548,24 +544,24 @@ class ProfileTest < Test::Unit::TestCase | ||
| 548 | 544 | ||
| 549 | should 'index profile identifier for searching' do | 545 | should 'index profile identifier for searching' do |
| 550 | Profile.destroy_all | 546 | Profile.destroy_all |
| 551 | - p = Profile.create!(:identifier => 'lalala', :name => 'Interesting Profile') | 547 | + p = create(Profile, :identifier => 'lalala') |
| 552 | assert_includes Profile.find_by_contents('lalala'), p | 548 | assert_includes Profile.find_by_contents('lalala'), p |
| 553 | end | 549 | end |
| 554 | 550 | ||
| 555 | should 'index profile name for searching' do | 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 | assert_includes Profile.find_by_contents('interesting'), p | 553 | assert_includes Profile.find_by_contents('interesting'), p |
| 558 | end | 554 | end |
| 559 | 555 | ||
| 560 | should 'enabled by default on creation' do | 556 | should 'enabled by default on creation' do |
| 561 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 557 | + profile = fast_create(Profile) |
| 562 | assert profile.enabled? | 558 | assert profile.enabled? |
| 563 | end | 559 | end |
| 564 | 560 | ||
| 565 | should 'categorize in the entire category hierarchy' do | 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 | profile = create_user('testuser').person | 566 | profile = create_user('testuser').person |
| 571 | profile.add_category(c3) | 567 | profile.add_category(c3) |
| @@ -580,11 +576,11 @@ class ProfileTest < Test::Unit::TestCase | @@ -580,11 +576,11 @@ class ProfileTest < Test::Unit::TestCase | ||
| 580 | end | 576 | end |
| 581 | 577 | ||
| 582 | should 'redefine the entire category set at once' do | 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 | profile.add_category(c4) | 585 | profile.add_category(c4) |
| 590 | 586 | ||
| @@ -594,33 +590,33 @@ class ProfileTest < Test::Unit::TestCase | @@ -594,33 +590,33 @@ class ProfileTest < Test::Unit::TestCase | ||
| 594 | end | 590 | end |
| 595 | 591 | ||
| 596 | should 'be able to create an profile already with categories' do | 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 | assert_equivalent [c1, c2], profile.categories(true) | 598 | assert_equivalent [c1, c2], profile.categories(true) |
| 603 | end | 599 | end |
| 604 | 600 | ||
| 605 | should 'be associated with a region' do | 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 | assert_equal region, profile.region | 605 | assert_equal region, profile.region |
| 610 | end | 606 | end |
| 611 | 607 | ||
| 612 | should 'categorized automatically in its region' do | 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 | assert_equal [region], profile.categories(true) | 612 | assert_equal [region], profile.categories(true) |
| 617 | end | 613 | end |
| 618 | 614 | ||
| 619 | should 'change categorization when changing region' do | 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 | profile.region = region2 | 621 | profile.region = region2 |
| 626 | profile.save! | 622 | profile.save! |
| @@ -629,8 +625,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -629,8 +625,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 629 | end | 625 | end |
| 630 | 626 | ||
| 631 | should 'remove categorization when removing region' do | 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 | profile.region = nil | 631 | profile.region = nil |
| 636 | profile.save! | 632 | profile.save! |
| @@ -639,8 +635,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -639,8 +635,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 639 | end | 635 | end |
| 640 | 636 | ||
| 641 | should 'not remove region, only dissasociate from it' do | 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 | profile.region = nil | 641 | profile.region = nil |
| 646 | profile.save! | 642 | profile.save! |
| @@ -651,19 +647,18 @@ class ProfileTest < Test::Unit::TestCase | @@ -651,19 +647,18 @@ class ProfileTest < Test::Unit::TestCase | ||
| 651 | end | 647 | end |
| 652 | 648 | ||
| 653 | should 'be able to create with categories and region at the same time' do | 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 | assert_equivalent [region, category], profile.categories(true) | 654 | assert_equivalent [region, category], profile.categories(true) |
| 659 | end | 655 | end |
| 660 | 656 | ||
| 661 | should 'be able to update categories and not get regions removed' do | 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 | profile.update_attributes!(:category_ids => [category2.id]) | 663 | profile.update_attributes!(:category_ids => [category2.id]) |
| 669 | 664 | ||
| @@ -671,11 +666,10 @@ class ProfileTest < Test::Unit::TestCase | @@ -671,11 +666,10 @@ class ProfileTest < Test::Unit::TestCase | ||
| 671 | end | 666 | end |
| 672 | 667 | ||
| 673 | should 'be able to update region and not get categories removed' do | 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 | profile.update_attributes!(:region => region2) | 674 | profile.update_attributes!(:region => region2) |
| 681 | 675 | ||
| @@ -691,16 +685,16 @@ class ProfileTest < Test::Unit::TestCase | @@ -691,16 +685,16 @@ class ProfileTest < Test::Unit::TestCase | ||
| 691 | end | 685 | end |
| 692 | 686 | ||
| 693 | should 'query region for location' do | 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 | end | 691 | end |
| 698 | 692 | ||
| 699 | should 'query region hierarchy for location up to 2 levels' do | 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 | assert_equal 'Salvador - Bahia', p.location | 698 | assert_equal 'Salvador - Bahia', p.location |
| 705 | end | 699 | end |
| 706 | 700 | ||
| @@ -735,21 +729,21 @@ class ProfileTest < Test::Unit::TestCase | @@ -735,21 +729,21 @@ class ProfileTest < Test::Unit::TestCase | ||
| 735 | end | 729 | end |
| 736 | 730 | ||
| 737 | should 'default home page is a TinyMceArticle' do | 731 | should 'default home page is a TinyMceArticle' do |
| 738 | - profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') | 732 | + profile = create(Profile) |
| 739 | assert_kind_of TinyMceArticle, profile.home_page | 733 | assert_kind_of TinyMceArticle, profile.home_page |
| 740 | end | 734 | end |
| 741 | 735 | ||
| 742 | should 'not add a category twice to profile' do | 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 | profile.category_ids = [c2,c3,c3].map(&:id) | 741 | profile.category_ids = [c2,c3,c3].map(&:id) |
| 748 | assert_equal [c2, c3], profile.categories(true) | 742 | assert_equal [c2, c3], profile.categories(true) |
| 749 | end | 743 | end |
| 750 | 744 | ||
| 751 | should 'not return nil members when a member is removed from system' do | 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 | member = create_user('test_user').person | 747 | member = create_user('test_user').person |
| 754 | p.add_member(member) | 748 | p.add_member(member) |
| 755 | 749 | ||
| @@ -880,16 +874,16 @@ class ProfileTest < Test::Unit::TestCase | @@ -880,16 +874,16 @@ class ProfileTest < Test::Unit::TestCase | ||
| 880 | end | 874 | end |
| 881 | 875 | ||
| 882 | should 'respond to public? as public_profile' do | 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 | assert p1.public? | 880 | assert p1.public? |
| 887 | assert !p2.public? | 881 | assert !p2.public? |
| 888 | end | 882 | end |
| 889 | 883 | ||
| 890 | should 'create a initial private folder when a public profile is created' do | 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 | assert p1.articles.find(:first, :conditions => {:public_article => false}) | 888 | assert p1.articles.find(:first, :conditions => {:public_article => false}) |
| 895 | assert !p2.articles.find(:first, :conditions => {:public_article => false}) | 889 | assert !p2.articles.find(:first, :conditions => {:public_article => false}) |
| @@ -897,7 +891,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -897,7 +891,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 897 | 891 | ||
| 898 | should 'remove member with many roles' do | 892 | should 'remove member with many roles' do |
| 899 | person = create_user('test_user').person | 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 | community.affiliate(person, Profile::Roles.all_roles(community.environment.id)) | 895 | community.affiliate(person, Profile::Roles.all_roles(community.environment.id)) |
| 902 | 896 | ||
| 903 | community.remove_member(person) | 897 | community.remove_member(person) |
| @@ -908,12 +902,12 @@ class ProfileTest < Test::Unit::TestCase | @@ -908,12 +902,12 @@ class ProfileTest < Test::Unit::TestCase | ||
| 908 | should 'copy set of articles from a template' do | 902 | should 'copy set of articles from a template' do |
| 909 | template = create_user('test_template').person | 903 | template = create_user('test_template').person |
| 910 | template.articles.destroy_all | 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 | Profile.any_instance.stubs(:template).returns(template) | 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 | assert_equal 1, p.top_level_articles.size | 912 | assert_equal 1, p.top_level_articles.size |
| 919 | top_art = p.top_level_articles[0] | 913 | top_art = p.top_level_articles[0] |
| @@ -926,14 +920,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -926,14 +920,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 926 | should 'copy homepage from template' do | 920 | should 'copy homepage from template' do |
| 927 | template = create_user('test_template').person | 921 | template = create_user('test_template').person |
| 928 | template.articles.destroy_all | 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 | template.home_page = a1 | 924 | template.home_page = a1 |
| 931 | template.save! | 925 | template.save! |
| 932 | 926 | ||
| 933 | Profile.any_instance.stubs(:template).returns(template) | 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 | assert_not_nil p.home_page | 931 | assert_not_nil p.home_page |
| 939 | assert_equal 'some xyz article', p.home_page.name | 932 | assert_equal 'some xyz article', p.home_page.name |
| @@ -942,12 +935,11 @@ class ProfileTest < Test::Unit::TestCase | @@ -942,12 +935,11 @@ class ProfileTest < Test::Unit::TestCase | ||
| 942 | should 'not advertise the articles copied from templates' do | 935 | should 'not advertise the articles copied from templates' do |
| 943 | template = create_user('test_template').person | 936 | template = create_user('test_template').person |
| 944 | template.articles.destroy_all | 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 | Profile.any_instance.stubs(:template).returns(template) | 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 | a_copy = p.articles[0] | 944 | a_copy = p.articles[0] |
| 953 | 945 | ||
| @@ -955,7 +947,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -955,7 +947,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 955 | end | 947 | end |
| 956 | 948 | ||
| 957 | should 'copy set of boxes from profile template' do | 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 | template.boxes.destroy_all | 951 | template.boxes.destroy_all |
| 960 | template.boxes << Box.new | 952 | template.boxes << Box.new |
| 961 | template.boxes[0].blocks << Block.new | 953 | template.boxes[0].blocks << Block.new |
| @@ -963,18 +955,18 @@ class ProfileTest < Test::Unit::TestCase | @@ -963,18 +955,18 @@ class ProfileTest < Test::Unit::TestCase | ||
| 963 | 955 | ||
| 964 | Profile.any_instance.stubs(:template).returns(template) | 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 | assert_equal 1, p.boxes.size | 960 | assert_equal 1, p.boxes.size |
| 969 | assert_equal 1, p.boxes[0].blocks.size | 961 | assert_equal 1, p.boxes[0].blocks.size |
| 970 | end | 962 | end |
| 971 | 963 | ||
| 972 | should 'copy layout template when applying template' do | 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 | template.layout_template = 'leftbar' | 966 | template.layout_template = 'leftbar' |
| 975 | template.save! | 967 | template.save! |
| 976 | 968 | ||
| 977 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | 969 | + p = create(Profile) |
| 978 | 970 | ||
| 979 | p.apply_template(template) | 971 | p.apply_template(template) |
| 980 | 972 | ||
| @@ -982,7 +974,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -982,7 +974,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 982 | end | 974 | end |
| 983 | 975 | ||
| 984 | should 'copy blocks when applying template' do | 976 | should 'copy blocks when applying template' do |
| 985 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | 977 | + template = fast_create(Profile) |
| 986 | template.boxes.destroy_all | 978 | template.boxes.destroy_all |
| 987 | template.boxes << Box.new | 979 | template.boxes << Box.new |
| 988 | template.boxes[0].blocks << Block.new | 980 | template.boxes[0].blocks << Block.new |
| @@ -997,7 +989,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -997,7 +989,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 997 | end | 989 | end |
| 998 | 990 | ||
| 999 | should 'copy articles when applying template' do | 991 | should 'copy articles when applying template' do |
| 1000 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | 992 | + template = fast_create(Profile) |
| 1001 | template.articles.create(:name => 'template article') | 993 | template.articles.create(:name => 'template article') |
| 1002 | template.save! | 994 | template.save! |
| 1003 | 995 | ||
| @@ -1009,14 +1001,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -1009,14 +1001,14 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1009 | end | 1001 | end |
| 1010 | 1002 | ||
| 1011 | should 'rename existing articles when applying template' do | 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 | template.boxes.destroy_all | 1005 | template.boxes.destroy_all |
| 1014 | template.boxes << Box.new | 1006 | template.boxes << Box.new |
| 1015 | template.boxes[0].blocks << Block.new | 1007 | template.boxes[0].blocks << Block.new |
| 1016 | template.articles.create(:name => 'some article') | 1008 | template.articles.create(:name => 'some article') |
| 1017 | template.save! | 1009 | template.save! |
| 1018 | 1010 | ||
| 1019 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | 1011 | + p = create(Profile) |
| 1020 | p.articles.create(:name => 'some article') | 1012 | p.articles.create(:name => 'some article') |
| 1021 | 1013 | ||
| 1022 | p.apply_template(template) | 1014 | p.apply_template(template) |
| @@ -1026,11 +1018,11 @@ class ProfileTest < Test::Unit::TestCase | @@ -1026,11 +1018,11 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1026 | end | 1018 | end |
| 1027 | 1019 | ||
| 1028 | should 'copy header when applying template' do | 1020 | should 'copy header when applying template' do |
| 1029 | - template = Profile.create!(:name => 'test template', :identifier => 'test_template') | 1021 | + template = fast_create(Profile) |
| 1030 | template[:custom_header] = '{name}' | 1022 | template[:custom_header] = '{name}' |
| 1031 | template.save! | 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 | p.apply_template(template) | 1027 | p.apply_template(template) |
| 1036 | 1028 | ||
| @@ -1040,11 +1032,9 @@ class ProfileTest < Test::Unit::TestCase | @@ -1040,11 +1032,9 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1040 | end | 1032 | end |
| 1041 | 1033 | ||
| 1042 | should 'copy footer when applying template' do | 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 | p.apply_template(template) | 1038 | p.apply_template(template) |
| 1049 | 1039 | ||
| 1050 | assert_equal '{address}', p[:custom_footer] | 1040 | assert_equal '{address}', p[:custom_footer] |
| @@ -1053,10 +1043,9 @@ class ProfileTest < Test::Unit::TestCase | @@ -1053,10 +1043,9 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1053 | end | 1043 | end |
| 1054 | 1044 | ||
| 1055 | should 'ignore failing validation when applying template' do | 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 | def p.validate | 1049 | def p.validate |
| 1061 | self.errors.add('identifier', 'is invalid') | 1050 | self.errors.add('identifier', 'is invalid') |
| 1062 | end | 1051 | end |
| @@ -1070,26 +1059,26 @@ class ProfileTest < Test::Unit::TestCase | @@ -1070,26 +1059,26 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1070 | end | 1059 | end |
| 1071 | 1060 | ||
| 1072 | should 'copy homepage when applying template' do | 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 | template.home_page = a1 | 1064 | template.home_page = a1 |
| 1077 | template.save! | 1065 | template.save! |
| 1078 | 1066 | ||
| 1079 | - p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | 1067 | + p = fast_create(Profile) |
| 1080 | p.apply_template(template) | 1068 | p.apply_template(template) |
| 1081 | 1069 | ||
| 1082 | assert_not_nil p.home_page | 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 | end | 1072 | end |
| 1085 | 1073 | ||
| 1086 | should 'not copy blocks default_title when applying template' do | 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 | template.boxes.destroy_all | 1076 | template.boxes.destroy_all |
| 1089 | template.boxes << Box.new | 1077 | template.boxes << Box.new |
| 1090 | b = Block.new() | 1078 | b = Block.new() |
| 1091 | template.boxes[0].blocks << b | 1079 | template.boxes[0].blocks << b |
| 1092 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | 1080 | + |
| 1081 | + p = create(Profile) | ||
| 1093 | assert b[:title].blank? | 1082 | assert b[:title].blank? |
| 1094 | 1083 | ||
| 1095 | p.copy_blocks_from(template) | 1084 | p.copy_blocks_from(template) |
| @@ -1098,12 +1087,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -1098,12 +1087,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1098 | end | 1087 | end |
| 1099 | 1088 | ||
| 1100 | should 'copy blocks title when applying template' do | 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 | template.boxes.destroy_all | 1091 | template.boxes.destroy_all |
| 1103 | template.boxes << Box.new | 1092 | template.boxes << Box.new |
| 1104 | b = Block.new(:title => 'default title') | 1093 | b = Block.new(:title => 'default title') |
| 1105 | template.boxes[0].blocks << b | 1094 | template.boxes[0].blocks << b |
| 1106 | - p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') | 1095 | + |
| 1096 | + p = create(Profile) | ||
| 1107 | assert !b[:title].blank? | 1097 | assert !b[:title].blank? |
| 1108 | 1098 | ||
| 1109 | p.copy_blocks_from(template) | 1099 | p.copy_blocks_from(template) |
| @@ -1116,7 +1106,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1116,7 +1106,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1116 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) | 1106 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) |
| 1117 | 1107 | ||
| 1118 | begin | 1108 | begin |
| 1119 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | 1109 | + p1 = fast_create(Profile) |
| 1120 | t = Theme.new('test_theme'); t.owner = p1; t.save | 1110 | t = Theme.new('test_theme'); t.owner = p1; t.save |
| 1121 | 1111 | ||
| 1122 | assert_equal [t], p1.themes | 1112 | assert_equal [t], p1.themes |
| @@ -1129,7 +1119,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1129,7 +1119,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1129 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) | 1119 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) |
| 1130 | 1120 | ||
| 1131 | begin | 1121 | begin |
| 1132 | - p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1') | 1122 | + p1 = fast_create(Profile) |
| 1133 | t = Theme.new('test_theme'); t.owner = p1; t.save | 1123 | t = Theme.new('test_theme'); t.owner = p1; t.save |
| 1134 | 1124 | ||
| 1135 | assert_equal t, p1.find_theme('test_theme') | 1125 | assert_equal t, p1.find_theme('test_theme') |
| @@ -1139,12 +1129,12 @@ class ProfileTest < Test::Unit::TestCase | @@ -1139,12 +1129,12 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1139 | end | 1129 | end |
| 1140 | 1130 | ||
| 1141 | should 'have a layout template' do | 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 | assert_equal 'default', p.layout_template | 1133 | assert_equal 'default', p.layout_template |
| 1144 | end | 1134 | end |
| 1145 | 1135 | ||
| 1146 | should 'get boxes limit from template' do | 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 | layout = mock | 1139 | layout = mock |
| 1150 | layout.expects(:number_of_boxes).returns(6) | 1140 | layout.expects(:number_of_boxes).returns(6) |
| @@ -1165,11 +1155,11 @@ class ProfileTest < Test::Unit::TestCase | @@ -1165,11 +1155,11 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1165 | end | 1155 | end |
| 1166 | 1156 | ||
| 1167 | should 'not be possible to have different profiles with the same identifier in the same environment' do | 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 | assert !p2.valid? | 1163 | assert !p2.valid? |
| 1174 | 1164 | ||
| 1175 | assert p2.errors.on(:identifier) | 1165 | assert p2.errors.on(:identifier) |
| @@ -1177,32 +1167,32 @@ class ProfileTest < Test::Unit::TestCase | @@ -1177,32 +1167,32 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1177 | end | 1167 | end |
| 1178 | 1168 | ||
| 1179 | should 'be possible to have different profiles with the same identifier in different environments' do | 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 | assert_not_equal p1.environment, p2.environment | 1175 | assert_not_equal p1.environment, p2.environment |
| 1186 | end | 1176 | end |
| 1187 | 1177 | ||
| 1188 | should 'has blog' do | 1178 | should 'has blog' do |
| 1189 | - p = create_user('testuser').person | 1179 | + p = fast_create(Profile) |
| 1190 | p.articles << Blog.new(:profile => p, :name => 'blog_feed_test') | 1180 | p.articles << Blog.new(:profile => p, :name => 'blog_feed_test') |
| 1191 | assert p.has_blog? | 1181 | assert p.has_blog? |
| 1192 | end | 1182 | end |
| 1193 | 1183 | ||
| 1194 | should 'not has blog' do | 1184 | should 'not has blog' do |
| 1195 | - p = create_user('testuser').person | 1185 | + p = fast_create(Profile) |
| 1196 | assert !p.has_blog? | 1186 | assert !p.has_blog? |
| 1197 | end | 1187 | end |
| 1198 | 1188 | ||
| 1199 | should 'get nil when no blog' do | 1189 | should 'get nil when no blog' do |
| 1200 | - p = create_user('testuser').person | 1190 | + p = fast_create(Profile) |
| 1201 | assert_nil p.blog | 1191 | assert_nil p.blog |
| 1202 | end | 1192 | end |
| 1203 | 1193 | ||
| 1204 | should 'list admins' do | 1194 | should 'list admins' do |
| 1205 | - c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 1195 | + c = fast_create(Profile) |
| 1206 | p = create_user('mytestuser').person | 1196 | p = create_user('mytestuser').person |
| 1207 | c.add_admin(p) | 1197 | c.add_admin(p) |
| 1208 | 1198 | ||
| @@ -1255,7 +1245,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1255,7 +1245,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1255 | 1245 | ||
| 1256 | should 'find task from all environment if is admin' do | 1246 | should 'find task from all environment if is admin' do |
| 1257 | env = Environment.default | 1247 | env = Environment.default |
| 1258 | - another = Environment.create!(:name => 'another_env') | 1248 | + another = fast_create(Environment) |
| 1259 | person = Person['ze'] | 1249 | person = Person['ze'] |
| 1260 | task1 = Task.create!(:requestor => person, :target => env) | 1250 | task1 = Task.create!(:requestor => person, :target => env) |
| 1261 | task2 = Task.create!(:requestor => person, :target => another) | 1251 | task2 = Task.create!(:requestor => person, :target => another) |
| @@ -1269,15 +1259,15 @@ class ProfileTest < Test::Unit::TestCase | @@ -1269,15 +1259,15 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1269 | end | 1259 | end |
| 1270 | 1260 | ||
| 1271 | should 'find task by id on all environments' do | 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 | task2 = Task.create!(:requestor => person, :target => another) | 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 | person.stubs(:is_admin?).with(env).returns(false) | 1271 | person.stubs(:is_admin?).with(env).returns(false) |
| 1282 | end | 1272 | end |
| 1283 | 1273 | ||
| @@ -1294,18 +1284,18 @@ class ProfileTest < Test::Unit::TestCase | @@ -1294,18 +1284,18 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1294 | end | 1284 | end |
| 1295 | 1285 | ||
| 1296 | should 'use its first domain hostname name if available' do | 1286 | should 'use its first domain hostname name if available' do |
| 1297 | - profile = create_user('testuser').person | 1287 | + profile = fast_create(Profile) |
| 1298 | profile.domains << Domain.new(:name => 'myowndomain.net') | 1288 | profile.domains << Domain.new(:name => 'myowndomain.net') |
| 1299 | assert_equal 'myowndomain.net', profile.default_hostname | 1289 | assert_equal 'myowndomain.net', profile.default_hostname |
| 1300 | end | 1290 | end |
| 1301 | 1291 | ||
| 1302 | should 'have a preferred domain name' do | 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 | end | 1299 | end |
| 1310 | 1300 | ||
| 1311 | should 'use preferred domain for hostname' do | 1301 | should 'use preferred domain for hostname' do |
| @@ -1316,16 +1306,16 @@ class ProfileTest < Test::Unit::TestCase | @@ -1316,16 +1306,16 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1316 | end | 1306 | end |
| 1317 | 1307 | ||
| 1318 | should 'provide a list of possible preferred domain names' do | 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 | assert_includes profile.possible_domains, domain1 | 1313 | assert_includes profile.possible_domains, domain1 |
| 1324 | assert_includes profile.possible_domains, domain2 | 1314 | assert_includes profile.possible_domains, domain2 |
| 1325 | end | 1315 | end |
| 1326 | 1316 | ||
| 1327 | should 'list folder articles' do | 1317 | should 'list folder articles' do |
| 1328 | - profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') | 1318 | + profile = fast_create(Profile) |
| 1329 | Article.destroy_all | 1319 | Article.destroy_all |
| 1330 | p1 = Folder.create!(:name => 'parent1', :profile => profile) | 1320 | p1 = Folder.create!(:name => 'parent1', :profile => profile) |
| 1331 | p2 = Blog.create!(:name => 'parent2', :profile => profile) | 1321 | p2 = Blog.create!(:name => 'parent2', :profile => profile) |
| @@ -1340,13 +1330,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -1340,13 +1330,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1340 | end | 1330 | end |
| 1341 | 1331 | ||
| 1342 | should 'validates profile image when save' do | 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 | profile.image.expects(:valid?).returns(false).at_least_once | 1334 | profile.image.expects(:valid?).returns(false).at_least_once |
| 1345 | assert !profile.valid? | 1335 | assert !profile.valid? |
| 1346 | end | 1336 | end |
| 1347 | 1337 | ||
| 1348 | should 'profile is invalid when image not valid' do | 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 | profile.image.expects(:valid?).returns(false).at_least_once | 1340 | profile.image.expects(:valid?).returns(false).at_least_once |
| 1351 | profile.image.errors.add(:size, "fake error") | 1341 | profile.image.errors.add(:size, "fake error") |
| 1352 | assert !profile.valid? | 1342 | assert !profile.valid? |
| @@ -1365,36 +1355,36 @@ class ProfileTest < Test::Unit::TestCase | @@ -1365,36 +1355,36 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1365 | end | 1355 | end |
| 1366 | 1356 | ||
| 1367 | should 'copy header and footer after create a person' do | 1357 | should 'copy header and footer after create a person' do |
| 1368 | - template = create_user('template').person | 1358 | + template = fast_create(Profile) |
| 1369 | template.custom_footer = "footer customized" | 1359 | template.custom_footer = "footer customized" |
| 1370 | template.custom_header = "header customized" | 1360 | template.custom_header = "header customized" |
| 1371 | Environment.any_instance.stubs(:person_template).returns(template) | 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 | assert_equal "footer customized", person.custom_footer | 1364 | assert_equal "footer customized", person.custom_footer |
| 1375 | assert_equal "header customized", person.custom_header | 1365 | assert_equal "header customized", person.custom_header |
| 1376 | end | 1366 | end |
| 1377 | 1367 | ||
| 1378 | should 'provide URL to leave' do | 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 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave'}, profile.leave_url) | 1370 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave'}, profile.leave_url) |
| 1381 | end | 1371 | end |
| 1382 | 1372 | ||
| 1383 | should 'provide URL to join' do | 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 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'join'}, profile.join_url) | 1375 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'join'}, profile.join_url) |
| 1386 | end | 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 | profile.category_ids = ['0', c.id, nil] | 1381 | profile.category_ids = ['0', c.id, nil] |
| 1392 | 1382 | ||
| 1393 | assert_equal [c], profile.categories | 1383 | assert_equal [c], profile.categories |
| 1394 | end | 1384 | end |
| 1395 | 1385 | ||
| 1396 | should 'get first blog when has multiple blogs' do | 1386 | should 'get first blog when has multiple blogs' do |
| 1397 | - p = create_user('testuser').person | 1387 | + p = fast_create(Profile) |
| 1398 | p.blogs << Blog.new(:profile => p, :name => 'Blog one') | 1388 | p.blogs << Blog.new(:profile => p, :name => 'Blog one') |
| 1399 | p.blogs << Blog.new(:profile => p, :name => 'Blog two') | 1389 | p.blogs << Blog.new(:profile => p, :name => 'Blog two') |
| 1400 | p.blogs << Blog.new(:profile => p, :name => 'Blog three') | 1390 | p.blogs << Blog.new(:profile => p, :name => 'Blog three') |
| @@ -1403,7 +1393,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1403,7 +1393,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1403 | end | 1393 | end |
| 1404 | 1394 | ||
| 1405 | should 'list all events' do | 1395 | should 'list all events' do |
| 1406 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | 1396 | + profile = fast_create(Profile) |
| 1407 | event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today) | 1397 | event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today) |
| 1408 | event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1) | 1398 | event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1) |
| 1409 | profile.events << [event1, event2] | 1399 | profile.events << [event1, event2] |
| @@ -1412,7 +1402,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1412,7 +1402,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1412 | end | 1402 | end |
| 1413 | 1403 | ||
| 1414 | should 'list events by day' do | 1404 | should 'list events by day' do |
| 1415 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | 1405 | + profile = fast_create(Profile) |
| 1416 | 1406 | ||
| 1417 | today = Date.today | 1407 | today = Date.today |
| 1418 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) | 1408 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) |
| @@ -1425,7 +1415,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -1425,7 +1415,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1425 | end | 1415 | end |
| 1426 | 1416 | ||
| 1427 | should 'list events in a range' do | 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 | today = Date.today | 1420 | today = Date.today |
| 1431 | event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 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,7 +1429,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1439 | end | 1429 | end |
| 1440 | 1430 | ||
| 1441 | should 'not list events out of range' do | 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 | today = Date.today | 1434 | today = Date.today |
| 1445 | event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 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,7 +1444,7 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1454 | end | 1444 | end |
| 1455 | 1445 | ||
| 1456 | should 'sort events by name' do | 1446 | should 'sort events by name' do |
| 1457 | - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | 1447 | + profile = fast_create(Profile) |
| 1458 | event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => Date.today) | 1448 | event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => Date.today) |
| 1459 | event2 = Event.new(:name => 'Debian Day', :start_date => Date.today) | 1449 | event2 = Event.new(:name => 'Debian Day', :start_date => Date.today) |
| 1460 | event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today) | 1450 | event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today) |
| @@ -1463,15 +1453,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -1463,15 +1453,14 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1463 | end | 1453 | end |
| 1464 | 1454 | ||
| 1465 | should 'be available if identifier doesnt exist on environment' do | 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 | assert_equal true, Profile.is_available?('identifier-test', env) | 1458 | assert_equal true, Profile.is_available?('identifier-test', env) |
| 1470 | end | 1459 | end |
| 1471 | 1460 | ||
| 1472 | should 'not be available if identifier exists on environment' do | 1461 | should 'not be available if identifier exists on environment' do |
| 1473 | p = create_user('identifier-test').person | 1462 | p = create_user('identifier-test').person |
| 1474 | - | 1463 | + p = fast_create(Profile, :identifier => 'identifier-test') |
| 1475 | assert_equal false, Profile.is_available?('identifier-test', Environment.default) | 1464 | assert_equal false, Profile.is_available?('identifier-test', Environment.default) |
| 1476 | end | 1465 | end |
| 1477 | 1466 |