Commit 7e00c87cbb6a87241fce4b75cba74c3bd9675882
1 parent
0e75f1c2
Exists in
master
and in
11 other branches
rails4: fix integration tests
Showing
35 changed files
with
846 additions
and
834 deletions
Show diff stats
lib/authenticated_test_helper.rb
| ... | ... | @@ -1,98 +0,0 @@ |
| 1 | -module AuthenticatedTestHelper | |
| 2 | - # Sets the current user in the session from the user fixtures. | |
| 3 | - def login_as(user) | |
| 4 | - @request.session[:user] = User.find_by_login(user.to_s).id | |
| 5 | - end | |
| 6 | - | |
| 7 | - def logout | |
| 8 | - @request.session.delete(:user) | |
| 9 | - end | |
| 10 | - | |
| 11 | - def content_type(type) | |
| 12 | - @request.env['Content-Type'] = type | |
| 13 | - end | |
| 14 | - | |
| 15 | - def accept(accept) | |
| 16 | - @request.env["HTTP_ACCEPT"] = accept | |
| 17 | - end | |
| 18 | - | |
| 19 | - def authorize_as(user) | |
| 20 | - if user | |
| 21 | - @request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}" | |
| 22 | - accept 'application/xml' | |
| 23 | - content_type 'application/xml' | |
| 24 | - else | |
| 25 | - @request.env["HTTP_AUTHORIZATION"] = nil | |
| 26 | - accept nil | |
| 27 | - content_type nil | |
| 28 | - end | |
| 29 | - end | |
| 30 | - | |
| 31 | - # Assert the block redirects to the login | |
| 32 | - # | |
| 33 | - # assert_requires_login(:bob) { |c| c.get :edit, :id => 1 } | |
| 34 | - # | |
| 35 | - def assert_requires_login(login = nil) | |
| 36 | - yield HttpLoginProxy.new(self, login) | |
| 37 | - end | |
| 38 | - | |
| 39 | - def assert_http_authentication_required(login = nil) | |
| 40 | - yield XmlLoginProxy.new(self, login) | |
| 41 | - end | |
| 42 | - | |
| 43 | - def reset!(*instance_vars) | |
| 44 | - instance_vars = [:controller, :request, :response] unless instance_vars.any? | |
| 45 | - instance_vars.collect! { |v| "@#{v}".to_sym } | |
| 46 | - instance_vars.each do |var| | |
| 47 | - instance_variable_set(var, instance_variable_get(var).class.new) | |
| 48 | - end | |
| 49 | - end | |
| 50 | -end | |
| 51 | - | |
| 52 | -class BaseLoginProxy | |
| 53 | - attr_reader :controller | |
| 54 | - attr_reader :options | |
| 55 | - def initialize(controller, login) | |
| 56 | - @controller = controller | |
| 57 | - @login = login | |
| 58 | - end | |
| 59 | - | |
| 60 | - private | |
| 61 | - def authenticated | |
| 62 | - raise NotImplementedError | |
| 63 | - end | |
| 64 | - | |
| 65 | - def check | |
| 66 | - raise NotImplementedError | |
| 67 | - end | |
| 68 | - | |
| 69 | - def method_missing(method, *args) | |
| 70 | - @controller.reset! | |
| 71 | - authenticate | |
| 72 | - @controller.send(method, *args) | |
| 73 | - check | |
| 74 | - end | |
| 75 | -end | |
| 76 | - | |
| 77 | -class HttpLoginProxy < BaseLoginProxy | |
| 78 | - protected | |
| 79 | - def authenticate | |
| 80 | - @controller.login_as @login if @login | |
| 81 | - end | |
| 82 | - | |
| 83 | - def check | |
| 84 | - @controller.assert_redirected_to :controller => 'account', :action => 'login' | |
| 85 | - end | |
| 86 | -end | |
| 87 | - | |
| 88 | -class XmlLoginProxy < BaseLoginProxy | |
| 89 | - protected | |
| 90 | - def authenticate | |
| 91 | - @controller.accept 'application/xml' | |
| 92 | - @controller.authorize_as @login if @login | |
| 93 | - end | |
| 94 | - | |
| 95 | - def check | |
| 96 | - @controller.assert_response 401 | |
| 97 | - end | |
| 98 | -end |
plugins/sniffer/test/integration/sniffer_map_test.rb
test/action_tracker_test_helper.rb
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -class UserStampSweeper < ActionController::Caching::Sweeper | |
| 2 | - private | |
| 3 | - def current_user | |
| 4 | - Person.first | |
| 5 | - end | |
| 6 | -end | |
| 7 | - | |
| 8 | -module ActionTracker | |
| 9 | - class Record | |
| 10 | - def back_in_time(time = 25.hours) | |
| 11 | - self.updated_at = Time.now.ago(time) | |
| 12 | - self.send :update_without_callbacks | |
| 13 | - self | |
| 14 | - end | |
| 15 | - end | |
| 16 | -end |
test/factories.rb
| ... | ... | @@ -1,496 +0,0 @@ |
| 1 | -module Noosfero::Factory | |
| 2 | - | |
| 3 | - def fast_create(name, attrs = {}, options = {}) | |
| 4 | - defaults = defaults_for(name) | |
| 5 | - attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
| 6 | - data = defaults_for(name.to_s.gsub('::','')).merge(attrs) | |
| 7 | - klass = name.to_s.camelize.constantize | |
| 8 | - if klass.superclass != ActiveRecord::Base | |
| 9 | - data[:type] = klass.to_s | |
| 10 | - end | |
| 11 | - if options[:timestamps] | |
| 12 | - fast_insert_with_timestamps(klass, data) | |
| 13 | - else | |
| 14 | - fast_insert(klass, data) | |
| 15 | - end | |
| 16 | - obj = klass.last(:order => "id") | |
| 17 | - if options[:category] | |
| 18 | - categories = options[:category] | |
| 19 | - unless categories.is_a?(Array) | |
| 20 | - categories = [categories] | |
| 21 | - end | |
| 22 | - categories.each do |category| | |
| 23 | - obj.add_category(category) | |
| 24 | - end | |
| 25 | - end | |
| 26 | - obj | |
| 27 | - end | |
| 28 | - | |
| 29 | - def create(name, attrs = {}) | |
| 30 | - target = 'create_' + name.to_s | |
| 31 | - if respond_to?(target) | |
| 32 | - send(target, attrs) | |
| 33 | - else | |
| 34 | - obj = build name | |
| 35 | - attrs.each{ |a, v| obj.send "#{a}=", v } | |
| 36 | - obj.save! | |
| 37 | - obj | |
| 38 | - end | |
| 39 | - end | |
| 40 | - | |
| 41 | - def build(name, attrs = {}) | |
| 42 | - defaults = defaults_for(name) | |
| 43 | - attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
| 44 | - data = defaults_for(name).merge(attrs) | |
| 45 | - object = name.to_s.camelize.constantize.new | |
| 46 | - if object.respond_to?(:assign_attributes) | |
| 47 | - object.assign_attributes(data, :without_protection => true) | |
| 48 | - else | |
| 49 | - data.each { |attribute, value| object.send(attribute.to_s+'=', value) } | |
| 50 | - end | |
| 51 | - object | |
| 52 | - end | |
| 53 | - | |
| 54 | - def defaults_for(name) | |
| 55 | - send('defaults_for_' + name.to_s.underscore) | |
| 56 | - rescue | |
| 57 | - {} | |
| 58 | - end | |
| 59 | - | |
| 60 | - def self.num_seq | |
| 61 | - @num_seq ||= 0 | |
| 62 | - @num_seq += 1 | |
| 63 | - @num_seq | |
| 64 | - end | |
| 65 | - | |
| 66 | - ###### old stuff to be rearranged | |
| 67 | - def create_admin_user(env) | |
| 68 | - admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) | |
| 69 | - 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_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_organizations', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance']) | |
| 70 | - create(RoleAssignment, :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]) | |
| 71 | - admin_user.login | |
| 72 | - end | |
| 73 | - | |
| 74 | - def create_environment(domainname) | |
| 75 | - environment = fast_create(Environment) | |
| 76 | - fast_create(Domain, :name => domainname, :owner_type => 'Environment', :owner_id => environment.id) | |
| 77 | - environment | |
| 78 | - end | |
| 79 | - | |
| 80 | - # Old version of create user. Use it if you need to create an user for | |
| 81 | - # testing that passes through the actual user creation process. | |
| 82 | - # | |
| 83 | - # Be aware that this is slow, though. | |
| 84 | - def create_user_full(name = nil, options = {}, person_options = {}) | |
| 85 | - name ||= 'user' + factory_num_seq.to_s | |
| 86 | - data = { | |
| 87 | - :login => name, | |
| 88 | - :email => name + '@noosfero.org', | |
| 89 | - :password => name.underscore, | |
| 90 | - :password_confirmation => name.underscore | |
| 91 | - }.merge(options) | |
| 92 | - user = build(User, data) | |
| 93 | - user.person_data = person_options | |
| 94 | - user.save! | |
| 95 | - user | |
| 96 | - end | |
| 97 | - | |
| 98 | - def person_data | |
| 99 | - {} | |
| 100 | - end | |
| 101 | - | |
| 102 | - # This method knows way too much about the model. But since creating an | |
| 103 | - # actual user is really expensive, for tests we need a fast alternative. | |
| 104 | - def create_user(name = nil, options = {}, person_options = {}) | |
| 105 | - name ||= 'user' + factory_num_seq.to_s | |
| 106 | - environment_id = options.delete(:environment_id) || (options.delete(:environment) || Environment.default).id | |
| 107 | - | |
| 108 | - password = options.delete(:password) | |
| 109 | - password_confirmation = options.delete(:password_confirmation) | |
| 110 | - raise build(Exception, "Passwords don't match") if (password && password_confirmation && password != password_confirmation) | |
| 111 | - crypted_password = (password || name).crypt('xy') | |
| 112 | - | |
| 113 | - data = { | |
| 114 | - :login => name, | |
| 115 | - :email => name + '@noosfero.org', | |
| 116 | - :crypted_password => crypted_password, | |
| 117 | - :password_type => 'crypt', | |
| 118 | - :salt => 'xy', | |
| 119 | - :environment_id => environment_id, | |
| 120 | - }.merge(options) | |
| 121 | - user = fast_insert_with_timestamps(User, data) | |
| 122 | - person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :name => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) | |
| 123 | - homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id }) | |
| 124 | - fast_update(person, {:home_page_id => homepage.id}) | |
| 125 | - box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) | |
| 126 | - block = fast_insert(Block, { :box_id => box.id, :type => 'MainBlock', :position => 0}) | |
| 127 | - user | |
| 128 | - end | |
| 129 | - | |
| 130 | - def fast_insert(klass, data) | |
| 131 | - names = data.keys | |
| 132 | - values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) } | |
| 133 | - sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')] | |
| 134 | - klass.connection.execute(sql) | |
| 135 | - klass.last(:order => 'id') | |
| 136 | - end | |
| 137 | - | |
| 138 | - def fast_insert_with_timestamps(klass, data) | |
| 139 | - now = Time.now | |
| 140 | - fast_insert(klass, { :created_at => now, :updated_at => now}.merge(data)) | |
| 141 | - end | |
| 142 | - | |
| 143 | - def fast_update(obj, data) | |
| 144 | - obj.class.connection.execute('update %s set %s where id = %d' % [obj.class.table_name, obj.class.send(:sanitize_sql_for_assignment, data), obj.id]) | |
| 145 | - end | |
| 146 | - | |
| 147 | - def give_permission(user, permission, target) | |
| 148 | - user = Person.find_by_identifier(user) if user.kind_of?(String) | |
| 149 | - target ||= user | |
| 150 | - i = 0 | |
| 151 | - while Role.find_by_name('test_role' + i.to_s) | |
| 152 | - i+=1 | |
| 153 | - end | |
| 154 | - | |
| 155 | - role = create(Role, :name => 'test_role' + i.to_s, :permissions => [permission]) | |
| 156 | - assert user.add_role(role, target) | |
| 157 | - assert user.has_permission?(permission, target) | |
| 158 | - user | |
| 159 | - end | |
| 160 | - | |
| 161 | - def create_user_with_permission(name, permission, target= nil) | |
| 162 | - user = create_user(name).person | |
| 163 | - give_permission(user, permission, target) | |
| 164 | - end | |
| 165 | - | |
| 166 | - | |
| 167 | - protected | |
| 168 | - | |
| 169 | - def factory_num_seq | |
| 170 | - Noosfero::Factory.num_seq | |
| 171 | - end | |
| 172 | - | |
| 173 | - ############################################### | |
| 174 | - # Environment | |
| 175 | - ############################################### | |
| 176 | - | |
| 177 | - def defaults_for_environment | |
| 178 | - seq = factory_num_seq | |
| 179 | - { | |
| 180 | - :name => "Environment %d" % seq, | |
| 181 | - :contact_email => "environment%d@example.com" % seq | |
| 182 | - } | |
| 183 | - end | |
| 184 | - | |
| 185 | - ############################################### | |
| 186 | - # Enterprise | |
| 187 | - ############################################### | |
| 188 | - | |
| 189 | - def defaults_for_enterprise | |
| 190 | - n = factory_num_seq.to_s | |
| 191 | - defaults_for_profile.merge({ :identifier => "enterprise-" + n, :name => 'Enterprise ' + n }) | |
| 192 | - end | |
| 193 | - | |
| 194 | - ############################################### | |
| 195 | - # Community | |
| 196 | - ############################################### | |
| 197 | - | |
| 198 | - def defaults_for_community | |
| 199 | - n = factory_num_seq.to_s | |
| 200 | - defaults_for_profile.merge({ :identifier => "community-" + n, :name => 'Community ' + n }) | |
| 201 | - end | |
| 202 | - | |
| 203 | - ############################################### | |
| 204 | - # Person | |
| 205 | - ############################################### | |
| 206 | - | |
| 207 | - def defaults_for_person | |
| 208 | - n = factory_num_seq.to_s | |
| 209 | - defaults_for_profile.merge({ :identifier => "person-" + n, :name => 'Person ' + n, :created_at => DateTime.now }) | |
| 210 | - end | |
| 211 | - | |
| 212 | - ############################################### | |
| 213 | - # Profile | |
| 214 | - ############################################### | |
| 215 | - | |
| 216 | - def defaults_for_profile | |
| 217 | - n = factory_num_seq.to_s | |
| 218 | - { :public_profile => true, :identifier => 'profile-' + n, :name => 'Profile ' + n, :environment_id => 1 } | |
| 219 | - end | |
| 220 | - | |
| 221 | - ############################################### | |
| 222 | - # Organization | |
| 223 | - ############################################### | |
| 224 | - | |
| 225 | - def defaults_for_organization | |
| 226 | - n = factory_num_seq.to_s | |
| 227 | - defaults_for_profile.merge({:identifier => 'organization-' + n, :name => 'Organization ' + n}) | |
| 228 | - end | |
| 229 | - | |
| 230 | - ############################################### | |
| 231 | - # Article (and friends) | |
| 232 | - ############################################### | |
| 233 | - | |
| 234 | - def defaults_for_article | |
| 235 | - name = 'My article ' + factory_num_seq.to_s | |
| 236 | - { :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 237 | - end | |
| 238 | - | |
| 239 | - alias :defaults_for_text_article :defaults_for_article | |
| 240 | - alias :defaults_for_textile_article :defaults_for_article | |
| 241 | - alias :defaults_for_tiny_mce_article :defaults_for_article | |
| 242 | - alias :defaults_for_rss_feed :defaults_for_article | |
| 243 | - alias :defaults_for_published_article :defaults_for_article | |
| 244 | - alias :defaults_for_folder :defaults_for_article | |
| 245 | - | |
| 246 | - ############################################### | |
| 247 | - # Event | |
| 248 | - ############################################### | |
| 249 | - | |
| 250 | - def defaults_for_event | |
| 251 | - num = factory_num_seq.to_s | |
| 252 | - { | |
| 253 | - :name => 'My event ' + num, | |
| 254 | - :slug => 'my-event-' + num, | |
| 255 | - :path => '/my-event-' + num, | |
| 256 | - :start_date => Date.today | |
| 257 | - } | |
| 258 | - end | |
| 259 | - | |
| 260 | - ############################################### | |
| 261 | - # UploadedFile | |
| 262 | - ############################################### | |
| 263 | - | |
| 264 | - def defaults_for_uploaded_file | |
| 265 | - name = 'My uploaded file ' + factory_num_seq.to_s | |
| 266 | - { :name => name, :abstract => name } | |
| 267 | - end | |
| 268 | - | |
| 269 | - ############################################### | |
| 270 | - # Blog | |
| 271 | - ############################################### | |
| 272 | - def defaults_for_blog | |
| 273 | - name = 'My blog ' + factory_num_seq.to_s | |
| 274 | - { :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 275 | - end | |
| 276 | - | |
| 277 | - def create_blog | |
| 278 | - profile = create(Profile, :identifier => 'testuser' + factory_num_seq.to_s, :name => 'Test user') | |
| 279 | - create(Blog, :name => 'blog', :profile => profile) | |
| 280 | - end | |
| 281 | - | |
| 282 | - ############################################### | |
| 283 | - # ExternalFeed | |
| 284 | - ############################################### | |
| 285 | - def defaults_for_external_feed | |
| 286 | - { :address => Rails.root.join('test', 'fixtures', 'files', 'feed.xml'), :blog_id => factory_num_seq } | |
| 287 | - end | |
| 288 | - | |
| 289 | - def create_external_feed(attrs = {}) | |
| 290 | - feed = build(:external_feed, attrs) | |
| 291 | - feed.blog = create_blog | |
| 292 | - feed.save! | |
| 293 | - feed | |
| 294 | - end | |
| 295 | - | |
| 296 | - ############################################### | |
| 297 | - # FeedReaderBlock | |
| 298 | - ############################################### | |
| 299 | - def defaults_for_feed_reader_block | |
| 300 | - { :address => Rails.root.join('test/fixtures/files/feed.xml') } | |
| 301 | - end | |
| 302 | - | |
| 303 | - ############################################### | |
| 304 | - # Domain | |
| 305 | - ############################################### | |
| 306 | - def defaults_for_domain | |
| 307 | - { :name => 'example' + factory_num_seq.to_s + '.com' } | |
| 308 | - end | |
| 309 | - | |
| 310 | - ############################################### | |
| 311 | - # Category | |
| 312 | - ############################################### | |
| 313 | - def defaults_for_category | |
| 314 | - name = 'category' + factory_num_seq.to_s | |
| 315 | - { :environment_id => 1, :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 316 | - end | |
| 317 | - | |
| 318 | - alias :defaults_for_region :defaults_for_category | |
| 319 | - alias :defaults_for_product_category :defaults_for_category | |
| 320 | - | |
| 321 | - ############################################### | |
| 322 | - # Box | |
| 323 | - ############################################### | |
| 324 | - def defaults_for_box | |
| 325 | - { } | |
| 326 | - end | |
| 327 | - | |
| 328 | - ############################################### | |
| 329 | - # Block | |
| 330 | - ############################################### | |
| 331 | - def defaults_for_block | |
| 332 | - { } | |
| 333 | - end | |
| 334 | - | |
| 335 | - alias :defaults_for_blog_archives_block :defaults_for_block | |
| 336 | - alias :defaults_for_profile_list_block :defaults_for_block | |
| 337 | - | |
| 338 | - ############################################### | |
| 339 | - # Task | |
| 340 | - ############################################### | |
| 341 | - def defaults_for_task | |
| 342 | - { :code => "task_for_test_#{factory_num_seq.to_s}" } | |
| 343 | - end | |
| 344 | - | |
| 345 | - alias :defaults_for_add_friend :defaults_for_task | |
| 346 | - alias :defaults_for_add_member :defaults_for_task | |
| 347 | - alias :defaults_for_create_community :defaults_for_task | |
| 348 | - alias :defaults_for_email_activation :defaults_for_task | |
| 349 | - | |
| 350 | - ############################################### | |
| 351 | - # Product | |
| 352 | - ############################################### | |
| 353 | - | |
| 354 | - def defaults_for_product | |
| 355 | - { :name => 'Product ' + factory_num_seq.to_s } | |
| 356 | - end | |
| 357 | - | |
| 358 | - ############################################### | |
| 359 | - # Input | |
| 360 | - ############################################### | |
| 361 | - | |
| 362 | - def defaults_for_input | |
| 363 | - { } | |
| 364 | - end | |
| 365 | - | |
| 366 | - ############################################### | |
| 367 | - # Contact | |
| 368 | - ############################################### | |
| 369 | - | |
| 370 | - def defaults_for_contact | |
| 371 | - { :subject => 'hello there', :message => 'here I come to SPAM you' } | |
| 372 | - end | |
| 373 | - | |
| 374 | - ############################################### | |
| 375 | - # Qualifier | |
| 376 | - ############################################### | |
| 377 | - | |
| 378 | - def defaults_for_qualifier | |
| 379 | - { :name => 'Qualifier ' + factory_num_seq.to_s, :environment_id => 1 } | |
| 380 | - end | |
| 381 | - | |
| 382 | - ############################################### | |
| 383 | - # Certifier | |
| 384 | - ############################################### | |
| 385 | - | |
| 386 | - def defaults_for_certifier | |
| 387 | - defaults_for_qualifier.merge({ :name => 'Certifier ' + factory_num_seq.to_s }) | |
| 388 | - end | |
| 389 | - | |
| 390 | - ############################################### | |
| 391 | - # Scrap | |
| 392 | - ############################################### | |
| 393 | - | |
| 394 | - def defaults_for_scrap(params = {}) | |
| 395 | - { :content => 'some content ', :sender_id => 1, :receiver_id => 1, :created_at => DateTime.now }.merge(params) | |
| 396 | - end | |
| 397 | - | |
| 398 | - ############################################### | |
| 399 | - # ActionTrackerNotification | |
| 400 | - ############################################### | |
| 401 | - | |
| 402 | - def defaults_for_action_tracker_notification(params = {}) | |
| 403 | - { :action_tracker_id => 1, :profile_id => 1 }.merge(params) | |
| 404 | - end | |
| 405 | - | |
| 406 | - ############################################### | |
| 407 | - # ActionTracker | |
| 408 | - ############################################### | |
| 409 | - | |
| 410 | - def defaults_for_action_tracker_record(params = {}) | |
| 411 | - { :created_at => DateTime.now, :verb => 'add_member_in_community', :user_type => 'Profile', :user_id => 1 }.merge(params) | |
| 412 | - end | |
| 413 | - | |
| 414 | - ############################################### | |
| 415 | - # Friendship | |
| 416 | - ############################################### | |
| 417 | - | |
| 418 | - def defaults_for_friendship(params = {}) | |
| 419 | - { :created_at => DateTime.now, :person_id => 1, :friend_id => 2 }.merge(params) | |
| 420 | - end | |
| 421 | - | |
| 422 | - ############################################### | |
| 423 | - # RoleAssignment | |
| 424 | - ############################################### | |
| 425 | - | |
| 426 | - def defaults_for_role_assignment(params = {}) | |
| 427 | - { :role_id => 1, :accessor_id => 1, :accessor_type => 'Profile', :resource_id => 2, :resource_type => 'Profile' }.merge(params) | |
| 428 | - end | |
| 429 | - | |
| 430 | - ############################################### | |
| 431 | - # User | |
| 432 | - ############################################### | |
| 433 | - | |
| 434 | - def defaults_for_user(params = {}) | |
| 435 | - username = "user_#{rand(1000)}" | |
| 436 | - { :login => username, :email => username + '@noosfero.colivre', :crypted_password => 'test'}.merge(params) | |
| 437 | - end | |
| 438 | - | |
| 439 | - ############################################### | |
| 440 | - # Forum | |
| 441 | - ############################################### | |
| 442 | - | |
| 443 | - def defaults_for_forum(params = {}) | |
| 444 | - name = "forum_#{rand(1000)}" | |
| 445 | - { :profile_id => 1, :path => name.to_slug, :name => name, :slug => name.to_slug }.merge(params) | |
| 446 | - end | |
| 447 | - | |
| 448 | - ############################################### | |
| 449 | - # Gallery | |
| 450 | - ############################################### | |
| 451 | - | |
| 452 | - def defaults_for_gallery(params = {}) | |
| 453 | - name = "gallery_#{rand(1000)}" | |
| 454 | - { :profile_id => 1, :path => name.to_slug, :name => name, :slug => name.to_slug }.merge(params) | |
| 455 | - end | |
| 456 | - | |
| 457 | - def defaults_for_suggest_article | |
| 458 | - { :name => 'Sender', :email => 'sender@example.com', :article => {:name => 'Some title', :body => 'some body text', :abstract => 'some abstract text'}} | |
| 459 | - end | |
| 460 | - | |
| 461 | - def defaults_for_comment(params = {}) | |
| 462 | - name = "comment_#{rand(1000)}" | |
| 463 | - { :title => name, :body => "my own comment", :source_id => 1, :source_type => 'Article' }.merge(params) | |
| 464 | - end | |
| 465 | - | |
| 466 | - ############################################### | |
| 467 | - # Unit | |
| 468 | - ############################################### | |
| 469 | - | |
| 470 | - def defaults_for_unit | |
| 471 | - { :singular => 'Litre', :plural => 'Litres', :environment_id => 1 } | |
| 472 | - end | |
| 473 | - | |
| 474 | - ############################################### | |
| 475 | - # Production Cost | |
| 476 | - ############################################### | |
| 477 | - | |
| 478 | - def defaults_for_production_cost | |
| 479 | - { :name => 'Production cost ' + factory_num_seq.to_s } | |
| 480 | - end | |
| 481 | - | |
| 482 | - ############################################### | |
| 483 | - # National Region | |
| 484 | - ############################################### | |
| 485 | - | |
| 486 | - def defaults_for_national_region | |
| 487 | - { :name => 'National region ' + factory_num_seq.to_s } | |
| 488 | - end | |
| 489 | - | |
| 490 | - def defaults_for_license | |
| 491 | - name = "License #{rand(1000)}" | |
| 492 | - slug = name.to_slug | |
| 493 | - { :name => name, :url => "#{slug}.org", :slug => slug, :environment_id => 1} | |
| 494 | - end | |
| 495 | - | |
| 496 | -end |
test/functional/account_controller_test.rb
| ... | ... | @@ -2,9 +2,7 @@ require_relative "../test_helper" |
| 2 | 2 | require 'account_controller' |
| 3 | 3 | |
| 4 | 4 | class AccountControllerTest < ActionController::TestCase |
| 5 | - # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead | |
| 6 | - # Then, you can remove it from this and the units test. | |
| 7 | - include AuthenticatedTestHelper | |
| 5 | + | |
| 8 | 6 | all_fixtures |
| 9 | 7 | |
| 10 | 8 | def teardown | ... | ... |
test/integration/approve_reject_enterprise_test.rb
test/integration/assets_menu_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class AssetsMenuTest < ActionController::IntegrationTest | |
| 3 | +class AssetsMenuTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | def setup |
| 6 | 6 | # HomeController.any_instance.stubs(:get_layout).returns('application') |
| ... | ... | @@ -9,18 +9,18 @@ class AssetsMenuTest < ActionController::IntegrationTest |
| 9 | 9 | parent = Category.create!(:name => "Parent Category", :environment => Environment.default, :display_color => '#888a85') |
| 10 | 10 | @category = Category.create!(:name => "Category A", :environment => Environment.default, :parent => parent) |
| 11 | 11 | end |
| 12 | - | |
| 12 | + | |
| 13 | 13 | should 'link to uncategorized assets at site root' do |
| 14 | 14 | get '/' |
| 15 | 15 | assert_tag :tag => 'a', :attributes => { :href => '/search/contents' } |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | should 'link to assets inside category root' do |
| 19 | - (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i| | |
| 19 | + (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i| | |
| 20 | 20 | enterprise = Enterprise.create! :identifier => "ent#{i}", :name => "enterprise#{i}" |
| 21 | 21 | ProfileCategorization.add_category_to_profile(@category, enterprise) |
| 22 | 22 | end |
| 23 | - | |
| 23 | + | |
| 24 | 24 | get '/cat/parent-category/category-a' |
| 25 | 25 | assert_tag :tag => 'a', :attributes => { :href => '/search/enterprises/parent-category/category-a' } |
| 26 | 26 | end | ... | ... |
test/integration/assigning_validator_organizations_to_regions_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class AssigningValidatorOrganizationsToRegionsTest < ActionController::IntegrationTest | |
| 3 | +class AssigningValidatorOrganizationsToRegionsTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | should 'be able to properly assign organizations as validators to regions' do |
| 6 | 6 | env = Environment.default |
| ... | ... | @@ -25,7 +25,7 @@ class AssigningValidatorOrganizationsToRegionsTest < ActionController::Integrati |
| 25 | 25 | get "/admin/region_validators/region/#{region1.id}", :search => 'two' |
| 26 | 26 | assert_response :success |
| 27 | 27 | assert_tag :tag => 'form', :attributes => { :action => "/admin/region_validators/add/#{region1.id}" }, :descendant => { :tag => 'input', :attributes => { :type => 'hidden', :name => 'validator_id', :value => org2.id } } |
| 28 | - | |
| 28 | + | |
| 29 | 29 | post "/admin/region_validators/add/#{region1.id}", :validator_id => org2.id |
| 30 | 30 | assert_response :redirect |
| 31 | 31 | ... | ... |
test/integration/blocks_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class BlocksTest < ActionController::IntegrationTest | |
| 3 | +class BlocksTest < ActionDispatch::IntegrationTest | |
| 4 | + | |
| 4 | 5 | def blog_on_article_block_bootstrap |
| 5 | 6 | profile = fast_create(Profile) |
| 6 | 7 | blog = fast_create(Blog, :name => 'Blog', :profile_id => profile.id) | ... | ... |
test/integration/controller_naming_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class ControllerNamingTest < ActionController::IntegrationTest | |
| 3 | +class ControllerNamingTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | should 'not have controllers with same name in different folders' do |
| 6 | 6 | controllers = Dir.glob(Rails.root.join("app", "controllers", "**", "*_controller.rb")).map { |item| item.split(/\//).last } | ... | ... |
test/integration/editing_person_info_test.rb
test/integration/enable_disable_features_test.rb
test/integration/enterprise_registration_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class EnterpriseRegistrationTest < ActionController::IntegrationTest | |
| 3 | +class EnterpriseRegistrationTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | fixtures :users, :profiles, :environments |
| 6 | 6 | |
| ... | ... | @@ -40,7 +40,7 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest |
| 40 | 40 | assert_difference 'CreateEnterprise.count' do |
| 41 | 41 | post '/enterprise_registration', :create_enterprise => data.merge(:target_id => org.id) |
| 42 | 42 | end |
| 43 | - | |
| 43 | + | |
| 44 | 44 | assert_template 'confirmation' |
| 45 | 45 | assert_tag :tag => 'a', :attributes => { :href => '/' } |
| 46 | 46 | |
| ... | ... | @@ -63,7 +63,7 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest |
| 63 | 63 | |
| 64 | 64 | post "/myprofile/myorg/enterprise_validation/approve/#{code}" |
| 65 | 65 | assert_response :redirect |
| 66 | - | |
| 66 | + | |
| 67 | 67 | follow_redirect! |
| 68 | 68 | assert_equal "/myprofile/myorg/enterprise_validation/view_processed/#{code}", path |
| 69 | 69 | assert_tag :span, :attributes => { :class => 'validation_approved' } | ... | ... |
test/integration/forgot_password_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class ForgotPasswordTest < ActionController::IntegrationTest | |
| 3 | +class ForgotPasswordTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | def setup |
| 6 | - ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 6 | + ActionDispatch::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | def test_forgot_password_with_login | ... | ... |
test/integration/http_caching_test.rb
test/integration/login_to_the_application_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class LoginToTheApplicationTest < ActionController::IntegrationTest | |
| 3 | +class LoginToTheApplicationTest < ActionDispatch::IntegrationTest | |
| 4 | + | |
| 4 | 5 | fixtures :users, :environments, :profiles |
| 5 | 6 | |
| 6 | 7 | def test_unauthenticated_user_tries_to_access_his_control_panel | ... | ... |
test/integration/manage_documents_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class ManageDocumentsTest < ActionController::IntegrationTest | |
| 3 | +class ManageDocumentsTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | |
| 5 | 5 | all_fixtures |
| 6 | 6 | |
| ... | ... | @@ -78,18 +78,18 @@ class ManageDocumentsTest < ActionController::IntegrationTest |
| 78 | 78 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}" } |
| 79 | 79 | get '/myprofile/myuser' |
| 80 | 80 | assert_response :success |
| 81 | - | |
| 81 | + | |
| 82 | 82 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' } |
| 83 | 83 | get '/myprofile/myuser/cms' |
| 84 | 84 | assert_response :success |
| 85 | 85 | |
| 86 | - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/destroy/#{article.id}", 'data-confirm' => /Are you sure/ } | |
| 86 | + assert_tag tag: 'a', attributes: { href: "/myprofile/myuser/cms/destroy/#{article.id}" } | |
| 87 | 87 | post "/myprofile/myuser/cms/destroy/#{article.id}" |
| 88 | 88 | |
| 89 | 89 | assert_response :redirect |
| 90 | 90 | follow_redirect! |
| 91 | 91 | assert_equal "/myuser", path |
| 92 | - | |
| 92 | + | |
| 93 | 93 | # the article was actually deleted |
| 94 | 94 | assert_raise ActiveRecord::RecordNotFound do |
| 95 | 95 | Article.find(article.id) | ... | ... |
test/integration/manage_friendships_test.rb
test/integration/online_doc_test.rb
test/integration/performance_test.rb
test/integration/routing_test.rb
test/integration/search_popup_test.rb
test/integration/signup_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class SignupTest < ActionController::IntegrationTest | |
| 3 | +class SignupTest < ActionDispatch::IntegrationTest | |
| 4 | + | |
| 4 | 5 | all_fixtures |
| 5 | 6 | |
| 6 | 7 | def setup |
| 7 | - ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 8 | + ActionDispatch::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 8 | 9 | end |
| 9 | 10 | |
| 10 | 11 | def test_signup_form_submission_must_be_blocked_for_fast_bots | ... | ... |
test/integration/user_registers_at_the_application_test.rb
| 1 | 1 | require_relative "../test_helper" |
| 2 | 2 | |
| 3 | -class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest | |
| 3 | +class UserRegistersAtTheApplicationTest < ActionDispatch::IntegrationTest | |
| 4 | 4 | fixtures :users, :environments, :profiles |
| 5 | 5 | |
| 6 | 6 | def test_successfull_registration |
| ... | ... | @@ -11,7 +11,7 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest |
| 11 | 11 | get '/account/signup' |
| 12 | 12 | |
| 13 | 13 | assert_response :success |
| 14 | - | |
| 14 | + | |
| 15 | 15 | post '/account/signup', :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } |
| 16 | 16 | assert_response :success |
| 17 | 17 | |
| ... | ... | @@ -32,7 +32,7 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest |
| 32 | 32 | get '/account/signup' |
| 33 | 33 | |
| 34 | 34 | assert_response :success |
| 35 | - | |
| 35 | + | |
| 36 | 36 | post '/account/signup', :user => { :login => 'ze', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } |
| 37 | 37 | assert_response :success |
| 38 | 38 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation', :class => 'errorExplanation' } | ... | ... |
test/integration/varnish_conf_test.rb
test/noosfero_doc_test.rb
| ... | ... | @@ -1,50 +0,0 @@ |
| 1 | -# encoding: UTF-8 | |
| 2 | -require 'mocha' | |
| 3 | - | |
| 4 | -module Noosfero::DocTest | |
| 5 | - | |
| 6 | - unless defined?(ROOT) | |
| 7 | - ROOT = Rails.root.join("test", "tmp", "doc") | |
| 8 | - end | |
| 9 | - | |
| 10 | - def create_doc(section, topic, language, title, body = nil) | |
| 11 | - dir = File.join(ROOT, section) | |
| 12 | - FileUtils.mkdir_p(dir) | |
| 13 | - File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | |
| 14 | - f.puts "<h1>#{title}</h1>" | |
| 15 | - f.puts body | |
| 16 | - end | |
| 17 | - end | |
| 18 | - | |
| 19 | - def setup_doc_test | |
| 20 | - FileUtils.mkdir_p(ROOT) | |
| 21 | - | |
| 22 | - # root | |
| 23 | - create_doc('', 'index', 'en', 'Noosfero online manual') | |
| 24 | - create_doc('', 'toc', 'en', '', '<ul><li><a href="/doc/user">User features</a></li><li><a href="/doc/cms">Content Management</a></li></ul>') | |
| 25 | - # cms | |
| 26 | - create_doc('cms', 'index', 'en', 'Content Management') | |
| 27 | - create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | |
| 28 | - create_doc('cms', 'toc', 'en', '') | |
| 29 | - create_doc('cms', 'toc', 'pt', '') | |
| 30 | - create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | |
| 31 | - create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | |
| 32 | - create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | |
| 33 | - create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | |
| 34 | - # user | |
| 35 | - create_doc('user', 'index', 'en', 'User features') | |
| 36 | - create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | |
| 37 | - create_doc('user', 'toc', 'en', '<ul><li><a href="/doc/user/commenting-articles">Commenting articles</a></li><li><a href="/doc/user/acceptins-friends">Accepting friends</a></li></ul>') | |
| 38 | - create_doc('user', 'toc', 'pt', '') | |
| 39 | - create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | |
| 40 | - create_doc('user', 'accepting-friends', 'pt', 'Aceitando amigos') | |
| 41 | - create_doc('user', 'commenting-articles', 'en', 'Commenting articles', 'How to access') | |
| 42 | - create_doc('user', 'commenting-articles', 'pt', 'Comentando artigos') | |
| 43 | - | |
| 44 | - DocSection.stubs(:root_dir).returns(ROOT) | |
| 45 | - end | |
| 46 | - | |
| 47 | - def tear_down_doc_test | |
| 48 | - FileUtils.rm_rf(ROOT) | |
| 49 | - end | |
| 50 | -end |
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +class UserStampSweeper < ActionController::Caching::Sweeper | |
| 2 | + private | |
| 3 | + def current_user | |
| 4 | + Person.first | |
| 5 | + end | |
| 6 | +end | |
| 7 | + | |
| 8 | +module ActionTracker | |
| 9 | + class Record | |
| 10 | + def back_in_time(time = 25.hours) | |
| 11 | + self.updated_at = Time.now.ago(time) | |
| 12 | + self.send :update_without_callbacks | |
| 13 | + self | |
| 14 | + end | |
| 15 | + end | |
| 16 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,99 @@ |
| 1 | +module AuthenticatedTestHelper | |
| 2 | + | |
| 3 | + # Sets the current user in the session from the user fixtures. | |
| 4 | + def login_as(user) | |
| 5 | + @request.session[:user] = User.find_by_login(user.to_s).id | |
| 6 | + end | |
| 7 | + | |
| 8 | + def logout | |
| 9 | + @request.session.delete(:user) | |
| 10 | + end | |
| 11 | + | |
| 12 | + def content_type(type) | |
| 13 | + @request.env['Content-Type'] = type | |
| 14 | + end | |
| 15 | + | |
| 16 | + def accept(accept) | |
| 17 | + @request.env["HTTP_ACCEPT"] = accept | |
| 18 | + end | |
| 19 | + | |
| 20 | + def authorize_as(user) | |
| 21 | + if user | |
| 22 | + @request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}" | |
| 23 | + accept 'application/xml' | |
| 24 | + content_type 'application/xml' | |
| 25 | + else | |
| 26 | + @request.env["HTTP_AUTHORIZATION"] = nil | |
| 27 | + accept nil | |
| 28 | + content_type nil | |
| 29 | + end | |
| 30 | + end | |
| 31 | + | |
| 32 | + # Assert the block redirects to the login | |
| 33 | + # | |
| 34 | + # assert_requires_login(:bob) { |c| c.get :edit, :id => 1 } | |
| 35 | + # | |
| 36 | + def assert_requires_login(login = nil) | |
| 37 | + yield HttpLoginProxy.new(self, login) | |
| 38 | + end | |
| 39 | + | |
| 40 | + def assert_http_authentication_required(login = nil) | |
| 41 | + yield XmlLoginProxy.new(self, login) | |
| 42 | + end | |
| 43 | + | |
| 44 | + def reset!(*instance_vars) | |
| 45 | + instance_vars = [:controller, :request, :response] unless instance_vars.any? | |
| 46 | + instance_vars.collect! { |v| "@#{v}".to_sym } | |
| 47 | + instance_vars.each do |var| | |
| 48 | + instance_variable_set(var, instance_variable_get(var).class.new) | |
| 49 | + end | |
| 50 | + end | |
| 51 | +end | |
| 52 | + | |
| 53 | +class BaseLoginProxy | |
| 54 | + attr_reader :controller | |
| 55 | + attr_reader :options | |
| 56 | + def initialize(controller, login) | |
| 57 | + @controller = controller | |
| 58 | + @login = login | |
| 59 | + end | |
| 60 | + | |
| 61 | + private | |
| 62 | + def authenticated | |
| 63 | + raise NotImplementedError | |
| 64 | + end | |
| 65 | + | |
| 66 | + def check | |
| 67 | + raise NotImplementedError | |
| 68 | + end | |
| 69 | + | |
| 70 | + def method_missing(method, *args) | |
| 71 | + @controller.reset! | |
| 72 | + authenticate | |
| 73 | + @controller.send(method, *args) | |
| 74 | + check | |
| 75 | + end | |
| 76 | +end | |
| 77 | + | |
| 78 | +class HttpLoginProxy < BaseLoginProxy | |
| 79 | + protected | |
| 80 | + def authenticate | |
| 81 | + @controller.login_as @login if @login | |
| 82 | + end | |
| 83 | + | |
| 84 | + def check | |
| 85 | + @controller.assert_redirected_to :controller => 'account', :action => 'login' | |
| 86 | + end | |
| 87 | +end | |
| 88 | + | |
| 89 | +class XmlLoginProxy < BaseLoginProxy | |
| 90 | + protected | |
| 91 | + def authenticate | |
| 92 | + @controller.accept 'application/xml' | |
| 93 | + @controller.authorize_as @login if @login | |
| 94 | + end | |
| 95 | + | |
| 96 | + def check | |
| 97 | + @controller.assert_response 401 | |
| 98 | + end | |
| 99 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | + | |
| 2 | +class ActionController::TestCase | |
| 3 | + | |
| 4 | + class_attribute :default_params | |
| 5 | + self.default_params = {} | |
| 6 | + | |
| 7 | + def get path, parameters = nil, session = nil, flash = nil | |
| 8 | + super path, if parameters then self.default_params.merge parameters else self.default_params end, session, flash | |
| 9 | + end | |
| 10 | + | |
| 11 | + def post path, parameters = nil, session = nil, flash = nil | |
| 12 | + super path, if parameters then self.default_params.merge parameters else self.default_params end, session, flash | |
| 13 | + end | |
| 14 | + | |
| 15 | +end | |
| 16 | + | ... | ... |
| ... | ... | @@ -0,0 +1,496 @@ |
| 1 | +module Noosfero::Factory | |
| 2 | + | |
| 3 | + def fast_create(name, attrs = {}, options = {}) | |
| 4 | + defaults = defaults_for(name) | |
| 5 | + attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
| 6 | + data = defaults_for(name.to_s.gsub('::','')).merge(attrs) | |
| 7 | + klass = name.to_s.camelize.constantize | |
| 8 | + if klass.superclass != ActiveRecord::Base | |
| 9 | + data[:type] = klass.to_s | |
| 10 | + end | |
| 11 | + if options[:timestamps] | |
| 12 | + fast_insert_with_timestamps(klass, data) | |
| 13 | + else | |
| 14 | + fast_insert(klass, data) | |
| 15 | + end | |
| 16 | + obj = klass.last(:order => "id") | |
| 17 | + if options[:category] | |
| 18 | + categories = options[:category] | |
| 19 | + unless categories.is_a?(Array) | |
| 20 | + categories = [categories] | |
| 21 | + end | |
| 22 | + categories.each do |category| | |
| 23 | + obj.add_category(category) | |
| 24 | + end | |
| 25 | + end | |
| 26 | + obj | |
| 27 | + end | |
| 28 | + | |
| 29 | + def create(name, attrs = {}) | |
| 30 | + target = 'create_' + name.to_s | |
| 31 | + if respond_to?(target) | |
| 32 | + send(target, attrs) | |
| 33 | + else | |
| 34 | + obj = build name | |
| 35 | + attrs.each{ |a, v| obj.send "#{a}=", v } | |
| 36 | + obj.save! | |
| 37 | + obj | |
| 38 | + end | |
| 39 | + end | |
| 40 | + | |
| 41 | + def build(name, attrs = {}) | |
| 42 | + defaults = defaults_for(name) | |
| 43 | + attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
| 44 | + data = defaults_for(name).merge(attrs) | |
| 45 | + object = name.to_s.camelize.constantize.new | |
| 46 | + if object.respond_to?(:assign_attributes) | |
| 47 | + object.assign_attributes(data, :without_protection => true) | |
| 48 | + else | |
| 49 | + data.each { |attribute, value| object.send(attribute.to_s+'=', value) } | |
| 50 | + end | |
| 51 | + object | |
| 52 | + end | |
| 53 | + | |
| 54 | + def defaults_for(name) | |
| 55 | + send('defaults_for_' + name.to_s.underscore) | |
| 56 | + rescue | |
| 57 | + {} | |
| 58 | + end | |
| 59 | + | |
| 60 | + def self.num_seq | |
| 61 | + @num_seq ||= 0 | |
| 62 | + @num_seq += 1 | |
| 63 | + @num_seq | |
| 64 | + end | |
| 65 | + | |
| 66 | + ###### old stuff to be rearranged | |
| 67 | + def create_admin_user(env) | |
| 68 | + admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) | |
| 69 | + 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_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_organizations', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance']) | |
| 70 | + create(RoleAssignment, :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]) | |
| 71 | + admin_user.login | |
| 72 | + end | |
| 73 | + | |
| 74 | + def create_environment(domainname) | |
| 75 | + environment = fast_create(Environment) | |
| 76 | + fast_create(Domain, :name => domainname, :owner_type => 'Environment', :owner_id => environment.id) | |
| 77 | + environment | |
| 78 | + end | |
| 79 | + | |
| 80 | + # Old version of create user. Use it if you need to create an user for | |
| 81 | + # testing that passes through the actual user creation process. | |
| 82 | + # | |
| 83 | + # Be aware that this is slow, though. | |
| 84 | + def create_user_full(name = nil, options = {}, person_options = {}) | |
| 85 | + name ||= 'user' + factory_num_seq.to_s | |
| 86 | + data = { | |
| 87 | + :login => name, | |
| 88 | + :email => name + '@noosfero.org', | |
| 89 | + :password => name.underscore, | |
| 90 | + :password_confirmation => name.underscore | |
| 91 | + }.merge(options) | |
| 92 | + user = build(User, data) | |
| 93 | + user.person_data = person_options | |
| 94 | + user.save! | |
| 95 | + user | |
| 96 | + end | |
| 97 | + | |
| 98 | + def person_data | |
| 99 | + {} | |
| 100 | + end | |
| 101 | + | |
| 102 | + # This method knows way too much about the model. But since creating an | |
| 103 | + # actual user is really expensive, for tests we need a fast alternative. | |
| 104 | + def create_user(name = nil, options = {}, person_options = {}) | |
| 105 | + name ||= 'user' + factory_num_seq.to_s | |
| 106 | + environment_id = options.delete(:environment_id) || (options.delete(:environment) || Environment.default).id | |
| 107 | + | |
| 108 | + password = options.delete(:password) | |
| 109 | + password_confirmation = options.delete(:password_confirmation) | |
| 110 | + raise build(Exception, "Passwords don't match") if (password && password_confirmation && password != password_confirmation) | |
| 111 | + crypted_password = (password || name).crypt('xy') | |
| 112 | + | |
| 113 | + data = { | |
| 114 | + :login => name, | |
| 115 | + :email => name + '@noosfero.org', | |
| 116 | + :crypted_password => crypted_password, | |
| 117 | + :password_type => 'crypt', | |
| 118 | + :salt => 'xy', | |
| 119 | + :environment_id => environment_id, | |
| 120 | + }.merge(options) | |
| 121 | + user = fast_insert_with_timestamps(User, data) | |
| 122 | + person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :name => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) | |
| 123 | + homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id }) | |
| 124 | + fast_update(person, {:home_page_id => homepage.id}) | |
| 125 | + box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) | |
| 126 | + block = fast_insert(Block, { :box_id => box.id, :type => 'MainBlock', :position => 0}) | |
| 127 | + user | |
| 128 | + end | |
| 129 | + | |
| 130 | + def fast_insert(klass, data) | |
| 131 | + names = data.keys | |
| 132 | + values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) } | |
| 133 | + sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')] | |
| 134 | + klass.connection.execute(sql) | |
| 135 | + klass.last(:order => 'id') | |
| 136 | + end | |
| 137 | + | |
| 138 | + def fast_insert_with_timestamps(klass, data) | |
| 139 | + now = Time.now | |
| 140 | + fast_insert(klass, { :created_at => now, :updated_at => now}.merge(data)) | |
| 141 | + end | |
| 142 | + | |
| 143 | + def fast_update(obj, data) | |
| 144 | + obj.class.connection.execute('update %s set %s where id = %d' % [obj.class.table_name, obj.class.send(:sanitize_sql_for_assignment, data), obj.id]) | |
| 145 | + end | |
| 146 | + | |
| 147 | + def give_permission(user, permission, target) | |
| 148 | + user = Person.find_by_identifier(user) if user.kind_of?(String) | |
| 149 | + target ||= user | |
| 150 | + i = 0 | |
| 151 | + while Role.find_by_name('test_role' + i.to_s) | |
| 152 | + i+=1 | |
| 153 | + end | |
| 154 | + | |
| 155 | + role = create(Role, :name => 'test_role' + i.to_s, :permissions => [permission]) | |
| 156 | + assert user.add_role(role, target) | |
| 157 | + assert user.has_permission?(permission, target) | |
| 158 | + user | |
| 159 | + end | |
| 160 | + | |
| 161 | + def create_user_with_permission(name, permission, target= nil) | |
| 162 | + user = create_user(name).person | |
| 163 | + give_permission(user, permission, target) | |
| 164 | + end | |
| 165 | + | |
| 166 | + | |
| 167 | + protected | |
| 168 | + | |
| 169 | + def factory_num_seq | |
| 170 | + Noosfero::Factory.num_seq | |
| 171 | + end | |
| 172 | + | |
| 173 | + ############################################### | |
| 174 | + # Environment | |
| 175 | + ############################################### | |
| 176 | + | |
| 177 | + def defaults_for_environment | |
| 178 | + seq = factory_num_seq | |
| 179 | + { | |
| 180 | + :name => "Environment %d" % seq, | |
| 181 | + :contact_email => "environment%d@example.com" % seq | |
| 182 | + } | |
| 183 | + end | |
| 184 | + | |
| 185 | + ############################################### | |
| 186 | + # Enterprise | |
| 187 | + ############################################### | |
| 188 | + | |
| 189 | + def defaults_for_enterprise | |
| 190 | + n = factory_num_seq.to_s | |
| 191 | + defaults_for_profile.merge({ :identifier => "enterprise-" + n, :name => 'Enterprise ' + n }) | |
| 192 | + end | |
| 193 | + | |
| 194 | + ############################################### | |
| 195 | + # Community | |
| 196 | + ############################################### | |
| 197 | + | |
| 198 | + def defaults_for_community | |
| 199 | + n = factory_num_seq.to_s | |
| 200 | + defaults_for_profile.merge({ :identifier => "community-" + n, :name => 'Community ' + n }) | |
| 201 | + end | |
| 202 | + | |
| 203 | + ############################################### | |
| 204 | + # Person | |
| 205 | + ############################################### | |
| 206 | + | |
| 207 | + def defaults_for_person | |
| 208 | + n = factory_num_seq.to_s | |
| 209 | + defaults_for_profile.merge({ :identifier => "person-" + n, :name => 'Person ' + n, :created_at => DateTime.now }) | |
| 210 | + end | |
| 211 | + | |
| 212 | + ############################################### | |
| 213 | + # Profile | |
| 214 | + ############################################### | |
| 215 | + | |
| 216 | + def defaults_for_profile | |
| 217 | + n = factory_num_seq.to_s | |
| 218 | + { :public_profile => true, :identifier => 'profile-' + n, :name => 'Profile ' + n, :environment_id => 1 } | |
| 219 | + end | |
| 220 | + | |
| 221 | + ############################################### | |
| 222 | + # Organization | |
| 223 | + ############################################### | |
| 224 | + | |
| 225 | + def defaults_for_organization | |
| 226 | + n = factory_num_seq.to_s | |
| 227 | + defaults_for_profile.merge({:identifier => 'organization-' + n, :name => 'Organization ' + n}) | |
| 228 | + end | |
| 229 | + | |
| 230 | + ############################################### | |
| 231 | + # Article (and friends) | |
| 232 | + ############################################### | |
| 233 | + | |
| 234 | + def defaults_for_article | |
| 235 | + name = 'My article ' + factory_num_seq.to_s | |
| 236 | + { :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 237 | + end | |
| 238 | + | |
| 239 | + alias :defaults_for_text_article :defaults_for_article | |
| 240 | + alias :defaults_for_textile_article :defaults_for_article | |
| 241 | + alias :defaults_for_tiny_mce_article :defaults_for_article | |
| 242 | + alias :defaults_for_rss_feed :defaults_for_article | |
| 243 | + alias :defaults_for_published_article :defaults_for_article | |
| 244 | + alias :defaults_for_folder :defaults_for_article | |
| 245 | + | |
| 246 | + ############################################### | |
| 247 | + # Event | |
| 248 | + ############################################### | |
| 249 | + | |
| 250 | + def defaults_for_event | |
| 251 | + num = factory_num_seq.to_s | |
| 252 | + { | |
| 253 | + :name => 'My event ' + num, | |
| 254 | + :slug => 'my-event-' + num, | |
| 255 | + :path => '/my-event-' + num, | |
| 256 | + :start_date => Date.today | |
| 257 | + } | |
| 258 | + end | |
| 259 | + | |
| 260 | + ############################################### | |
| 261 | + # UploadedFile | |
| 262 | + ############################################### | |
| 263 | + | |
| 264 | + def defaults_for_uploaded_file | |
| 265 | + name = 'My uploaded file ' + factory_num_seq.to_s | |
| 266 | + { :name => name, :abstract => name } | |
| 267 | + end | |
| 268 | + | |
| 269 | + ############################################### | |
| 270 | + # Blog | |
| 271 | + ############################################### | |
| 272 | + def defaults_for_blog | |
| 273 | + name = 'My blog ' + factory_num_seq.to_s | |
| 274 | + { :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 275 | + end | |
| 276 | + | |
| 277 | + def create_blog | |
| 278 | + profile = create(Profile, :identifier => 'testuser' + factory_num_seq.to_s, :name => 'Test user') | |
| 279 | + create(Blog, :name => 'blog', :profile => profile) | |
| 280 | + end | |
| 281 | + | |
| 282 | + ############################################### | |
| 283 | + # ExternalFeed | |
| 284 | + ############################################### | |
| 285 | + def defaults_for_external_feed | |
| 286 | + { :address => Rails.root.join('test', 'fixtures', 'files', 'feed.xml'), :blog_id => factory_num_seq } | |
| 287 | + end | |
| 288 | + | |
| 289 | + def create_external_feed(attrs = {}) | |
| 290 | + feed = build(:external_feed, attrs) | |
| 291 | + feed.blog = create_blog | |
| 292 | + feed.save! | |
| 293 | + feed | |
| 294 | + end | |
| 295 | + | |
| 296 | + ############################################### | |
| 297 | + # FeedReaderBlock | |
| 298 | + ############################################### | |
| 299 | + def defaults_for_feed_reader_block | |
| 300 | + { :address => Rails.root.join('test/fixtures/files/feed.xml') } | |
| 301 | + end | |
| 302 | + | |
| 303 | + ############################################### | |
| 304 | + # Domain | |
| 305 | + ############################################### | |
| 306 | + def defaults_for_domain | |
| 307 | + { :name => 'example' + factory_num_seq.to_s + '.com' } | |
| 308 | + end | |
| 309 | + | |
| 310 | + ############################################### | |
| 311 | + # Category | |
| 312 | + ############################################### | |
| 313 | + def defaults_for_category | |
| 314 | + name = 'category' + factory_num_seq.to_s | |
| 315 | + { :environment_id => 1, :name => name, :slug => name.to_slug, :path => name.to_slug } | |
| 316 | + end | |
| 317 | + | |
| 318 | + alias :defaults_for_region :defaults_for_category | |
| 319 | + alias :defaults_for_product_category :defaults_for_category | |
| 320 | + | |
| 321 | + ############################################### | |
| 322 | + # Box | |
| 323 | + ############################################### | |
| 324 | + def defaults_for_box | |
| 325 | + { } | |
| 326 | + end | |
| 327 | + | |
| 328 | + ############################################### | |
| 329 | + # Block | |
| 330 | + ############################################### | |
| 331 | + def defaults_for_block | |
| 332 | + { } | |
| 333 | + end | |
| 334 | + | |
| 335 | + alias :defaults_for_blog_archives_block :defaults_for_block | |
| 336 | + alias :defaults_for_profile_list_block :defaults_for_block | |
| 337 | + | |
| 338 | + ############################################### | |
| 339 | + # Task | |
| 340 | + ############################################### | |
| 341 | + def defaults_for_task | |
| 342 | + { :code => "task_for_test_#{factory_num_seq.to_s}" } | |
| 343 | + end | |
| 344 | + | |
| 345 | + alias :defaults_for_add_friend :defaults_for_task | |
| 346 | + alias :defaults_for_add_member :defaults_for_task | |
| 347 | + alias :defaults_for_create_community :defaults_for_task | |
| 348 | + alias :defaults_for_email_activation :defaults_for_task | |
| 349 | + | |
| 350 | + ############################################### | |
| 351 | + # Product | |
| 352 | + ############################################### | |
| 353 | + | |
| 354 | + def defaults_for_product | |
| 355 | + { :name => 'Product ' + factory_num_seq.to_s } | |
| 356 | + end | |
| 357 | + | |
| 358 | + ############################################### | |
| 359 | + # Input | |
| 360 | + ############################################### | |
| 361 | + | |
| 362 | + def defaults_for_input | |
| 363 | + { } | |
| 364 | + end | |
| 365 | + | |
| 366 | + ############################################### | |
| 367 | + # Contact | |
| 368 | + ############################################### | |
| 369 | + | |
| 370 | + def defaults_for_contact | |
| 371 | + { :subject => 'hello there', :message => 'here I come to SPAM you' } | |
| 372 | + end | |
| 373 | + | |
| 374 | + ############################################### | |
| 375 | + # Qualifier | |
| 376 | + ############################################### | |
| 377 | + | |
| 378 | + def defaults_for_qualifier | |
| 379 | + { :name => 'Qualifier ' + factory_num_seq.to_s, :environment_id => 1 } | |
| 380 | + end | |
| 381 | + | |
| 382 | + ############################################### | |
| 383 | + # Certifier | |
| 384 | + ############################################### | |
| 385 | + | |
| 386 | + def defaults_for_certifier | |
| 387 | + defaults_for_qualifier.merge({ :name => 'Certifier ' + factory_num_seq.to_s }) | |
| 388 | + end | |
| 389 | + | |
| 390 | + ############################################### | |
| 391 | + # Scrap | |
| 392 | + ############################################### | |
| 393 | + | |
| 394 | + def defaults_for_scrap(params = {}) | |
| 395 | + { :content => 'some content ', :sender_id => 1, :receiver_id => 1, :created_at => DateTime.now }.merge(params) | |
| 396 | + end | |
| 397 | + | |
| 398 | + ############################################### | |
| 399 | + # ActionTrackerNotification | |
| 400 | + ############################################### | |
| 401 | + | |
| 402 | + def defaults_for_action_tracker_notification(params = {}) | |
| 403 | + { :action_tracker_id => 1, :profile_id => 1 }.merge(params) | |
| 404 | + end | |
| 405 | + | |
| 406 | + ############################################### | |
| 407 | + # ActionTracker | |
| 408 | + ############################################### | |
| 409 | + | |
| 410 | + def defaults_for_action_tracker_record(params = {}) | |
| 411 | + { :created_at => DateTime.now, :verb => 'add_member_in_community', :user_type => 'Profile', :user_id => 1 }.merge(params) | |
| 412 | + end | |
| 413 | + | |
| 414 | + ############################################### | |
| 415 | + # Friendship | |
| 416 | + ############################################### | |
| 417 | + | |
| 418 | + def defaults_for_friendship(params = {}) | |
| 419 | + { :created_at => DateTime.now, :person_id => 1, :friend_id => 2 }.merge(params) | |
| 420 | + end | |
| 421 | + | |
| 422 | + ############################################### | |
| 423 | + # RoleAssignment | |
| 424 | + ############################################### | |
| 425 | + | |
| 426 | + def defaults_for_role_assignment(params = {}) | |
| 427 | + { :role_id => 1, :accessor_id => 1, :accessor_type => 'Profile', :resource_id => 2, :resource_type => 'Profile' }.merge(params) | |
| 428 | + end | |
| 429 | + | |
| 430 | + ############################################### | |
| 431 | + # User | |
| 432 | + ############################################### | |
| 433 | + | |
| 434 | + def defaults_for_user(params = {}) | |
| 435 | + username = "user_#{rand(1000)}" | |
| 436 | + { :login => username, :email => username + '@noosfero.colivre', :crypted_password => 'test'}.merge(params) | |
| 437 | + end | |
| 438 | + | |
| 439 | + ############################################### | |
| 440 | + # Forum | |
| 441 | + ############################################### | |
| 442 | + | |
| 443 | + def defaults_for_forum(params = {}) | |
| 444 | + name = "forum_#{rand(1000)}" | |
| 445 | + { :profile_id => 1, :path => name.to_slug, :name => name, :slug => name.to_slug }.merge(params) | |
| 446 | + end | |
| 447 | + | |
| 448 | + ############################################### | |
| 449 | + # Gallery | |
| 450 | + ############################################### | |
| 451 | + | |
| 452 | + def defaults_for_gallery(params = {}) | |
| 453 | + name = "gallery_#{rand(1000)}" | |
| 454 | + { :profile_id => 1, :path => name.to_slug, :name => name, :slug => name.to_slug }.merge(params) | |
| 455 | + end | |
| 456 | + | |
| 457 | + def defaults_for_suggest_article | |
| 458 | + { :name => 'Sender', :email => 'sender@example.com', :article => {:name => 'Some title', :body => 'some body text', :abstract => 'some abstract text'}} | |
| 459 | + end | |
| 460 | + | |
| 461 | + def defaults_for_comment(params = {}) | |
| 462 | + name = "comment_#{rand(1000)}" | |
| 463 | + { :title => name, :body => "my own comment", :source_id => 1, :source_type => 'Article' }.merge(params) | |
| 464 | + end | |
| 465 | + | |
| 466 | + ############################################### | |
| 467 | + # Unit | |
| 468 | + ############################################### | |
| 469 | + | |
| 470 | + def defaults_for_unit | |
| 471 | + { :singular => 'Litre', :plural => 'Litres', :environment_id => 1 } | |
| 472 | + end | |
| 473 | + | |
| 474 | + ############################################### | |
| 475 | + # Production Cost | |
| 476 | + ############################################### | |
| 477 | + | |
| 478 | + def defaults_for_production_cost | |
| 479 | + { :name => 'Production cost ' + factory_num_seq.to_s } | |
| 480 | + end | |
| 481 | + | |
| 482 | + ############################################### | |
| 483 | + # National Region | |
| 484 | + ############################################### | |
| 485 | + | |
| 486 | + def defaults_for_national_region | |
| 487 | + { :name => 'National region ' + factory_num_seq.to_s } | |
| 488 | + end | |
| 489 | + | |
| 490 | + def defaults_for_license | |
| 491 | + name = "License #{rand(1000)}" | |
| 492 | + slug = name.to_slug | |
| 493 | + { :name => name, :url => "#{slug}.org", :slug => slug, :environment_id => 1} | |
| 494 | + end | |
| 495 | + | |
| 496 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | + | |
| 2 | +class ActionDispatch::IntegrationTest | |
| 3 | + | |
| 4 | + extend Test::Should | |
| 5 | + | |
| 6 | + def assert_can_login | |
| 7 | + assert_tag :tag => 'a', :attributes => { :id => 'link_login' } | |
| 8 | + end | |
| 9 | + | |
| 10 | + def assert_can_signup | |
| 11 | + assert_tag :tag => 'a', :attributes => { :href => '/account/signup'} | |
| 12 | + end | |
| 13 | + | |
| 14 | + def login(username, password) | |
| 15 | + ActionDispatch::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 16 | + | |
| 17 | + post '/account/login', :user => { :login => username, :password => password } | |
| 18 | + assert_response :redirect | |
| 19 | + follow_redirect! | |
| 20 | + assert_not_equal '/account/login', path | |
| 21 | + end | |
| 22 | + | |
| 23 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | +# encoding: UTF-8 | |
| 2 | +require 'mocha' | |
| 3 | + | |
| 4 | +module Noosfero::DocTest | |
| 5 | + | |
| 6 | + unless defined?(ROOT) | |
| 7 | + ROOT = Rails.root.join("test", "tmp", "doc") | |
| 8 | + end | |
| 9 | + | |
| 10 | + def create_doc(section, topic, language, title, body = nil) | |
| 11 | + dir = File.join(ROOT, section) | |
| 12 | + FileUtils.mkdir_p(dir) | |
| 13 | + File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | |
| 14 | + f.puts "<h1>#{title}</h1>" | |
| 15 | + f.puts body | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 19 | + def setup_doc_test | |
| 20 | + FileUtils.mkdir_p(ROOT) | |
| 21 | + | |
| 22 | + # root | |
| 23 | + create_doc('', 'index', 'en', 'Noosfero online manual') | |
| 24 | + create_doc('', 'toc', 'en', '', '<ul><li><a href="/doc/user">User features</a></li><li><a href="/doc/cms">Content Management</a></li></ul>') | |
| 25 | + # cms | |
| 26 | + create_doc('cms', 'index', 'en', 'Content Management') | |
| 27 | + create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | |
| 28 | + create_doc('cms', 'toc', 'en', '') | |
| 29 | + create_doc('cms', 'toc', 'pt', '') | |
| 30 | + create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | |
| 31 | + create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | |
| 32 | + create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | |
| 33 | + create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | |
| 34 | + # user | |
| 35 | + create_doc('user', 'index', 'en', 'User features') | |
| 36 | + create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | |
| 37 | + create_doc('user', 'toc', 'en', '<ul><li><a href="/doc/user/commenting-articles">Commenting articles</a></li><li><a href="/doc/user/acceptins-friends">Accepting friends</a></li></ul>') | |
| 38 | + create_doc('user', 'toc', 'pt', '') | |
| 39 | + create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | |
| 40 | + create_doc('user', 'accepting-friends', 'pt', 'Aceitando amigos') | |
| 41 | + create_doc('user', 'commenting-articles', 'en', 'Commenting articles', 'How to access') | |
| 42 | + create_doc('user', 'commenting-articles', 'pt', 'Comentando artigos') | |
| 43 | + | |
| 44 | + DocSection.stubs(:root_dir).returns(ROOT) | |
| 45 | + end | |
| 46 | + | |
| 47 | + def tear_down_doc_test | |
| 48 | + FileUtils.rm_rf(ROOT) | |
| 49 | + end | |
| 50 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,70 @@ |
| 1 | +module NoosferoTestHelper | |
| 2 | + | |
| 3 | + def link_to(content, url, options = {}) | |
| 4 | + "<a href='#{url.inspect}'>#{content}</a>" | |
| 5 | + end | |
| 6 | + | |
| 7 | + def content_tag(tag, content, options = {}) | |
| 8 | + tag_attr = options.blank? ? '' : ' ' + options.collect{ |o| "#{o[0]}=\"#{o[1]}\"" }.join(' ') | |
| 9 | + "<#{tag}#{tag_attr}>#{content}</#{tag}>" | |
| 10 | + end | |
| 11 | + | |
| 12 | + def submit_tag(content, options = {}) | |
| 13 | + content | |
| 14 | + end | |
| 15 | + | |
| 16 | + def remote_function(options = {}) | |
| 17 | + '' | |
| 18 | + end | |
| 19 | + | |
| 20 | + def tag(tag, args = {}) | |
| 21 | + attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') | |
| 22 | + "<#{tag} #{attrs} />" | |
| 23 | + end | |
| 24 | + | |
| 25 | + def options_from_collection_for_select(collection, value_method, content_method) | |
| 26 | + "<option value='fake value'>fake content</option>" | |
| 27 | + end | |
| 28 | + | |
| 29 | + def select_tag(id, collection, options = {}) | |
| 30 | + "<select id='#{id}'>fake content</select>" | |
| 31 | + end | |
| 32 | + | |
| 33 | + def options_for_select(collection, selected = nil) | |
| 34 | + collection.map{|item| "<option value='#{item[1]}'>#{item[0]}</option>"}.join("\n") | |
| 35 | + end | |
| 36 | + | |
| 37 | + def params | |
| 38 | + {} | |
| 39 | + end | |
| 40 | + | |
| 41 | + def ui_icon(icon) | |
| 42 | + icon | |
| 43 | + end | |
| 44 | + | |
| 45 | + def will_paginate(arg1, arg2) | |
| 46 | + end | |
| 47 | + | |
| 48 | + def javascript_tag(any) | |
| 49 | + '' | |
| 50 | + end | |
| 51 | + def javascript_include_tag(any) | |
| 52 | + '' | |
| 53 | + end | |
| 54 | + def check_box_tag(name, value = 1, checked = false, options = {}) | |
| 55 | + name | |
| 56 | + end | |
| 57 | + def stylesheet_link_tag(arg) | |
| 58 | + arg | |
| 59 | + end | |
| 60 | + | |
| 61 | + def strip_tags(html) | |
| 62 | + html.gsub(/<[^>]+>/, '') | |
| 63 | + end | |
| 64 | + | |
| 65 | + def icon_for_article(article) | |
| 66 | + '' | |
| 67 | + end | |
| 68 | + | |
| 69 | +end | |
| 70 | + | ... | ... |
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | + | |
| 2 | +module Test | |
| 3 | + | |
| 4 | + module Should | |
| 5 | + | |
| 6 | + def should name, &block | |
| 7 | + @shoulds ||= [] | |
| 8 | + | |
| 9 | + destname = 'test_should_' + name.gsub(/[^a-zA-z0-9]+/, '_') | |
| 10 | + if @shoulds.include?(destname) | |
| 11 | + raise "there is already a test named \"#{destname}\"" | |
| 12 | + end | |
| 13 | + | |
| 14 | + @shoulds << destname | |
| 15 | + if block_given? | |
| 16 | + self.send(:define_method, destname, &block) | |
| 17 | + else | |
| 18 | + self.send(:define_method, destname) do | |
| 19 | + flunk 'pending: should ' + name | |
| 20 | + end | |
| 21 | + end | |
| 22 | + | |
| 23 | + end | |
| 24 | + | |
| 25 | + end | |
| 26 | + | |
| 27 | +end | ... | ... |
test/test_helper.rb
| ... | ... | @@ -9,10 +9,14 @@ require 'mocha/mini_test' |
| 9 | 9 | require "minitest/reporters" |
| 10 | 10 | Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new, ENV, Minitest.backtrace_filter |
| 11 | 11 | |
| 12 | -require 'authenticated_test_helper' | |
| 13 | -require_relative 'factories' | |
| 14 | -require_relative 'noosfero_doc_test' | |
| 15 | -require_relative 'action_tracker_test_helper' | |
| 12 | +require_relative 'support/should' | |
| 13 | +require_relative 'support/factories' | |
| 14 | +require_relative 'support/integration_test' | |
| 15 | +require_relative 'support/controller_test_case' | |
| 16 | +require_relative 'support/authenticated_test_helper' | |
| 17 | +require_relative 'support/action_tracker_test_helper' | |
| 18 | +require_relative 'support/noosfero_doc_test' | |
| 19 | +require_relative 'support/noosfero_test_helper' | |
| 16 | 20 | |
| 17 | 21 | FileUtils.rm_rf(Rails.root.join('index', 'test')) |
| 18 | 22 | |
| ... | ... | @@ -53,6 +57,8 @@ class ActiveSupport::TestCase |
| 53 | 57 | |
| 54 | 58 | include AuthenticatedTestHelper |
| 55 | 59 | |
| 60 | + extend Test::Should | |
| 61 | + | |
| 56 | 62 | fixtures :environments, :roles |
| 57 | 63 | |
| 58 | 64 | def self.all_fixtures |
| ... | ... | @@ -61,25 +67,6 @@ class ActiveSupport::TestCase |
| 61 | 67 | end |
| 62 | 68 | end |
| 63 | 69 | |
| 64 | - def self.should(name, &block) | |
| 65 | - @shoulds ||= [] | |
| 66 | - | |
| 67 | - destname = 'test_should_' + name.gsub(/[^a-zA-z0-9]+/, '_') | |
| 68 | - if @shoulds.include?(destname) | |
| 69 | - raise "there is already a test named \"#{destname}\"" | |
| 70 | - end | |
| 71 | - | |
| 72 | - @shoulds << destname | |
| 73 | - if block_given? | |
| 74 | - self.send(:define_method, destname, &block) | |
| 75 | - else | |
| 76 | - self.send(:define_method, destname) do | |
| 77 | - flunk 'pending: should ' + name | |
| 78 | - end | |
| 79 | - end | |
| 80 | - | |
| 81 | - end | |
| 82 | - | |
| 83 | 70 | # deprecated on minitest |
| 84 | 71 | def assert_block message=nil |
| 85 | 72 | assert message || 'yield' do |
| ... | ... | @@ -214,108 +201,3 @@ class ActiveSupport::TestCase |
| 214 | 201 | |
| 215 | 202 | end |
| 216 | 203 | |
| 217 | -module NoosferoTestHelper | |
| 218 | - def link_to(content, url, options = {}) | |
| 219 | - "<a href='#{url.inspect}'>#{content}</a>" | |
| 220 | - end | |
| 221 | - | |
| 222 | - def content_tag(tag, content, options = {}) | |
| 223 | - tag_attr = options.blank? ? '' : ' ' + options.collect{ |o| "#{o[0]}=\"#{o[1]}\"" }.join(' ') | |
| 224 | - "<#{tag}#{tag_attr}>#{content}</#{tag}>" | |
| 225 | - end | |
| 226 | - | |
| 227 | - def submit_tag(content, options = {}) | |
| 228 | - content | |
| 229 | - end | |
| 230 | - | |
| 231 | - def remote_function(options = {}) | |
| 232 | - '' | |
| 233 | - end | |
| 234 | - | |
| 235 | - def tag(tag, args = {}) | |
| 236 | - attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') | |
| 237 | - "<#{tag} #{attrs} />" | |
| 238 | - end | |
| 239 | - | |
| 240 | - def options_from_collection_for_select(collection, value_method, content_method) | |
| 241 | - "<option value='fake value'>fake content</option>" | |
| 242 | - end | |
| 243 | - | |
| 244 | - def select_tag(id, collection, options = {}) | |
| 245 | - "<select id='#{id}'>fake content</select>" | |
| 246 | - end | |
| 247 | - | |
| 248 | - def options_for_select(collection, selected = nil) | |
| 249 | - collection.map{|item| "<option value='#{item[1]}'>#{item[0]}</option>"}.join("\n") | |
| 250 | - end | |
| 251 | - | |
| 252 | - def params | |
| 253 | - {} | |
| 254 | - end | |
| 255 | - | |
| 256 | - def ui_icon(icon) | |
| 257 | - icon | |
| 258 | - end | |
| 259 | - | |
| 260 | - def will_paginate(arg1, arg2) | |
| 261 | - end | |
| 262 | - | |
| 263 | - def javascript_tag(any) | |
| 264 | - '' | |
| 265 | - end | |
| 266 | - def javascript_include_tag(any) | |
| 267 | - '' | |
| 268 | - end | |
| 269 | - def check_box_tag(name, value = 1, checked = false, options = {}) | |
| 270 | - name | |
| 271 | - end | |
| 272 | - def stylesheet_link_tag(arg) | |
| 273 | - arg | |
| 274 | - end | |
| 275 | - | |
| 276 | - def strip_tags(html) | |
| 277 | - html.gsub(/<[^>]+>/, '') | |
| 278 | - end | |
| 279 | - | |
| 280 | - def icon_for_article(article) | |
| 281 | - '' | |
| 282 | - end | |
| 283 | - | |
| 284 | -end | |
| 285 | - | |
| 286 | -class ActionController::TestCase | |
| 287 | - | |
| 288 | - class_attribute :default_params | |
| 289 | - self.default_params = {} | |
| 290 | - | |
| 291 | - def get path, parameters = nil, session = nil, flash = nil | |
| 292 | - super path, if parameters then self.default_params.merge parameters else self.default_params end, session, flash | |
| 293 | - end | |
| 294 | - | |
| 295 | - def post path, parameters = nil, session = nil, flash = nil | |
| 296 | - super path, if parameters then self.default_params.merge parameters else self.default_params end, session, flash | |
| 297 | - end | |
| 298 | - | |
| 299 | -end | |
| 300 | - | |
| 301 | -class ActionController::IntegrationTest | |
| 302 | - def assert_can_login | |
| 303 | - assert_tag :tag => 'a', :attributes => { :id => 'link_login' } | |
| 304 | - end | |
| 305 | - | |
| 306 | - def assert_can_signup | |
| 307 | - assert_tag :tag => 'a', :attributes => { :href => '/account/signup'} | |
| 308 | - end | |
| 309 | - | |
| 310 | - def login(username, password) | |
| 311 | - ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | |
| 312 | - | |
| 313 | - post '/account/login', :user => { :login => username, :password => password } | |
| 314 | - assert_response :redirect | |
| 315 | - follow_redirect! | |
| 316 | - assert_not_equal '/account/login', path | |
| 317 | - end | |
| 318 | - | |
| 319 | -end | |
| 320 | - | |
| 321 | -Profile | ... | ... |