From e84e899bef927197870ded7dc0b7f9b1db8b5900 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 25 Feb 2011 15:31:05 +0100 Subject: [PATCH] fix #1097 by unpacking gems into vendor except RedCloth which needs native extentions --- .../has_many_polymorphs-2.13/.specification | 309 ++ .../gems/has_many_polymorphs-2.13/CHANGELOG | 84 + vendor/gems/has_many_polymorphs-2.13/LICENSE | 184 ++ vendor/gems/has_many_polymorphs-2.13/Manifest | 173 ++ vendor/gems/has_many_polymorphs-2.13/README | 205 ++ vendor/gems/has_many_polymorphs-2.13/Rakefile | 28 + vendor/gems/has_many_polymorphs-2.13/TODO | 2 + .../has_many_polymorphs-2.13/examples/hmph.rb | 69 + .../generators/tagging/tagging_generator.rb | 97 + .../generators/tagging/templates/migration.rb | 28 + .../generators/tagging/templates/tag.rb | 39 + .../generators/tagging/templates/tag_test.rb | 15 + .../generators/tagging/templates/tagging.rb | 16 + .../tagging/templates/tagging_extensions.rb | 203 ++ .../tagging/templates/tagging_test.rb | 85 + .../generators/tagging/templates/taggings.yml | 23 + .../generators/tagging/templates/tags.yml | 7 + .../has_many_polymorphs.gemspec | 40 + vendor/gems/has_many_polymorphs-2.13/init.rb | 2 + .../lib/has_many_polymorphs.rb | 27 + .../lib/has_many_polymorphs/association.rb | 159 ++ .../lib/has_many_polymorphs/autoload.rb | 69 + .../lib/has_many_polymorphs/base.rb | 60 + .../lib/has_many_polymorphs/class_methods.rb | 600 ++++ .../lib/has_many_polymorphs/configuration.rb | 19 + .../has_many_polymorphs/debugging_tools.rb | 103 + .../rake_task_redefine_task.rb | 35 + .../lib/has_many_polymorphs/reflection.rb | 58 + .../has_many_polymorphs/support_methods.rb | 84 + .../test/fixtures/bow_wows.yml | 10 + .../test/fixtures/cats.yml | 18 + .../test/fixtures/eaters_foodstuffs.yml | 0 .../test/fixtures/fish.yml | 12 + .../test/fixtures/frogs.yml | 5 + .../test/fixtures/keep_your_enemies_close.yml | 0 .../test/fixtures/little_whale_pupils.yml | 0 .../test/fixtures/people.yml | 7 + .../test/fixtures/petfoods.yml | 11 + .../test/fixtures/whales.yml | 5 + .../test/fixtures/wild_boars.yml | 10 + .../test/generator/tagging_generator_test.rb | 42 + .../test/integration/app/README | 182 ++ .../test/integration/app/Rakefile | 19 + .../app/app/controllers/application.rb | 7 + .../app/app/controllers/bones_controller.rb | 5 + .../app/app/helpers/addresses_helper.rb | 2 + .../app/app/helpers/application_helper.rb | 3 + .../app/app/helpers/bones_helper.rb | 2 + .../app/app/helpers/sellers_helper.rb | 28 + .../app/app/helpers/states_helper.rb | 2 + .../app/app/helpers/users_helper.rb | 2 + .../test/integration/app/app/models/bone.rb | 2 + .../app/app/models/double_sti_parent.rb | 2 + .../models/double_sti_parent_relationship.rb | 2 + .../app/app/models/organic_substance.rb | 2 + .../app/app/models/single_sti_parent.rb | 4 + .../models/single_sti_parent_relationship.rb | 4 + .../test/integration/app/app/models/stick.rb | 2 + .../test/integration/app/app/models/stone.rb | 2 + .../app/app/views/addresses/edit.html.erb | 12 + .../app/app/views/addresses/index.html.erb | 18 + .../app/app/views/addresses/new.html.erb | 11 + .../app/app/views/addresses/show.html.erb | 3 + .../app/app/views/bones/index.rhtml | 5 + .../app/app/views/layouts/addresses.html.erb | 17 + .../app/app/views/layouts/sellers.html.erb | 17 + .../app/app/views/layouts/states.html.erb | 17 + .../app/app/views/layouts/users.html.erb | 17 + .../app/app/views/sellers/edit.html.erb | 12 + .../app/app/views/sellers/index.html.erb | 20 + .../app/app/views/sellers/new.html.erb | 11 + .../app/app/views/sellers/show.html.erb | 3 + .../app/app/views/states/edit.html.erb | 12 + .../app/app/views/states/index.html.erb | 19 + .../app/app/views/states/new.html.erb | 11 + .../app/app/views/states/show.html.erb | 3 + .../app/app/views/users/edit.html.erb | 12 + .../app/app/views/users/index.html.erb | 22 + .../app/app/views/users/new.html.erb | 11 + .../app/app/views/users/show.html.erb | 3 + .../test/integration/app/config/boot.rb | 110 + .../test/integration/app/config/database.yml | 17 + .../integration/app/config/environment.rb | 19 + .../app/config/environment.rb.canonical | 19 + .../app/config/environments/development.rb | 9 + .../app/config/environments/production.rb | 18 + .../app/config/environments/test.rb | 19 + .../integration/app/config/locomotive.yml | 6 + .../test/integration/app/config/routes.rb | 33 + .../app/config/ultrasphinx/default.base | 56 + .../ultrasphinx/development.conf.canonical | 155 + .../app/db/migrate/001_create_sticks.rb | 11 + .../app/db/migrate/002_create_stones.rb | 11 + .../migrate/003_create_organic_substances.rb | 11 + .../app/db/migrate/004_create_bones.rb | 8 + .../migrate/005_create_single_sti_parents.rb | 11 + .../migrate/006_create_double_sti_parents.rb | 11 + ..._create_single_sti_parent_relationships.rb | 13 + ..._create_double_sti_parent_relationships.rb | 14 + .../db/migrate/009_create_library_model.rb | 11 + .../test/integration/app/doc/README_FOR_APP | 2 + .../generators/commenting_generator_test.rb | 83 + .../test/integration/app/lib/library_model.rb | 2 + .../test/integration/app/public/404.html | 30 + .../test/integration/app/public/500.html | 30 + .../test/integration/app/public/dispatch.cgi | 10 + .../test/integration/app/public/dispatch.fcgi | 24 + .../test/integration/app/public/dispatch.rb | 10 + .../test/integration/app/public/favicon.ico | 0 .../integration/app/public/images/rails.png | Bin 0 -> 1787 bytes .../test/integration/app/public/index.html | 277 ++ .../app/public/javascripts/application.js | 2 + .../app/public/javascripts/controls.js | 833 ++++++ .../app/public/javascripts/dragdrop.js | 942 ++++++ .../app/public/javascripts/effects.js | 1088 +++++++ .../app/public/javascripts/prototype.js | 2515 +++++++++++++++++ .../test/integration/app/public/robots.txt | 1 + .../app/public/stylesheets/scaffold.css | 74 + .../test/integration/app/script/about | 3 + .../test/integration/app/script/breakpointer | 3 + .../test/integration/app/script/console | 3 + .../test/integration/app/script/destroy | 3 + .../test/integration/app/script/generate | 3 + .../app/script/performance/benchmarker | 3 + .../app/script/performance/profiler | 3 + .../test/integration/app/script/plugin | 3 + .../integration/app/script/process/inspector | 3 + .../integration/app/script/process/reaper | 3 + .../integration/app/script/process/spawner | 3 + .../test/integration/app/script/runner | 3 + .../test/integration/app/script/server | 3 + .../double_sti_parent_relationships.yml | 7 + .../app/test/fixtures/double_sti_parents.yml | 7 + .../app/test/fixtures/organic_substances.yml | 5 + .../single_sti_parent_relationships.yml | 7 + .../app/test/fixtures/single_sti_parents.yml | 7 + .../integration/app/test/fixtures/sticks.yml | 7 + .../integration/app/test/fixtures/stones.yml | 7 + .../functional/addresses_controller_test.rb | 57 + .../test/functional/bones_controller_test.rb | 8 + .../functional/sellers_controller_test.rb | 57 + .../test/functional/states_controller_test.rb | 57 + .../test/functional/users_controller_test.rb | 57 + .../test/integration/app/test/test_helper.rb | 8 + .../integration/app/test/unit/bone_test.rb | 8 + .../double_sti_parent_relationship_test.rb | 8 + .../app/test/unit/double_sti_parent_test.rb | 8 + .../app/test/unit/organic_substance_test.rb | 8 + .../single_sti_parent_relationship_test.rb | 8 + .../app/test/unit/single_sti_parent_test.rb | 8 + .../integration/app/test/unit/stick_test.rb | 8 + .../integration/app/test/unit/stone_test.rb | 8 + .../test/integration/server_test.rb | 43 + .../test/models/aquatic/fish.rb | 5 + .../test/models/aquatic/pupils_whale.rb | 7 + .../test/models/aquatic/whale.rb | 15 + .../models/beautiful_fight_relationship.rb | 26 + .../test/models/canine.rb | 9 + .../test/models/cat.rb | 5 + .../test/models/dog.rb | 18 + .../test/models/eaters_foodstuff.rb | 10 + .../test/models/frog.rb | 4 + .../test/models/kitten.rb | 3 + .../test/models/parentship.rb | 4 + .../test/models/person.rb | 9 + .../test/models/petfood.rb | 39 + .../test/models/tabby.rb | 2 + .../test/models/wild_boar.rb | 3 + .../test/modules/extension_module.rb | 9 + .../test/modules/other_extension_module.rb | 9 + .../test/patches/symlinked_plugins_1.2.6.diff | 46 + .../has_many_polymorphs-2.13/test/schema.rb | 87 + .../has_many_polymorphs-2.13/test/setup.rb | 14 + .../test/test_helper.rb | 51 + .../test/unit/has_many_polymorphs_test.rb | 714 +++++ vendor/gems/rack-1.1.0/.specification | 314 ++ vendor/gems/rack-1.1.0/COPYING | 18 + vendor/gems/rack-1.1.0/KNOWN-ISSUES | 21 + vendor/gems/rack-1.1.0/RDOX | 0 vendor/gems/rack-1.1.0/README | 399 +++ vendor/gems/rack-1.1.0/SPEC | 171 ++ vendor/gems/rack-1.1.0/bin/rackup | 4 + vendor/gems/rack-1.1.0/contrib/rack_logo.svg | 111 + vendor/gems/rack-1.1.0/example/lobster.ru | 4 + .../rack-1.1.0/example/protectedlobster.rb | 14 + .../rack-1.1.0/example/protectedlobster.ru | 8 + vendor/gems/rack-1.1.0/lib/rack.rb | 92 + .../rack-1.1.0/lib/rack/adapter/camping.rb | 22 + .../lib/rack/auth/abstract/handler.rb | 37 + .../lib/rack/auth/abstract/request.rb | 37 + vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb | 58 + .../rack-1.1.0/lib/rack/auth/digest/md5.rb | 124 + .../rack-1.1.0/lib/rack/auth/digest/nonce.rb | 51 + .../rack-1.1.0/lib/rack/auth/digest/params.rb | 55 + .../lib/rack/auth/digest/request.rb | 40 + vendor/gems/rack-1.1.0/lib/rack/builder.rb | 80 + vendor/gems/rack-1.1.0/lib/rack/cascade.rb | 41 + vendor/gems/rack-1.1.0/lib/rack/chunked.rb | 49 + .../gems/rack-1.1.0/lib/rack/commonlogger.rb | 49 + .../rack-1.1.0/lib/rack/conditionalget.rb | 47 + vendor/gems/rack-1.1.0/lib/rack/config.rb | 15 + .../rack-1.1.0/lib/rack/content_length.rb | 29 + .../gems/rack-1.1.0/lib/rack/content_type.rb | 23 + vendor/gems/rack-1.1.0/lib/rack/deflater.rb | 96 + vendor/gems/rack-1.1.0/lib/rack/directory.rb | 157 + vendor/gems/rack-1.1.0/lib/rack/etag.rb | 23 + vendor/gems/rack-1.1.0/lib/rack/file.rb | 90 + vendor/gems/rack-1.1.0/lib/rack/handler.rb | 88 + .../gems/rack-1.1.0/lib/rack/handler/cgi.rb | 61 + .../lib/rack/handler/evented_mongrel.rb | 8 + .../rack-1.1.0/lib/rack/handler/fastcgi.rb | 89 + .../gems/rack-1.1.0/lib/rack/handler/lsws.rb | 63 + .../rack-1.1.0/lib/rack/handler/mongrel.rb | 90 + .../gems/rack-1.1.0/lib/rack/handler/scgi.rb | 62 + .../lib/rack/handler/swiftiplied_mongrel.rb | 8 + .../gems/rack-1.1.0/lib/rack/handler/thin.rb | 18 + .../rack-1.1.0/lib/rack/handler/webrick.rb | 69 + vendor/gems/rack-1.1.0/lib/rack/head.rb | 19 + vendor/gems/rack-1.1.0/lib/rack/lint.rb | 575 ++++ vendor/gems/rack-1.1.0/lib/rack/lobster.rb | 65 + vendor/gems/rack-1.1.0/lib/rack/lock.rb | 16 + vendor/gems/rack-1.1.0/lib/rack/logger.rb | 20 + .../rack-1.1.0/lib/rack/methodoverride.rb | 27 + vendor/gems/rack-1.1.0/lib/rack/mime.rb | 206 ++ vendor/gems/rack-1.1.0/lib/rack/mock.rb | 189 ++ vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb | 18 + vendor/gems/rack-1.1.0/lib/rack/recursive.rb | 57 + vendor/gems/rack-1.1.0/lib/rack/reloader.rb | 109 + vendor/gems/rack-1.1.0/lib/rack/request.rb | 271 ++ vendor/gems/rack-1.1.0/lib/rack/response.rb | 149 + .../rack-1.1.0/lib/rack/rewindable_input.rb | 100 + vendor/gems/rack-1.1.0/lib/rack/runtime.rb | 27 + vendor/gems/rack-1.1.0/lib/rack/sendfile.rb | 142 + vendor/gems/rack-1.1.0/lib/rack/server.rb | 212 ++ .../lib/rack/session/abstract/id.rb | 140 + .../rack-1.1.0/lib/rack/session/cookie.rb | 90 + .../rack-1.1.0/lib/rack/session/memcache.rb | 119 + .../gems/rack-1.1.0/lib/rack/session/pool.rb | 100 + .../rack-1.1.0/lib/rack/showexceptions.rb | 349 +++ vendor/gems/rack-1.1.0/lib/rack/showstatus.rb | 106 + vendor/gems/rack-1.1.0/lib/rack/static.rb | 38 + vendor/gems/rack-1.1.0/lib/rack/urlmap.rb | 56 + vendor/gems/rack-1.1.0/lib/rack/utils.rb | 620 ++++ vendor/gems/rack-1.1.0/rack.gemspec | 38 + .../rack-1.1.0/test/spec_rack_auth_basic.rb | 73 + .../rack-1.1.0/test/spec_rack_auth_digest.rb | 226 ++ .../gems/rack-1.1.0/test/spec_rack_builder.rb | 84 + .../gems/rack-1.1.0/test/spec_rack_camping.rb | 51 + .../gems/rack-1.1.0/test/spec_rack_cascade.rb | 48 + vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb | 89 + .../gems/rack-1.1.0/test/spec_rack_chunked.rb | 62 + .../rack-1.1.0/test/spec_rack_commonlogger.rb | 61 + .../test/spec_rack_conditionalget.rb | 41 + .../gems/rack-1.1.0/test/spec_rack_config.rb | 24 + .../test/spec_rack_content_length.rb | 43 + .../rack-1.1.0/test/spec_rack_content_type.rb | 30 + .../rack-1.1.0/test/spec_rack_deflater.rb | 127 + .../rack-1.1.0/test/spec_rack_directory.rb | 61 + vendor/gems/rack-1.1.0/test/spec_rack_etag.rb | 17 + .../gems/rack-1.1.0/test/spec_rack_fastcgi.rb | 89 + vendor/gems/rack-1.1.0/test/spec_rack_file.rb | 75 + .../gems/rack-1.1.0/test/spec_rack_handler.rb | 43 + vendor/gems/rack-1.1.0/test/spec_rack_head.rb | 30 + vendor/gems/rack-1.1.0/test/spec_rack_lint.rb | 528 ++++ .../gems/rack-1.1.0/test/spec_rack_lobster.rb | 45 + vendor/gems/rack-1.1.0/test/spec_rack_lock.rb | 38 + .../gems/rack-1.1.0/test/spec_rack_logger.rb | 21 + .../test/spec_rack_methodoverride.rb | 60 + vendor/gems/rack-1.1.0/test/spec_rack_mock.rb | 243 ++ .../gems/rack-1.1.0/test/spec_rack_mongrel.rb | 189 ++ .../rack-1.1.0/test/spec_rack_nulllogger.rb | 13 + .../rack-1.1.0/test/spec_rack_recursive.rb | 77 + .../gems/rack-1.1.0/test/spec_rack_request.rb | 545 ++++ .../rack-1.1.0/test/spec_rack_response.rb | 221 ++ .../test/spec_rack_rewindable_input.rb | 118 + .../gems/rack-1.1.0/test/spec_rack_runtime.rb | 35 + .../rack-1.1.0/test/spec_rack_sendfile.rb | 86 + .../test/spec_rack_session_cookie.rb | 73 + .../test/spec_rack_session_memcache.rb | 273 ++ .../rack-1.1.0/test/spec_rack_session_pool.rb | 172 ++ .../test/spec_rack_showexceptions.rb | 21 + .../rack-1.1.0/test/spec_rack_showstatus.rb | 72 + .../gems/rack-1.1.0/test/spec_rack_static.rb | 37 + vendor/gems/rack-1.1.0/test/spec_rack_thin.rb | 91 + .../gems/rack-1.1.0/test/spec_rack_urlmap.rb | 215 ++ .../gems/rack-1.1.0/test/spec_rack_utils.rb | 552 ++++ .../gems/rack-1.1.0/test/spec_rack_webrick.rb | 130 + vendor/gems/rack-1.1.0/test/spec_rackup.rb | 154 + vendor/gems/sanitize-1.2.1/.specification | 124 + vendor/gems/sanitize-1.2.1/HISTORY | 90 + vendor/gems/sanitize-1.2.1/LICENSE | 18 + vendor/gems/sanitize-1.2.1/README.rdoc | 333 +++ vendor/gems/sanitize-1.2.1/lib/sanitize.rb | 245 ++ .../sanitize-1.2.1/lib/sanitize/config.rb | 70 + .../lib/sanitize/config/basic.rb | 49 + .../lib/sanitize/config/relaxed.rb | 57 + .../lib/sanitize/config/restricted.rb | 29 + .../sanitize-1.2.1/lib/sanitize/version.rb | 3 + .../gems/will_paginate-2.3.15/.specification | 108 + .../gems/will_paginate-2.3.15/CHANGELOG.rdoc | 139 + vendor/gems/will_paginate-2.3.15/LICENSE | 18 + vendor/gems/will_paginate-2.3.15/README.rdoc | 107 + vendor/gems/will_paginate-2.3.15/Rakefile | 53 + .../will_paginate-2.3.15/lib/will_paginate.rb | 90 + .../lib/will_paginate/array.rb | 16 + .../lib/will_paginate/collection.rb | 144 + .../lib/will_paginate/core_ext.rb | 43 + .../lib/will_paginate/finder.rb | 264 ++ .../lib/will_paginate/named_scope.rb | 170 ++ .../lib/will_paginate/named_scope_patch.rb | 37 + .../lib/will_paginate/version.rb | 9 + .../lib/will_paginate/view_helpers.rb | 410 +++ vendor/gems/will_paginate-2.3.15/test/boot.rb | 21 + .../test/collection_test.rb | 143 + vendor/gems/will_paginate-2.3.15/test/console | 8 + .../will_paginate-2.3.15/test/database.yml | 22 + .../will_paginate-2.3.15/test/finder_test.rb | 496 ++++ .../test/fixtures/admin.rb | 3 + .../test/fixtures/developer.rb | 14 + .../test/fixtures/developers_projects.yml | 13 + .../test/fixtures/project.rb | 17 + .../test/fixtures/projects.yml | 6 + .../test/fixtures/replies.yml | 29 + .../test/fixtures/reply.rb | 7 + .../test/fixtures/schema.rb | 38 + .../test/fixtures/topic.rb | 12 + .../test/fixtures/topics.yml | 30 + .../test/fixtures/user.rb | 2 + .../test/fixtures/users.yml | 35 + .../gems/will_paginate-2.3.15/test/helper.rb | 37 + .../test/lib/activerecord_test_case.rb | 43 + .../test/lib/activerecord_test_connector.rb | 76 + .../test/lib/load_fixtures.rb | 11 + .../test/lib/view_test_process.rb | 179 ++ .../gems/will_paginate-2.3.15/test/tasks.rake | 59 + .../will_paginate-2.3.15/test/view_test.rb | 373 +++ 336 files changed, 27758 insertions(+) create mode 100644 vendor/gems/has_many_polymorphs-2.13/.specification create mode 100644 vendor/gems/has_many_polymorphs-2.13/CHANGELOG create mode 100644 vendor/gems/has_many_polymorphs-2.13/LICENSE create mode 100644 vendor/gems/has_many_polymorphs-2.13/Manifest create mode 100644 vendor/gems/has_many_polymorphs-2.13/README create mode 100644 vendor/gems/has_many_polymorphs-2.13/Rakefile create mode 100644 vendor/gems/has_many_polymorphs-2.13/TODO create mode 100644 vendor/gems/has_many_polymorphs-2.13/examples/hmph.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/tagging_generator.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/migration.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_extensions.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/taggings.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tags.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/has_many_polymorphs.gemspec create mode 100644 vendor/gems/has_many_polymorphs-2.13/init.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/association.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/autoload.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/base.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/class_methods.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/configuration.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/debugging_tools.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/rake_task_redefine_task.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/reflection.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/support_methods.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/bow_wows.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/cats.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/eaters_foodstuffs.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/fish.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/frogs.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/keep_your_enemies_close.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/little_whale_pupils.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/people.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/petfoods.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/whales.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/fixtures/wild_boars.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/generator/tagging_generator_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/README create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/Rakefile create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/application.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/bones_controller.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/addresses_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/application_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/bones_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/sellers_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/states_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/users_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/bone.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent_relationship.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/organic_substance.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent_relationship.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stick.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stone.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/edit.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/index.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/new.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/show.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/bones/index.rhtml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/addresses.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/sellers.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/states.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/users.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/edit.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/index.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/new.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/show.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/edit.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/index.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/new.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/show.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/edit.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/index.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/new.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/show.html.erb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/boot.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/database.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb.canonical create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/development.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/production.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/locomotive.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/routes.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/default.base create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/development.conf.canonical create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/001_create_sticks.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/002_create_stones.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/003_create_organic_substances.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/004_create_bones.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/005_create_single_sti_parents.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/006_create_double_sti_parents.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/009_create_library_model.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/doc/README_FOR_APP create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/generators/commenting_generator_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/lib/library_model.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/404.html create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/500.html create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.cgi create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.fcgi create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/favicon.ico create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/images/rails.png create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/index.html create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/application.js create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/controls.js create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/dragdrop.js create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/effects.js create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/prototype.js create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/robots.txt create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/stylesheets/scaffold.css create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/about create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/breakpointer create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/console create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/destroy create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/generate create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/benchmarker create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/profiler create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/plugin create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/inspector create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/reaper create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/spawner create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/runner create mode 100755 vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/server create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parent_relationships.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parents.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/organic_substances.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parent_relationships.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parents.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/sticks.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/stones.yml create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/addresses_controller_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/bones_controller_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/sellers_controller_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/states_controller_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/users_controller_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/test_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/bone_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_relationship_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/organic_substance_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_relationship_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stick_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stone_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/integration/server_test.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/fish.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/pupils_whale.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/whale.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/beautiful_fight_relationship.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/canine.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/cat.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/dog.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/eaters_foodstuff.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/frog.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/kitten.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/parentship.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/person.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/petfood.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/tabby.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/models/wild_boar.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/modules/extension_module.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/modules/other_extension_module.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/patches/symlinked_plugins_1.2.6.diff create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/schema.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/setup.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/test_helper.rb create mode 100644 vendor/gems/has_many_polymorphs-2.13/test/unit/has_many_polymorphs_test.rb create mode 100644 vendor/gems/rack-1.1.0/.specification create mode 100644 vendor/gems/rack-1.1.0/COPYING create mode 100644 vendor/gems/rack-1.1.0/KNOWN-ISSUES create mode 100644 vendor/gems/rack-1.1.0/RDOX create mode 100644 vendor/gems/rack-1.1.0/README create mode 100644 vendor/gems/rack-1.1.0/SPEC create mode 100755 vendor/gems/rack-1.1.0/bin/rackup create mode 100644 vendor/gems/rack-1.1.0/contrib/rack_logo.svg create mode 100644 vendor/gems/rack-1.1.0/example/lobster.ru create mode 100644 vendor/gems/rack-1.1.0/example/protectedlobster.rb create mode 100644 vendor/gems/rack-1.1.0/example/protectedlobster.ru create mode 100644 vendor/gems/rack-1.1.0/lib/rack.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/adapter/camping.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/abstract/handler.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/abstract/request.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/digest/md5.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/digest/nonce.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/digest/params.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/auth/digest/request.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/builder.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/cascade.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/chunked.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/commonlogger.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/conditionalget.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/config.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/content_length.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/content_type.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/deflater.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/directory.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/etag.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/file.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/cgi.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/evented_mongrel.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/fastcgi.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/lsws.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/mongrel.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/scgi.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/swiftiplied_mongrel.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/thin.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/handler/webrick.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/head.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/lint.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/lobster.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/lock.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/logger.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/methodoverride.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/mime.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/mock.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/recursive.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/reloader.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/request.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/response.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/rewindable_input.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/runtime.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/sendfile.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/server.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/session/abstract/id.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/session/cookie.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/session/memcache.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/session/pool.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/showexceptions.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/showstatus.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/static.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/urlmap.rb create mode 100644 vendor/gems/rack-1.1.0/lib/rack/utils.rb create mode 100644 vendor/gems/rack-1.1.0/rack.gemspec create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_auth_basic.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_auth_digest.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_builder.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_camping.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_cascade.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_chunked.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_commonlogger.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_conditionalget.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_config.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_content_length.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_content_type.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_deflater.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_directory.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_etag.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_fastcgi.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_file.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_handler.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_head.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_lint.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_lobster.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_lock.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_logger.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_methodoverride.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_mock.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_mongrel.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_nulllogger.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_recursive.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_request.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_response.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_rewindable_input.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_runtime.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_sendfile.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_session_cookie.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_session_memcache.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_session_pool.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_showexceptions.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_showstatus.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_static.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_thin.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_urlmap.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_utils.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rack_webrick.rb create mode 100644 vendor/gems/rack-1.1.0/test/spec_rackup.rb create mode 100644 vendor/gems/sanitize-1.2.1/.specification create mode 100644 vendor/gems/sanitize-1.2.1/HISTORY create mode 100644 vendor/gems/sanitize-1.2.1/LICENSE create mode 100644 vendor/gems/sanitize-1.2.1/README.rdoc create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize.rb create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize/config.rb create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize/config/basic.rb create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize/config/relaxed.rb create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize/config/restricted.rb create mode 100644 vendor/gems/sanitize-1.2.1/lib/sanitize/version.rb create mode 100644 vendor/gems/will_paginate-2.3.15/.specification create mode 100644 vendor/gems/will_paginate-2.3.15/CHANGELOG.rdoc create mode 100644 vendor/gems/will_paginate-2.3.15/LICENSE create mode 100644 vendor/gems/will_paginate-2.3.15/README.rdoc create mode 100644 vendor/gems/will_paginate-2.3.15/Rakefile create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/array.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/collection.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/core_ext.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope_patch.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/version.rb create mode 100644 vendor/gems/will_paginate-2.3.15/lib/will_paginate/view_helpers.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/boot.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/collection_test.rb create mode 100755 vendor/gems/will_paginate-2.3.15/test/console create mode 100644 vendor/gems/will_paginate-2.3.15/test/database.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/finder_test.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/admin.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/developer.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/developers_projects.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/project.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/projects.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/replies.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/reply.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/schema.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/topic.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/topics.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/user.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/fixtures/users.yml create mode 100644 vendor/gems/will_paginate-2.3.15/test/helper.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_case.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_connector.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/lib/load_fixtures.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/lib/view_test_process.rb create mode 100644 vendor/gems/will_paginate-2.3.15/test/tasks.rake create mode 100644 vendor/gems/will_paginate-2.3.15/test/view_test.rb diff --git a/vendor/gems/has_many_polymorphs-2.13/.specification b/vendor/gems/has_many_polymorphs-2.13/.specification new file mode 100644 index 00000000..6cf0d84b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/.specification @@ -0,0 +1,309 @@ +--- !ruby/object:Gem::Specification +name: has_many_polymorphs +version: !ruby/object:Gem::Version + hash: 25 + prerelease: false + segments: + - 2 + - 13 + version: "2.13" +platform: ruby +authors: +- "" +autorequire: +bindir: bin +cert_chain: +- | + -----BEGIN CERTIFICATE----- + MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARldmFu + MRgwFgYKCZImiZPyLGQBGRYIY2xvdWRidXIxEjAQBgoJkiaJk/IsZAEZFgJzdDAe + Fw0wNzA5MTYxMDMzMDBaFw0wODA5MTUxMDMzMDBaMD0xDTALBgNVBAMMBGV2YW4x + GDAWBgoJkiaJk/IsZAEZFghjbG91ZGJ1cjESMBAGCgmSJomT8ixkARkWAnN0MIIB + IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5C0Io89nyApnr+PvbNFge9Vs + yRWAlGBUEMahpXp28VrrfXZT0rAW7JBo4PlCE3jl4nE4dzE6gAdItSycjTosrw7A + Ir5+xoyl4Vb35adv56TIQQXvNz+BzlqnkAY5JN0CSBRTQb6mxS3hFyD/h4qgDosj + R2RFVzHqSxCS8xq4Ny8uzOwOi+Xyu4w67fI5JvnPvMxqrlR1eaIQHmxnf76RzC46 + QO5QhufjAYGGXd960XzbQsQyTDUYJzrvT7AdOfiyZzKQykKt8dEpDn+QPjFTnGnT + QmgJBX5WJN0lHF2l1sbv3gh4Kn1tZu+kTUqeXY6ShAoDTyvZRiFqQdwh8w2lTQID + AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU+WqJz3xQ + XSea1hRvvHWcIMgeeC4wDQYJKoZIhvcNAQEFBQADggEBAGLZ75jfOEW8Nsl26CTt + JFrWxQTcQT/UljeefVE3xYr7lc9oQjbqO3FOyued3qW7TaNEtZfSHoYeUSMYbpw1 + XAwocIPuSRFDGM4B+hgQGVDx8PMGiJKom4qLXjO40UZsR7QyN/u869Vj45LURm6h + MBcPeqCASI+WNprj9+uZa2kmHiitrFqqfMBNlm5IFbn9XeYSta9AHVvs5QQqV2m5 + hIPfLqCyxsn/YgOGvo6iwyQTWyTswamaAC3HRWZxIS1sfn/Ssqa7E7oQMkv5FAXr + x5rKePfXINf8XTJczkl9OBEYdE9aNdJsJpXD0asLgGVwBICS5Bjohp6mizJcDC1+ + yZ0= + -----END CERTIFICATE----- + +date: 2009-02-02 00:00:00 +01:00 +default_executable: +dependencies: +- !ruby/object:Gem::Dependency + name: activerecord + prerelease: false + requirement: &id001 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :runtime + version_requirements: *id001 +- !ruby/object:Gem::Dependency + name: echoe + prerelease: false + requirement: &id002 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id002 +description: An ActiveRecord plugin for self-referential and double-sided polymorphic associations. +email: "" +executables: [] + +extensions: [] + +extra_rdoc_files: +- CHANGELOG +- generators/tagging/templates/migration.rb +- generators/tagging/templates/tag.rb +- generators/tagging/templates/tagging.rb +- generators/tagging/templates/tagging_extensions.rb +- lib/has_many_polymorphs/association.rb +- lib/has_many_polymorphs/autoload.rb +- lib/has_many_polymorphs/class_methods.rb +- lib/has_many_polymorphs/configuration.rb +- lib/has_many_polymorphs/reflection.rb +- LICENSE +- README +- test/integration/app/doc/README_FOR_APP +- test/integration/app/README +- TODO +files: +- CHANGELOG +- examples/hmph.rb +- generators/tagging/tagging_generator.rb +- generators/tagging/templates/migration.rb +- generators/tagging/templates/tag.rb +- generators/tagging/templates/tag_test.rb +- generators/tagging/templates/tagging.rb +- generators/tagging/templates/tagging_extensions.rb +- generators/tagging/templates/tagging_test.rb +- generators/tagging/templates/taggings.yml +- generators/tagging/templates/tags.yml +- init.rb +- lib/has_many_polymorphs/association.rb +- lib/has_many_polymorphs/autoload.rb +- lib/has_many_polymorphs/base.rb +- lib/has_many_polymorphs/class_methods.rb +- lib/has_many_polymorphs/configuration.rb +- lib/has_many_polymorphs/debugging_tools.rb +- lib/has_many_polymorphs/rake_task_redefine_task.rb +- lib/has_many_polymorphs/reflection.rb +- lib/has_many_polymorphs/support_methods.rb +- lib/has_many_polymorphs.rb +- LICENSE +- Manifest +- Rakefile +- README +- test/fixtures/bow_wows.yml +- test/fixtures/cats.yml +- test/fixtures/eaters_foodstuffs.yml +- test/fixtures/fish.yml +- test/fixtures/frogs.yml +- test/fixtures/keep_your_enemies_close.yml +- test/fixtures/little_whale_pupils.yml +- test/fixtures/people.yml +- test/fixtures/petfoods.yml +- test/fixtures/whales.yml +- test/fixtures/wild_boars.yml +- test/generator/tagging_generator_test.rb +- test/integration/app/app/controllers/application.rb +- test/integration/app/app/controllers/bones_controller.rb +- test/integration/app/app/helpers/addresses_helper.rb +- test/integration/app/app/helpers/application_helper.rb +- test/integration/app/app/helpers/bones_helper.rb +- test/integration/app/app/helpers/sellers_helper.rb +- test/integration/app/app/helpers/states_helper.rb +- test/integration/app/app/helpers/users_helper.rb +- test/integration/app/app/models/bone.rb +- test/integration/app/app/models/double_sti_parent.rb +- test/integration/app/app/models/double_sti_parent_relationship.rb +- test/integration/app/app/models/organic_substance.rb +- test/integration/app/app/models/single_sti_parent.rb +- test/integration/app/app/models/single_sti_parent_relationship.rb +- test/integration/app/app/models/stick.rb +- test/integration/app/app/models/stone.rb +- test/integration/app/app/views/addresses/edit.html.erb +- test/integration/app/app/views/addresses/index.html.erb +- test/integration/app/app/views/addresses/new.html.erb +- test/integration/app/app/views/addresses/show.html.erb +- test/integration/app/app/views/bones/index.rhtml +- test/integration/app/app/views/layouts/addresses.html.erb +- test/integration/app/app/views/layouts/sellers.html.erb +- test/integration/app/app/views/layouts/states.html.erb +- test/integration/app/app/views/layouts/users.html.erb +- test/integration/app/app/views/sellers/edit.html.erb +- test/integration/app/app/views/sellers/index.html.erb +- test/integration/app/app/views/sellers/new.html.erb +- test/integration/app/app/views/sellers/show.html.erb +- test/integration/app/app/views/states/edit.html.erb +- test/integration/app/app/views/states/index.html.erb +- test/integration/app/app/views/states/new.html.erb +- test/integration/app/app/views/states/show.html.erb +- test/integration/app/app/views/users/edit.html.erb +- test/integration/app/app/views/users/index.html.erb +- test/integration/app/app/views/users/new.html.erb +- test/integration/app/app/views/users/show.html.erb +- test/integration/app/config/boot.rb +- test/integration/app/config/database.yml +- test/integration/app/config/environment.rb +- test/integration/app/config/environment.rb.canonical +- test/integration/app/config/environments/development.rb +- test/integration/app/config/environments/production.rb +- test/integration/app/config/environments/test.rb +- test/integration/app/config/locomotive.yml +- test/integration/app/config/routes.rb +- test/integration/app/config/ultrasphinx/default.base +- test/integration/app/config/ultrasphinx/development.conf.canonical +- test/integration/app/db/migrate/001_create_sticks.rb +- test/integration/app/db/migrate/002_create_stones.rb +- test/integration/app/db/migrate/003_create_organic_substances.rb +- test/integration/app/db/migrate/004_create_bones.rb +- test/integration/app/db/migrate/005_create_single_sti_parents.rb +- test/integration/app/db/migrate/006_create_double_sti_parents.rb +- test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +- test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +- test/integration/app/db/migrate/009_create_library_model.rb +- test/integration/app/doc/README_FOR_APP +- test/integration/app/generators/commenting_generator_test.rb +- test/integration/app/lib/library_model.rb +- test/integration/app/public/404.html +- test/integration/app/public/500.html +- test/integration/app/public/dispatch.cgi +- test/integration/app/public/dispatch.fcgi +- test/integration/app/public/dispatch.rb +- test/integration/app/public/favicon.ico +- test/integration/app/public/images/rails.png +- test/integration/app/public/index.html +- test/integration/app/public/javascripts/application.js +- test/integration/app/public/javascripts/controls.js +- test/integration/app/public/javascripts/dragdrop.js +- test/integration/app/public/javascripts/effects.js +- test/integration/app/public/javascripts/prototype.js +- test/integration/app/public/robots.txt +- test/integration/app/public/stylesheets/scaffold.css +- test/integration/app/Rakefile +- test/integration/app/README +- test/integration/app/script/about +- test/integration/app/script/breakpointer +- test/integration/app/script/console +- test/integration/app/script/destroy +- test/integration/app/script/generate +- test/integration/app/script/performance/benchmarker +- test/integration/app/script/performance/profiler +- test/integration/app/script/plugin +- test/integration/app/script/process/inspector +- test/integration/app/script/process/reaper +- test/integration/app/script/process/spawner +- test/integration/app/script/runner +- test/integration/app/script/server +- test/integration/app/test/fixtures/double_sti_parent_relationships.yml +- test/integration/app/test/fixtures/double_sti_parents.yml +- test/integration/app/test/fixtures/organic_substances.yml +- test/integration/app/test/fixtures/single_sti_parent_relationships.yml +- test/integration/app/test/fixtures/single_sti_parents.yml +- test/integration/app/test/fixtures/sticks.yml +- test/integration/app/test/fixtures/stones.yml +- test/integration/app/test/functional/addresses_controller_test.rb +- test/integration/app/test/functional/bones_controller_test.rb +- test/integration/app/test/functional/sellers_controller_test.rb +- test/integration/app/test/functional/states_controller_test.rb +- test/integration/app/test/functional/users_controller_test.rb +- test/integration/app/test/test_helper.rb +- test/integration/app/test/unit/bone_test.rb +- test/integration/app/test/unit/double_sti_parent_relationship_test.rb +- test/integration/app/test/unit/double_sti_parent_test.rb +- test/integration/app/test/unit/organic_substance_test.rb +- test/integration/app/test/unit/single_sti_parent_relationship_test.rb +- test/integration/app/test/unit/single_sti_parent_test.rb +- test/integration/app/test/unit/stick_test.rb +- test/integration/app/test/unit/stone_test.rb +- test/integration/server_test.rb +- test/models/aquatic/fish.rb +- test/models/aquatic/pupils_whale.rb +- test/models/aquatic/whale.rb +- test/models/beautiful_fight_relationship.rb +- test/models/canine.rb +- test/models/cat.rb +- test/models/dog.rb +- test/models/eaters_foodstuff.rb +- test/models/frog.rb +- test/models/kitten.rb +- test/models/parentship.rb +- test/models/person.rb +- test/models/petfood.rb +- test/models/tabby.rb +- test/models/wild_boar.rb +- test/modules/extension_module.rb +- test/modules/other_extension_module.rb +- test/patches/symlinked_plugins_1.2.6.diff +- test/schema.rb +- test/setup.rb +- test/test_helper.rb +- test/unit/has_many_polymorphs_test.rb +- TODO +- has_many_polymorphs.gemspec +has_rdoc: true +homepage: http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/ +licenses: [] + +post_install_message: +rdoc_options: +- --line-numbers +- --inline-source +- --title +- Has_many_polymorphs +- --main +- README +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +required_rubygems_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 11 + segments: + - 1 + - 2 + version: "1.2" +requirements: [] + +rubyforge_project: fauna +rubygems_version: 1.3.7 +signing_key: +specification_version: 2 +summary: An ActiveRecord plugin for self-referential and double-sided polymorphic associations. +test_files: +- test/generator/tagging_generator_test.rb +- test/integration/server_test.rb +- test/unit/has_many_polymorphs_test.rb diff --git a/vendor/gems/has_many_polymorphs-2.13/CHANGELOG b/vendor/gems/has_many_polymorphs-2.13/CHANGELOG new file mode 100644 index 00000000..ec8ef45f --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/CHANGELOG @@ -0,0 +1,84 @@ +v2.13. Merge various fixes for Rails 2.2.2. + +v2.12. Improvements to the test suite; bugfixes for STI children (rsl). Remove fancy dependency system in favor of using Dispatcher::to_prepare every time. + +v2.11. Rails 1.2.6 tagging generator compatibility; change test suite to use included integration app. + +v2.10. Add :parent_conditions option; bugfix for nullified conditions; bugfix for self-referential tagging generator; allow setting of has_many_polymorphs_options hash in Configuration's after_initialize if you need to adjust the autoload behavior; clear error message on missing or improperly namespaced models; fix .build on double-sided relationships; add :namespace key for easier set up of Camping apps or other unusual class structures. + +v2.9. Gem version renumbering; my apologies if this messes anyone up. + +v2.8. RDoc documentation; repository relocation; Rakefile cleanup; remove deprecated plugin-specific class caching. + +v2.7.5. Various bugfixes; Postgres problems may remain on edge. + +v2.7.3. Use new :source and :source_type options in 1.2.3 (David Lemstra); fix pluralization bug; add some tests; experimental tagging generator. + +v2.7.2. Deprecate has_many_polymorphs_cache_classes= option because it doesn't really work. Use config.cache_classes= instead to cache all reloadable items. + +v2.7.1. Dispatcher.to_prepare didn't fire in the console; now using a config.after_initialize wrapper instead. + +v2.7. Dependency injection framework elimates having to care about load order. + +v2.6. Make the logger act sane for the gem version. + +v2.5.2. Allow :skip_duplicates on double relationships. + +v2.5.1. Renamed :ignore_duplicates to :skip_duplicates to better express its non-passive behavior; made sure not to load target set on push unless necessary. + +v2.5. Activerecord compatibility branch becomes trunk: extra options now supported for double polymorphism; conditions nulled-out and propogated to child relationships; more tests; new :ignore_duplicates option on macro can be set to false if you want << to push duplicate associations. + +v2.4.1. Code split into multiple files; tests added for pluralization check; Rails 1.1.6 no longer supported. + +v2.4. Unlimited mixed class association extensions for both single and double targets and joins. + +v2.3. Gem version + +v2.2. API change; prefix on methods is now singular when using :rename_individual_collections. + +v2.1. Add configuration option to cache polymorphic classes in development mode. + +v2.0. Collection methods (push, delete, clear) now on individual collections. + +v1.9.2. Disjoint collection sides bugfix, don't raise on new records. + +v1.9.1. Double classify bugfix. + +v1.9. Large changes to properly support double polymorphism. + +v1.8.2. Bugfix to make sure the type gets checked on doubly polymorphic parents. + +v1.8.1. Bugfix for sqlite3 child attribute retrieval. + +v1.8. Bugfix for instantiating attributes of namespaced models. + +v1.7.1. Bugfix for double polymorphic relationships. + +v1.7. Double polymorphic relationships (includes new API method). + +v1.6. Namespaced model support. + +v1.5. Bugfix for Postgres and Mysql under 1.1.6; refactored tests (hildofur); properly handles legacy table names set with set_table_name(). + +v1.4. STI support added (use the child class names, not the base class). + +v1.3. Bug regarding table names with underscores in SQL query fixed. + +v1.2. License change, again. + +v1.1. File_column bug fixed. + +v1.0. Tests written; after_find and after_initialize now correctly called. + +v0.5. SQL performance enhancements added. + +v0.4. Rewrote singletons as full-fledged proxy class so that marshalling works (e.g. in the session). + +v0.3. Caching added. + +v0.2. Fixed dependency reloading problem in development mode. + +v0.1. License change. + +v0. Added :dependent support on the join table; no changelog before this version. + diff --git a/vendor/gems/has_many_polymorphs-2.13/LICENSE b/vendor/gems/has_many_polymorphs-2.13/LICENSE new file mode 100644 index 00000000..90eec26b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/LICENSE @@ -0,0 +1,184 @@ +Academic Free License (AFL) v. 3.0 + +This Academic Free License (the "License") applies to any original work +of authorship (the "Original Work") whose owner (the "Licensor") has +placed the following licensing notice adjacent to the copyright notice +for the Original Work: + +Licensed under the Academic Free License version 3.0 + +1) Grant of Copyright License. Licensor grants You a worldwide, +royalty-free, non-exclusive, sublicensable license, for the duration of +the copyright, to do the following: + +a) to reproduce the Original Work in copies, either alone or as part of +a collective work; + +b) to translate, adapt, alter, transform, modify, or arrange the +Original Work, thereby creating derivative works ("Derivative Works") +based upon the Original Work; + +c) to distribute or communicate copies of the Original Work and +Derivative Works to the public, under any license of your choice that +does not contradict the terms and conditions, including Licensor's +reserved rights and remedies, in this Academic Free License; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor grants You a worldwide, +royalty-free, non-exclusive, sublicensable license, under patent claims +owned or controlled by the Licensor that are embodied in the Original +Work as furnished by the Licensor, for the duration of the patents, to +make, use, sell, offer for sale, have made, and import the Original Work +and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the +preferred form of the Original Work for making modifications to it and +all available documentation describing how to modify the Original Work. +Licensor agrees to provide a machine-readable copy of the Source Code of +the Original Work along with each copy of the Original Work that +Licensor distributes. Licensor reserves the right to satisfy this +obligation by placing a machine-readable copy of the Source Code in an +information repository reasonably calculated to permit inexpensive and +convenient access by You for as long as Licensor continues to distribute +the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor the +names of any contributors to the Original Work, nor any of their +trademarks or service marks, may be used to endorse or promote products +derived from this Original Work without express prior permission of the +Licensor. Except as expressly stated herein, nothing in this License +grants any license to Licensor's trademarks, copyrights, patents, trade +secrets or any other intellectual property. No patent license is granted +to make, use, sell, offer for sale, have made, or import embodiments of +any patent claims other than the licensed claims defined in Section 2. +No license is granted to the trademarks of Licensor even if such marks +are included in the Original Work. Nothing in this License shall be +interpreted to prohibit Licensor from licensing under terms different +from this License any Original Work that Licensor otherwise would have a +right to license. + +5) External Deployment. The term "External Deployment" means the use, +distribution, or communication of the Original Work or Derivative Works +in any way such that the Original Work or Derivative Works may be used +by anyone other than You, whether those works are distributed or +communicated to those persons or made available as an application +intended for use over a network. As an express condition for the grants +of license hereunder, You must treat any External Deployment by You of +the Original Work or a Derivative Work as a distribution under section +1(c). + +6) Attribution Rights. You must retain, in the Source Code of any +Derivative Works that You create, all copyright, patent, or trademark +notices from the Source Code of the Original Work, as well as any +notices of licensing and any descriptive text identified therein as an +"Attribution Notice." You must cause the Source Code for any Derivative +Works that You create to carry a prominent Attribution Notice reasonably +calculated to inform recipients that You have modified the Original +Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants +that the copyright in and to the Original Work and the patent rights +granted herein by Licensor are owned by the Licensor or are sublicensed +to You under the terms of this License with the permission of the +contributor(s) of those copyrights and patent rights. Except as +expressly stated in the immediately preceding sentence, the Original +Work is provided under this License on an "AS IS" BASIS and WITHOUT +WARRANTY, either express or implied, including, without limitation, the +warranties of non-infringement, merchantability or fitness for a +particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL +WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential +part of this License. No license to the Original Work is granted by this +License except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal +theory, whether in tort (including negligence), contract, or otherwise, +shall the Licensor be liable to anyone for any indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or the use of the Original Work including, +without limitation, damages for loss of goodwill, work stoppage, +computer failure or malfunction, or any and all other commercial damages +or losses. This limitation of liability shall not apply to the extent +applicable law prohibits such limitation. + +9) Acceptance and Termination. If, at any time, You expressly assented +to this License, that assent indicates your clear and irrevocable +acceptance of this License and all of its terms and conditions. If You +distribute or communicate copies of the Original Work or a Derivative +Work, You must make a reasonable effort under the circumstances to +obtain the express assent of recipients to the terms of this License. +This License conditions your rights to undertake the activities listed +in Section 1, including your right to create Derivative Works based upon +the Original Work, and doing so without honoring these terms and +conditions is prohibited by copyright law and international treaty. +Nothing in this License is intended to affect copyright exceptions and +limitations (including "fair use" or "fair dealing"). This License shall +terminate immediately and You may no longer exercise any of the rights +granted to You by this License upon your failure to honor the conditions +in Section 1(c). + +10) Termination for Patent Action. This License shall terminate +automatically and You may no longer exercise any of the rights granted +to You by this License as of the date You commence an action, including +a cross-claim or counterclaim, against Licensor or any licensee alleging +that the Original Work infringes a patent. This termination provision +shall not apply for an action alleging patent infringement by +combinations of the Original Work with other software or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating +to this License may be brought only in the courts of a jurisdiction +wherein the Licensor resides or in which Licensor conducts its primary +business, and under the laws of that jurisdiction excluding its +conflict-of-law provisions. The application of the United Nations +Convention on Contracts for the International Sale of Goods is expressly +excluded. Any use of the Original Work outside the scope of this License +or after its termination shall be subject to the requirements and +penalties of copyright or patent law in the appropriate jurisdiction. +This section shall survive the termination of this License. + +12) Attorneys' Fees. In any action to enforce the terms of this License +or seeking damages relating thereto, the prevailing party shall be +entitled to recover its costs and expenses, including, without +limitation, reasonable attorneys' fees and costs incurred in connection +with such action, including any appeal of such action. This section +shall survive the termination of this License. + +13) Miscellaneous. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this License, +whether in upper or lower case, means an individual or a legal entity +exercising rights under, and complying with all of the terms of, this +License. For legal entities, "You" includes any entity that controls, is +controlled by, or is under common control with you. For purposes of this +definition, "control" means (i) the power, direct or indirect, to cause +the direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not +otherwise restricted or conditioned by this License or by law, and +Licensor promises not to interfere with or be responsible for such uses +by You. + +16) Modification of This License. This License is Copyright (c) 2005 +Lawrence Rosen. Permission is granted to copy, distribute, or +communicate this License without modification. Nothing in this License +permits You to modify this License as applied to the Original Work or to +Derivative Works. However, You may modify the text of this License and +copy, distribute or communicate your modified version (the "Modified +License") and apply it to other original works of authorship subject to +the following conditions: (i) You may not indicate in any way that your +Modified License is the "Academic Free License" or "AFL" and you may not +use those names in the name of your Modified License; (ii) You must +replace the notice specified in the first paragraph above with the +notice "Licensed under " or with a notice +of your own that is not confusingly similar to the notice in this +License; and (iii) You may not claim that your original works are open +source software unless your Modified License has been approved by Open +Source Initiative (OSI) and You comply with its license review and +certification process. + diff --git a/vendor/gems/has_many_polymorphs-2.13/Manifest b/vendor/gems/has_many_polymorphs-2.13/Manifest new file mode 100644 index 00000000..c0555eff --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/Manifest @@ -0,0 +1,173 @@ +CHANGELOG +examples/hmph.rb +generators/tagging/tagging_generator.rb +generators/tagging/templates/migration.rb +generators/tagging/templates/tag.rb +generators/tagging/templates/tag_test.rb +generators/tagging/templates/tagging.rb +generators/tagging/templates/tagging_extensions.rb +generators/tagging/templates/tagging_test.rb +generators/tagging/templates/taggings.yml +generators/tagging/templates/tags.yml +init.rb +lib/has_many_polymorphs/association.rb +lib/has_many_polymorphs/autoload.rb +lib/has_many_polymorphs/base.rb +lib/has_many_polymorphs/class_methods.rb +lib/has_many_polymorphs/configuration.rb +lib/has_many_polymorphs/debugging_tools.rb +lib/has_many_polymorphs/rake_task_redefine_task.rb +lib/has_many_polymorphs/reflection.rb +lib/has_many_polymorphs/support_methods.rb +lib/has_many_polymorphs.rb +LICENSE +Manifest +Rakefile +README +test/fixtures/bow_wows.yml +test/fixtures/cats.yml +test/fixtures/eaters_foodstuffs.yml +test/fixtures/fish.yml +test/fixtures/frogs.yml +test/fixtures/keep_your_enemies_close.yml +test/fixtures/little_whale_pupils.yml +test/fixtures/people.yml +test/fixtures/petfoods.yml +test/fixtures/whales.yml +test/fixtures/wild_boars.yml +test/generator/tagging_generator_test.rb +test/integration/app/app/controllers/application.rb +test/integration/app/app/controllers/bones_controller.rb +test/integration/app/app/helpers/addresses_helper.rb +test/integration/app/app/helpers/application_helper.rb +test/integration/app/app/helpers/bones_helper.rb +test/integration/app/app/helpers/sellers_helper.rb +test/integration/app/app/helpers/states_helper.rb +test/integration/app/app/helpers/users_helper.rb +test/integration/app/app/models/bone.rb +test/integration/app/app/models/double_sti_parent.rb +test/integration/app/app/models/double_sti_parent_relationship.rb +test/integration/app/app/models/organic_substance.rb +test/integration/app/app/models/single_sti_parent.rb +test/integration/app/app/models/single_sti_parent_relationship.rb +test/integration/app/app/models/stick.rb +test/integration/app/app/models/stone.rb +test/integration/app/app/views/addresses/edit.html.erb +test/integration/app/app/views/addresses/index.html.erb +test/integration/app/app/views/addresses/new.html.erb +test/integration/app/app/views/addresses/show.html.erb +test/integration/app/app/views/bones/index.rhtml +test/integration/app/app/views/layouts/addresses.html.erb +test/integration/app/app/views/layouts/sellers.html.erb +test/integration/app/app/views/layouts/states.html.erb +test/integration/app/app/views/layouts/users.html.erb +test/integration/app/app/views/sellers/edit.html.erb +test/integration/app/app/views/sellers/index.html.erb +test/integration/app/app/views/sellers/new.html.erb +test/integration/app/app/views/sellers/show.html.erb +test/integration/app/app/views/states/edit.html.erb +test/integration/app/app/views/states/index.html.erb +test/integration/app/app/views/states/new.html.erb +test/integration/app/app/views/states/show.html.erb +test/integration/app/app/views/users/edit.html.erb +test/integration/app/app/views/users/index.html.erb +test/integration/app/app/views/users/new.html.erb +test/integration/app/app/views/users/show.html.erb +test/integration/app/config/boot.rb +test/integration/app/config/database.yml +test/integration/app/config/environment.rb +test/integration/app/config/environment.rb.canonical +test/integration/app/config/environments/development.rb +test/integration/app/config/environments/production.rb +test/integration/app/config/environments/test.rb +test/integration/app/config/locomotive.yml +test/integration/app/config/routes.rb +test/integration/app/config/ultrasphinx/default.base +test/integration/app/config/ultrasphinx/development.conf.canonical +test/integration/app/db/migrate/001_create_sticks.rb +test/integration/app/db/migrate/002_create_stones.rb +test/integration/app/db/migrate/003_create_organic_substances.rb +test/integration/app/db/migrate/004_create_bones.rb +test/integration/app/db/migrate/005_create_single_sti_parents.rb +test/integration/app/db/migrate/006_create_double_sti_parents.rb +test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +test/integration/app/db/migrate/009_create_library_model.rb +test/integration/app/doc/README_FOR_APP +test/integration/app/generators/commenting_generator_test.rb +test/integration/app/lib/library_model.rb +test/integration/app/public/404.html +test/integration/app/public/500.html +test/integration/app/public/dispatch.cgi +test/integration/app/public/dispatch.fcgi +test/integration/app/public/dispatch.rb +test/integration/app/public/favicon.ico +test/integration/app/public/images/rails.png +test/integration/app/public/index.html +test/integration/app/public/javascripts/application.js +test/integration/app/public/javascripts/controls.js +test/integration/app/public/javascripts/dragdrop.js +test/integration/app/public/javascripts/effects.js +test/integration/app/public/javascripts/prototype.js +test/integration/app/public/robots.txt +test/integration/app/public/stylesheets/scaffold.css +test/integration/app/Rakefile +test/integration/app/README +test/integration/app/script/about +test/integration/app/script/breakpointer +test/integration/app/script/console +test/integration/app/script/destroy +test/integration/app/script/generate +test/integration/app/script/performance/benchmarker +test/integration/app/script/performance/profiler +test/integration/app/script/plugin +test/integration/app/script/process/inspector +test/integration/app/script/process/reaper +test/integration/app/script/process/spawner +test/integration/app/script/runner +test/integration/app/script/server +test/integration/app/test/fixtures/double_sti_parent_relationships.yml +test/integration/app/test/fixtures/double_sti_parents.yml +test/integration/app/test/fixtures/organic_substances.yml +test/integration/app/test/fixtures/single_sti_parent_relationships.yml +test/integration/app/test/fixtures/single_sti_parents.yml +test/integration/app/test/fixtures/sticks.yml +test/integration/app/test/fixtures/stones.yml +test/integration/app/test/functional/addresses_controller_test.rb +test/integration/app/test/functional/bones_controller_test.rb +test/integration/app/test/functional/sellers_controller_test.rb +test/integration/app/test/functional/states_controller_test.rb +test/integration/app/test/functional/users_controller_test.rb +test/integration/app/test/test_helper.rb +test/integration/app/test/unit/bone_test.rb +test/integration/app/test/unit/double_sti_parent_relationship_test.rb +test/integration/app/test/unit/double_sti_parent_test.rb +test/integration/app/test/unit/organic_substance_test.rb +test/integration/app/test/unit/single_sti_parent_relationship_test.rb +test/integration/app/test/unit/single_sti_parent_test.rb +test/integration/app/test/unit/stick_test.rb +test/integration/app/test/unit/stone_test.rb +test/integration/server_test.rb +test/models/aquatic/fish.rb +test/models/aquatic/pupils_whale.rb +test/models/aquatic/whale.rb +test/models/beautiful_fight_relationship.rb +test/models/canine.rb +test/models/cat.rb +test/models/dog.rb +test/models/eaters_foodstuff.rb +test/models/frog.rb +test/models/kitten.rb +test/models/parentship.rb +test/models/person.rb +test/models/petfood.rb +test/models/tabby.rb +test/models/wild_boar.rb +test/modules/extension_module.rb +test/modules/other_extension_module.rb +test/patches/symlinked_plugins_1.2.6.diff +test/schema.rb +test/setup.rb +test/test_helper.rb +test/unit/has_many_polymorphs_test.rb +TODO diff --git a/vendor/gems/has_many_polymorphs-2.13/README b/vendor/gems/has_many_polymorphs-2.13/README new file mode 100644 index 00000000..2f3f73f9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/README @@ -0,0 +1,205 @@ +Has_many_polymorphs + +An ActiveRecord plugin for self-referential and double-sided polymorphic associations. + +== License + +Copyright 2006-2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. + +The public certificate for the gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem]. + +If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails. + +== Description + +This plugin lets you define self-referential and double-sided polymorphic associations in your models. It is an extension of has_many :through. + +“Polymorphic” means an association can freely point to any of several unrelated model classes, instead of being tied to one particular class. + +== Features + +* self-references +* double-sided polymorphism +* efficient database usage +* STI support +* namespace support +* automatic individual and reverse associations + +The plugin also includes a generator for a tagging system, a common use case (see below). + +== Requirements + +* Rails 2.2.2 or greater + += Usage + +== Installation + +To install the Rails plugin, run: + script/plugin install git://github.com/fauna/has_many_polymorphs.git + +There's also a gem version. To install it instead, run: + sudo gem install has_many_polymorphs + +If you are using the gem, make sure to add require 'has_many_polymorphs' to environment.rb, before Rails::Initializer block. + +== Configuration + +Setup the parent model as so: + + class Kennel < ActiveRecord::Base + has_many_polymorphs :guests, :from => [:dogs, :cats, :birds] + end + +The join model: + + class GuestsKennel < ActiveRecord::Base + belongs_to :kennel + belongs_to :guest, :polymorphic => true + end + +One of the child models: + + class Dog < ActiveRecord::Base + # nothing + end + +For your parent and child models, you don't need any special fields in your migration. For the join model (GuestsKennel), use a migration like so: + + class CreateGuestsKennels < ActiveRecord::Migration + def self.up + create_table :guests_kennels do |t| + t.references :guest, :polymorphic => true + t.references :kennel + end + end + + def self.down + drop_table :guests_kennels + end + end + +See ActiveRecord::Associations::PolymorphicClassMethods for more configuration options. + +== Helper methods example + + >> k = Kennel.find(1) + # + >> k.guests.map(&:class) + [Dog, Cat, Cat, Bird] + + >> k.guests.push(Cat.create); k.cats.size + 3 + >> k.guests << Cat.create; k.cats.size + 4 + >> k.guests.size + 6 + + >> d = k.dogs.first + # + >> d.kennels + [#] + + >> k.guests.delete(d); k.dogs.size + 0 + >> k.guests.size + 5 + +Note that the parent method is always plural, even if there is only one parent (Dog#kennels, not Dog#kennel). + +See ActiveRecord::Associations::PolymorphicAssociation for more helper method details. + += Extras + +== Double-sided polymorphism + +Double-sided relationships are defined on the join model: + + class Devouring < ActiveRecord::Base + belongs_to :guest, :polymorphic => true + belongs_to :eaten, :polymorphic => true + + acts_as_double_polymorphic_join( + :guests =>[:dogs, :cats], + :eatens => [:cats, :birds] + ) + end + +Now, dogs and cats can eat birds and cats. Birds can't eat anything (they aren't guests) and dogs can't be eaten by anything (since they aren't eatens). The keys stand for what the models are, not what they do. + +In this case, each guest/eaten relationship is called a Devouring. + +In your migration, you need to declare both sides as polymorphic: + + class CreateDevourings < ActiveRecord::Migration + def self.up + create_table :devourings do |t| + t.references :guest, :polymorphic => true + t.references :eaten, :polymorphic => true + end + end + + def self.down + drop_table :devourings + end + end + +See ActiveRecord::Associations::PolymorphicClassMethods for more. + +== Tagging generator + +Has_many_polymorphs includes a tagging system generator. Run: + script/generate tagging Dog Cat [...MoreModels...] + +This adds a migration and new Tag and Tagging models in app/models. It configures Tag with an appropriate has_many_polymorphs call against the models you list at the command line. It also adds the file lib/tagging_extensions.rb and requires it in environment.rb. + +Tests will also be generated. + +Once you've run the generator, you can tag records as follows: + + >> d = Dog.create(:name => "Rover") + # + >> d.tag_list + "" + >> d.tag_with "fierce loud" + # + >> d.tag_list + "fierce loud" + >> c = Cat.create(:name => "Chloe") + # + >> c.tag_with "fierce cute" + # + >> c.tag_list + "cute fierce" + >> Tag.find_by_name("fierce").taggables + [#, #] + +The generator accepts the optional flag --skip-migration to skip generating a migration (for example, if you are converting from acts_as_taggable). It also accepts the flag --self-referential if you want to be able to tag tags. + +See ActiveRecord::Base::TaggingExtensions, Tag, and Tagging for more. + +== Troubleshooting + +Some debugging tools are available in lib/has_many_polymorphs/debugging_tools.rb. + +If you are having trouble, think very carefully about how your model classes, key columns, and table names relate. You may have to explicitly specify options on your join model such as :class_name, :foreign_key, or :as. The included tests are a good place to look for examples. + +Note that because of the way Rails reloads model classes, the plugin can sometimes bog down your development server. Set config.cache_classes = true in config/environments/development.rb to avoid this. + +== Reporting problems + +The support forum is here[http://rubyforge.org/forum/forum.php?forum_id=16450]. + +Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC. + +== Further resources + +* http://blog.evanweaver.com/articles/2007/08/15/polymorphs-tutorial +* http://blog.evanweaver.com/articles/2007/02/22/polymorphs-25-total-insanity-branch +* http://blog.evanweaver.com/articles/2007/02/09/how-to-find-the-most-popular-tags +* http://blog.evanweaver.com/articles/2007/01/13/growing-up-your-acts_as_taggable +* http://blog.evanweaver.com/articles/2006/12/02/polymorphs-19 +* http://blog.evanweaver.com/articles/2006/11/05/directed-double-polymorphic-associations +* http://blog.evanweaver.com/articles/2006/11/04/namespaced-model-support-in-has_many_polymorphs +* http://blog.evanweaver.com/articles/2006/09/26/sti-support-in-has_many_polymorphs +* http://blog.evanweaver.com/articles/2006/09/11/make-polymorphic-children-belong-to-only-one-parent diff --git a/vendor/gems/has_many_polymorphs-2.13/Rakefile b/vendor/gems/has_many_polymorphs-2.13/Rakefile new file mode 100644 index 00000000..b93a94f5 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/Rakefile @@ -0,0 +1,28 @@ + +require 'echoe' + +Echoe.new("has_many_polymorphs") do |p| + p.project = "fauna" + p.summary = "An ActiveRecord plugin for self-referential and double-sided polymorphic associations." + p.url = "http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/" + p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/" + p.dependencies = ["activerecord"] + p.rdoc_pattern = /polymorphs\/association|polymorphs\/class_methods|polymorphs\/reflection|polymorphs\/autoload|polymorphs\/configuration|README|CHANGELOG|TODO|LICENSE|templates\/migration\.rb|templates\/tag\.rb|templates\/tagging\.rb|templates\/tagging_extensions\.rb/ + p.require_signed = true + p.clean_pattern += ["**/ruby_sess*", "**/generated_models/**"] + p.test_pattern = ["test/unit/*_test.rb", "test/integration/*_test.rb", "test/generator/*_test.rb"] +end + +desc "Run all the tests for every database adapter" +task "test_all" do + ['mysql', 'postgresql', 'sqlite3'].each do |adapter| + ENV['DB'] = adapter + ENV['PRODUCTION'] = nil + STDERR.puts "#{'='*80}\nDevelopment mode for #{adapter}\n#{'='*80}" + system("rake test:multi_rails:all") + + ENV['PRODUCTION'] = '1' + STDERR.puts "#{'='*80}\nProduction mode for #{adapter}\n#{'='*80}" + system("rake test:multi_rails:all") + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/TODO b/vendor/gems/has_many_polymorphs-2.13/TODO new file mode 100644 index 00000000..b06e28f2 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/TODO @@ -0,0 +1,2 @@ + +* Tag cloud method diff --git a/vendor/gems/has_many_polymorphs-2.13/examples/hmph.rb b/vendor/gems/has_many_polymorphs-2.13/examples/hmph.rb new file mode 100644 index 00000000..67017505 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/examples/hmph.rb @@ -0,0 +1,69 @@ +require 'camping' +require 'has_many_polymorphs' + +Camping.goes :Hmph + +module Hmph::Models + class GuestsKennel < Base + belongs_to :kennel + belongs_to :guest, :polymorphic => true + end + + class Dog < Base + end + + class Cat < Base + end + + class Bird < Base + end + + class Kennel < Base + has_many_polymorphs :guests, + :from => [:dogs, :cats, :birds], + :through => :guests_kennels, + :namespace => :"hmph/models/" + end + + class InitialSchema < V 1.0 + def self.up + create_table :hmph_kennels do |t| + t.column :created_at, :datetime + t.column :modified_at, :datetime + t.column :name, :string, :default => 'Anonymous Kennel' + end + + create_table :hmph_guests_kennels do |t| + t.column :guest_id, :integer + t.column :guest_type, :string + t.column :kennel_id, :integer + end + + create_table :hmph_dogs do |t| + t.column :name, :string, :default => 'Fido' + end + + create_table :hmph_cats do |t| + t.column :name, :string, :default => 'Morris' + end + + create_table :hmph_birds do |t| + t.column :name, :string, :default => 'Polly' + end + end + + def self.down + drop_table :hmph_kennels + drop_table :hmph_guests_kennels + drop_table :hmph_dogs + drop_table :hmph_cats + drop_table :hmph_birds + end + end +end + +module Hmph::Controllers +end + +module Hmph::Views +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/tagging_generator.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/tagging_generator.rb new file mode 100644 index 00000000..d99b10f8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/tagging_generator.rb @@ -0,0 +1,97 @@ +require 'ruby-debug' and Debugger.start if ENV['USER'] == 'eweaver' + +class TaggingGenerator < Rails::Generator::NamedBase + default_options :skip_migration => false + default_options :self_referential => false + attr_reader :parent_association_name + attr_reader :taggable_models + + def initialize(runtime_args, runtime_options = {}) + parse!(runtime_args, runtime_options) + + @parent_association_name = (runtime_args.include?("--self-referential") ? "tagger" : "tag") + @taggable_models = runtime_args.reject{|opt| opt =~ /^--/}.map do |taggable| + ":" + taggable.underscore.pluralize + end + @taggable_models += [":tags"] if runtime_args.include?("--self-referential") + @taggable_models.uniq! + + verify @taggable_models + hacks + runtime_args.unshift("placeholder") + super + end + + def verify models + puts "** Warning: only one taggable model specified; tests may not run properly." if models.size < 2 + models.each do |model| + model = model[1..-1].classify + next if model == "Tag" # don't load ourselves when --self-referential is used + self.class.const_get(model) rescue puts "** Error: model #{model[1..-1].classify} could not be loaded." or exit + end + end + + def hacks + # add the extension require in environment.rb + phrase = "require 'tagging_extensions'" + filename = "#{RAILS_ROOT}/config/environment.rb" + unless (open(filename) do |file| + file.grep(/#{Regexp.escape phrase}/).any? + end) + open(filename, 'a+') do |file| + file.puts "\n" + phrase + "\n" + end + end + end + + def manifest + record do |m| + m.class_collisions class_path, class_name, "#{class_name}Test" + + m.directory File.join('app/models', class_path) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/fixtures', class_path) + m.directory File.join('test/fixtures', class_path) + m.directory File.join('lib') + + m.template 'tag.rb', File.join('app/models', class_path, "tag.rb") + m.template 'tag_test.rb', File.join('test/unit', class_path, "tag_test.rb") + m.template 'tags.yml', File.join('test/fixtures', class_path, "tags.yml") + + m.template 'tagging.rb', File.join('app/models', class_path, "tagging.rb") + m.template 'tagging_test.rb', File.join('test/unit', class_path, "tagging_test.rb") + m.template 'taggings.yml', File.join('test/fixtures', class_path, "taggings.yml") + + m.template 'tagging_extensions.rb', File.join('lib', 'tagging_extensions.rb') + + unless options[:skip_migration] + m.migration_template 'migration.rb', 'db/migrate', + :migration_file_name => "create_tags_and_taggings" + end + + end + end + + protected + def banner + "Usage: #{$0} generate tagging [TaggableModelA TaggableModelB ...]" + end + + def add_options!(opt) + opt.separator '' + opt.separator 'Options:' + opt.on("--skip-migration", + "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } + opt.on("--self-referential", + "Allow tags to tag themselves.") { |v| options[:self_referential] = v } + end + + # Useful for generating tests/fixtures + def model_one + taggable_models[0][1..-1].classify + end + + def model_two + taggable_models[1][1..-1].classify rescue model_one + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/migration.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/migration.rb new file mode 100644 index 00000000..582b54c6 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/migration.rb @@ -0,0 +1,28 @@ + +# A migration to add tables for Tag and Tagging. This file is automatically generated and added to your app if you run the tagging generator included with has_many_polymorphs. + +class CreateTagsAndTaggings < ActiveRecord::Migration + + # Add the new tables. + def self.up + create_table :tags do |t| + t.column :name, :string, :null => false + end + add_index :tags, :name, :unique => true + + create_table :taggings do |t| + t.column :<%= parent_association_name -%>_id, :integer, :null => false + t.column :taggable_id, :integer, :null => false + t.column :taggable_type, :string, :null => false + # t.column :position, :integer # Uncomment this if you need to use acts_as_list. + end + add_index :taggings, [:<%= parent_association_name -%>_id, :taggable_id, :taggable_type], :unique => true + end + + # Remove the tables. + def self.down + drop_table :tags + drop_table :taggings + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag.rb new file mode 100644 index 00000000..1966a76b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag.rb @@ -0,0 +1,39 @@ + +# The Tag model. This model is automatically generated and added to your app if you run the tagging generator included with has_many_polymorphs. + +class Tag < ActiveRecord::Base + + DELIMITER = " " # Controls how to split and join tagnames from strings. You may need to change the validates_format_of parameters if you change this. + + # If database speed becomes an issue, you could remove these validations and rescue the ActiveRecord database constraint errors instead. + validates_presence_of :name + validates_uniqueness_of :name, :case_sensitive => false + + # Change this validation if you need more complex tag names. + validates_format_of :name, :with => /^[a-zA-Z0-9\_\-]+$/, :message => "can not contain special characters" + + # Set up the polymorphic relationship. + has_many_polymorphs :taggables, + :from => [<%= taggable_models.join(", ") %>], + :through => :taggings, + :dependent => :destroy, +<% if options[:self_referential] -%> :as => :<%= parent_association_name -%>, +<% end -%> + :skip_duplicates => false, + :parent_extend => proc { + # Defined on the taggable models, not on Tag itself. Return the tagnames associated with this record as a string. + def to_s + self.map(&:name).sort.join(Tag::DELIMITER) + end + } + + # Callback to strip extra spaces from the tagname before saving it. If you allow tags to be renamed later, you might want to use the before_save callback instead. + def before_create + self.name = name.downcase.strip.squeeze(" ") + end + + # Tag::Error class. Raised by ActiveRecord::Base::TaggingExtensions if something goes wrong. + class Error < StandardError + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag_test.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag_test.rb new file mode 100644 index 00000000..f4ab543a --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tag_test.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TagTest < Test::Unit::TestCase + fixtures <%= taggable_models[0..1].join(", ") -%> + + def setup + @obj = <%= model_two %>.find(:first) + @obj.tag_with "pale imperial" + end + + def test_to_s + assert_equal "imperial pale", <%= model_two -%>.find(:first).tags.to_s + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging.rb new file mode 100644 index 00000000..bb5ea28f --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging.rb @@ -0,0 +1,16 @@ + +# The Tagging join model. This model is automatically generated and added to your app if you run the tagging generator included with has_many_polymorphs. + +class Tagging < ActiveRecord::Base + + belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Tag\"" if options[:self_referential] %> + belongs_to :taggable, :polymorphic => true + + # If you also need to use acts_as_list, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables. + # acts_as_list :scope => :taggable + + # This callback makes sure that an orphaned Tag is deleted if it no longer tags anything. + def after_destroy + <%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.taggings.count == 0 + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_extensions.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_extensions.rb new file mode 100644 index 00000000..ca7e6add --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_extensions.rb @@ -0,0 +1,203 @@ +class ActiveRecord::Base #:nodoc: + + # These extensions make models taggable. This file is automatically generated and required by your app if you run the tagging generator included with has_many_polymorphs. + module TaggingExtensions + + # Add tags to self. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags. + # + # We need to avoid name conflicts with the built-in ActiveRecord association methods, thus the underscores. + def _add_tags incoming + taggable?(true) + tag_cast_to_string(incoming).each do |tag_name| + begin + tag = Tag.find_or_create_by_name(tag_name) + raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record? + tags << tag + rescue ActiveRecord::StatementInvalid => e + raise unless e.to_s =~ /duplicate/i + end + end + end + + # Removes tags from self. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags. + def _remove_tags outgoing + taggable?(true) + outgoing = tag_cast_to_string(outgoing) + <% if options[:self_referential] %> + # because of http://dev.rubyonrails.org/ticket/6466 + taggings.destroy(*(taggings.find(:all, :include => :<%= parent_association_name -%>).select do |tagging| + outgoing.include? tagging.<%= parent_association_name -%>.name + end)) + <% else -%> + <%= parent_association_name -%>s.delete(*(<%= parent_association_name -%>s.select do |tag| + outgoing.include? tag.name + end)) + <% end -%> + end + + # Returns the tags on self as a string. + def tag_list + # Redefined later to avoid an RDoc parse error. + end + + # Replace the existing tags on self. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags. + def tag_with list + #:stopdoc: + taggable?(true) + list = tag_cast_to_string(list) + + # Transactions may not be ideal for you here; be aware. + Tag.transaction do + current = <%= parent_association_name -%>s.map(&:name) + _add_tags(list - current) + _remove_tags(current - list) + end + + self + #:startdoc: + end + + # Returns the tags on self as a string. + def tag_list #:nodoc: + #:stopdoc: + taggable?(true) + <%= parent_association_name -%>s.reload + <%= parent_association_name -%>s.to_s + #:startdoc: + end + + def tag_list=(value) + tag_with(value) + end + + private + + def tag_cast_to_string obj #:nodoc: + case obj + when Array + obj.map! do |item| + case item + when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot. + when Tag then item.name + when String then item + else + raise "Invalid type" + end + end + when String + obj = obj.split(Tag::DELIMITER).map do |tag_name| + tag_name.strip.squeeze(" ") + end + else + raise "Invalid object of class #{obj.class} as tagging method parameter" + end.flatten.compact.map(&:downcase).uniq + end + + # Check if a model is in the :taggables target list. The alternative to this check is to explicitly include a TaggingMethods module (which you would create) in each target model. + def taggable?(should_raise = false) #:nodoc: + unless flag = respond_to?(:<%= parent_association_name -%>s) + raise "#{self.class} is not a taggable model" if should_raise + end + flag + end + + end + + module TaggingFinders + # Find all the objects tagged with the supplied list of tags + # + # Usage : Model.tagged_with("ruby") + # Model.tagged_with("hello", "world") + # Model.tagged_with("hello", "world", :limit => 10) + # + # XXX This query strategy is not performant, and needs to be rewritten as an inverted join or a series of unions + # + def tagged_with(*tag_list) + options = tag_list.last.is_a?(Hash) ? tag_list.pop : {} + tag_list = parse_tags(tag_list) + + scope = scope(:find) + options[:select] ||= "#{table_name}.*" + options[:from] ||= "#{table_name}, tags, taggings" + + sql = "SELECT #{(scope && scope[:select]) || options[:select]} " + sql << "FROM #{(scope && scope[:from]) || options[:from]} " + + add_joins!(sql, options[:joins], scope) + + sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " + sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' " + sql << "AND taggings.tag_id = tags.id " + + tag_list_condition = tag_list.map {|name| "'#{name}'"}.join(", ") + + sql << "AND (tags.name IN (#{sanitize_sql(tag_list_condition)})) " + sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions] + + columns = column_names.map do |column| + "#{table_name}.#{column}" + end.join(", ") + + sql << "GROUP BY #{columns} " + sql << "HAVING COUNT(taggings.tag_id) = #{tag_list.size}" + + add_order!(sql, options[:order], scope) + add_limit!(sql, options, scope) + add_lock!(sql, options, scope) + + find_by_sql(sql) + end + + def self.tagged_with_any(*tag_list) + options = tag_list.last.is_a?(Hash) ? tag_list.pop : {} + tag_list = parse_tags(tag_list) + + scope = scope(:find) + options[:select] ||= "#{table_name}.*" + options[:from] ||= "#{table_name}, meta_tags, taggings" + + sql = "SELECT #{(scope && scope[:select]) || options[:select]} " + sql << "FROM #{(scope && scope[:from]) || options[:from]} " + + add_joins!(sql, options, scope) + + sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " + sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' " + sql << "AND taggings.meta_tag_id = meta_tags.id " + + sql << "AND (" + or_options = [] + tag_list.each do |name| + or_options << "meta_tags.name = '#{name}'" + end + or_options_joined = or_options.join(" OR ") + sql << "#{or_options_joined}) " + + + sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions] + + columns = column_names.map do |column| + "#{table_name}.#{column}" + end.join(", ") + + sql << "GROUP BY #{columns} " + + add_order!(sql, options[:order], scope) + add_limit!(sql, options, scope) + add_lock!(sql, options, scope) + + find_by_sql(sql) + end + + def parse_tags(tags) + return [] if tags.blank? + tags = Array(tags).first + tags = tags.respond_to?(:flatten) ? tags.flatten : tags.split(Tag::DELIMITER) + tags.map { |tag| tag.strip.squeeze(" ") }.flatten.compact.map(&:downcase).uniq + end + + end + + include TaggingExtensions + extend TaggingFinders +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_test.rb b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_test.rb new file mode 100644 index 00000000..f055d381 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tagging_test.rb @@ -0,0 +1,85 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TaggingTest < Test::Unit::TestCase + fixtures :tags, :taggings, <%= taggable_models[0..1].join(", ") -%> + + def setup + @objs = <%= model_two %>.find(:all, :limit => 2) + + @obj1 = @objs[0] + @obj1.tag_with("pale") + @obj1.reload + + @obj2 = @objs[1] + @obj2.tag_with("pale imperial") + @obj2.reload + +<% if taggable_models.size > 1 -%> + @obj3 = <%= model_one -%>.find(:first) +<% end -%> + @tag1 = Tag.find(1) + @tag2 = Tag.find(2) + @tagging1 = Tagging.find(1) + end + + def test_tag_with + @obj2.tag_with "hoppy pilsner" + assert_equal "hoppy pilsner", @obj2.tag_list + end + + def test_find_tagged_with + @obj1.tag_with "seasonal lager ipa" + @obj2.tag_with ["lager", "stout", "fruity", "seasonal"] + + result1 = [@obj1] + assert_equal <%= model_two %>.tagged_with("ipa"), result1 + assert_equal <%= model_two %>.tagged_with("ipa lager"), result1 + assert_equal <%= model_two %>.tagged_with("ipa", "lager"), result1 + + result2 = [@obj1.id, @obj2.id].sort + assert_equal <%= model_two %>.tagged_with("seasonal").map(&:id).sort, result2 + assert_equal <%= model_two %>.tagged_with("seasonal lager").map(&:id).sort, result2 + assert_equal <%= model_two %>.tagged_with("seasonal", "lager").map(&:id).sort, result2 + end + +<% if options[:self_referential] -%> + def test_self_referential_tag_with + @tag1.tag_with [1, 2] + assert @tag1.tags.include?(@tag1) + assert !@tag2.tags.include?(@tag1) + end + +<% end -%> + def test__add_tags + @obj1._add_tags "porter longneck" + assert Tag.find_by_name("porter").taggables.include?(@obj1) + assert Tag.find_by_name("longneck").taggables.include?(@obj1) + assert_equal "longneck pale porter", @obj1.tag_list + + @obj1._add_tags [2] + assert_equal "imperial longneck pale porter", @obj1.tag_list + end + + def test__remove_tags + @obj2._remove_tags ["2", @tag1] + assert @obj2.tags.empty? + end + + def test_tag_list + assert_equal "imperial pale", @obj2.tag_list + end + + def test_taggable + assert_raises(RuntimeError) do + @tagging1.send(:taggable?, true) + end + assert !@tagging1.send(:taggable?) +<% if taggable_models.size > 1 -%> + assert @obj3.send(:taggable?) +<% end -%> +<% if options[:self_referential] -%> + assert @tag1.send(:taggable?) +<% end -%> + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/taggings.yml b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/taggings.yml new file mode 100644 index 00000000..0cf13b9d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/taggings.yml @@ -0,0 +1,23 @@ +--- +<% if taggable_models.size > 1 -%> +taggings_003: + <%= parent_association_name -%>_id: "2" + id: "3" + taggable_type: <%= model_one %> + taggable_id: "1" +<% end -%> +taggings_004: + <%= parent_association_name -%>_id: "2" + id: "4" + taggable_type: <%= model_two %> + taggable_id: "2" +taggings_001: + <%= parent_association_name -%>_id: "1" + id: "1" + taggable_type: <%= model_two %> + taggable_id: "1" +taggings_002: + <%= parent_association_name -%>_id: "1" + id: "2" + taggable_type: <%= model_two %> + taggable_id: "2" diff --git a/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tags.yml b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tags.yml new file mode 100644 index 00000000..517a8ce5 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/generators/tagging/templates/tags.yml @@ -0,0 +1,7 @@ +--- +tags_001: + name: pale + id: "1" +tags_002: + name: imperial + id: "2" diff --git a/vendor/gems/has_many_polymorphs-2.13/has_many_polymorphs.gemspec b/vendor/gems/has_many_polymorphs-2.13/has_many_polymorphs.gemspec new file mode 100644 index 00000000..3e1a69b7 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/has_many_polymorphs.gemspec @@ -0,0 +1,40 @@ +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{has_many_polymorphs} + s.version = "2.13" + + s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= + s.authors = [""] + s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"] + s.date = %q{2009-02-02} + s.description = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.} + s.email = %q{} + s.extra_rdoc_files = ["CHANGELOG", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/reflection.rb", "LICENSE", "README", "test/integration/app/doc/README_FOR_APP", "test/integration/app/README", "TODO"] + s.files = ["CHANGELOG", "examples/hmph.rb", "generators/tagging/tagging_generator.rb", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tag_test.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "generators/tagging/templates/tagging_test.rb", "generators/tagging/templates/taggings.yml", "generators/tagging/templates/tags.yml", "init.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/base.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/debugging_tools.rb", "lib/has_many_polymorphs/rake_task_redefine_task.rb", "lib/has_many_polymorphs/reflection.rb", "lib/has_many_polymorphs/support_methods.rb", "lib/has_many_polymorphs.rb", "LICENSE", "Manifest", "Rakefile", "README", "test/fixtures/bow_wows.yml", "test/fixtures/cats.yml", "test/fixtures/eaters_foodstuffs.yml", "test/fixtures/fish.yml", "test/fixtures/frogs.yml", "test/fixtures/keep_your_enemies_close.yml", "test/fixtures/little_whale_pupils.yml", "test/fixtures/people.yml", "test/fixtures/petfoods.yml", "test/fixtures/whales.yml", "test/fixtures/wild_boars.yml", "test/generator/tagging_generator_test.rb", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/bones_controller.rb", "test/integration/app/app/helpers/addresses_helper.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/bones_helper.rb", "test/integration/app/app/helpers/sellers_helper.rb", "test/integration/app/app/helpers/states_helper.rb", "test/integration/app/app/helpers/users_helper.rb", "test/integration/app/app/models/bone.rb", "test/integration/app/app/models/double_sti_parent.rb", "test/integration/app/app/models/double_sti_parent_relationship.rb", "test/integration/app/app/models/organic_substance.rb", "test/integration/app/app/models/single_sti_parent.rb", "test/integration/app/app/models/single_sti_parent_relationship.rb", "test/integration/app/app/models/stick.rb", "test/integration/app/app/models/stone.rb", "test/integration/app/app/views/addresses/edit.html.erb", "test/integration/app/app/views/addresses/index.html.erb", "test/integration/app/app/views/addresses/new.html.erb", "test/integration/app/app/views/addresses/show.html.erb", "test/integration/app/app/views/bones/index.rhtml", "test/integration/app/app/views/layouts/addresses.html.erb", "test/integration/app/app/views/layouts/sellers.html.erb", "test/integration/app/app/views/layouts/states.html.erb", "test/integration/app/app/views/layouts/users.html.erb", "test/integration/app/app/views/sellers/edit.html.erb", "test/integration/app/app/views/sellers/index.html.erb", "test/integration/app/app/views/sellers/new.html.erb", "test/integration/app/app/views/sellers/show.html.erb", "test/integration/app/app/views/states/edit.html.erb", "test/integration/app/app/views/states/index.html.erb", "test/integration/app/app/views/states/new.html.erb", "test/integration/app/app/views/states/show.html.erb", "test/integration/app/app/views/users/edit.html.erb", "test/integration/app/app/views/users/index.html.erb", "test/integration/app/app/views/users/new.html.erb", "test/integration/app/app/views/users/show.html.erb", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environment.rb.canonical", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/locomotive.yml", "test/integration/app/config/routes.rb", "test/integration/app/config/ultrasphinx/default.base", "test/integration/app/config/ultrasphinx/development.conf.canonical", "test/integration/app/db/migrate/001_create_sticks.rb", "test/integration/app/db/migrate/002_create_stones.rb", "test/integration/app/db/migrate/003_create_organic_substances.rb", "test/integration/app/db/migrate/004_create_bones.rb", "test/integration/app/db/migrate/005_create_single_sti_parents.rb", "test/integration/app/db/migrate/006_create_double_sti_parents.rb", "test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb", "test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb", "test/integration/app/db/migrate/009_create_library_model.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/generators/commenting_generator_test.rb", "test/integration/app/lib/library_model.rb", "test/integration/app/public/404.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/index.html", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/public/stylesheets/scaffold.css", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/breakpointer", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/fixtures/double_sti_parent_relationships.yml", "test/integration/app/test/fixtures/double_sti_parents.yml", "test/integration/app/test/fixtures/organic_substances.yml", "test/integration/app/test/fixtures/single_sti_parent_relationships.yml", "test/integration/app/test/fixtures/single_sti_parents.yml", "test/integration/app/test/fixtures/sticks.yml", "test/integration/app/test/fixtures/stones.yml", "test/integration/app/test/functional/addresses_controller_test.rb", "test/integration/app/test/functional/bones_controller_test.rb", "test/integration/app/test/functional/sellers_controller_test.rb", "test/integration/app/test/functional/states_controller_test.rb", "test/integration/app/test/functional/users_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/app/test/unit/bone_test.rb", "test/integration/app/test/unit/double_sti_parent_relationship_test.rb", "test/integration/app/test/unit/double_sti_parent_test.rb", "test/integration/app/test/unit/organic_substance_test.rb", "test/integration/app/test/unit/single_sti_parent_relationship_test.rb", "test/integration/app/test/unit/single_sti_parent_test.rb", "test/integration/app/test/unit/stick_test.rb", "test/integration/app/test/unit/stone_test.rb", "test/integration/server_test.rb", "test/models/aquatic/fish.rb", "test/models/aquatic/pupils_whale.rb", "test/models/aquatic/whale.rb", "test/models/beautiful_fight_relationship.rb", "test/models/canine.rb", "test/models/cat.rb", "test/models/dog.rb", "test/models/eaters_foodstuff.rb", "test/models/frog.rb", "test/models/kitten.rb", "test/models/parentship.rb", "test/models/person.rb", "test/models/petfood.rb", "test/models/tabby.rb", "test/models/wild_boar.rb", "test/modules/extension_module.rb", "test/modules/other_extension_module.rb", "test/patches/symlinked_plugins_1.2.6.diff", "test/schema.rb", "test/setup.rb", "test/test_helper.rb", "test/unit/has_many_polymorphs_test.rb", "TODO", "has_many_polymorphs.gemspec"] + s.has_rdoc = true + s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/} + s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Has_many_polymorphs", "--main", "README"] + s.require_paths = ["lib"] + s.rubyforge_project = %q{fauna} + s.rubygems_version = %q{1.3.1} + s.signing_key = %q{/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem} + s.summary = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.} + s.test_files = ["test/generator/tagging_generator_test.rb", "test/integration/server_test.rb", "test/unit/has_many_polymorphs_test.rb"] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 2 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/init.rb b/vendor/gems/has_many_polymorphs-2.13/init.rb new file mode 100644 index 00000000..3939a253 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/init.rb @@ -0,0 +1,2 @@ + +require 'has_many_polymorphs' diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs.rb new file mode 100644 index 00000000..03c600cc --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs.rb @@ -0,0 +1,27 @@ + +require 'active_record' + +RAILS_DEFAULT_LOGGER = nil unless defined? RAILS_DEFAULT_LOGGER + +require 'has_many_polymorphs/reflection' +require 'has_many_polymorphs/association' +require 'has_many_polymorphs/class_methods' + +require 'has_many_polymorphs/support_methods' +require 'has_many_polymorphs/base' + +class ActiveRecord::Base + extend ActiveRecord::Associations::PolymorphicClassMethods +end + +if ENV['HMP_DEBUG'] || ENV['RAILS_ENV'] =~ /development|test/ && ENV['USER'] == 'eweaver' + require 'has_many_polymorphs/debugging_tools' +end + +if defined? Rails and RAILS_ENV and RAILS_ROOT + _logger_warn "rails environment detected" + require 'has_many_polymorphs/configuration' + require 'has_many_polymorphs/autoload' +end + +_logger_debug "loaded ok" diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/association.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/association.rb new file mode 100644 index 00000000..a2b2d81a --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/association.rb @@ -0,0 +1,159 @@ +module ActiveRecord #:nodoc: + module Associations #:nodoc: + + class PolymorphicError < ActiveRecordError #:nodoc: + end + + class PolymorphicMethodNotSupportedError < ActiveRecordError #:nodoc: + end + + # The association class for a has_many_polymorphs association. + class PolymorphicAssociation < HasManyThroughAssociation + + # Push a record onto the association. Triggers a database load for a uniqueness check only if :skip_duplicates is true. Return value is undefined. + def <<(*records) + return if records.empty? + + if @reflection.options[:skip_duplicates] + _logger_debug "Loading instances for polymorphic duplicate push check; use :skip_duplicates => false and perhaps a database constraint to avoid this possible performance issue" + load_target + end + + @reflection.klass.transaction do + flatten_deeper(records).each do |record| + if @owner.new_record? or not record.respond_to?(:new_record?) or record.new_record? + raise PolymorphicError, "You can't associate unsaved records." + end + next if @reflection.options[:skip_duplicates] and @target.include? record + @owner.send(@reflection.through_reflection.name).proxy_target << @reflection.klass.create!(construct_join_attributes(record)) + @target << record if loaded? + end + end + + self + end + + alias :push :<< + alias :concat :<< + + # Runs a find against the association contents, returning the matched records. All regular find options except :include are supported. + def find(*args) + opts = args._extract_options! + opts.delete :include + super(*(args + [opts])) + end + + def construct_scope + _logger_warn "Warning; not all usage scenarios for polymorphic scopes are supported yet." + super + end + + # Deletes a record from the association. Return value is undefined. + def delete(*records) + records = flatten_deeper(records) + records.reject! {|record| @target.delete(record) if record.new_record?} + return if records.empty? + + @reflection.klass.transaction do + records.each do |record| + joins = @reflection.through_reflection.name + @owner.send(joins).delete(@owner.send(joins).select do |join| + join.send(@reflection.options[:polymorphic_key]) == record.id and + join.send(@reflection.options[:polymorphic_type_key]) == "#{record.class.base_class}" + end) + @target.delete(record) + end + end + end + + # Clears all records from the association. Returns an empty array. + def clear(klass = nil) + load_target + return if @target.empty? + + if klass + delete(@target.select {|r| r.is_a? klass }) + else + @owner.send(@reflection.through_reflection.name).clear + @target.clear + end + [] + end + + protected + +# undef :sum +# undef :create! + + def construct_quoted_owner_attributes(*args) #:nodoc: + # no access to returning() here? why not? + type_key = @reflection.options[:foreign_type_key] + {@reflection.primary_key_name => @owner.id, + type_key=> (@owner.class.base_class.name if type_key)} + end + + def construct_from #:nodoc: + # build the FROM part of the query, in this case, the polymorphic join table + @reflection.klass.table_name + end + + def construct_owner #:nodoc: + # the table name for the owner object's class + @owner.class.table_name + end + + def construct_owner_key #:nodoc: + # the primary key field for the owner object + @owner.class.primary_key + end + + def construct_select(custom_select = nil) #:nodoc: + # build the select query + selected = custom_select || @reflection.options[:select] + end + + def construct_joins(custom_joins = nil) #:nodoc: + # build the string of default joins + "JOIN #{construct_owner} polymorphic_parent ON #{construct_from}.#{@reflection.options[:foreign_key]} = polymorphic_parent.#{construct_owner_key} " + + @reflection.options[:from].map do |plural| + klass = plural._as_class + "LEFT JOIN #{klass.table_name} ON #{construct_from}.#{@reflection.options[:polymorphic_key]} = #{klass.table_name}.#{klass.primary_key} AND #{construct_from}.#{@reflection.options[:polymorphic_type_key]} = #{@reflection.klass.quote_value(klass.base_class.name)}" + end.uniq.join(" ") + " #{custom_joins}" + end + + def construct_conditions #:nodoc: + # build the fully realized condition string + conditions = construct_quoted_owner_attributes.map do |field, value| + "#{construct_from}.#{field} = #{@reflection.klass.quote_value(value)}" if value + end + conditions << custom_conditions if custom_conditions + "(" + conditions.compact.join(') AND (') + ")" + end + + def custom_conditions #:nodoc: + # custom conditions... not as messy as has_many :through because our joins are a little smarter + if @reflection.options[:conditions] + "(" + interpolate_sql(@reflection.klass.send(:sanitize_sql, @reflection.options[:conditions])) + ")" + end + end + + alias :construct_owner_attributes :construct_quoted_owner_attributes + alias :conditions :custom_conditions # XXX possibly not necessary + alias :sql_conditions :custom_conditions # XXX ditto + + # construct attributes for join for a particular record + def construct_join_attributes(record) #:nodoc: + {@reflection.options[:polymorphic_key] => record.id, + @reflection.options[:polymorphic_type_key] => "#{record.class.base_class}", + @reflection.options[:foreign_key] => @owner.id}.merge(@reflection.options[:foreign_type_key] ? + {@reflection.options[:foreign_type_key] => "#{@owner.class.base_class}"} : {}) # for double-sided relationships + end + + def build(attrs = nil) #:nodoc: + raise PolymorphicMethodNotSupportedError, "You can't associate new records." + end + + end + + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/autoload.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/autoload.rb new file mode 100644 index 00000000..f05c9dc8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/autoload.rb @@ -0,0 +1,69 @@ +require 'initializer' unless defined? ::Rails::Initializer +require 'action_controller/dispatcher' unless defined? ::ActionController::Dispatcher + +module HasManyPolymorphs + +=begin rdoc +Searches for models that use has_many_polymorphs or acts_as_double_polymorphic_join and makes sure that they get loaded during app initialization. This ensures that helper methods are injected into the target classes. + +Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_polymorphs_options. For example, if you need an application extension to be required before has_many_polymorphs loads your models, add an after_initialize block in config/environment.rb that appends to the 'requirements' key: + Rails::Initializer.run do |config| + # your other configuration here + + config.after_initialize do + config.has_many_polymorphs_options['requirements'] << 'lib/my_extension' + end + end + +=end + + DEFAULT_OPTIONS = { + :file_pattern => "#{RAILS_ROOT}/app/models/**/*.rb", + :file_exclusions => ['svn', 'CVS', 'bzr'], + :methods => ['has_many_polymorphs', 'acts_as_double_polymorphic_join'], + :requirements => []} + + mattr_accessor :options + @@options = HashWithIndifferentAccess.new(DEFAULT_OPTIONS) + + # Dispatcher callback to load polymorphic relationships from the top down. + def self.autoload + + _logger_debug "autoload hook invoked" + + options[:requirements].each do |requirement| + _logger_warn "forcing requirement load of #{requirement}" + require requirement + end + + Dir.glob(options[:file_pattern]).each do |filename| + next if filename =~ /#{options[:file_exclusions].join("|")}/ + open filename do |file| + if file.grep(/#{options[:methods].join("|")}/).any? + begin + model = File.basename(filename)[0..-4].camelize + _logger_warn "preloading parent model #{model}" + model.constantize + rescue Object => e + _logger_warn "#{model} could not be preloaded: #{e.inspect}" + end + end + end + end + end + +end + +class Rails::Initializer #:nodoc: + # Make sure it gets loaded in the console, tests, and migrations + def after_initialize_with_autoload + after_initialize_without_autoload + HasManyPolymorphs.autoload + end + alias_method_chain :after_initialize, :autoload +end + +ActionController::Dispatcher.to_prepare(:has_many_polymorphs_autoload) do + # Make sure it gets loaded in the app + HasManyPolymorphs.autoload +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/base.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/base.rb new file mode 100644 index 00000000..9513039c --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/base.rb @@ -0,0 +1,60 @@ + +module ActiveRecord + class Base + + class << self + + # Interprets a polymorphic row from a unified SELECT, returning the appropriate ActiveRecord instance. Overrides ActiveRecord::Base.instantiate_without_callbacks. + def instantiate_with_polymorphic_checks(record) + if record['polymorphic_parent_class'] + reflection = record['polymorphic_parent_class'].constantize.reflect_on_association(record['polymorphic_association_id'].to_sym) +# _logger_debug "Instantiating a polymorphic row for #{record['polymorphic_parent_class']}.reflect_on_association(:#{record['polymorphic_association_id']})" + + # rewrite the record with the right column names + table_aliases = reflection.options[:table_aliases].dup + record = Hash[*table_aliases.keys.map {|key| [key, record[table_aliases[key]]] }.flatten] + + # find the real child class + klass = record["#{self.table_name}.#{reflection.options[:polymorphic_type_key]}"].constantize + if sti_klass = record["#{klass.table_name}.#{klass.inheritance_column}"] + klass = klass.class_eval do compute_type(sti_klass) end # in case of namespaced STI models + end + + # check that the join actually joined to something + unless (child_id = record["#{self.table_name}.#{reflection.options[:polymorphic_key]}"]) == record["#{klass.table_name}.#{klass.primary_key}"] + raise ActiveRecord::Associations::PolymorphicError, + "Referential integrity violation; child <#{klass.name}:#{child_id}> was not found for #{reflection.name.inspect}" + end + + # eject the join keys + # XXX not very readable + record = Hash[*record._select do |column, value| + column[/^#{klass.table_name}/] + end.map do |column, value| + [column[/\.(.*)/, 1], value] + end.flatten] + + # allocate and assign values + returning(klass.allocate) do |obj| + obj.instance_variable_set("@attributes", record) + obj.instance_variable_set("@attributes_cache", Hash.new) + + if obj.respond_to_without_attributes?(:after_find) + obj.send(:callback, :after_find) + end + + if obj.respond_to_without_attributes?(:after_initialize) + obj.send(:callback, :after_initialize) + end + + end + else + instantiate_without_polymorphic_checks(record) + end + end + + alias_method_chain :instantiate, :polymorphic_checks + end + + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/class_methods.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/class_methods.rb new file mode 100644 index 00000000..394985cf --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/class_methods.rb @@ -0,0 +1,600 @@ + +module ActiveRecord #:nodoc: + module Associations #:nodoc: + +=begin rdoc + +Class methods added to ActiveRecord::Base for setting up polymorphic associations. + +== Notes + +STI association targets must enumerated and named. For example, if Dog and Cat both inherit from Animal, you still need to say [:dogs, :cats], and not [:animals]. + +Namespaced models follow the Rails underscore convention. ZooAnimal::Lion becomes :'zoo_animal/lion'. + +You do not need to set up any other associations other than for either the regular method or the double. The join associations and all individual and reverse associations are generated for you. However, a join model and table are required. + +There is a tentative report that you can make the parent model be its own join model, but this is untested. + +=end + + module PolymorphicClassMethods + + RESERVED_DOUBLES_KEYS = [:conditions, :order, :limit, :offset, :extend, :skip_duplicates, + :join_extend, :dependent, :rename_individual_collections, + :namespace] #:nodoc: + +=begin rdoc + +This method creates a doubled-sided polymorphic relationship. It must be called on the join model: + + class Devouring < ActiveRecord::Base + belongs_to :eater, :polymorphic => true + belongs_to :eaten, :polymorphic => true + + acts_as_double_polymorphic_join( + :eaters => [:dogs, :cats], + :eatens => [:cats, :birds] + ) + end + +The method works by defining one or more special has_many_polymorphs association on every model in the target lists, depending on which side of the association it is on. Double self-references will work. + +The two association names and their value arrays are the only required parameters. + +== Available options + +These options are passed through to targets on both sides of the association. If you want to affect only one side, prepend the key with the name of that side. For example, :eaters_extend. + +:dependent:: Accepts :destroy, :nullify, or :delete_all. Controls how the join record gets treated on any association delete (whether from the polymorph or from an individual collection); defaults to :destroy. +:skip_duplicates:: If true, will check to avoid pushing already associated records (but also triggering a database load). Defaults to true. +:rename_individual_collections:: If true, all individual collections are prepended with the polymorph name, and the children's parent collection is appended with "\_of_#{association_name}". +:extend:: One or an array of mixed modules and procs, which are applied to the polymorphic association (usually to define custom methods). +:join_extend:: One or an array of mixed modules and procs, which are applied to the join association. +:conditions:: An array or string of conditions for the SQL WHERE clause. +:order:: A string for the SQL ORDER BY clause. +:limit:: An integer. Affects the polymorphic and individual associations. +:offset:: An integer. Only affects the polymorphic association. +:namespace:: A symbol. Prepended to all the models in the :from and :through keys. This is especially useful for Camping, which namespaces models by default. + +=end + + def acts_as_double_polymorphic_join options={}, &extension + + collections, options = extract_double_collections(options) + + # handle the block + options[:extend] = (if options[:extend] + Array(options[:extend]) + [extension] + else + extension + end) if extension + + collection_option_keys = make_general_option_keys_specific!(options, collections) + + join_name = self.name.tableize.to_sym + collections.each do |association_id, children| + parent_hash_key = (collections.keys - [association_id]).first # parents are the entries in the _other_ children array + + begin + parent_foreign_key = self.reflect_on_association(parent_hash_key._singularize).primary_key_name + rescue NoMethodError + raise PolymorphicError, "Couldn't find 'belongs_to' association for :#{parent_hash_key._singularize} in #{self.name}." unless parent_foreign_key + end + + parents = collections[parent_hash_key] + conflicts = (children & parents) # set intersection + parents.each do |plural_parent_name| + + parent_class = plural_parent_name._as_class + singular_reverse_association_id = parent_hash_key._singularize + + internal_options = { + :is_double => true, + :from => children, + :as => singular_reverse_association_id, + :through => join_name.to_sym, + :foreign_key => parent_foreign_key, + :foreign_type_key => parent_foreign_key.to_s.sub(/_id$/, '_type'), + :singular_reverse_association_id => singular_reverse_association_id, + :conflicts => conflicts + } + + general_options = Hash[*options._select do |key, value| + collection_option_keys[association_id].include? key and !value.nil? + end.map do |key, value| + [key.to_s[association_id.to_s.length+1..-1].to_sym, value] + end._flatten_once] # rename side-specific options to general names + + general_options.each do |key, value| + # avoid clobbering keys that appear in both option sets + if internal_options[key] + general_options[key] = Array(value) + Array(internal_options[key]) + end + end + + parent_class.send(:has_many_polymorphs, association_id, internal_options.merge(general_options)) + + if conflicts.include? plural_parent_name + # unify the alternate sides of the conflicting children + (conflicts).each do |method_name| + unless parent_class.instance_methods.include?(method_name) + parent_class.send(:define_method, method_name) do + (self.send("#{singular_reverse_association_id}_#{method_name}") + + self.send("#{association_id._singularize}_#{method_name}")).freeze + end + end + end + + # unify the join model... join model is always renamed for doubles, unlike child associations + unless parent_class.instance_methods.include?(join_name) + parent_class.send(:define_method, join_name) do + (self.send("#{join_name}_as_#{singular_reverse_association_id}") + + self.send("#{join_name}_as_#{association_id._singularize}")).freeze + end + end + else + unless parent_class.instance_methods.include?(join_name) + parent_class.send(:alias_method, join_name, "#{join_name}_as_#{singular_reverse_association_id}") + end + end + + end + end + end + + private + + def extract_double_collections(options) + collections = options._select do |key, value| + value.is_a? Array and key.to_s !~ /(#{RESERVED_DOUBLES_KEYS.map(&:to_s).join('|')})$/ + end + + raise PolymorphicError, "Couldn't understand options in acts_as_double_polymorphic_join. Valid parameters are your two class collections, and then #{RESERVED_DOUBLES_KEYS.inspect[1..-2]}, with optionally your collection names prepended and joined with an underscore." unless collections.size == 2 + + options = options._select do |key, value| + !collections[key] + end + + [collections, options] + end + + def make_general_option_keys_specific!(options, collections) + collection_option_keys = Hash[*collections.keys.map do |key| + [key, RESERVED_DOUBLES_KEYS.map{|option| "#{key}_#{option}".to_sym}] + end._flatten_once] + + collections.keys.each do |collection| + options.each do |key, value| + next if collection_option_keys.values.flatten.include? key + # shift the general options to the individual sides + collection_key = "#{collection}_#{key}".to_sym + collection_value = options[collection_key] + case key + when :conditions + collection_value, value = sanitize_sql(collection_value), sanitize_sql(value) + options[collection_key] = (collection_value ? "(#{collection_value}) AND (#{value})" : value) + when :order + options[collection_key] = (collection_value ? "#{collection_value}, #{value}" : value) + when :extend, :join_extend + options[collection_key] = Array(collection_value) + Array(value) + else + options[collection_key] ||= value + end + end + end + + collection_option_keys + end + + + + public + +=begin rdoc + +This method createds a single-sided polymorphic relationship. + + class Petfood < ActiveRecord::Base + has_many_polymorphs :eaters, :from => [:dogs, :cats, :birds] + end + +The only required parameter, aside from the association name, is :from. + +The method generates a number of associations aside from the polymorphic one. In this example Petfood also gets dogs, cats, and birds, and Dog, Cat, and Bird get petfoods. (The reverse association to the parents is always plural.) + +== Available options + +:from:: An array of symbols representing the target models. Required. +:as:: A symbol for the parent's interface in the join--what the parent 'acts as'. +:through:: A symbol representing the class of the join model. Follows Rails defaults if not supplied (the parent and the association names, alphabetized, concatenated with an underscore, and singularized). +:dependent:: Accepts :destroy, :nullify, :delete_all. Controls how the join record gets treated on any associate delete (whether from the polymorph or from an individual collection); defaults to :destroy. +:skip_duplicates:: If true, will check to avoid pushing already associated records (but also triggering a database load). Defaults to true. +:rename_individual_collections:: If true, all individual collections are prepended with the polymorph name, and the children's parent collection is appended with "_of_#{association_name}". For example, zoos becomes zoos_of_animals. This is to help avoid method name collisions in crowded classes. +:extend:: One or an array of mixed modules and procs, which are applied to the polymorphic association (usually to define custom methods). +:join_extend:: One or an array of mixed modules and procs, which are applied to the join association. +:parent_extend:: One or an array of mixed modules and procs, which are applied to the target models' association to the parents. +:conditions:: An array or string of conditions for the SQL WHERE clause. +:parent_conditions:: An array or string of conditions which are applied to the target models' association to the parents. +:order:: A string for the SQL ORDER BY clause. +:parent_order:: A string for the SQL ORDER BY which is applied to the target models' association to the parents. +:group:: An array or string of conditions for the SQL GROUP BY clause. Affects the polymorphic and individual associations. +:limit:: An integer. Affects the polymorphic and individual associations. +:offset:: An integer. Only affects the polymorphic association. +:namespace:: A symbol. Prepended to all the models in the :from and :through keys. This is especially useful for Camping, which namespaces models by default. +:uniq:: If true, the records returned are passed through a pure-Ruby uniq before they are returned. Rarely needed. +:foreign_key:: The column name for the parent's id in the join. +:foreign_type_key:: The column name for the parent's class name in the join, if the parent itself is polymorphic. Rarely needed--if you're thinking about using this, you almost certainly want to use acts_as_double_polymorphic_join() instead. +:polymorphic_key:: The column name for the child's id in the join. +:polymorphic_type_key:: The column name for the child's class name in the join. + +If you pass a block, it gets converted to a Proc and added to :extend. + +== On condition nullification + +When you request an individual association, non-applicable but fully-qualified fields in the polymorphic association's :conditions, :order, and :group options get changed to NULL. For example, if you set :conditions => "dogs.name != 'Spot'", when you request .cats, the conditions string is changed to NULL != 'Spot'. + +Be aware, however, that NULL != 'Spot' returns false due to SQL's 3-value logic. Instead, you need to use the :conditions string "dogs.name IS NULL OR dogs.name != 'Spot'" to get the behavior you probably expect for negative matches. + +=end + + def has_many_polymorphs (association_id, options = {}, &extension) + _logger_debug "associating #{self}.#{association_id}" + reflection = create_has_many_polymorphs_reflection(association_id, options, &extension) + # puts "Created reflection #{reflection.inspect}" + # configure_dependency_for_has_many(reflection) + collection_reader_method(reflection, PolymorphicAssociation) + end + + # Composed method that assigns option defaults, builds the reflection object, and sets up all the related associations on the parent, join, and targets. + def create_has_many_polymorphs_reflection(association_id, options, &extension) #:nodoc: + options.assert_valid_keys( + :from, + :as, + :through, + :foreign_key, + :foreign_type_key, + :polymorphic_key, # same as :association_foreign_key + :polymorphic_type_key, + :dependent, # default :destroy, only affects the join table + :skip_duplicates, # default true, only affects the polymorphic collection + :ignore_duplicates, # deprecated + :is_double, + :rename_individual_collections, + :reverse_association_id, # not used + :singular_reverse_association_id, + :conflicts, + :extend, + :join_class_name, + :join_extend, + :parent_extend, + :table_aliases, + :select, # applies to the polymorphic relationship + :conditions, # applies to the polymorphic relationship, the children, and the join + # :include, + :parent_conditions, + :parent_order, + :order, # applies to the polymorphic relationship, the children, and the join + :group, # only applies to the polymorphic relationship and the children + :limit, # only applies to the polymorphic relationship and the children + :offset, # only applies to the polymorphic relationship + :parent_order, + :parent_group, + :parent_limit, + :parent_offset, + # :source, + :namespace, + :uniq, # XXX untested, only applies to the polymorphic relationship + # :finder_sql, + # :counter_sql, + # :before_add, + # :after_add, + # :before_remove, + # :after_remove + :dummy) + + # validate against the most frequent configuration mistakes + verify_pluralization_of(association_id) + raise PolymorphicError, ":from option must be an array" unless options[:from].is_a? Array + options[:from].each{|plural| verify_pluralization_of(plural)} + + options[:as] ||= self.name.demodulize.underscore.to_sym + options[:conflicts] = Array(options[:conflicts]) + options[:foreign_key] ||= "#{options[:as]}_id" + + options[:association_foreign_key] = + options[:polymorphic_key] ||= "#{association_id._singularize}_id" + options[:polymorphic_type_key] ||= "#{association_id._singularize}_type" + + if options.has_key? :ignore_duplicates + _logger_warn "DEPRECATION WARNING: please use :skip_duplicates instead of :ignore_duplicates" + options[:skip_duplicates] = options[:ignore_duplicates] + end + options[:skip_duplicates] = true unless options.has_key? :skip_duplicates + options[:dependent] = :destroy unless options.has_key? :dependent + options[:conditions] = sanitize_sql(options[:conditions]) + + # options[:finder_sql] ||= "(options[:polymorphic_key] + + options[:through] ||= build_join_table_symbol(association_id, (options[:as]._pluralize or self.table_name)) + + # set up namespaces if we have a namespace key + # XXX needs test coverage + if options[:namespace] + namespace = options[:namespace].to_s.chomp("/") + "/" + options[:from].map! do |child| + "#{namespace}#{child}".to_sym + end + options[:through] = "#{namespace}#{options[:through]}".to_sym + end + + options[:join_class_name] ||= options[:through]._classify + options[:table_aliases] ||= build_table_aliases([options[:through]] + options[:from]) + options[:select] ||= build_select(association_id, options[:table_aliases]) + + options[:through] = "#{options[:through]}_as_#{options[:singular_reverse_association_id]}" if options[:singular_reverse_association_id] + options[:through] = demodulate(options[:through]).to_sym + + options[:extend] = spiked_create_extension_module(association_id, Array(options[:extend]) + Array(extension)) + options[:join_extend] = spiked_create_extension_module(association_id, Array(options[:join_extend]), "Join") + options[:parent_extend] = spiked_create_extension_module(association_id, Array(options[:parent_extend]), "Parent") + + # create the reflection object + returning(create_reflection(:has_many_polymorphs, association_id, options, self)) do |reflection| + # set up the other related associations + create_join_association(association_id, reflection) + create_has_many_through_associations_for_parent_to_children(association_id, reflection) + create_has_many_through_associations_for_children_to_parent(association_id, reflection) + end + end + + private + + + # table mapping for use at the instantiation point + + def build_table_aliases(from) + # for the targets + returning({}) do |aliases| + from.map(&:to_s).sort.map(&:to_sym).each_with_index do |plural, t_index| + begin + table = plural._as_class.table_name + rescue NameError => e + raise PolymorphicError, "Could not find a valid class for #{plural.inspect} (tried #{plural.to_s._classify}). If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead." + end + begin + plural._as_class.columns.map(&:name).each_with_index do |field, f_index| + aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}" + end + rescue ActiveRecord::StatementInvalid => e + _logger_warn "Looks like your table doesn't exist for #{plural.to_s._classify}.\nError #{e}\nSkipping..." + end + end + end + end + + def build_select(association_id, aliases) + # instantiate has to know which reflection the results are coming from + (["\'#{self.name}\' AS polymorphic_parent_class", + "\'#{association_id}\' AS polymorphic_association_id"] + + aliases.map do |table, _alias| + "#{table} AS #{_alias}" + end.sort).join(", ") + end + + # method sub-builders + + def create_join_association(association_id, reflection) + + options = { + :foreign_key => reflection.options[:foreign_key], + :dependent => reflection.options[:dependent], + :class_name => reflection.klass.name, + :extend => reflection.options[:join_extend] + # :limit => reflection.options[:limit], + # :offset => reflection.options[:offset], + # :order => devolve(association_id, reflection, reflection.options[:order], reflection.klass, true), + # :conditions => devolve(association_id, reflection, reflection.options[:conditions], reflection.klass, true) + } + + if reflection.options[:foreign_type_key] + type_check = "#{reflection.options[:foreign_type_key]} = #{quote_value(self.base_class.name)}" + conjunction = options[:conditions] ? " AND " : nil + options[:conditions] = "#{options[:conditions]}#{conjunction}#{type_check}" + options[:as] = reflection.options[:as] + end + + has_many(reflection.options[:through], options) + + inject_before_save_into_join_table(association_id, reflection) + end + + def inject_before_save_into_join_table(association_id, reflection) + sti_hook = "sti_class_rewrite" + rewrite_procedure = %[self.send(:#{reflection.options[:polymorphic_type_key]}=, self.#{reflection.options[:polymorphic_type_key]}.constantize.base_class.name)] + + # XXX should be abstracted? + reflection.klass.class_eval %[ + unless instance_methods.include? "before_save_with_#{sti_hook}" + if instance_methods.include? "before_save" + alias_method :before_save_without_#{sti_hook}, :before_save + def before_save_with_#{sti_hook} + before_save_without_#{sti_hook} + #{rewrite_procedure} + end + else + def before_save_with_#{sti_hook} + #{rewrite_procedure} + end + end + alias_method :before_save, :before_save_with_#{sti_hook} + end + ] + end + + def create_has_many_through_associations_for_children_to_parent(association_id, reflection) + + child_pluralization_map(association_id, reflection).each do |plural, singular| + if singular == reflection.options[:as] + raise PolymorphicError, if reflection.options[:is_double] + "You can't give either of the sides in a double-polymorphic join the same name as any of the individual target classes." + else + "You can't have a self-referential polymorphic has_many :through without renaming the non-polymorphic foreign key in the join model." + end + end + + parent = self + plural._as_class.instance_eval do + # this shouldn't be called at all during doubles; there is no way to traverse to a double polymorphic parent (XXX is that right?) + unless reflection.options[:is_double] or reflection.options[:conflicts].include? self.name.tableize.to_sym + + # the join table + through = "#{reflection.options[:through]}#{'_as_child' if parent == self}".to_sym + has_many(through, + :as => association_id._singularize, +# :source => association_id._singularize, +# :source_type => reflection.options[:polymorphic_type_key], + :class_name => reflection.klass.name, + :dependent => reflection.options[:dependent], + :extend => reflection.options[:join_extend], + # :limit => reflection.options[:limit], + # :offset => reflection.options[:offset], + :order => devolve(association_id, reflection, reflection.options[:parent_order], reflection.klass), + :conditions => devolve(association_id, reflection, reflection.options[:parent_conditions], reflection.klass) + ) + + # the association to the target's parents + association = "#{reflection.options[:as]._pluralize}#{"_of_#{association_id}" if reflection.options[:rename_individual_collections]}".to_sym + has_many(association, + :through => through, + :class_name => parent.name, + :source => reflection.options[:as], + :foreign_key => reflection.options[:foreign_key], + :extend => reflection.options[:parent_extend], + :conditions => reflection.options[:parent_conditions], + :order => reflection.options[:parent_order], + :offset => reflection.options[:parent_offset], + :limit => reflection.options[:parent_limit], + :group => reflection.options[:parent_group]) + +# debugger if association == :parents +# +# nil + + end + end + end + end + + def create_has_many_through_associations_for_parent_to_children(association_id, reflection) + child_pluralization_map(association_id, reflection).each do |plural, singular| + #puts ":source => #{child}" + current_association = demodulate(child_association_map(association_id, reflection)[plural]) + source = demodulate(singular) + + if reflection.options[:conflicts].include? plural + # XXX check this + current_association = "#{association_id._singularize}_#{current_association}" if reflection.options[:conflicts].include? self.name.tableize.to_sym + source = "#{source}_as_#{association_id._singularize}".to_sym + end + + # make push/delete accessible from the individual collections but still operate via the general collection + extension_module = self.class_eval %[ + module #{self.name + current_association._classify + "PolymorphicChildAssociationExtension"} + def push *args; proxy_owner.send(:#{association_id}).send(:push, *args); self; end + alias :<< :push + def delete *args; proxy_owner.send(:#{association_id}).send(:delete, *args); end + def clear; proxy_owner.send(:#{association_id}).send(:clear, #{singular._classify}); end + self + end] + + has_many(current_association.to_sym, + :through => reflection.options[:through], + :source => association_id._singularize, + :source_type => plural._as_class.base_class.name, + :class_name => plural._as_class.name, # make STI not conflate subtypes + :extend => (Array(extension_module) + reflection.options[:extend]), + :limit => reflection.options[:limit], + # :offset => reflection.options[:offset], + :order => devolve(association_id, reflection, reflection.options[:order], plural._as_class), + :conditions => devolve(association_id, reflection, reflection.options[:conditions], plural._as_class), + :group => devolve(association_id, reflection, reflection.options[:group], plural._as_class) + ) + + end + end + + # some support methods + + def child_pluralization_map(association_id, reflection) + Hash[*reflection.options[:from].map do |plural| + [plural, plural._singularize] + end.flatten] + end + + def child_association_map(association_id, reflection) + Hash[*reflection.options[:from].map do |plural| + [plural, "#{association_id._singularize.to_s + "_" if reflection.options[:rename_individual_collections]}#{plural}".to_sym] + end.flatten] + end + + def demodulate(s) + s.to_s.gsub('/', '_').to_sym + end + + def build_join_table_symbol(association_id, name) + [name.to_s, association_id.to_s].sort.join("_").to_sym + end + + def all_classes_for(association_id, reflection) + klasses = [self, reflection.klass, *child_pluralization_map(association_id, reflection).keys.map(&:_as_class)] + klasses += klasses.map(&:base_class) + klasses.uniq + end + + def devolve(association_id, reflection, string, klass, remove_inappropriate_clauses = false) + # XXX remove_inappropriate_clauses is not implemented; we'll wait until someone actually needs it + return unless string + string = string.dup + # _logger_debug "devolving #{string} for #{klass}" + inappropriate_classes = (all_classes_for(association_id, reflection) - # the join class must always be preserved + [klass, klass.base_class, reflection.klass, reflection.klass.base_class]) + inappropriate_classes.map do |klass| + klass.columns.map do |column| + [klass.table_name, column.name] + end.map do |table, column| + ["#{table}.#{column}", "`#{table}`.#{column}", "#{table}.`#{column}`", "`#{table}`.`#{column}`"] + end + end.flatten.sort_by(&:size).reverse.each do |quoted_reference| + # _logger_debug "devolved #{quoted_reference} to NULL" + # XXX clause removal would go here + string.gsub!(quoted_reference, "NULL") + end + # _logger_debug "altered to #{string}" + string + end + + def verify_pluralization_of(sym) + sym = sym.to_s + singular = sym.singularize + plural = singular.pluralize + raise PolymorphicError, "Pluralization rules not set up correctly. You passed :#{sym}, which singularizes to :#{singular}, but that pluralizes to :#{plural}, which is different. Maybe you meant :#{plural} to begin with?" unless sym == plural + end + + def spiked_create_extension_module(association_id, extensions, identifier = nil) + module_extensions = extensions.select{|e| e.is_a? Module} + proc_extensions = extensions.select{|e| e.is_a? Proc } + + # support namespaced anonymous blocks as well as multiple procs + proc_extensions.each_with_index do |proc_extension, index| + module_name = "#{self.to_s}#{association_id._classify}Polymorphic#{identifier}AssociationExtension#{index}" + the_module = self.class_eval "module #{module_name}; self; end" # XXX hrm + the_module.class_eval &proc_extension + module_extensions << the_module + end + module_extensions + end + + end + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/configuration.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/configuration.rb new file mode 100644 index 00000000..9de21617 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/configuration.rb @@ -0,0 +1,19 @@ + +=begin rdoc +Access the has_many_polymorphs_options hash in your Rails::Initializer.run#after_initialize block if you need to modify the behavior of Rails::Initializer::HasManyPolymorphsAutoload. +=end + +module Rails #:nodoc: + class Configuration + + def has_many_polymorphs_options + ::HasManyPolymorphs.options + end + + def has_many_polymorphs_options=(hash) + ::HasManyPolymorphs.options = HashWithIndifferentAccess.new(hash) + end + + end +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/debugging_tools.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/debugging_tools.rb new file mode 100644 index 00000000..22c9af38 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/debugging_tools.rb @@ -0,0 +1,103 @@ + +=begin rdoc + +Debugging tools for Has_many_polymorphs. + +Enable the different tools by setting the environment variable HMP_DEBUG. Settings with special meaning are "ruby-debug", "trace", and "dependencies". + +== Code generation + +Enabled by default when HMP_DEBUG is set. + +Ouputs a folder generated_models/ in RAILS_ROOT containing valid Ruby files explaining all the ActiveRecord relationships set up by the plugin, as well as listing the line in the plugin that called each particular association method. + +== Ruby-debug + +Enable by setting HMP_DEBUG to "ruby-debug". + +Starts ruby-debug for the life of the process. + +== Trace + +Enable by setting HMP_DEBUG to "ruby-debug". + +Outputs an indented trace of relevant method calls as they occur. + +== Dependencies + +Enable by setting HMP_DEBUG to "dependencies". + +Turns on Rails' default dependency logging. + +=end + +_logger_warn "debug mode enabled" + +class << ActiveRecord::Base + COLLECTION_METHODS = [:belongs_to, :has_many, :has_and_belongs_to_many, :has_one, + :has_many_polymorphs, :acts_as_double_polymorphic_join].each do |method_name| + alias_method "original_#{method_name}".to_sym, method_name + undef_method method_name + end + + unless defined? GENERATED_CODE_DIR + GENERATED_CODE_DIR = "#{RAILS_ROOT}/generated_models" + + begin + system "rm -rf #{GENERATED_CODE_DIR}" + Dir.mkdir GENERATED_CODE_DIR + rescue Errno::EACCES + _logger_warn "no permissions for generated code dir: #{GENERATED_CODE_DIR}" + end + + if File.exist? GENERATED_CODE_DIR + alias :original_method_missing :method_missing + def method_missing(method_name, *args, &block) + if COLLECTION_METHODS.include? method_name.to_sym + Dir.chdir GENERATED_CODE_DIR do + filename = "#{demodulate(self.name.underscore)}.rb" + contents = File.open(filename).read rescue "\nclass #{self.name}\n\nend\n" + line = caller[1][/\:(\d+)\:/, 1] + contents[-5..-5] = "\n #{method_name} #{args[0..-2].inspect[1..-2]},\n #{args[-1].inspect[1..-2].gsub(" :", "\n :").gsub("=>", " => ")}\n#{ block ? " #{block.inspect.sub(/\@.*\//, '@')}\n" : ""} # called from line #{line}\n\n" + File.open(filename, "w") do |file| + file.puts contents + end + end + # doesn't actually display block contents + self.send("original_#{method_name}", *args, &block) + else + self.send(:original_method_missing, method_name, *args, &block) + end + end + end + + end +end + +case ENV['HMP_DEBUG'] + + when "ruby-debug" + require 'rubygems' + require 'ruby-debug' + Debugger.start + _logger_warn "ruby-debug enabled." + + when "trace" + _logger_warn "method tracing enabled" + $debug_trace_indent = 0 + set_trace_func (proc do |event, file, line, id, binding, classname| + if id.to_s =~ /instantiate/ #/IRB|Wirble|RubyLex|RubyToken|Logger|ConnectionAdapters|SQLite3|MonitorMixin|Benchmark|Inflector|Inflections/ + if event == 'call' + puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id} from #{file.split('/').last}::#{line}" + $debug_trace_indent += 1 + elsif event == 'return' + $debug_trace_indent -= 1 unless $debug_trace_indent == 0 + puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id}" + end + end + end) + + when "dependencies" + _logger_warn "dependency activity being logged" + (::Dependencies.log_activity = true) rescue nil +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/rake_task_redefine_task.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/rake_task_redefine_task.rb new file mode 100644 index 00000000..217d2590 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/rake_task_redefine_task.rb @@ -0,0 +1,35 @@ + +# Redefine instead of chain a Rake task +# http://www.bigbold.com/snippets/posts/show/2032 + +module Rake + module TaskManager + def redefine_task(task_class, args, &block) + task_name, deps = resolve_args(args) + task_name = task_class.scope_name(@scope, task_name) + deps = [deps] unless deps.respond_to?(:to_ary) + deps = deps.collect {|d| d.to_s } + task = @tasks[task_name.to_s] = task_class.new(task_name, self) + task.application = self + task.add_comment(@last_comment) + @last_comment = nil + task.enhance(deps, &block) + task + end + end + class Task + class << self + def redefine_task(args, &block) + Rake.application.redefine_task(self, args, &block) + end + end + end +end + +class Object + def silently + stderr, stdout, $stderr, $stdout = $stderr, $stdout, StringIO.new, StringIO.new + yield + $stderr, $stdout = stderr, stdout + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/reflection.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/reflection.rb new file mode 100644 index 00000000..0091397d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/reflection.rb @@ -0,0 +1,58 @@ +module ActiveRecord #:nodoc: + module Reflection #:nodoc: + + module ClassMethods #:nodoc: + + # Update the default reflection switch so that :has_many_polymorphs types get instantiated. + # It's not a composed method so we have to override the whole thing. + def create_reflection(macro, name, options, active_record) + case macro + when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many + klass = options[:through] ? ThroughReflection : AssociationReflection + reflection = klass.new(macro, name, options, active_record) + when :composed_of + reflection = AggregateReflection.new(macro, name, options, active_record) + # added by has_many_polymorphs # + when :has_many_polymorphs + reflection = PolymorphicReflection.new(macro, name, options, active_record) + end + write_inheritable_hash :reflections, name => reflection + reflection + end + + end + + class PolymorphicError < ActiveRecordError #:nodoc: + end + +=begin rdoc + +The reflection built by the has_many_polymorphs method. + +Inherits from ActiveRecord::Reflection::AssociationReflection. + +=end + + class PolymorphicReflection < ThroughReflection + # Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection. + def check_validity! + # nothing + end + + # Return the source reflection. + def source_reflection + # normally is the has_many to the through model, but we return ourselves, + # since there isn't a real source class for a polymorphic target + self + end + + # Set the classname of the target. Uses the join class name. + def class_name + # normally is the classname of the association target + @class_name ||= options[:join_class_name] + end + + end + + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/support_methods.rb b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/support_methods.rb new file mode 100644 index 00000000..89ca52a4 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/lib/has_many_polymorphs/support_methods.rb @@ -0,0 +1,84 @@ + +class String + + # Changes an underscored string into a class reference. + def _as_class + # classify expects self to be plural + self.classify.constantize + end + + # For compatibility with the Symbol extensions. + alias :_singularize :singularize + alias :_pluralize :pluralize + alias :_classify :classify +end + +class Symbol + + # Changes an underscored symbol into a class reference. + def _as_class; self.to_s._as_class; end + + # Changes a plural symbol into a singular symbol. + def _singularize; self.to_s.singularize.to_sym; end + + # Changes a singular symbol into a plural symbol. + def _pluralize; self.to_s.pluralize.to_sym; end + + # Changes a symbol into a class name string. + def _classify; self.to_s.classify; end +end + +class Array + + # Flattens the first level of self. + def _flatten_once + self.inject([]){|r, el| r + Array(el)} + end + + # Rails 1.2.3 compatibility method. Copied from http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb?rev=7217 + def _extract_options! + last.is_a?(::Hash) ? pop : {} + end +end + +class Hash + + # An implementation of select that returns a Hash. + def _select + Hash[*self.select do |key, value| + yield key, value + end._flatten_once] + end +end + +class Object + + # Returns the metaclass of self. + def _metaclass; (class << self; self; end); end + + # Logger shortcut. + def _logger_debug s + s = "** has_many_polymorphs: #{s}" + RAILS_DEFAULT_LOGGER.debug(s) if RAILS_DEFAULT_LOGGER + end + + # Logger shortcut. + def _logger_warn s + s = "** has_many_polymorphs: #{s}" + if RAILS_DEFAULT_LOGGER + RAILS_DEFAULT_LOGGER.warn(s) + else + $stderr.puts(s) + end + end + +end + +class ActiveRecord::Base + + # Return the base class name as a string. + def _base_class_name + self.class.base_class.name.to_s + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/bow_wows.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/bow_wows.yml new file mode 100644 index 00000000..00be9d88 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/bow_wows.yml @@ -0,0 +1,10 @@ +rover: + id: 1 + name: Rover + created_at: "2007-01-01 12:00:00" + updated_at: "2007-01-04 10:00:00" +spot: + id: 2 + name: Spot + created_at: "2007-01-02 12:00:00" + updated_at: "2007-01-03 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/cats.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/cats.yml new file mode 100644 index 00000000..aed894f9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/cats.yml @@ -0,0 +1,18 @@ +chloe: + id: 1 + cat_type: Kitten + name: Chloe + created_at: "2007-04-01 12:00:00" + updated_at: "2007-04-04 10:00:00" +alice: + id: 2 + cat_type: Kitten + name: Alice + created_at: "2007-04-02 12:00:00" + updated_at: "2007-04-03 10:00:00" +toby: + id: 3 + cat_type: Tabby + name: Toby + created_at: "2007-04-02 12:00:00" + updated_at: "2007-04-03 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/eaters_foodstuffs.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/eaters_foodstuffs.yml new file mode 100644 index 00000000..e69de29b diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/fish.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/fish.yml new file mode 100644 index 00000000..3974a672 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/fish.yml @@ -0,0 +1,12 @@ +swimmy: + id: 1 + name: Swimmy + speed: 10 + created_at: "2007-02-01 12:00:00" + updated_at: "2007-02-04 10:00:00" +jaws: + id: 2 + name: Jaws + speed: 20 + created_at: "2007-02-02 12:00:00" + updated_at: "2007-02-03 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/frogs.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/frogs.yml new file mode 100644 index 00000000..e9d37d7c --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/frogs.yml @@ -0,0 +1,5 @@ +froggy: + id: 1 + name: Froggy + created_at: "2007-05-01 12:00:00" + updated_at: "2007-05-04 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/keep_your_enemies_close.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/keep_your_enemies_close.yml new file mode 100644 index 00000000..e69de29b diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/little_whale_pupils.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/little_whale_pupils.yml new file mode 100644 index 00000000..e69de29b diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/people.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/people.yml new file mode 100644 index 00000000..085d2172 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/people.yml @@ -0,0 +1,7 @@ +bob: + id: 1 + name: Bob + age: 45 + created_at: "2007-04-01 12:00:00" + updated_at: "2007-04-04 10:00:00" + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/petfoods.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/petfoods.yml new file mode 100644 index 00000000..a117d294 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/petfoods.yml @@ -0,0 +1,11 @@ +kibbles: + the_petfood_primary_key: 1 + name: Kibbles + created_at: "2007-06-01 12:00:00" + updated_at: "2007-06-04 10:00:00" +bits: + the_petfood_primary_key: 2 + name: Bits + created_at: "2007-06-02 12:00:00" + updated_at: "2007-06-03 10:00:00" + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/whales.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/whales.yml new file mode 100644 index 00000000..bded734e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/whales.yml @@ -0,0 +1,5 @@ +shamu: + id: 1 + name: Shamu + created_at: "2007-03-01 12:00:00" + updated_at: "2007-03-04 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/fixtures/wild_boars.yml b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/wild_boars.yml new file mode 100644 index 00000000..73fd3e2e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/fixtures/wild_boars.yml @@ -0,0 +1,10 @@ +puma: + id: 1 + name: Puma + created_at: "2007-07-01 12:00:00" + updated_at: "2007-07-04 10:00:00" +jacrazy: + id: 2 + name: Jacrazy + created_at: "2007-07-02 12:00:00" + updated_at: "2007-07-03 10:00:00" diff --git a/vendor/gems/has_many_polymorphs-2.13/test/generator/tagging_generator_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/generator/tagging_generator_test.rb new file mode 100644 index 00000000..34e20c4f --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/generator/tagging_generator_test.rb @@ -0,0 +1,42 @@ +require 'fileutils' +require File.dirname(__FILE__) + '/../test_helper' + +class TaggingGeneratorTest < Test::Unit::TestCase + + def setup + Dir.chdir RAILS_ROOT do + truncate + + # Revert environment lib requires + FileUtils.cp "config/environment.rb.canonical", "config/environment.rb" + + # Delete generator output + ["app/models/tag.rb", "app/models/tagging.rb", + "test/unit/tag_test.rb", "test/unit/tagging_test.rb", + "test/fixtures/tags.yml", "test/fixtures/taggings.yml", + "lib/tagging_extensions.rb", + "db/migrate/010_create_tags_and_taggings.rb"].each do |file| + File.delete file if File.exist? file + end + + # Rebuild database + Echoe.silence do + system("ruby #{HERE}/setup.rb") + end + end + end + + alias :teardown :setup + + def test_generator + Dir.chdir RAILS_ROOT do + Echoe.silence do + assert system("script/generate tagging Stick Stone -q -f") + assert system("rake db:migrate") + assert system("rake db:fixtures:load") + assert system("rake test:units") + end + end + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/README b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/README new file mode 100644 index 00000000..0d6affdd --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/README @@ -0,0 +1,182 @@ +== Welcome to Rails + +Rails is a web-application and persistence framework that includes everything +needed to create database-backed web-applications according to the +Model-View-Control pattern of separation. This pattern splits the view (also +called the presentation) into "dumb" templates that are primarily responsible +for inserting pre-built data in between HTML tags. The model contains the +"smart" domain objects (such as Account, Product, Person, Post) that holds all +the business logic and knows how to persist themselves to a database. The +controller handles the incoming requests (such as Save New Account, Update +Product, Show Post) by manipulating the model and directing data to the view. + +In Rails, the model is handled by what's called an object-relational mapping +layer entitled Active Record. This layer allows you to present the data from +database rows as objects and embellish these data objects with business logic +methods. You can read more about Active Record in +link:files/vendor/rails/activerecord/README.html. + +The controller and view are handled by the Action Pack, which handles both +layers by its two parts: Action View and Action Controller. These two layers +are bundled in a single package due to their heavy interdependence. This is +unlike the relationship between the Active Record and Action Pack that is much +more separate. Each of these packages can be used independently outside of +Rails. You can read more about Action Pack in +link:files/vendor/rails/actionpack/README.html. + + +== Getting started + +1. At the command prompt, start a new rails application using the rails command + and your application name. Ex: rails myapp + (If you've downloaded rails in a complete tgz or zip, this step is already done) +2. Change directory into myapp and start the web server: script/server (run with --help for options) +3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!" +4. Follow the guidelines to start developing your application + + +== Web Servers + +By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise +Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server, +Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures +that you can always get up and running quickly. + +Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is +suitable for development and deployment of Rails applications. If you have Ruby Gems installed, +getting up and running with mongrel is as easy as: gem install mongrel. +More info at: http://mongrel.rubyforge.org + +If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than +Mongrel and WEBrick and also suited for production use, but requires additional +installation and currently only works well on OS X/Unix (Windows users are encouraged +to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from +http://www.lighttpd.net. + +And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby +web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not +for production. + +But of course its also possible to run Rails on any platform that supports FCGI. +Apache, LiteSpeed, IIS are just a few. For more information on FCGI, +please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI + + +== Debugging Rails + +Have "tail -f" commands running on the server.log and development.log. Rails will +automatically display debugging and runtime information to these files. Debugging +info will also be shown in the browser on requests from 127.0.0.1. + + +== Breakpoints + +Breakpoint support is available through the script/breakpointer client. This +means that you can break out of execution at any point in the code, investigate +and change the model, AND then resume execution! Example: + + class WeblogController < ActionController::Base + def index + @posts = Post.find(:all) + breakpoint "Breaking out from the list" + end + end + +So the controller will accept the action, run the first line, then present you +with a IRB prompt in the breakpointer window. Here you can do things like: + +Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint' + + >> @posts.inspect + => "[#nil, \"body\"=>nil, \"id\"=>\"1\"}>, + #\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]" + >> @posts.first.title = "hello from a breakpoint" + => "hello from a breakpoint" + +...and even better is that you can examine how your runtime objects actually work: + + >> f = @posts.first + => #nil, "body"=>nil, "id"=>"1"}> + >> f. + Display all 152 possibilities? (y or n) + +Finally, when you're ready to resume execution, you press CTRL-D + + +== Console + +You can interact with the domain model by starting the console through script/console. +Here you'll have all parts of the application configured, just like it is when the +application is running. You can inspect domain models, change values, and save to the +database. Starting the script without arguments will launch it in the development environment. +Passing an argument will specify a different environment, like script/console production. + +To reload your controllers and models after launching the console run reload! + +To reload your controllers and models after launching the console run reload! + + + +== Description of contents + +app + Holds all the code that's specific to this particular application. + +app/controllers + Holds controllers that should be named like weblogs_controller.rb for + automated URL mapping. All controllers should descend from ApplicationController + which itself descends from ActionController::Base. + +app/models + Holds models that should be named like post.rb. + Most models will descend from ActiveRecord::Base. + +app/views + Holds the template files for the view that should be named like + weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby + syntax. + +app/views/layouts + Holds the template files for layouts to be used with views. This models the common + header/footer method of wrapping views. In your views, define a layout using the + layout :default and create a file named default.rhtml. Inside default.rhtml, + call <% yield %> to render the view using this layout. + +app/helpers + Holds view helpers that should be named like weblogs_helper.rb. These are generated + for you automatically when using script/generate for controllers. Helpers can be used to + wrap functionality for your views into methods. + +config + Configuration files for the Rails environment, the routing map, the database, and other dependencies. + +components + Self-contained mini-applications that can bundle together controllers, models, and views. + +db + Contains the database schema in schema.rb. db/migrate contains all + the sequence of Migrations for your schema. + +doc + This directory is where your application documentation will be stored when generated + using rake doc:app + +lib + Application specific libraries. Basically, any kind of custom code that doesn't + belong under controllers, models, or helpers. This directory is in the load path. + +public + The directory available for the web server. Contains subdirectories for images, stylesheets, + and javascripts. Also contains the dispatchers and the default HTML files. This should be + set as the DOCUMENT_ROOT of your web server. + +script + Helper scripts for automation and generation. + +test + Unit and functional tests along with fixtures. When using the script/generate scripts, template + test files will be generated for you and placed in this directory. + +vendor + External libraries that the application depends on. Also includes the plugins subdirectory. + This directory is in the load path. diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/Rakefile b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/Rakefile new file mode 100644 index 00000000..2573c13c --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/Rakefile @@ -0,0 +1,19 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require(File.join(File.dirname(__FILE__), 'config', 'boot')) + +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +require 'tasks/rails' + +namespace :test do + desc "a new rake task to include generators" + Rake::TestTask.new(:generators) do |t| + t.libs << 'lib' + t.test_files = FileList['test/generators/*_test.rb'] + t.verbose = true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/application.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/application.rb new file mode 100644 index 00000000..057f4f7e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/application.rb @@ -0,0 +1,7 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + # Pick a unique cookie name to distinguish our session data from others' + session :session_key => '_testapp_session_id' +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/bones_controller.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/bones_controller.rb new file mode 100644 index 00000000..29bfe0c0 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/controllers/bones_controller.rb @@ -0,0 +1,5 @@ +class BonesController < ApplicationController + def index + @bones = Bone.find(:all) + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/addresses_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/addresses_helper.rb new file mode 100644 index 00000000..5f4dc138 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/addresses_helper.rb @@ -0,0 +1,2 @@ +module AddressesHelper +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/application_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/application_helper.rb new file mode 100644 index 00000000..22a7940e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/application_helper.rb @@ -0,0 +1,3 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/bones_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/bones_helper.rb new file mode 100644 index 00000000..c188f669 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/bones_helper.rb @@ -0,0 +1,2 @@ +module BonesHelper +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/sellers_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/sellers_helper.rb new file mode 100644 index 00000000..4bdecd54 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/sellers_helper.rb @@ -0,0 +1,28 @@ +module SellersHelper + + def display_address(seller) + logger.info "Seller Data ====================" + logger.info seller.inspect + logger.info "Seller responds to address " + seller.respond_to?("address").to_s + logger.info "Seller responds to address= " + seller.respond_to?("address=").to_s + # logger.info seller.methods.sort.inspect + logger.info "User Data ====================" + logger.info seller.user.inspect + logger.info "User responds to address " + seller.user.respond_to?("address").to_s + logger.info "User responds to address= " + seller.user.respond_to?("address=").to_s + # logger.info seller.user.methods.sort.inspect + display_address = Array.new + if seller.address + display_address << seller.address.city if seller.address.city + display_address << seller.address.state.abbreviation if seller.address.state && seller.address.state.abbreviation + display_address << seller.address.zip_postal_code if seller.address.zip_postal_code + end + + unless display_address.empty? + "Location: " + display_address.join(", ") + else + "Location: unknown" + end + end + +end \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/states_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/states_helper.rb new file mode 100644 index 00000000..f98bdc7c --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/states_helper.rb @@ -0,0 +1,2 @@ +module StatesHelper +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/users_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/users_helper.rb new file mode 100644 index 00000000..2310a240 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/bone.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/bone.rb new file mode 100644 index 00000000..f9268612 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/bone.rb @@ -0,0 +1,2 @@ +class Bone < OrganicSubstance +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent.rb new file mode 100644 index 00000000..5bc344f7 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent.rb @@ -0,0 +1,2 @@ +class DoubleStiParent < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent_relationship.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent_relationship.rb new file mode 100644 index 00000000..10b6255b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/double_sti_parent_relationship.rb @@ -0,0 +1,2 @@ +class DoubleStiParentRelationship < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/organic_substance.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/organic_substance.rb new file mode 100644 index 00000000..e9a080d9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/organic_substance.rb @@ -0,0 +1,2 @@ +class OrganicSubstance < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent.rb new file mode 100644 index 00000000..5e4410bb --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent.rb @@ -0,0 +1,4 @@ + +class SingleStiParent < ActiveRecord::Base + has_many_polymorphs :the_bones, :from => [:bones], :through => :single_sti_parent_relationship +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent_relationship.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent_relationship.rb new file mode 100644 index 00000000..7f783c15 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/single_sti_parent_relationship.rb @@ -0,0 +1,4 @@ +class SingleStiParentRelationship < ActiveRecord::Base + belongs_to :single_sti_parent + belongs_to :the_bone, :polymorphic => true +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stick.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stick.rb new file mode 100644 index 00000000..4992506a --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stick.rb @@ -0,0 +1,2 @@ +class Stick < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stone.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stone.rb new file mode 100644 index 00000000..8617396e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/models/stone.rb @@ -0,0 +1,2 @@ +class Stone < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/edit.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/edit.html.erb new file mode 100644 index 00000000..6b6a3894 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/edit.html.erb @@ -0,0 +1,12 @@ +

Editing address

+ +<%= error_messages_for :address %> + +<% form_for(@address) do |f| %> +

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @address %> | +<%= link_to 'Back', addresses_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/index.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/index.html.erb new file mode 100644 index 00000000..86d0d387 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/index.html.erb @@ -0,0 +1,18 @@ +

Listing addresses

+ + + + + +<% for address in @addresses %> + + + + + +<% end %> +
<%= link_to 'Show', address %><%= link_to 'Edit', edit_address_path(address) %><%= link_to 'Destroy', address, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New address', new_address_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/new.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/new.html.erb new file mode 100644 index 00000000..1fae44cf --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/new.html.erb @@ -0,0 +1,11 @@ +

New address

+ +<%= error_messages_for :address %> + +<% form_for(@address) do |f| %> +

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', addresses_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/show.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/show.html.erb new file mode 100644 index 00000000..a75ddbd5 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/addresses/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_address_path(@address) %> | +<%= link_to 'Back', addresses_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/bones/index.rhtml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/bones/index.rhtml new file mode 100644 index 00000000..06f1dad3 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/bones/index.rhtml @@ -0,0 +1,5 @@ + +

Bones: index

+<% @bones.each do |bone| %> +

ID: <%= bone.id %>

+<% end %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/addresses.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/addresses.html.erb new file mode 100644 index 00000000..84583552 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/addresses.html.erb @@ -0,0 +1,17 @@ + + + + + + Addresses: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/sellers.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/sellers.html.erb new file mode 100644 index 00000000..bc08e9be --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/sellers.html.erb @@ -0,0 +1,17 @@ + + + + + + Sellers: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/states.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/states.html.erb new file mode 100644 index 00000000..b2b086fd --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/states.html.erb @@ -0,0 +1,17 @@ + + + + + + States: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/users.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/users.html.erb new file mode 100644 index 00000000..23757aa6 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/layouts/users.html.erb @@ -0,0 +1,17 @@ + + + + + + Users: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/edit.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/edit.html.erb new file mode 100644 index 00000000..14c41036 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/edit.html.erb @@ -0,0 +1,12 @@ +

Editing seller

+ +<%= error_messages_for :seller %> + +<% form_for(@seller) do |f| %> +

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @seller %> | +<%= link_to 'Back', sellers_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/index.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/index.html.erb new file mode 100644 index 00000000..97ef0457 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/index.html.erb @@ -0,0 +1,20 @@ +

Listing sellers

+ + + + + +<% for seller in @sellers %> + + + + + + + +<% end %> +
<%= h(seller.company_name) %><%= h(display_address(seller)) %><%= link_to 'Show', seller %><%= link_to 'Edit', edit_seller_path(seller) %><%= link_to 'Destroy', seller, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New seller', new_seller_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/new.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/new.html.erb new file mode 100644 index 00000000..6814338d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/new.html.erb @@ -0,0 +1,11 @@ +

New seller

+ +<%= error_messages_for :seller %> + +<% form_for(@seller) do |f| %> +

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', sellers_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/show.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/show.html.erb new file mode 100644 index 00000000..f21dcfa7 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/sellers/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_seller_path(@seller) %> | +<%= link_to 'Back', sellers_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/edit.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/edit.html.erb new file mode 100644 index 00000000..dc59d08b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/edit.html.erb @@ -0,0 +1,12 @@ +

Editing state

+ +<%= error_messages_for :state %> + +<% form_for(@state) do |f| %> +

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @state %> | +<%= link_to 'Back', states_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/index.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/index.html.erb new file mode 100644 index 00000000..07c11ae1 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/index.html.erb @@ -0,0 +1,19 @@ +

Listing states

+ + + + + +<% for state in @states %> + + + + + + +<% end %> +
<%= state.name %><%= link_to 'Show', state %><%= link_to 'Edit', edit_state_path(state) %><%= link_to 'Destroy', state, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New state', new_state_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/new.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/new.html.erb new file mode 100644 index 00000000..5caacd5d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/new.html.erb @@ -0,0 +1,11 @@ +

New state

+ +<%= error_messages_for :state %> + +<% form_for(@state) do |f| %> +

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', states_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/show.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/show.html.erb new file mode 100644 index 00000000..ba5c32fb --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/states/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_state_path(@state) %> | +<%= link_to 'Back', states_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/edit.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/edit.html.erb new file mode 100644 index 00000000..b497ec93 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/edit.html.erb @@ -0,0 +1,12 @@ +

Editing user

+ +<%= error_messages_for :user %> + +<% form_for(@user) do |f| %> +

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @user %> | +<%= link_to 'Back', users_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/index.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/index.html.erb new file mode 100644 index 00000000..6397e64e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/index.html.erb @@ -0,0 +1,22 @@ +

Listing users

+ + + + + +<% for user in @users %> + + + + + + + + + +<% end %> +
<%= h(user.login) %><%= h(user.address.line_1) %><%= h(user.address.city) %><%= h(user.address.state.name) %><%= link_to 'Show', user %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New user', new_user_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/new.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/new.html.erb new file mode 100644 index 00000000..bc76aa6b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/new.html.erb @@ -0,0 +1,11 @@ +

New user

+ +<%= error_messages_for :user %> + +<% form_for(@user) do |f| %> +

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', users_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/show.html.erb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/show.html.erb new file mode 100644 index 00000000..3109a37d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/app/views/users/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/boot.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/boot.rb new file mode 100644 index 00000000..cb9a72da --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/boot.rb @@ -0,0 +1,110 @@ +# Don't change this file! +# Configure your app in config/environment.rb and config/environments/*.rb + +RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) + +module Rails + class << self + def boot! + unless booted? + preinitialize + pick_boot.run + end + end + + def booted? + defined? Rails::Initializer + end + + def pick_boot + (vendor_rails? ? VendorBoot : GemBoot).new + end + + def vendor_rails? + File.exist?("#{RAILS_ROOT}/vendor/rails") + end + + def preinitialize + load(preinitializer_path) if File.exists?(preinitializer_path) + end + + def preinitializer_path + "#{RAILS_ROOT}/config/preinitializer.rb" + end + end + + class Boot + def run + load_initializer + Rails::Initializer.run(:set_load_path) + end + end + + class VendorBoot < Boot + def load_initializer + require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" + end + end + + class GemBoot < Boot + def load_initializer + self.class.load_rubygems + load_rails_gem + require 'initializer' + end + + def load_rails_gem + if version = self.class.gem_version + STDERR.puts "Boot.rb loading version #{version}" + gem 'rails', version + else + STDERR.puts "Boot.rb loading latest available version" + gem 'rails' + end + rescue Gem::LoadError => load_error + $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) + exit 1 + end + + class << self + def rubygems_version + Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion + end + + def gem_version + if defined? RAILS_GEM_VERSION + RAILS_GEM_VERSION + elsif ENV.include?('RAILS_GEM_VERSION') + ENV['RAILS_GEM_VERSION'] + else + parse_gem_version(read_environment_rb) + end + end + + def load_rubygems + require 'rubygems' + + unless rubygems_version >= '0.9.4' + $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.) + exit 1 + end + + rescue LoadError + $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org) + exit 1 + end + + def parse_gem_version(text) + $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([!~<>=]*\s*[\d.]+)'/ + end + + private + def read_environment_rb + File.read("#{RAILS_ROOT}/config/environment.rb") + end + end + end +end + +# All that for this: +Rails.boot! diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/database.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/database.yml new file mode 100644 index 00000000..c64a5d89 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/database.yml @@ -0,0 +1,17 @@ + +defaults: &defaults + adapter: <%= ENV['DB'] || 'mysql' %> + host: localhost + database: hmp_development + username: root + password: + +development: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb new file mode 100644 index 00000000..39f34dee --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb @@ -0,0 +1,19 @@ +require File.join(File.dirname(__FILE__), 'boot') +require 'action_controller' + +Rails::Initializer.run do |config| + + if ActionController::Base.respond_to? 'session=' + config.action_controller.session = {:session_key => '_app_session', :secret => '22cde4d5c1a61ba69a81795322cde4d5c1a61ba69a817953'} + end + + config.load_paths << "#{RAILS_ROOT}/app/models/person" # moduleless model path + + config.after_initialize do + config.has_many_polymorphs_options['requirements'] << "#{RAILS_ROOT}/lib/library_model" + end +end + +# Dependencies.log_activity = true + +ENV['RAILS_ASSET_ID'] = Time.now.to_i.to_s diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb.canonical b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb.canonical new file mode 100644 index 00000000..39f34dee --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environment.rb.canonical @@ -0,0 +1,19 @@ +require File.join(File.dirname(__FILE__), 'boot') +require 'action_controller' + +Rails::Initializer.run do |config| + + if ActionController::Base.respond_to? 'session=' + config.action_controller.session = {:session_key => '_app_session', :secret => '22cde4d5c1a61ba69a81795322cde4d5c1a61ba69a817953'} + end + + config.load_paths << "#{RAILS_ROOT}/app/models/person" # moduleless model path + + config.after_initialize do + config.has_many_polymorphs_options['requirements'] << "#{RAILS_ROOT}/lib/library_model" + end +end + +# Dependencies.log_activity = true + +ENV['RAILS_ASSET_ID'] = Time.now.to_i.to_s diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/development.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/development.rb new file mode 100644 index 00000000..54ae4ed2 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/development.rb @@ -0,0 +1,9 @@ + +config.cache_classes = ENV['PRODUCTION'] +config.whiny_nils = true +config.action_controller.consider_all_requests_local = !ENV['PRODUCTION'] +config.action_controller.perform_caching = ENV['PRODUCTION'] +# The following has been deprecated in Rails 2.1 and removed in 2.2 +config.action_view.cache_template_extensions = ENV['PRODUCTION'] if Rails::VERSION::MAJOR < 2 or Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR < 1 +config.action_view.debug_rjs = !ENV['PRODUCTION'] +config.action_mailer.raise_delivery_errors = false diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/production.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/production.rb new file mode 100644 index 00000000..cb295b83 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/production.rb @@ -0,0 +1,18 @@ +# Settings specified here will take precedence over those in config/environment.rb + +# The production environment is meant for finished, "live" apps. +# Code is not reloaded between requests +config.cache_classes = true + +# Use a different logger for distributed setups +# config.logger = SyslogLogger.new + +# Full error reports are disabled and caching is turned on +config.action_controller.consider_all_requests_local = false +config.action_controller.perform_caching = true + +# Enable serving of images, stylesheets, and javascripts from an asset server +# config.action_controller.asset_host = "http://assets.example.com" + +# Disable delivery errors, bad email addresses will be ignored +# config.action_mailer.raise_delivery_errors = false diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/test.rb new file mode 100644 index 00000000..f0689b92 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/environments/test.rb @@ -0,0 +1,19 @@ +# Settings specified here will take precedence over those in config/environment.rb + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! +config.cache_classes = true + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_controller.perform_caching = false + +# Tell ActionMailer not to deliver emails to the real world. +# The :test delivery method accumulates sent emails in the +# ActionMailer::Base.deliveries array. +config.action_mailer.delivery_method = :test \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/locomotive.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/locomotive.yml new file mode 100644 index 00000000..01d79773 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/locomotive.yml @@ -0,0 +1,6 @@ +--- +mode: development +runs_at_launch: 0 +identifier: testapp +port: 3005 +bundle: /Applications/Locomotive2/Bundles/rmagickRailsMar2007_i386.locobundle \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/routes.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/routes.rb new file mode 100644 index 00000000..b83b6f4d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/routes.rb @@ -0,0 +1,33 @@ +ActionController::Routing::Routes.draw do |map| + map.resources :states + + map.resources :states + + map.resources :addresses + + map.resources :sellers + + map.resources :users + + # The priority is based upon order of creation: first created -> highest priority. + + # Sample of regular route: + # map.connect 'products/:id', :controller => 'catalog', :action => 'view' + # Keep in mind you can assign values other than :controller and :action + + # Sample of named route: + # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' + # This route can be invoked with purchase_url(:id => product.id) + + # You can have the root of your site routed by hooking up '' + # -- just remember to delete public/index.html. + # map.connect '', :controller => "welcome" + + # Allow downloading Web Service WSDL as a file with an extension + # instead of a file named 'wsdl' + map.connect ':controller/service.wsdl', :action => 'wsdl' + + # Install the default route as the lowest priority. + map.connect ':controller/:action/:id.:format' + map.connect ':controller/:action/:id' +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/default.base b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/default.base new file mode 100644 index 00000000..2886ccdc --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/default.base @@ -0,0 +1,56 @@ +# +# Sphinx/Ultrasphinx user-configurable options. +# +# Copy this file to RAILS_ROOT/config/ultrasphinx. +# You can use individual namespaces if you want (e.g. "development.base"). +# + +indexer +{ + # Indexer running options + mem_limit = 256M +} + +searchd +{ + # Daemon options + # What interface the search daemon should listen on and where to store its logs + address = 0.0.0.0 + port = 3313 + log = /tmp/sphinx/searchd.log + query_log = /tmp/sphinx/query.log + read_timeout = 5 + max_children = 300 + pid_file = /tmp/sphinx/searchd.pid + max_matches = 100000 +} + +client +{ + # Client options + dictionary_name = ts + # How your application connects to the search daemon (not necessarily the same as above) + server_host = localhost + server_port = 3313 +} + +source +{ + # Individual SQL source options + sql_range_step = 20000 + strip_html = 0 + index_html_attrs = + sql_query_post = +} + +index +{ + # Index building options + path = /tmp/sphinx/ + docinfo = extern # just leave this alone + morphology = stem_en + stopwords = # /path/to/stopwords.txt + min_word_len = 1 + charset_type = utf-8 # or sbcs (Single Byte Character Set) + charset_table = 0..9, A..Z->a..z, -, _, ., &, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F,U+C5->U+E5, U+E5, U+C4->U+E4, U+E4, U+D6->U+F6, U+F6, U+16B, U+0c1->a, U+0c4->a, U+0c9->e, U+0cd->i, U+0d3->o, U+0d4->o, U+0da->u, U+0dd->y, U+0e1->a, U+0e4->a, U+0e9->e, U+0ed->i, U+0f3->o, U+0f4->o, U+0fa->u, U+0fd->y, U+104->U+105, U+105, U+106->U+107, U+10c->c, U+10d->c, U+10e->d, U+10f->d, U+116->U+117, U+117, U+118->U+119, U+11a->e, U+11b->e, U+12E->U+12F, U+12F, U+139->l, U+13a->l, U+13d->l, U+13e->l, U+141->U+142, U+142, U+143->U+144, U+144,U+147->n, U+148->n, U+154->r, U+155->r, U+158->r, U+159->r, U+15A->U+15B, U+15B, U+160->s, U+160->U+161, U+161->s, U+164->t, U+165->t, U+16A->U+16B, U+16B, U+16e->u, U+16f->u, U+172->U+173, U+173, U+179->U+17A, U+17A, U+17B->U+17C, U+17C, U+17d->z, U+17e->z, +} diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/development.conf.canonical b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/development.conf.canonical new file mode 100644 index 00000000..f08e8ed4 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/config/ultrasphinx/development.conf.canonical @@ -0,0 +1,155 @@ + +# Auto-generated at Wed Oct 03 03:57:12 -0400 2007. +# Hand modifications will be overwritten. +# /Users/eweaver/Desktop/projects/chow/vendor/plugins/ultrasphinx/test/integration/app/config/ultrasphinx/default.base +indexer { + mem_limit = 256M +} +searchd { + read_timeout = 5 + max_children = 300 + log = /tmp/sphinx/searchd.log + port = 3313 + max_matches = 100000 + query_log = /tmp/sphinx/query.log + pid_file = /tmp/sphinx/searchd.pid + address = 0.0.0.0 +} + +# Source configuration + +source geo__states +{ + strip_html = 0 + sql_range_step = 20000 + index_html_attrs = + sql_query_post = + +type = mysql +sql_query_pre = SET SESSION group_concat_max_len = 65535 +sql_query_pre = SET NAMES utf8 + +sql_db = app_development +sql_host = localhost +sql_pass = +sql_user = root +sql_query_range = SELECT MIN(id), MAX(id) FROM states +sql_query = SELECT (states.id * 4 + 0) AS id, CAST(GROUP_CONCAT(addresses.name SEPARATOR ' ') AS CHAR) AS address_name, 0 AS capitalization, 'Geo::State' AS class, 0 AS class_id, '' AS company, '' AS company_name, 0 AS company_name_facet, '' AS content, UNIX_TIMESTAMP('1970-01-01 00:00:00') AS created_at, 0 AS deleted, '' AS email, '__empty_searchable__' AS empty_searchable, '' AS login, '' AS name, '' AS state, 0 AS user_id FROM states LEFT OUTER JOIN addresses ON states.id = addresses.state_id WHERE states.id >= $start AND states.id <= $end GROUP BY id + +sql_group_column = capitalization +sql_group_column = class_id +sql_group_column = company_name_facet +sql_date_column = created_at +sql_group_column = deleted +sql_group_column = user_id +sql_query_info = SELECT * FROM states WHERE states.id = (($id - 0) / 4) +} + + +# Source configuration + +source sellers +{ + strip_html = 0 + sql_range_step = 20000 + index_html_attrs = + sql_query_post = + +type = mysql +sql_query_pre = SET SESSION group_concat_max_len = 65535 +sql_query_pre = SET NAMES utf8 + +sql_db = app_development +sql_host = localhost +sql_pass = +sql_user = root +sql_query_range = SELECT MIN(id), MAX(id) FROM sellers +sql_query = SELECT (sellers.id * 4 + 1) AS id, '' AS address_name, sellers.capitalization AS capitalization, 'Seller' AS class, 1 AS class_id, '' AS company, sellers.company_name AS company_name, CRC32(sellers.company_name) AS company_name_facet, '' AS content, UNIX_TIMESTAMP(sellers.created_at) AS created_at, 0 AS deleted, '' AS email, '__empty_searchable__' AS empty_searchable, '' AS login, '' AS name, '' AS state, sellers.user_id AS user_id FROM sellers WHERE sellers.id >= $start AND sellers.id <= $end GROUP BY id + +sql_group_column = capitalization +sql_group_column = class_id +sql_group_column = company_name_facet +sql_date_column = created_at +sql_group_column = deleted +sql_group_column = user_id +sql_query_info = SELECT * FROM sellers WHERE sellers.id = (($id - 1) / 4) +} + + +# Source configuration + +source geo__addresses +{ + strip_html = 0 + sql_range_step = 20000 + index_html_attrs = + sql_query_post = + +type = mysql +sql_query_pre = SET SESSION group_concat_max_len = 65535 +sql_query_pre = SET NAMES utf8 + +sql_db = app_development +sql_host = localhost +sql_pass = +sql_user = root +sql_query_range = SELECT MIN(id), MAX(id) FROM addresses +sql_query = SELECT (addresses.id * 4 + 2) AS id, '' AS address_name, 0 AS capitalization, 'Geo::Address' AS class, 2 AS class_id, '' AS company, '' AS company_name, 0 AS company_name_facet, CONCAT_WS(' ', addresses.line_1, addresses.line_2, addresses.city, addresses.province_region, addresses.zip_postal_code) AS content, UNIX_TIMESTAMP('1970-01-01 00:00:00') AS created_at, 0 AS deleted, '' AS email, '__empty_searchable__' AS empty_searchable, '' AS login, addresses.name AS name, states.name AS state, 0 AS user_id FROM addresses LEFT OUTER JOIN states ON states.id = addresses.state_id WHERE addresses.id >= $start AND addresses.id <= $end GROUP BY id + +sql_group_column = capitalization +sql_group_column = class_id +sql_group_column = company_name_facet +sql_date_column = created_at +sql_group_column = deleted +sql_group_column = user_id +sql_query_info = SELECT * FROM addresses WHERE addresses.id = (($id - 2) / 4) +} + + +# Source configuration + +source users +{ + strip_html = 0 + sql_range_step = 20000 + index_html_attrs = + sql_query_post = + +type = mysql +sql_query_pre = SET SESSION group_concat_max_len = 65535 +sql_query_pre = SET NAMES utf8 + +sql_db = app_development +sql_host = localhost +sql_pass = +sql_user = root +sql_query_range = SELECT MIN(id), MAX(id) FROM users +sql_query = SELECT (users.id * 4 + 3) AS id, '' AS address_name, 0 AS capitalization, 'User' AS class, 3 AS class_id, sellers.company_name AS company, '' AS company_name, 0 AS company_name_facet, '' AS content, UNIX_TIMESTAMP('1970-01-01 00:00:00') AS created_at, users.deleted AS deleted, users.email AS email, '__empty_searchable__' AS empty_searchable, users.login AS login, '' AS name, '' AS state, 0 AS user_id FROM users LEFT OUTER JOIN sellers ON users.id = sellers.user_id WHERE users.id >= $start AND users.id <= $end AND (deleted = 0) GROUP BY id + +sql_group_column = capitalization +sql_group_column = class_id +sql_group_column = company_name_facet +sql_date_column = created_at +sql_group_column = deleted +sql_group_column = user_id +sql_query_info = SELECT * FROM users WHERE users.id = (($id - 3) / 4) +} + + +# Index configuration + +index complete +{ + source = geo__addresses + source = geo__states + source = sellers + source = users + charset_type = utf-8 + charset_table = 0..9, A..Z->a..z, -, _, ., &, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F,U+C5->U+E5, U+E5, U+C4->U+E4, U+E4, U+D6->U+F6, U+F6, U+16B, U+0c1->a, U+0c4->a, U+0c9->e, U+0cd->i, U+0d3->o, U+0d4->o, U+0da->u, U+0dd->y, U+0e1->a, U+0e4->a, U+0e9->e, U+0ed->i, U+0f3->o, U+0f4->o, U+0fa->u, U+0fd->y, U+104->U+105, U+105, U+106->U+107, U+10c->c, U+10d->c, U+10e->d, U+10f->d, U+116->U+117, U+117, U+118->U+119, U+11a->e, U+11b->e, U+12E->U+12F, U+12F, U+139->l, U+13a->l, U+13d->l, U+13e->l, U+141->U+142, U+142, U+143->U+144, U+144,U+147->n, U+148->n, U+154->r, U+155->r, U+158->r, U+159->r, U+15A->U+15B, U+15B, U+160->s, U+160->U+161, U+161->s, U+164->t, U+165->t, U+16A->U+16B, U+16B, U+16e->u, U+16f->u, U+172->U+173, U+173, U+179->U+17A, U+17A, U+17B->U+17C, U+17C, U+17d->z, U+17e->z, + min_word_len = 1 + stopwords = + path = /tmp/sphinx//sphinx_index_complete + docinfo = extern + morphology = stem_en +} + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/001_create_sticks.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/001_create_sticks.rb new file mode 100644 index 00000000..6193c313 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/001_create_sticks.rb @@ -0,0 +1,11 @@ +class CreateSticks < ActiveRecord::Migration + def self.up + create_table :sticks do |t| + t.column :name, :string + end + end + + def self.down + drop_table :sticks + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/002_create_stones.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/002_create_stones.rb new file mode 100644 index 00000000..4c1ec154 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/002_create_stones.rb @@ -0,0 +1,11 @@ +class CreateStones < ActiveRecord::Migration + def self.up + create_table :stones do |t| + t.column :name, :string + end + end + + def self.down + drop_table :stones + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/003_create_organic_substances.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/003_create_organic_substances.rb new file mode 100644 index 00000000..1bf82da6 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/003_create_organic_substances.rb @@ -0,0 +1,11 @@ +class CreateOrganicSubstances < ActiveRecord::Migration + def self.up + create_table :organic_substances do |t| + t.column :type, :string + end + end + + def self.down + drop_table :organic_substances + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/004_create_bones.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/004_create_bones.rb new file mode 100644 index 00000000..6faa0aa1 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/004_create_bones.rb @@ -0,0 +1,8 @@ +class CreateBones < ActiveRecord::Migration + def self.up + # Using STI + end + + def self.down + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/005_create_single_sti_parents.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/005_create_single_sti_parents.rb new file mode 100644 index 00000000..eef14621 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/005_create_single_sti_parents.rb @@ -0,0 +1,11 @@ +class CreateSingleStiParents < ActiveRecord::Migration + def self.up + create_table :single_sti_parents do |t| + t.column :name, :string + end + end + + def self.down + drop_table :single_sti_parents + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/006_create_double_sti_parents.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/006_create_double_sti_parents.rb new file mode 100644 index 00000000..2a28f4ab --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/006_create_double_sti_parents.rb @@ -0,0 +1,11 @@ +class CreateDoubleStiParents < ActiveRecord::Migration + def self.up + create_table :double_sti_parents do |t| + t.column :name, :string + end + end + + def self.down + drop_table :double_sti_parents + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb new file mode 100644 index 00000000..deceeec7 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb @@ -0,0 +1,13 @@ +class CreateSingleStiParentRelationships < ActiveRecord::Migration + def self.up + create_table :single_sti_parent_relationships do |t| + t.column :the_bone_type, :string, :null => false + t.column :the_bone_id, :integer, :null => false + t.column :single_sti_parent_id, :integer, :null => false + end + end + + def self.down + drop_table :single_sti_parent_relationships + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb new file mode 100644 index 00000000..46605d9b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb @@ -0,0 +1,14 @@ +class CreateDoubleStiParentRelationships < ActiveRecord::Migration + def self.up + create_table :double_sti_parent_relationships do |t| + t.column :the_bone_type, :string, :null => false + t.column :the_bone_id, :integer, :null => false + t.column :parent_type, :string, :null => false + t.column :parent_id, :integer, :null => false + end + end + + def self.down + drop_table :double_sti_parent_relationships + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/009_create_library_model.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/009_create_library_model.rb new file mode 100644 index 00000000..bdf7cf46 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/db/migrate/009_create_library_model.rb @@ -0,0 +1,11 @@ +class CreateLibraryModel < ActiveRecord::Migration + def self.up + create_table :library_models do |t| + t.column :name, :string + end + end + + def self.down + drop_table :library_models + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/doc/README_FOR_APP b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/doc/README_FOR_APP new file mode 100644 index 00000000..ac6c1491 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/doc/README_FOR_APP @@ -0,0 +1,2 @@ +Use this README file to introduce your application and point to useful places in the API for learning more. +Run "rake appdoc" to generate API documentation for your models and controllers. \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/generators/commenting_generator_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/generators/commenting_generator_test.rb new file mode 100644 index 00000000..96c6a799 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/generators/commenting_generator_test.rb @@ -0,0 +1,83 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'fileutils' + +class CommentingGeneratorTest < Test::Unit::TestCase + + def test_ensure_comments_dont_exist + # make sure the comments are already defined + assert_equal false, Object.send(:const_defined?, :Comment) + assert_equal false, Object.send(:const_defined?, :Commenting) + end + + def test_ensure_files_exist_after_generator_runs + run_generator + + # make sure the files are there + for generated_file in generated_files do + assert File.exists?(File.expand_path(generated_file)) + end + end + + def test_classes_exist_with_associations + run_generator + assert_nothing_raised { Commenting } + assert_nothing_raised { Comment } + citation = Citation.find(:first) + assert !citation.nil? + assert citation.respond_to?(:comments) + user = User.find(:first) + assert !user.nil? + assert user.respond_to?(:comments) + end + + def teardown + Object.send(:remove_const, :Comment) if Object.send(:const_defined?, :Comment) + Object.send(:remove_const, :Commenting) if Object.send(:const_defined?, :Commenting) + remove_all_generated_files + remove_require_for_commenting_extensions + end + + def generated_files + generated_files = [File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'comment.rb')] + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'commenting.rb') + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'test', 'unit', 'commenting_test.rb') + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'test', 'unit', 'comment_test.rb') + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'lib', 'commenting_extensions.rb') + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'test', 'fixtures', 'comments.yml') + generated_files << File.join(File.dirname(__FILE__), '..', '..', 'test', 'fixtures', 'commentings.yml') + end + + def remove_all_generated_files + for generated_file in generated_files do + if File.exists?(generated_file) + assert FileUtils.rm(generated_file) + end + end + end + + def run_migrate + `rake db:migrate RAILS_ENV=test` + end + + def run_generator + command = File.join(File.dirname(__FILE__), '..', '..', 'script', 'generate') + `#{command} commenting Citation User` + run_migrate + end + + def remove_require_for_commenting_extensions + environment = File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment.rb') + new_environment = '' + if File.exists?(environment) + if (open(environment) { |file| file.grep(/Rails/).any? }) + IO.readlines(environment).each do |line| + new_environment += line unless line.match(/commenting_extensions/i) + end + File.open(environment, "w+") do |f| + f.pos = 0 + f.print new_environment + end + end + end + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/lib/library_model.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/lib/library_model.rb new file mode 100644 index 00000000..e27106fa --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/lib/library_model.rb @@ -0,0 +1,2 @@ +class LibraryModel < ActiveRecord::Base +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/404.html b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/404.html new file mode 100644 index 00000000..eff660b9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/404.html @@ -0,0 +1,30 @@ + + + + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/500.html b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/500.html new file mode 100644 index 00000000..f0aee0e9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/500.html @@ -0,0 +1,30 @@ + + + + + + + We're sorry, but something went wrong + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
+ + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.cgi b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.cgi new file mode 100755 index 00000000..9b5ae760 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.cgi @@ -0,0 +1,10 @@ +#!/usr/local/bin/ruby + +require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) + +# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: +# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired +require "dispatcher" + +ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun) +Dispatcher.dispatch \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.fcgi b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.fcgi new file mode 100755 index 00000000..664dbbbe --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.fcgi @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +# +# You may specify the path to the FastCGI crash log (a log of unhandled +# exceptions which forced the FastCGI instance to exit, great for debugging) +# and the number of requests to process before running garbage collection. +# +# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log +# and the GC period is nil (turned off). A reasonable number of requests +# could range from 10-100 depending on the memory footprint of your app. +# +# Example: +# # Default log path, normal GC behavior. +# RailsFCGIHandler.process! +# +# # Default log path, 50 requests between GC. +# RailsFCGIHandler.process! nil, 50 +# +# # Custom log path, normal GC behavior. +# RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log' +# +require File.dirname(__FILE__) + "/../config/environment" +require 'fcgi_handler' + +RailsFCGIHandler.process! diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.rb new file mode 100755 index 00000000..9b5ae760 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/dispatch.rb @@ -0,0 +1,10 @@ +#!/usr/local/bin/ruby + +require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) + +# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: +# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired +require "dispatcher" + +ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun) +Dispatcher.dispatch \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/favicon.ico b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/favicon.ico new file mode 100644 index 00000000..e69de29b diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/images/rails.png b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/images/rails.png new file mode 100644 index 0000000000000000000000000000000000000000..b8441f182e06974083cf08f0acaf0e2fd612bd40 GIT binary patch literal 1787 zcmVCLdthj)A!BBmWB&y|X`RY;f`BJ<_ju%@N||NoLFD~mQl$aHGjq>;5dG_D{h(5s}0 z6&=HANU$m__3PuddU(lvR_xWj`}Oho@9EyQt-n!E*P(KhM@X_VFV2l&>deNZJT%y8iwA zoG>u1B`p2=_u9k4v1Mud`1+qvOZoHg#bITJ9U`qBAek?40RR96!AV3xRCwBy*IQ$v zN(=yC9IhRft9V64L`77pqF_Cx@c;kSNoGK)`?Ps*cP(EtGlYZ{D5cxspMQvjKH)Oh6X(pa|J{ zGy1J$Ej7=Z{uvmMfRRsE;v`p;45B~6*ep#hM^ji zl$+7qoWq~}ewG=61uFw0He{tJurMU&4Iv?=B^eR(wAHk!miA)O7p_+YR>lbmU3rmn ze?+ze(+sEd6foB&*l9+?zkr_a-5*v&p*?c}HOGtyHg6r{WFYpQ=#z0Hc7VWLx$>M3|b0|Gn z+5t#z6*ffSVc6DjpmB2?AAR@@vB!wCK?9Yl;33;Q7^%(401QW|k=R8b!OwtLJPjjm zO9Ia;qCq)rOq!1Ia*6#A%#xb}yDx1P*pWla>9j$bnMn3CBqe4`TRll_Iy29kmG?4fbKuF=XqU|?3b@B zA`&a?KIgZ|KJx5eND_c3Em=WZn@xW8hRJ^G&sY^b(FW?WC9W_sb;+lAPdLTdBaKIK;-f}*h4|1aTjw7qX_k~e{TWO7jqcekERN;Jyh%67)q4rKpL*CEYL;|#GY{B@5 zi52XoC?xsoorJKxsliugF#z38MJqrYCWV(t<=G&f;^Me13&AiI9{3jUZ$ zFM`*L(9qc^VMxkz1oaDH!1pcD^IXp>Z0Jb=_qs?Vsrs{mp<^{$N!EC9o+`CO-(o}E zJ`y{*;9s|wr22-QoJ87y^~;)Q@b%P4UgSSsx>2$o@Vd{%Pk0@4qZ^fhB(vt$c1TG> z*{Ad;foraENbld`=MCNm4?9kvlgK~&J>ialpJ7nua zx0oRzwG5;}Qne)Fg(N3kf?JVmB;}y&5(0+~r*aL$0Zof8fe!AtHWH>A^1Y)@G@GsA zup`R{Qg?{+MaxTq#2n{6w|)c&yaJ7{U4ngAH5v6I)*;@rEBE*ehIPBwKBQU)YKE8F0lR!Sm?sE4Xk-sj&E$|A-9n dP56HS1^^A-61FoN)nxzx002ovPDHLkV1kw_Sd9Px literal 0 HcmV?d00001 diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/index.html b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/index.html new file mode 100644 index 00000000..a2daab72 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/index.html @@ -0,0 +1,277 @@ + + + + + Ruby on Rails: Welcome aboard + + + + + + +
+ + +
+ + + + +
+

Getting started

+

Here’s how to get rolling:

+ +
    +
  1. +

    Create your databases and edit config/database.yml

    +

    Rails needs to know your login and password.

    +
  2. + +
  3. +

    Use script/generate to create your models and controllers

    +

    To see all available options, run it without parameters.

    +
  4. + +
  5. +

    Set up a default route and remove or rename this file

    +

    Routes are setup in config/routes.rb.

    +
  6. +
+
+
+ + +
+ + \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/application.js b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/application.js new file mode 100644 index 00000000..fe457769 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/application.js @@ -0,0 +1,2 @@ +// Place your application-specific JavaScript functions and classes here +// This file is automatically included by javascript_include_tag :defaults diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/controls.js b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/controls.js new file mode 100644 index 00000000..8c273f87 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/controls.js @@ -0,0 +1,833 @@ +// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan) +// (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com) +// Contributors: +// Richard Livsey +// Rahul Bhargava +// Rob Wills +// +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ + +// Autocompleter.Base handles all the autocompletion functionality +// that's independent of the data source for autocompletion. This +// includes drawing the autocompletion menu, observing keyboard +// and mouse events, and similar. +// +// Specific autocompleters need to provide, at the very least, +// a getUpdatedChoices function that will be invoked every time +// the text inside the monitored textbox changes. This method +// should get the text for which to provide autocompletion by +// invoking this.getToken(), NOT by directly accessing +// this.element.value. This is to allow incremental tokenized +// autocompletion. Specific auto-completion logic (AJAX, etc) +// belongs in getUpdatedChoices. +// +// Tokenized incremental autocompletion is enabled automatically +// when an autocompleter is instantiated with the 'tokens' option +// in the options parameter, e.g.: +// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' }); +// will incrementally autocomplete with a comma as the token. +// Additionally, ',' in the above example can be replaced with +// a token array, e.g. { tokens: [',', '\n'] } which +// enables autocompletion on multiple tokens. This is most +// useful when one of the tokens is \n (a newline), as it +// allows smart autocompletion after linebreaks. + +if(typeof Effect == 'undefined') + throw("controls.js requires including script.aculo.us' effects.js library"); + +var Autocompleter = {} +Autocompleter.Base = function() {}; +Autocompleter.Base.prototype = { + baseInitialize: function(element, update, options) { + this.element = $(element); + this.update = $(update); + this.hasFocus = false; + this.changed = false; + this.active = false; + this.index = 0; + this.entryCount = 0; + + if(this.setOptions) + this.setOptions(options); + else + this.options = options || {}; + + this.options.paramName = this.options.paramName || this.element.name; + this.options.tokens = this.options.tokens || []; + this.options.frequency = this.options.frequency || 0.4; + this.options.minChars = this.options.minChars || 1; + this.options.onShow = this.options.onShow || + function(element, update){ + if(!update.style.position || update.style.position=='absolute') { + update.style.position = 'absolute'; + Position.clone(element, update, { + setHeight: false, + offsetTop: element.offsetHeight + }); + } + Effect.Appear(update,{duration:0.15}); + }; + this.options.onHide = this.options.onHide || + function(element, update){ new Effect.Fade(update,{duration:0.15}) }; + + if(typeof(this.options.tokens) == 'string') + this.options.tokens = new Array(this.options.tokens); + + this.observer = null; + + this.element.setAttribute('autocomplete','off'); + + Element.hide(this.update); + + Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this)); + Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this)); + }, + + show: function() { + if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update); + if(!this.iefix && + (navigator.appVersion.indexOf('MSIE')>0) && + (navigator.userAgent.indexOf('Opera')<0) && + (Element.getStyle(this.update, 'position')=='absolute')) { + new Insertion.After(this.update, + ''); + this.iefix = $(this.update.id+'_iefix'); + } + if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50); + }, + + fixIEOverlapping: function() { + Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)}); + this.iefix.style.zIndex = 1; + this.update.style.zIndex = 2; + Element.show(this.iefix); + }, + + hide: function() { + this.stopIndicator(); + if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update); + if(this.iefix) Element.hide(this.iefix); + }, + + startIndicator: function() { + if(this.options.indicator) Element.show(this.options.indicator); + }, + + stopIndicator: function() { + if(this.options.indicator) Element.hide(this.options.indicator); + }, + + onKeyPress: function(event) { + if(this.active) + switch(event.keyCode) { + case Event.KEY_TAB: + case Event.KEY_RETURN: + this.selectEntry(); + Event.stop(event); + case Event.KEY_ESC: + this.hide(); + this.active = false; + Event.stop(event); + return; + case Event.KEY_LEFT: + case Event.KEY_RIGHT: + return; + case Event.KEY_UP: + this.markPrevious(); + this.render(); + if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event); + return; + case Event.KEY_DOWN: + this.markNext(); + this.render(); + if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event); + return; + } + else + if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || + (navigator.appVersion.indexOf('AppleWebKit') > 0 && event.keyCode == 0)) return; + + this.changed = true; + this.hasFocus = true; + + if(this.observer) clearTimeout(this.observer); + this.observer = + setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000); + }, + + activate: function() { + this.changed = false; + this.hasFocus = true; + this.getUpdatedChoices(); + }, + + onHover: function(event) { + var element = Event.findElement(event, 'LI'); + if(this.index != element.autocompleteIndex) + { + this.index = element.autocompleteIndex; + this.render(); + } + Event.stop(event); + }, + + onClick: function(event) { + var element = Event.findElement(event, 'LI'); + this.index = element.autocompleteIndex; + this.selectEntry(); + this.hide(); + }, + + onBlur: function(event) { + // needed to make click events working + setTimeout(this.hide.bind(this), 250); + this.hasFocus = false; + this.active = false; + }, + + render: function() { + if(this.entryCount > 0) { + for (var i = 0; i < this.entryCount; i++) + this.index==i ? + Element.addClassName(this.getEntry(i),"selected") : + Element.removeClassName(this.getEntry(i),"selected"); + + if(this.hasFocus) { + this.show(); + this.active = true; + } + } else { + this.active = false; + this.hide(); + } + }, + + markPrevious: function() { + if(this.index > 0) this.index-- + else this.index = this.entryCount-1; + this.getEntry(this.index).scrollIntoView(true); + }, + + markNext: function() { + if(this.index < this.entryCount-1) this.index++ + else this.index = 0; + this.getEntry(this.index).scrollIntoView(false); + }, + + getEntry: function(index) { + return this.update.firstChild.childNodes[index]; + }, + + getCurrentEntry: function() { + return this.getEntry(this.index); + }, + + selectEntry: function() { + this.active = false; + this.updateElement(this.getCurrentEntry()); + }, + + updateElement: function(selectedElement) { + if (this.options.updateElement) { + this.options.updateElement(selectedElement); + return; + } + var value = ''; + if (this.options.select) { + var nodes = document.getElementsByClassName(this.options.select, selectedElement) || []; + if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select); + } else + value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal'); + + var lastTokenPos = this.findLastToken(); + if (lastTokenPos != -1) { + var newValue = this.element.value.substr(0, lastTokenPos + 1); + var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/); + if (whitespace) + newValue += whitespace[0]; + this.element.value = newValue + value; + } else { + this.element.value = value; + } + this.element.focus(); + + if (this.options.afterUpdateElement) + this.options.afterUpdateElement(this.element, selectedElement); + }, + + updateChoices: function(choices) { + if(!this.changed && this.hasFocus) { + this.update.innerHTML = choices; + Element.cleanWhitespace(this.update); + Element.cleanWhitespace(this.update.down()); + + if(this.update.firstChild && this.update.down().childNodes) { + this.entryCount = + this.update.down().childNodes.length; + for (var i = 0; i < this.entryCount; i++) { + var entry = this.getEntry(i); + entry.autocompleteIndex = i; + this.addObservers(entry); + } + } else { + this.entryCount = 0; + } + + this.stopIndicator(); + this.index = 0; + + if(this.entryCount==1 && this.options.autoSelect) { + this.selectEntry(); + this.hide(); + } else { + this.render(); + } + } + }, + + addObservers: function(element) { + Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this)); + Event.observe(element, "click", this.onClick.bindAsEventListener(this)); + }, + + onObserverEvent: function() { + this.changed = false; + if(this.getToken().length>=this.options.minChars) { + this.startIndicator(); + this.getUpdatedChoices(); + } else { + this.active = false; + this.hide(); + } + }, + + getToken: function() { + var tokenPos = this.findLastToken(); + if (tokenPos != -1) + var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,''); + else + var ret = this.element.value; + + return /\n/.test(ret) ? '' : ret; + }, + + findLastToken: function() { + var lastTokenPos = -1; + + for (var i=0; i lastTokenPos) + lastTokenPos = thisTokenPos; + } + return lastTokenPos; + } +} + +Ajax.Autocompleter = Class.create(); +Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { + initialize: function(element, update, url, options) { + this.baseInitialize(element, update, options); + this.options.asynchronous = true; + this.options.onComplete = this.onComplete.bind(this); + this.options.defaultParams = this.options.parameters || null; + this.url = url; + }, + + getUpdatedChoices: function() { + entry = encodeURIComponent(this.options.paramName) + '=' + + encodeURIComponent(this.getToken()); + + this.options.parameters = this.options.callback ? + this.options.callback(this.element, entry) : entry; + + if(this.options.defaultParams) + this.options.parameters += '&' + this.options.defaultParams; + + new Ajax.Request(this.url, this.options); + }, + + onComplete: function(request) { + this.updateChoices(request.responseText); + } + +}); + +// The local array autocompleter. Used when you'd prefer to +// inject an array of autocompletion options into the page, rather +// than sending out Ajax queries, which can be quite slow sometimes. +// +// The constructor takes four parameters. The first two are, as usual, +// the id of the monitored textbox, and id of the autocompletion menu. +// The third is the array you want to autocomplete from, and the fourth +// is the options block. +// +// Extra local autocompletion options: +// - choices - How many autocompletion choices to offer +// +// - partialSearch - If false, the autocompleter will match entered +// text only at the beginning of strings in the +// autocomplete array. Defaults to true, which will +// match text at the beginning of any *word* in the +// strings in the autocomplete array. If you want to +// search anywhere in the string, additionally set +// the option fullSearch to true (default: off). +// +// - fullSsearch - Search anywhere in autocomplete array strings. +// +// - partialChars - How many characters to enter before triggering +// a partial match (unlike minChars, which defines +// how many characters are required to do any match +// at all). Defaults to 2. +// +// - ignoreCase - Whether to ignore case when autocompleting. +// Defaults to true. +// +// It's possible to pass in a custom function as the 'selector' +// option, if you prefer to write your own autocompletion logic. +// In that case, the other options above will not apply unless +// you support them. + +Autocompleter.Local = Class.create(); +Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { + initialize: function(element, update, array, options) { + this.baseInitialize(element, update, options); + this.options.array = array; + }, + + getUpdatedChoices: function() { + this.updateChoices(this.options.selector(this)); + }, + + setOptions: function(options) { + this.options = Object.extend({ + choices: 10, + partialSearch: true, + partialChars: 2, + ignoreCase: true, + fullSearch: false, + selector: function(instance) { + var ret = []; // Beginning matches + var partial = []; // Inside matches + var entry = instance.getToken(); + var count = 0; + + for (var i = 0; i < instance.options.array.length && + ret.length < instance.options.choices ; i++) { + + var elem = instance.options.array[i]; + var foundPos = instance.options.ignoreCase ? + elem.toLowerCase().indexOf(entry.toLowerCase()) : + elem.indexOf(entry); + + while (foundPos != -1) { + if (foundPos == 0 && elem.length != entry.length) { + ret.push("
  • " + elem.substr(0, entry.length) + "" + + elem.substr(entry.length) + "
  • "); + break; + } else if (entry.length >= instance.options.partialChars && + instance.options.partialSearch && foundPos != -1) { + if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) { + partial.push("
  • " + elem.substr(0, foundPos) + "" + + elem.substr(foundPos, entry.length) + "" + elem.substr( + foundPos + entry.length) + "
  • "); + break; + } + } + + foundPos = instance.options.ignoreCase ? + elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : + elem.indexOf(entry, foundPos + 1); + + } + } + if (partial.length) + ret = ret.concat(partial.slice(0, instance.options.choices - ret.length)) + return "
      " + ret.join('') + "
    "; + } + }, options || {}); + } +}); + +// AJAX in-place editor +// +// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor + +// Use this if you notice weird scrolling problems on some browsers, +// the DOM might be a bit confused when this gets called so do this +// waits 1 ms (with setTimeout) until it does the activation +Field.scrollFreeActivate = function(field) { + setTimeout(function() { + Field.activate(field); + }, 1); +} + +Ajax.InPlaceEditor = Class.create(); +Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99"; +Ajax.InPlaceEditor.prototype = { + initialize: function(element, url, options) { + this.url = url; + this.element = $(element); + + this.options = Object.extend({ + paramName: "value", + okButton: true, + okText: "ok", + cancelLink: true, + cancelText: "cancel", + savingText: "Saving...", + clickToEditText: "Click to edit", + okText: "ok", + rows: 1, + onComplete: function(transport, element) { + new Effect.Highlight(element, {startcolor: this.options.highlightcolor}); + }, + onFailure: function(transport) { + alert("Error communicating with the server: " + transport.responseText.stripTags()); + }, + callback: function(form) { + return Form.serialize(form); + }, + handleLineBreaks: true, + loadingText: 'Loading...', + savingClassName: 'inplaceeditor-saving', + loadingClassName: 'inplaceeditor-loading', + formClassName: 'inplaceeditor-form', + highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor, + highlightendcolor: "#FFFFFF", + externalControl: null, + submitOnBlur: false, + ajaxOptions: {}, + evalScripts: false + }, options || {}); + + if(!this.options.formId && this.element.id) { + this.options.formId = this.element.id + "-inplaceeditor"; + if ($(this.options.formId)) { + // there's already a form with that name, don't specify an id + this.options.formId = null; + } + } + + if (this.options.externalControl) { + this.options.externalControl = $(this.options.externalControl); + } + + this.originalBackground = Element.getStyle(this.element, 'background-color'); + if (!this.originalBackground) { + this.originalBackground = "transparent"; + } + + this.element.title = this.options.clickToEditText; + + this.onclickListener = this.enterEditMode.bindAsEventListener(this); + this.mouseoverListener = this.enterHover.bindAsEventListener(this); + this.mouseoutListener = this.leaveHover.bindAsEventListener(this); + Event.observe(this.element, 'click', this.onclickListener); + Event.observe(this.element, 'mouseover', this.mouseoverListener); + Event.observe(this.element, 'mouseout', this.mouseoutListener); + if (this.options.externalControl) { + Event.observe(this.options.externalControl, 'click', this.onclickListener); + Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener); + Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener); + } + }, + enterEditMode: function(evt) { + if (this.saving) return; + if (this.editing) return; + this.editing = true; + this.onEnterEditMode(); + if (this.options.externalControl) { + Element.hide(this.options.externalControl); + } + Element.hide(this.element); + this.createForm(); + this.element.parentNode.insertBefore(this.form, this.element); + if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField); + // stop the event to avoid a page refresh in Safari + if (evt) { + Event.stop(evt); + } + return false; + }, + createForm: function() { + this.form = document.createElement("form"); + this.form.id = this.options.formId; + Element.addClassName(this.form, this.options.formClassName) + this.form.onsubmit = this.onSubmit.bind(this); + + this.createEditField(); + + if (this.options.textarea) { + var br = document.createElement("br"); + this.form.appendChild(br); + } + + if (this.options.okButton) { + okButton = document.createElement("input"); + okButton.type = "submit"; + okButton.value = this.options.okText; + okButton.className = 'editor_ok_button'; + this.form.appendChild(okButton); + } + + if (this.options.cancelLink) { + cancelLink = document.createElement("a"); + cancelLink.href = "#"; + cancelLink.appendChild(document.createTextNode(this.options.cancelText)); + cancelLink.onclick = this.onclickCancel.bind(this); + cancelLink.className = 'editor_cancel'; + this.form.appendChild(cancelLink); + } + }, + hasHTMLLineBreaks: function(string) { + if (!this.options.handleLineBreaks) return false; + return string.match(/
    /i); + }, + convertHTMLLineBreaks: function(string) { + return string.replace(/
    /gi, "\n").replace(//gi, "\n").replace(/<\/p>/gi, "\n").replace(/

    /gi, ""); + }, + createEditField: function() { + var text; + if(this.options.loadTextURL) { + text = this.options.loadingText; + } else { + text = this.getText(); + } + + var obj = this; + + if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) { + this.options.textarea = false; + var textField = document.createElement("input"); + textField.obj = this; + textField.type = "text"; + textField.name = this.options.paramName; + textField.value = text; + textField.style.backgroundColor = this.options.highlightcolor; + textField.className = 'editor_field'; + var size = this.options.size || this.options.cols || 0; + if (size != 0) textField.size = size; + if (this.options.submitOnBlur) + textField.onblur = this.onSubmit.bind(this); + this.editField = textField; + } else { + this.options.textarea = true; + var textArea = document.createElement("textarea"); + textArea.obj = this; + textArea.name = this.options.paramName; + textArea.value = this.convertHTMLLineBreaks(text); + textArea.rows = this.options.rows; + textArea.cols = this.options.cols || 40; + textArea.className = 'editor_field'; + if (this.options.submitOnBlur) + textArea.onblur = this.onSubmit.bind(this); + this.editField = textArea; + } + + if(this.options.loadTextURL) { + this.loadExternalText(); + } + this.form.appendChild(this.editField); + }, + getText: function() { + return this.element.innerHTML; + }, + loadExternalText: function() { + Element.addClassName(this.form, this.options.loadingClassName); + this.editField.disabled = true; + new Ajax.Request( + this.options.loadTextURL, + Object.extend({ + asynchronous: true, + onComplete: this.onLoadedExternalText.bind(this) + }, this.options.ajaxOptions) + ); + }, + onLoadedExternalText: function(transport) { + Element.removeClassName(this.form, this.options.loadingClassName); + this.editField.disabled = false; + this.editField.value = transport.responseText.stripTags(); + Field.scrollFreeActivate(this.editField); + }, + onclickCancel: function() { + this.onComplete(); + this.leaveEditMode(); + return false; + }, + onFailure: function(transport) { + this.options.onFailure(transport); + if (this.oldInnerHTML) { + this.element.innerHTML = this.oldInnerHTML; + this.oldInnerHTML = null; + } + return false; + }, + onSubmit: function() { + // onLoading resets these so we need to save them away for the Ajax call + var form = this.form; + var value = this.editField.value; + + // do this first, sometimes the ajax call returns before we get a chance to switch on Saving... + // which means this will actually switch on Saving... *after* we've left edit mode causing Saving... + // to be displayed indefinitely + this.onLoading(); + + if (this.options.evalScripts) { + new Ajax.Request( + this.url, Object.extend({ + parameters: this.options.callback(form, value), + onComplete: this.onComplete.bind(this), + onFailure: this.onFailure.bind(this), + asynchronous:true, + evalScripts:true + }, this.options.ajaxOptions)); + } else { + new Ajax.Updater( + { success: this.element, + // don't update on failure (this could be an option) + failure: null }, + this.url, Object.extend({ + parameters: this.options.callback(form, value), + onComplete: this.onComplete.bind(this), + onFailure: this.onFailure.bind(this) + }, this.options.ajaxOptions)); + } + // stop the event to avoid a page refresh in Safari + if (arguments.length > 1) { + Event.stop(arguments[0]); + } + return false; + }, + onLoading: function() { + this.saving = true; + this.removeForm(); + this.leaveHover(); + this.showSaving(); + }, + showSaving: function() { + this.oldInnerHTML = this.element.innerHTML; + this.element.innerHTML = this.options.savingText; + Element.addClassName(this.element, this.options.savingClassName); + this.element.style.backgroundColor = this.originalBackground; + Element.show(this.element); + }, + removeForm: function() { + if(this.form) { + if (this.form.parentNode) Element.remove(this.form); + this.form = null; + } + }, + enterHover: function() { + if (this.saving) return; + this.element.style.backgroundColor = this.options.highlightcolor; + if (this.effect) { + this.effect.cancel(); + } + Element.addClassName(this.element, this.options.hoverClassName) + }, + leaveHover: function() { + if (this.options.backgroundColor) { + this.element.style.backgroundColor = this.oldBackground; + } + Element.removeClassName(this.element, this.options.hoverClassName) + if (this.saving) return; + this.effect = new Effect.Highlight(this.element, { + startcolor: this.options.highlightcolor, + endcolor: this.options.highlightendcolor, + restorecolor: this.originalBackground + }); + }, + leaveEditMode: function() { + Element.removeClassName(this.element, this.options.savingClassName); + this.removeForm(); + this.leaveHover(); + this.element.style.backgroundColor = this.originalBackground; + Element.show(this.element); + if (this.options.externalControl) { + Element.show(this.options.externalControl); + } + this.editing = false; + this.saving = false; + this.oldInnerHTML = null; + this.onLeaveEditMode(); + }, + onComplete: function(transport) { + this.leaveEditMode(); + this.options.onComplete.bind(this)(transport, this.element); + }, + onEnterEditMode: function() {}, + onLeaveEditMode: function() {}, + dispose: function() { + if (this.oldInnerHTML) { + this.element.innerHTML = this.oldInnerHTML; + } + this.leaveEditMode(); + Event.stopObserving(this.element, 'click', this.onclickListener); + Event.stopObserving(this.element, 'mouseover', this.mouseoverListener); + Event.stopObserving(this.element, 'mouseout', this.mouseoutListener); + if (this.options.externalControl) { + Event.stopObserving(this.options.externalControl, 'click', this.onclickListener); + Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener); + Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener); + } + } +}; + +Ajax.InPlaceCollectionEditor = Class.create(); +Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype); +Object.extend(Ajax.InPlaceCollectionEditor.prototype, { + createEditField: function() { + if (!this.cached_selectTag) { + var selectTag = document.createElement("select"); + var collection = this.options.collection || []; + var optionTag; + collection.each(function(e,i) { + optionTag = document.createElement("option"); + optionTag.value = (e instanceof Array) ? e[0] : e; + if((typeof this.options.value == 'undefined') && + ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true; + if(this.options.value==optionTag.value) optionTag.selected = true; + optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); + selectTag.appendChild(optionTag); + }.bind(this)); + this.cached_selectTag = selectTag; + } + + this.editField = this.cached_selectTag; + if(this.options.loadTextURL) this.loadExternalText(); + this.form.appendChild(this.editField); + this.options.callback = function(form, value) { + return "value=" + encodeURIComponent(value); + } + } +}); + +// Delayed observer, like Form.Element.Observer, +// but waits for delay after last key input +// Ideal for live-search fields + +Form.Element.DelayedObserver = Class.create(); +Form.Element.DelayedObserver.prototype = { + initialize: function(element, delay, callback) { + this.delay = delay || 0.5; + this.element = $(element); + this.callback = callback; + this.timer = null; + this.lastValue = $F(this.element); + Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this)); + }, + delayedListener: function(event) { + if(this.lastValue == $F(this.element)) return; + if(this.timer) clearTimeout(this.timer); + this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000); + this.lastValue = $F(this.element); + }, + onTimerEvent: function() { + this.timer = null; + this.callback(this.element, $F(this.element)); + } +}; diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/dragdrop.js b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/dragdrop.js new file mode 100644 index 00000000..c71ddb82 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/dragdrop.js @@ -0,0 +1,942 @@ +// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// (c) 2005, 2006 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) +// +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ + +if(typeof Effect == 'undefined') + throw("dragdrop.js requires including script.aculo.us' effects.js library"); + +var Droppables = { + drops: [], + + remove: function(element) { + this.drops = this.drops.reject(function(d) { return d.element==$(element) }); + }, + + add: function(element) { + element = $(element); + var options = Object.extend({ + greedy: true, + hoverclass: null, + tree: false + }, arguments[1] || {}); + + // cache containers + if(options.containment) { + options._containers = []; + var containment = options.containment; + if((typeof containment == 'object') && + (containment.constructor == Array)) { + containment.each( function(c) { options._containers.push($(c)) }); + } else { + options._containers.push($(containment)); + } + } + + if(options.accept) options.accept = [options.accept].flatten(); + + Element.makePositioned(element); // fix IE + options.element = element; + + this.drops.push(options); + }, + + findDeepestChild: function(drops) { + deepest = drops[0]; + + for (i = 1; i < drops.length; ++i) + if (Element.isParent(drops[i].element, deepest.element)) + deepest = drops[i]; + + return deepest; + }, + + isContained: function(element, drop) { + var containmentNode; + if(drop.tree) { + containmentNode = element.treeNode; + } else { + containmentNode = element.parentNode; + } + return drop._containers.detect(function(c) { return containmentNode == c }); + }, + + isAffected: function(point, element, drop) { + return ( + (drop.element!=element) && + ((!drop._containers) || + this.isContained(element, drop)) && + ((!drop.accept) || + (Element.classNames(element).detect( + function(v) { return drop.accept.include(v) } ) )) && + Position.within(drop.element, point[0], point[1]) ); + }, + + deactivate: function(drop) { + if(drop.hoverclass) + Element.removeClassName(drop.element, drop.hoverclass); + this.last_active = null; + }, + + activate: function(drop) { + if(drop.hoverclass) + Element.addClassName(drop.element, drop.hoverclass); + this.last_active = drop; + }, + + show: function(point, element) { + if(!this.drops.length) return; + var affected = []; + + if(this.last_active) this.deactivate(this.last_active); + this.drops.each( function(drop) { + if(Droppables.isAffected(point, element, drop)) + affected.push(drop); + }); + + if(affected.length>0) { + drop = Droppables.findDeepestChild(affected); + Position.within(drop.element, point[0], point[1]); + if(drop.onHover) + drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element)); + + Droppables.activate(drop); + } + }, + + fire: function(event, element) { + if(!this.last_active) return; + Position.prepare(); + + if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active)) + if (this.last_active.onDrop) + this.last_active.onDrop(element, this.last_active.element, event); + }, + + reset: function() { + if(this.last_active) + this.deactivate(this.last_active); + } +} + +var Draggables = { + drags: [], + observers: [], + + register: function(draggable) { + if(this.drags.length == 0) { + this.eventMouseUp = this.endDrag.bindAsEventListener(this); + this.eventMouseMove = this.updateDrag.bindAsEventListener(this); + this.eventKeypress = this.keyPress.bindAsEventListener(this); + + Event.observe(document, "mouseup", this.eventMouseUp); + Event.observe(document, "mousemove", this.eventMouseMove); + Event.observe(document, "keypress", this.eventKeypress); + } + this.drags.push(draggable); + }, + + unregister: function(draggable) { + this.drags = this.drags.reject(function(d) { return d==draggable }); + if(this.drags.length == 0) { + Event.stopObserving(document, "mouseup", this.eventMouseUp); + Event.stopObserving(document, "mousemove", this.eventMouseMove); + Event.stopObserving(document, "keypress", this.eventKeypress); + } + }, + + activate: function(draggable) { + if(draggable.options.delay) { + this._timeout = setTimeout(function() { + Draggables._timeout = null; + window.focus(); + Draggables.activeDraggable = draggable; + }.bind(this), draggable.options.delay); + } else { + window.focus(); // allows keypress events if window isn't currently focused, fails for Safari + this.activeDraggable = draggable; + } + }, + + deactivate: function() { + this.activeDraggable = null; + }, + + updateDrag: function(event) { + if(!this.activeDraggable) return; + var pointer = [Event.pointerX(event), Event.pointerY(event)]; + // Mozilla-based browsers fire successive mousemove events with + // the same coordinates, prevent needless redrawing (moz bug?) + if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return; + this._lastPointer = pointer; + + this.activeDraggable.updateDrag(event, pointer); + }, + + endDrag: function(event) { + if(this._timeout) { + clearTimeout(this._timeout); + this._timeout = null; + } + if(!this.activeDraggable) return; + this._lastPointer = null; + this.activeDraggable.endDrag(event); + this.activeDraggable = null; + }, + + keyPress: function(event) { + if(this.activeDraggable) + this.activeDraggable.keyPress(event); + }, + + addObserver: function(observer) { + this.observers.push(observer); + this._cacheObserverCallbacks(); + }, + + removeObserver: function(element) { // element instead of observer fixes mem leaks + this.observers = this.observers.reject( function(o) { return o.element==element }); + this._cacheObserverCallbacks(); + }, + + notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag' + if(this[eventName+'Count'] > 0) + this.observers.each( function(o) { + if(o[eventName]) o[eventName](eventName, draggable, event); + }); + if(draggable.options[eventName]) draggable.options[eventName](draggable, event); + }, + + _cacheObserverCallbacks: function() { + ['onStart','onEnd','onDrag'].each( function(eventName) { + Draggables[eventName+'Count'] = Draggables.observers.select( + function(o) { return o[eventName]; } + ).length; + }); + } +} + +/*--------------------------------------------------------------------------*/ + +var Draggable = Class.create(); +Draggable._dragging = {}; + +Draggable.prototype = { + initialize: function(element) { + var defaults = { + handle: false, + reverteffect: function(element, top_offset, left_offset) { + var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; + new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur, + queue: {scope:'_draggable', position:'end'} + }); + }, + endeffect: function(element) { + var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0; + new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity, + queue: {scope:'_draggable', position:'end'}, + afterFinish: function(){ + Draggable._dragging[element] = false + } + }); + }, + zindex: 1000, + revert: false, + scroll: false, + scrollSensitivity: 20, + scrollSpeed: 15, + snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] } + delay: 0 + }; + + if(!arguments[1] || typeof arguments[1].endeffect == 'undefined') + Object.extend(defaults, { + starteffect: function(element) { + element._opacity = Element.getOpacity(element); + Draggable._dragging[element] = true; + new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7}); + } + }); + + var options = Object.extend(defaults, arguments[1] || {}); + + this.element = $(element); + + if(options.handle && (typeof options.handle == 'string')) + this.handle = this.element.down('.'+options.handle, 0); + + if(!this.handle) this.handle = $(options.handle); + if(!this.handle) this.handle = this.element; + + if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { + options.scroll = $(options.scroll); + this._isScrollChild = Element.childOf(this.element, options.scroll); + } + + Element.makePositioned(this.element); // fix IE + + this.delta = this.currentDelta(); + this.options = options; + this.dragging = false; + + this.eventMouseDown = this.initDrag.bindAsEventListener(this); + Event.observe(this.handle, "mousedown", this.eventMouseDown); + + Draggables.register(this); + }, + + destroy: function() { + Event.stopObserving(this.handle, "mousedown", this.eventMouseDown); + Draggables.unregister(this); + }, + + currentDelta: function() { + return([ + parseInt(Element.getStyle(this.element,'left') || '0'), + parseInt(Element.getStyle(this.element,'top') || '0')]); + }, + + initDrag: function(event) { + if(typeof Draggable._dragging[this.element] != 'undefined' && + Draggable._dragging[this.element]) return; + if(Event.isLeftClick(event)) { + // abort on form elements, fixes a Firefox issue + var src = Event.element(event); + if(src.tagName && ( + src.tagName=='INPUT' || + src.tagName=='SELECT' || + src.tagName=='OPTION' || + src.tagName=='BUTTON' || + src.tagName=='TEXTAREA')) return; + + var pointer = [Event.pointerX(event), Event.pointerY(event)]; + var pos = Position.cumulativeOffset(this.element); + this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) }); + + Draggables.activate(this); + Event.stop(event); + } + }, + + startDrag: function(event) { + this.dragging = true; + + if(this.options.zindex) { + this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0); + this.element.style.zIndex = this.options.zindex; + } + + if(this.options.ghosting) { + this._clone = this.element.cloneNode(true); + Position.absolutize(this.element); + this.element.parentNode.insertBefore(this._clone, this.element); + } + + if(this.options.scroll) { + if (this.options.scroll == window) { + var where = this._getWindowScroll(this.options.scroll); + this.originalScrollLeft = where.left; + this.originalScrollTop = where.top; + } else { + this.originalScrollLeft = this.options.scroll.scrollLeft; + this.originalScrollTop = this.options.scroll.scrollTop; + } + } + + Draggables.notify('onStart', this, event); + + if(this.options.starteffect) this.options.starteffect(this.element); + }, + + updateDrag: function(event, pointer) { + if(!this.dragging) this.startDrag(event); + Position.prepare(); + Droppables.show(pointer, this.element); + Draggables.notify('onDrag', this, event); + + this.draw(pointer); + if(this.options.change) this.options.change(this); + + if(this.options.scroll) { + this.stopScrolling(); + + var p; + if (this.options.scroll == window) { + with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; } + } else { + p = Position.page(this.options.scroll); + p[0] += this.options.scroll.scrollLeft + Position.deltaX; + p[1] += this.options.scroll.scrollTop + Position.deltaY; + p.push(p[0]+this.options.scroll.offsetWidth); + p.push(p[1]+this.options.scroll.offsetHeight); + } + var speed = [0,0]; + if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity); + if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity); + if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity); + if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity); + this.startScrolling(speed); + } + + // fix AppleWebKit rendering + if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); + + Event.stop(event); + }, + + finishDrag: function(event, success) { + this.dragging = false; + + if(this.options.ghosting) { + Position.relativize(this.element); + Element.remove(this._clone); + this._clone = null; + } + + if(success) Droppables.fire(event, this.element); + Draggables.notify('onEnd', this, event); + + var revert = this.options.revert; + if(revert && typeof revert == 'function') revert = revert(this.element); + + var d = this.currentDelta(); + if(revert && this.options.reverteffect) { + this.options.reverteffect(this.element, + d[1]-this.delta[1], d[0]-this.delta[0]); + } else { + this.delta = d; + } + + if(this.options.zindex) + this.element.style.zIndex = this.originalZ; + + if(this.options.endeffect) + this.options.endeffect(this.element); + + Draggables.deactivate(this); + Droppables.reset(); + }, + + keyPress: function(event) { + if(event.keyCode!=Event.KEY_ESC) return; + this.finishDrag(event, false); + Event.stop(event); + }, + + endDrag: function(event) { + if(!this.dragging) return; + this.stopScrolling(); + this.finishDrag(event, true); + Event.stop(event); + }, + + draw: function(point) { + var pos = Position.cumulativeOffset(this.element); + if(this.options.ghosting) { + var r = Position.realOffset(this.element); + pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; + } + + var d = this.currentDelta(); + pos[0] -= d[0]; pos[1] -= d[1]; + + if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) { + pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; + pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; + } + + var p = [0,1].map(function(i){ + return (point[i]-pos[i]-this.offset[i]) + }.bind(this)); + + if(this.options.snap) { + if(typeof this.options.snap == 'function') { + p = this.options.snap(p[0],p[1],this); + } else { + if(this.options.snap instanceof Array) { + p = p.map( function(v, i) { + return Math.round(v/this.options.snap[i])*this.options.snap[i] }.bind(this)) + } else { + p = p.map( function(v) { + return Math.round(v/this.options.snap)*this.options.snap }.bind(this)) + } + }} + + var style = this.element.style; + if((!this.options.constraint) || (this.options.constraint=='horizontal')) + style.left = p[0] + "px"; + if((!this.options.constraint) || (this.options.constraint=='vertical')) + style.top = p[1] + "px"; + + if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering + }, + + stopScrolling: function() { + if(this.scrollInterval) { + clearInterval(this.scrollInterval); + this.scrollInterval = null; + Draggables._lastScrollPointer = null; + } + }, + + startScrolling: function(speed) { + if(!(speed[0] || speed[1])) return; + this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; + this.lastScrolled = new Date(); + this.scrollInterval = setInterval(this.scroll.bind(this), 10); + }, + + scroll: function() { + var current = new Date(); + var delta = current - this.lastScrolled; + this.lastScrolled = current; + if(this.options.scroll == window) { + with (this._getWindowScroll(this.options.scroll)) { + if (this.scrollSpeed[0] || this.scrollSpeed[1]) { + var d = delta / 1000; + this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] ); + } + } + } else { + this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000; + this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000; + } + + Position.prepare(); + Droppables.show(Draggables._lastPointer, this.element); + Draggables.notify('onDrag', this); + if (this._isScrollChild) { + Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); + Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; + Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; + if (Draggables._lastScrollPointer[0] < 0) + Draggables._lastScrollPointer[0] = 0; + if (Draggables._lastScrollPointer[1] < 0) + Draggables._lastScrollPointer[1] = 0; + this.draw(Draggables._lastScrollPointer); + } + + if(this.options.change) this.options.change(this); + }, + + _getWindowScroll: function(w) { + var T, L, W, H; + with (w.document) { + if (w.document.documentElement && documentElement.scrollTop) { + T = documentElement.scrollTop; + L = documentElement.scrollLeft; + } else if (w.document.body) { + T = body.scrollTop; + L = body.scrollLeft; + } + if (w.innerWidth) { + W = w.innerWidth; + H = w.innerHeight; + } else if (w.document.documentElement && documentElement.clientWidth) { + W = documentElement.clientWidth; + H = documentElement.clientHeight; + } else { + W = body.offsetWidth; + H = body.offsetHeight + } + } + return { top: T, left: L, width: W, height: H }; + } +} + +/*--------------------------------------------------------------------------*/ + +var SortableObserver = Class.create(); +SortableObserver.prototype = { + initialize: function(element, observer) { + this.element = $(element); + this.observer = observer; + this.lastValue = Sortable.serialize(this.element); + }, + + onStart: function() { + this.lastValue = Sortable.serialize(this.element); + }, + + onEnd: function() { + Sortable.unmark(); + if(this.lastValue != Sortable.serialize(this.element)) + this.observer(this.element) + } +} + +var Sortable = { + SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, + + sortables: {}, + + _findRootElement: function(element) { + while (element.tagName != "BODY") { + if(element.id && Sortable.sortables[element.id]) return element; + element = element.parentNode; + } + }, + + options: function(element) { + element = Sortable._findRootElement($(element)); + if(!element) return; + return Sortable.sortables[element.id]; + }, + + destroy: function(element){ + var s = Sortable.options(element); + + if(s) { + Draggables.removeObserver(s.element); + s.droppables.each(function(d){ Droppables.remove(d) }); + s.draggables.invoke('destroy'); + + delete Sortable.sortables[s.element.id]; + } + }, + + create: function(element) { + element = $(element); + var options = Object.extend({ + element: element, + tag: 'li', // assumes li children, override with tag: 'tagname' + dropOnEmpty: false, + tree: false, + treeTag: 'ul', + overlap: 'vertical', // one of 'vertical', 'horizontal' + constraint: 'vertical', // one of 'vertical', 'horizontal', false + containment: element, // also takes array of elements (or id's); or false + handle: false, // or a CSS class + only: false, + delay: 0, + hoverclass: null, + ghosting: false, + scroll: false, + scrollSensitivity: 20, + scrollSpeed: 15, + format: this.SERIALIZE_RULE, + onChange: Prototype.emptyFunction, + onUpdate: Prototype.emptyFunction + }, arguments[1] || {}); + + // clear any old sortable with same element + this.destroy(element); + + // build options for the draggables + var options_for_draggable = { + revert: true, + scroll: options.scroll, + scrollSpeed: options.scrollSpeed, + scrollSensitivity: options.scrollSensitivity, + delay: options.delay, + ghosting: options.ghosting, + constraint: options.constraint, + handle: options.handle }; + + if(options.starteffect) + options_for_draggable.starteffect = options.starteffect; + + if(options.reverteffect) + options_for_draggable.reverteffect = options.reverteffect; + else + if(options.ghosting) options_for_draggable.reverteffect = function(element) { + element.style.top = 0; + element.style.left = 0; + }; + + if(options.endeffect) + options_for_draggable.endeffect = options.endeffect; + + if(options.zindex) + options_for_draggable.zindex = options.zindex; + + // build options for the droppables + var options_for_droppable = { + overlap: options.overlap, + containment: options.containment, + tree: options.tree, + hoverclass: options.hoverclass, + onHover: Sortable.onHover + } + + var options_for_tree = { + onHover: Sortable.onEmptyHover, + overlap: options.overlap, + containment: options.containment, + hoverclass: options.hoverclass + } + + // fix for gecko engine + Element.cleanWhitespace(element); + + options.draggables = []; + options.droppables = []; + + // drop on empty handling + if(options.dropOnEmpty || options.tree) { + Droppables.add(element, options_for_tree); + options.droppables.push(element); + } + + (this.findElements(element, options) || []).each( function(e) { + // handles are per-draggable + var handle = options.handle ? + $(e).down('.'+options.handle,0) : e; + options.draggables.push( + new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); + Droppables.add(e, options_for_droppable); + if(options.tree) e.treeNode = element; + options.droppables.push(e); + }); + + if(options.tree) { + (Sortable.findTreeElements(element, options) || []).each( function(e) { + Droppables.add(e, options_for_tree); + e.treeNode = element; + options.droppables.push(e); + }); + } + + // keep reference + this.sortables[element.id] = options; + + // for onupdate + Draggables.addObserver(new SortableObserver(element, options.onUpdate)); + + }, + + // return all suitable-for-sortable elements in a guaranteed order + findElements: function(element, options) { + return Element.findChildren( + element, options.only, options.tree ? true : false, options.tag); + }, + + findTreeElements: function(element, options) { + return Element.findChildren( + element, options.only, options.tree ? true : false, options.treeTag); + }, + + onHover: function(element, dropon, overlap) { + if(Element.isParent(dropon, element)) return; + + if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) { + return; + } else if(overlap>0.5) { + Sortable.mark(dropon, 'before'); + if(dropon.previousSibling != element) { + var oldParentNode = element.parentNode; + element.style.visibility = "hidden"; // fix gecko rendering + dropon.parentNode.insertBefore(element, dropon); + if(dropon.parentNode!=oldParentNode) + Sortable.options(oldParentNode).onChange(element); + Sortable.options(dropon.parentNode).onChange(element); + } + } else { + Sortable.mark(dropon, 'after'); + var nextElement = dropon.nextSibling || null; + if(nextElement != element) { + var oldParentNode = element.parentNode; + element.style.visibility = "hidden"; // fix gecko rendering + dropon.parentNode.insertBefore(element, nextElement); + if(dropon.parentNode!=oldParentNode) + Sortable.options(oldParentNode).onChange(element); + Sortable.options(dropon.parentNode).onChange(element); + } + } + }, + + onEmptyHover: function(element, dropon, overlap) { + var oldParentNode = element.parentNode; + var droponOptions = Sortable.options(dropon); + + if(!Element.isParent(dropon, element)) { + var index; + + var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only}); + var child = null; + + if(children) { + var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap); + + for (index = 0; index < children.length; index += 1) { + if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) { + offset -= Element.offsetSize (children[index], droponOptions.overlap); + } else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) { + child = index + 1 < children.length ? children[index + 1] : null; + break; + } else { + child = children[index]; + break; + } + } + } + + dropon.insertBefore(element, child); + + Sortable.options(oldParentNode).onChange(element); + droponOptions.onChange(element); + } + }, + + unmark: function() { + if(Sortable._marker) Sortable._marker.hide(); + }, + + mark: function(dropon, position) { + // mark on ghosting only + var sortable = Sortable.options(dropon.parentNode); + if(sortable && !sortable.ghosting) return; + + if(!Sortable._marker) { + Sortable._marker = + ($('dropmarker') || Element.extend(document.createElement('DIV'))). + hide().addClassName('dropmarker').setStyle({position:'absolute'}); + document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); + } + var offsets = Position.cumulativeOffset(dropon); + Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); + + if(position=='after') + if(sortable.overlap == 'horizontal') + Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'}); + else + Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'}); + + Sortable._marker.show(); + }, + + _tree: function(element, options, parent) { + var children = Sortable.findElements(element, options) || []; + + for (var i = 0; i < children.length; ++i) { + var match = children[i].id.match(options.format); + + if (!match) continue; + + var child = { + id: encodeURIComponent(match ? match[1] : null), + element: element, + parent: parent, + children: [], + position: parent.children.length, + container: $(children[i]).down(options.treeTag) + } + + /* Get the element containing the children and recurse over it */ + if (child.container) + this._tree(child.container, options, child) + + parent.children.push (child); + } + + return parent; + }, + + tree: function(element) { + element = $(element); + var sortableOptions = this.options(element); + var options = Object.extend({ + tag: sortableOptions.tag, + treeTag: sortableOptions.treeTag, + only: sortableOptions.only, + name: element.id, + format: sortableOptions.format + }, arguments[1] || {}); + + var root = { + id: null, + parent: null, + children: [], + container: element, + position: 0 + } + + return Sortable._tree(element, options, root); + }, + + /* Construct a [i] index for a particular node */ + _constructIndex: function(node) { + var index = ''; + do { + if (node.id) index = '[' + node.position + ']' + index; + } while ((node = node.parent) != null); + return index; + }, + + sequence: function(element) { + element = $(element); + var options = Object.extend(this.options(element), arguments[1] || {}); + + return $(this.findElements(element, options) || []).map( function(item) { + return item.id.match(options.format) ? item.id.match(options.format)[1] : ''; + }); + }, + + setSequence: function(element, new_sequence) { + element = $(element); + var options = Object.extend(this.options(element), arguments[2] || {}); + + var nodeMap = {}; + this.findElements(element, options).each( function(n) { + if (n.id.match(options.format)) + nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode]; + n.parentNode.removeChild(n); + }); + + new_sequence.each(function(ident) { + var n = nodeMap[ident]; + if (n) { + n[1].appendChild(n[0]); + delete nodeMap[ident]; + } + }); + }, + + serialize: function(element) { + element = $(element); + var options = Object.extend(Sortable.options(element), arguments[1] || {}); + var name = encodeURIComponent( + (arguments[1] && arguments[1].name) ? arguments[1].name : element.id); + + if (options.tree) { + return Sortable.tree(element, arguments[1]).children.map( function (item) { + return [name + Sortable._constructIndex(item) + "[id]=" + + encodeURIComponent(item.id)].concat(item.children.map(arguments.callee)); + }).flatten().join('&'); + } else { + return Sortable.sequence(element, arguments[1]).map( function(item) { + return name + "[]=" + encodeURIComponent(item); + }).join('&'); + } + } +} + +// Returns true if child is contained within element +Element.isParent = function(child, element) { + if (!child.parentNode || child == element) return false; + if (child.parentNode == element) return true; + return Element.isParent(child.parentNode, element); +} + +Element.findChildren = function(element, only, recursive, tagName) { + if(!element.hasChildNodes()) return null; + tagName = tagName.toUpperCase(); + if(only) only = [only].flatten(); + var elements = []; + $A(element.childNodes).each( function(e) { + if(e.tagName && e.tagName.toUpperCase()==tagName && + (!only || (Element.classNames(e).detect(function(v) { return only.include(v) })))) + elements.push(e); + if(recursive) { + var grandchildren = Element.findChildren(e, only, recursive, tagName); + if(grandchildren) elements.push(grandchildren); + } + }); + + return (elements.length>0 ? elements.flatten() : []); +} + +Element.offsetSize = function (element, type) { + return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; +} diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/effects.js b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/effects.js new file mode 100644 index 00000000..3b02eda2 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/effects.js @@ -0,0 +1,1088 @@ +// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// Contributors: +// Justin Palmer (http://encytemedia.com/) +// Mark Pilgrim (http://diveintomark.org/) +// Martin Bialasinki +// +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ + +// converts rgb() and #xxx to #xxxxxx format, +// returns self (or first argument) if not convertable +String.prototype.parseColor = function() { + var color = '#'; + if(this.slice(0,4) == 'rgb(') { + var cols = this.slice(4,this.length-1).split(','); + var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3); + } else { + if(this.slice(0,1) == '#') { + if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase(); + if(this.length==7) color = this.toLowerCase(); + } + } + return(color.length==7 ? color : (arguments[0] || this)); +} + +/*--------------------------------------------------------------------------*/ + +Element.collectTextNodes = function(element) { + return $A($(element).childNodes).collect( function(node) { + return (node.nodeType==3 ? node.nodeValue : + (node.hasChildNodes() ? Element.collectTextNodes(node) : '')); + }).flatten().join(''); +} + +Element.collectTextNodesIgnoreClass = function(element, className) { + return $A($(element).childNodes).collect( function(node) { + return (node.nodeType==3 ? node.nodeValue : + ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? + Element.collectTextNodesIgnoreClass(node, className) : '')); + }).flatten().join(''); +} + +Element.setContentZoom = function(element, percent) { + element = $(element); + element.setStyle({fontSize: (percent/100) + 'em'}); + if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); + return element; +} + +Element.getOpacity = function(element){ + element = $(element); + var opacity; + if (opacity = element.getStyle('opacity')) + return parseFloat(opacity); + if (opacity = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) + if(opacity[1]) return parseFloat(opacity[1]) / 100; + return 1.0; +} + +Element.setOpacity = function(element, value){ + element= $(element); + if (value == 1){ + element.setStyle({ opacity: + (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? + 0.999999 : 1.0 }); + if(/MSIE/.test(navigator.userAgent) && !window.opera) + element.setStyle({filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')}); + } else { + if(value < 0.00001) value = 0; + element.setStyle({opacity: value}); + if(/MSIE/.test(navigator.userAgent) && !window.opera) + element.setStyle( + { filter: element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + + 'alpha(opacity='+value*100+')' }); + } + return element; +} + +Element.getInlineOpacity = function(element){ + return $(element).style.opacity || ''; +} + +Element.forceRerendering = function(element) { + try { + element = $(element); + var n = document.createTextNode(' '); + element.appendChild(n); + element.removeChild(n); + } catch(e) { } +}; + +/*--------------------------------------------------------------------------*/ + +Array.prototype.call = function() { + var args = arguments; + this.each(function(f){ f.apply(this, args) }); +} + +/*--------------------------------------------------------------------------*/ + +var Effect = { + _elementDoesNotExistError: { + name: 'ElementDoesNotExistError', + message: 'The specified DOM element does not exist, but is required for this effect to operate' + }, + tagifyText: function(element) { + if(typeof Builder == 'undefined') + throw("Effect.tagifyText requires including script.aculo.us' builder.js library"); + + var tagifyStyle = 'position:relative'; + if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1'; + + element = $(element); + $A(element.childNodes).each( function(child) { + if(child.nodeType==3) { + child.nodeValue.toArray().each( function(character) { + element.insertBefore( + Builder.node('span',{style: tagifyStyle}, + character == ' ' ? String.fromCharCode(160) : character), + child); + }); + Element.remove(child); + } + }); + }, + multiple: function(element, effect) { + var elements; + if(((typeof element == 'object') || + (typeof element == 'function')) && + (element.length)) + elements = element; + else + elements = $(element).childNodes; + + var options = Object.extend({ + speed: 0.1, + delay: 0.0 + }, arguments[2] || {}); + var masterDelay = options.delay; + + $A(elements).each( function(element, index) { + new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay })); + }); + }, + PAIRS: { + 'slide': ['SlideDown','SlideUp'], + 'blind': ['BlindDown','BlindUp'], + 'appear': ['Appear','Fade'] + }, + toggle: function(element, effect) { + element = $(element); + effect = (effect || 'appear').toLowerCase(); + var options = Object.extend({ + queue: { position:'end', scope:(element.id || 'global'), limit: 1 } + }, arguments[2] || {}); + Effect[element.visible() ? + Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options); + } +}; + +var Effect2 = Effect; // deprecated + +/* ------------- transitions ------------- */ + +Effect.Transitions = { + linear: Prototype.K, + sinoidal: function(pos) { + return (-Math.cos(pos*Math.PI)/2) + 0.5; + }, + reverse: function(pos) { + return 1-pos; + }, + flicker: function(pos) { + return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; + }, + wobble: function(pos) { + return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; + }, + pulse: function(pos, pulses) { + pulses = pulses || 5; + return ( + Math.round((pos % (1/pulses)) * pulses) == 0 ? + ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : + 1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) + ); + }, + none: function(pos) { + return 0; + }, + full: function(pos) { + return 1; + } +}; + +/* ------------- core effects ------------- */ + +Effect.ScopedQueue = Class.create(); +Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), { + initialize: function() { + this.effects = []; + this.interval = null; + }, + _each: function(iterator) { + this.effects._each(iterator); + }, + add: function(effect) { + var timestamp = new Date().getTime(); + + var position = (typeof effect.options.queue == 'string') ? + effect.options.queue : effect.options.queue.position; + + switch(position) { + case 'front': + // move unstarted effects after this effect + this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) { + e.startOn += effect.finishOn; + e.finishOn += effect.finishOn; + }); + break; + case 'with-last': + timestamp = this.effects.pluck('startOn').max() || timestamp; + break; + case 'end': + // start effect after last queued effect has finished + timestamp = this.effects.pluck('finishOn').max() || timestamp; + break; + } + + effect.startOn += timestamp; + effect.finishOn += timestamp; + + if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) + this.effects.push(effect); + + if(!this.interval) + this.interval = setInterval(this.loop.bind(this), 40); + }, + remove: function(effect) { + this.effects = this.effects.reject(function(e) { return e==effect }); + if(this.effects.length == 0) { + clearInterval(this.interval); + this.interval = null; + } + }, + loop: function() { + var timePos = new Date().getTime(); + this.effects.invoke('loop', timePos); + } +}); + +Effect.Queues = { + instances: $H(), + get: function(queueName) { + if(typeof queueName != 'string') return queueName; + + if(!this.instances[queueName]) + this.instances[queueName] = new Effect.ScopedQueue(); + + return this.instances[queueName]; + } +} +Effect.Queue = Effect.Queues.get('global'); + +Effect.DefaultOptions = { + transition: Effect.Transitions.sinoidal, + duration: 1.0, // seconds + fps: 25.0, // max. 25fps due to Effect.Queue implementation + sync: false, // true for combining + from: 0.0, + to: 1.0, + delay: 0.0, + queue: 'parallel' +} + +Effect.Base = function() {}; +Effect.Base.prototype = { + position: null, + start: function(options) { + this.options = Object.extend(Object.extend({},Effect.DefaultOptions), options || {}); + this.currentFrame = 0; + this.state = 'idle'; + this.startOn = this.options.delay*1000; + this.finishOn = this.startOn + (this.options.duration*1000); + this.event('beforeStart'); + if(!this.options.sync) + Effect.Queues.get(typeof this.options.queue == 'string' ? + 'global' : this.options.queue.scope).add(this); + }, + loop: function(timePos) { + if(timePos >= this.startOn) { + if(timePos >= this.finishOn) { + this.render(1.0); + this.cancel(); + this.event('beforeFinish'); + if(this.finish) this.finish(); + this.event('afterFinish'); + return; + } + var pos = (timePos - this.startOn) / (this.finishOn - this.startOn); + var frame = Math.round(pos * this.options.fps * this.options.duration); + if(frame > this.currentFrame) { + this.render(pos); + this.currentFrame = frame; + } + } + }, + render: function(pos) { + if(this.state == 'idle') { + this.state = 'running'; + this.event('beforeSetup'); + if(this.setup) this.setup(); + this.event('afterSetup'); + } + if(this.state == 'running') { + if(this.options.transition) pos = this.options.transition(pos); + pos *= (this.options.to-this.options.from); + pos += this.options.from; + this.position = pos; + this.event('beforeUpdate'); + if(this.update) this.update(pos); + this.event('afterUpdate'); + } + }, + cancel: function() { + if(!this.options.sync) + Effect.Queues.get(typeof this.options.queue == 'string' ? + 'global' : this.options.queue.scope).remove(this); + this.state = 'finished'; + }, + event: function(eventName) { + if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this); + if(this.options[eventName]) this.options[eventName](this); + }, + inspect: function() { + return '#'; + } +} + +Effect.Parallel = Class.create(); +Object.extend(Object.extend(Effect.Parallel.prototype, Effect.Base.prototype), { + initialize: function(effects) { + this.effects = effects || []; + this.start(arguments[1]); + }, + update: function(position) { + this.effects.invoke('render', position); + }, + finish: function(position) { + this.effects.each( function(effect) { + effect.render(1.0); + effect.cancel(); + effect.event('beforeFinish'); + if(effect.finish) effect.finish(position); + effect.event('afterFinish'); + }); + } +}); + +Effect.Event = Class.create(); +Object.extend(Object.extend(Effect.Event.prototype, Effect.Base.prototype), { + initialize: function() { + var options = Object.extend({ + duration: 0 + }, arguments[0] || {}); + this.start(options); + }, + update: Prototype.emptyFunction +}); + +Effect.Opacity = Class.create(); +Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), { + initialize: function(element) { + this.element = $(element); + if(!this.element) throw(Effect._elementDoesNotExistError); + // make this work on IE on elements without 'layout' + if(/MSIE/.test(navigator.userAgent) && !window.opera && (!this.element.currentStyle.hasLayout)) + this.element.setStyle({zoom: 1}); + var options = Object.extend({ + from: this.element.getOpacity() || 0.0, + to: 1.0 + }, arguments[1] || {}); + this.start(options); + }, + update: function(position) { + this.element.setOpacity(position); + } +}); + +Effect.Move = Class.create(); +Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), { + initialize: function(element) { + this.element = $(element); + if(!this.element) throw(Effect._elementDoesNotExistError); + var options = Object.extend({ + x: 0, + y: 0, + mode: 'relative' + }, arguments[1] || {}); + this.start(options); + }, + setup: function() { + // Bug in Opera: Opera returns the "real" position of a static element or + // relative element that does not have top/left explicitly set. + // ==> Always set top and left for position relative elements in your stylesheets + // (to 0 if you do not need them) + this.element.makePositioned(); + this.originalLeft = parseFloat(this.element.getStyle('left') || '0'); + this.originalTop = parseFloat(this.element.getStyle('top') || '0'); + if(this.options.mode == 'absolute') { + // absolute movement, so we need to calc deltaX and deltaY + this.options.x = this.options.x - this.originalLeft; + this.options.y = this.options.y - this.originalTop; + } + }, + update: function(position) { + this.element.setStyle({ + left: Math.round(this.options.x * position + this.originalLeft) + 'px', + top: Math.round(this.options.y * position + this.originalTop) + 'px' + }); + } +}); + +// for backwards compatibility +Effect.MoveBy = function(element, toTop, toLeft) { + return new Effect.Move(element, + Object.extend({ x: toLeft, y: toTop }, arguments[3] || {})); +}; + +Effect.Scale = Class.create(); +Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { + initialize: function(element, percent) { + this.element = $(element); + if(!this.element) throw(Effect._elementDoesNotExistError); + var options = Object.extend({ + scaleX: true, + scaleY: true, + scaleContent: true, + scaleFromCenter: false, + scaleMode: 'box', // 'box' or 'contents' or {} with provided values + scaleFrom: 100.0, + scaleTo: percent + }, arguments[2] || {}); + this.start(options); + }, + setup: function() { + this.restoreAfterFinish = this.options.restoreAfterFinish || false; + this.elementPositioning = this.element.getStyle('position'); + + this.originalStyle = {}; + ['top','left','width','height','fontSize'].each( function(k) { + this.originalStyle[k] = this.element.style[k]; + }.bind(this)); + + this.originalTop = this.element.offsetTop; + this.originalLeft = this.element.offsetLeft; + + var fontSize = this.element.getStyle('font-size') || '100%'; + ['em','px','%','pt'].each( function(fontSizeType) { + if(fontSize.indexOf(fontSizeType)>0) { + this.fontSize = parseFloat(fontSize); + this.fontSizeType = fontSizeType; + } + }.bind(this)); + + this.factor = (this.options.scaleTo - this.options.scaleFrom)/100; + + this.dims = null; + if(this.options.scaleMode=='box') + this.dims = [this.element.offsetHeight, this.element.offsetWidth]; + if(/^content/.test(this.options.scaleMode)) + this.dims = [this.element.scrollHeight, this.element.scrollWidth]; + if(!this.dims) + this.dims = [this.options.scaleMode.originalHeight, + this.options.scaleMode.originalWidth]; + }, + update: function(position) { + var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); + if(this.options.scaleContent && this.fontSize) + this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType }); + this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale); + }, + finish: function(position) { + if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle); + }, + setDimensions: function(height, width) { + var d = {}; + if(this.options.scaleX) d.width = Math.round(width) + 'px'; + if(this.options.scaleY) d.height = Math.round(height) + 'px'; + if(this.options.scaleFromCenter) { + var topd = (height - this.dims[0])/2; + var leftd = (width - this.dims[1])/2; + if(this.elementPositioning == 'absolute') { + if(this.options.scaleY) d.top = this.originalTop-topd + 'px'; + if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px'; + } else { + if(this.options.scaleY) d.top = -topd + 'px'; + if(this.options.scaleX) d.left = -leftd + 'px'; + } + } + this.element.setStyle(d); + } +}); + +Effect.Highlight = Class.create(); +Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), { + initialize: function(element) { + this.element = $(element); + if(!this.element) throw(Effect._elementDoesNotExistError); + var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); + this.start(options); + }, + setup: function() { + // Prevent executing on elements not in the layout flow + if(this.element.getStyle('display')=='none') { this.cancel(); return; } + // Disable background image during the effect + this.oldStyle = { + backgroundImage: this.element.getStyle('background-image') }; + this.element.setStyle({backgroundImage: 'none'}); + if(!this.options.endcolor) + this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff'); + if(!this.options.restorecolor) + this.options.restorecolor = this.element.getStyle('background-color'); + // init color calculations + this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this)); + this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this)); + }, + update: function(position) { + this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){ + return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) }); + }, + finish: function() { + this.element.setStyle(Object.extend(this.oldStyle, { + backgroundColor: this.options.restorecolor + })); + } +}); + +Effect.ScrollTo = Class.create(); +Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), { + initialize: function(element) { + this.element = $(element); + this.start(arguments[1] || {}); + }, + setup: function() { + Position.prepare(); + var offsets = Position.cumulativeOffset(this.element); + if(this.options.offset) offsets[1] += this.options.offset; + var max = window.innerHeight ? + window.height - window.innerHeight : + document.body.scrollHeight - + (document.documentElement.clientHeight ? + document.documentElement.clientHeight : document.body.clientHeight); + this.scrollStart = Position.deltaY; + this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart; + }, + update: function(position) { + Position.prepare(); + window.scrollTo(Position.deltaX, + this.scrollStart + (position*this.delta)); + } +}); + +/* ------------- combination effects ------------- */ + +Effect.Fade = function(element) { + element = $(element); + var oldOpacity = element.getInlineOpacity(); + var options = Object.extend({ + from: element.getOpacity() || 1.0, + to: 0.0, + afterFinishInternal: function(effect) { + if(effect.options.to!=0) return; + effect.element.hide().setStyle({opacity: oldOpacity}); + }}, arguments[1] || {}); + return new Effect.Opacity(element,options); +} + +Effect.Appear = function(element) { + element = $(element); + var options = Object.extend({ + from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0), + to: 1.0, + // force Safari to render floated elements properly + afterFinishInternal: function(effect) { + effect.element.forceRerendering(); + }, + beforeSetup: function(effect) { + effect.element.setOpacity(effect.options.from).show(); + }}, arguments[1] || {}); + return new Effect.Opacity(element,options); +} + +Effect.Puff = function(element) { + element = $(element); + var oldStyle = { + opacity: element.getInlineOpacity(), + position: element.getStyle('position'), + top: element.style.top, + left: element.style.left, + width: element.style.width, + height: element.style.height + }; + return new Effect.Parallel( + [ new Effect.Scale(element, 200, + { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }), + new Effect.Opacity(element, { sync: true, to: 0.0 } ) ], + Object.extend({ duration: 1.0, + beforeSetupInternal: function(effect) { + Position.absolutize(effect.effects[0].element) + }, + afterFinishInternal: function(effect) { + effect.effects[0].element.hide().setStyle(oldStyle); } + }, arguments[1] || {}) + ); +} + +Effect.BlindUp = function(element) { + element = $(element); + element.makeClipping(); + return new Effect.Scale(element, 0, + Object.extend({ scaleContent: false, + scaleX: false, + restoreAfterFinish: true, + afterFinishInternal: function(effect) { + effect.element.hide().undoClipping(); + } + }, arguments[1] || {}) + ); +} + +Effect.BlindDown = function(element) { + element = $(element); + var elementDimensions = element.getDimensions(); + return new Effect.Scale(element, 100, Object.extend({ + scaleContent: false, + scaleX: false, + scaleFrom: 0, + scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, + restoreAfterFinish: true, + afterSetup: function(effect) { + effect.element.makeClipping().setStyle({height: '0px'}).show(); + }, + afterFinishInternal: function(effect) { + effect.element.undoClipping(); + } + }, arguments[1] || {})); +} + +Effect.SwitchOff = function(element) { + element = $(element); + var oldOpacity = element.getInlineOpacity(); + return new Effect.Appear(element, Object.extend({ + duration: 0.4, + from: 0, + transition: Effect.Transitions.flicker, + afterFinishInternal: function(effect) { + new Effect.Scale(effect.element, 1, { + duration: 0.3, scaleFromCenter: true, + scaleX: false, scaleContent: false, restoreAfterFinish: true, + beforeSetup: function(effect) { + effect.element.makePositioned().makeClipping(); + }, + afterFinishInternal: function(effect) { + effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity}); + } + }) + } + }, arguments[1] || {})); +} + +Effect.DropOut = function(element) { + element = $(element); + var oldStyle = { + top: element.getStyle('top'), + left: element.getStyle('left'), + opacity: element.getInlineOpacity() }; + return new Effect.Parallel( + [ new Effect.Move(element, {x: 0, y: 100, sync: true }), + new Effect.Opacity(element, { sync: true, to: 0.0 }) ], + Object.extend( + { duration: 0.5, + beforeSetup: function(effect) { + effect.effects[0].element.makePositioned(); + }, + afterFinishInternal: function(effect) { + effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle); + } + }, arguments[1] || {})); +} + +Effect.Shake = function(element) { + element = $(element); + var oldStyle = { + top: element.getStyle('top'), + left: element.getStyle('left') }; + return new Effect.Move(element, + { x: 20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { + new Effect.Move(effect.element, + { x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { + new Effect.Move(effect.element, + { x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { + new Effect.Move(effect.element, + { x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { + new Effect.Move(effect.element, + { x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { + new Effect.Move(effect.element, + { x: -20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { + effect.element.undoPositioned().setStyle(oldStyle); + }}) }}) }}) }}) }}) }}); +} + +Effect.SlideDown = function(element) { + element = $(element).cleanWhitespace(); + // SlideDown need to have the content of the element wrapped in a container element with fixed height! + var oldInnerBottom = element.down().getStyle('bottom'); + var elementDimensions = element.getDimensions(); + return new Effect.Scale(element, 100, Object.extend({ + scaleContent: false, + scaleX: false, + scaleFrom: window.opera ? 0 : 1, + scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, + restoreAfterFinish: true, + afterSetup: function(effect) { + effect.element.makePositioned(); + effect.element.down().makePositioned(); + if(window.opera) effect.element.setStyle({top: ''}); + effect.element.makeClipping().setStyle({height: '0px'}).show(); + }, + afterUpdateInternal: function(effect) { + effect.element.down().setStyle({bottom: + (effect.dims[0] - effect.element.clientHeight) + 'px' }); + }, + afterFinishInternal: function(effect) { + effect.element.undoClipping().undoPositioned(); + effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); } + }, arguments[1] || {}) + ); +} + +Effect.SlideUp = function(element) { + element = $(element).cleanWhitespace(); + var oldInnerBottom = element.down().getStyle('bottom'); + return new Effect.Scale(element, window.opera ? 0 : 1, + Object.extend({ scaleContent: false, + scaleX: false, + scaleMode: 'box', + scaleFrom: 100, + restoreAfterFinish: true, + beforeStartInternal: function(effect) { + effect.element.makePositioned(); + effect.element.down().makePositioned(); + if(window.opera) effect.element.setStyle({top: ''}); + effect.element.makeClipping().show(); + }, + afterUpdateInternal: function(effect) { + effect.element.down().setStyle({bottom: + (effect.dims[0] - effect.element.clientHeight) + 'px' }); + }, + afterFinishInternal: function(effect) { + effect.element.hide().undoClipping().undoPositioned().setStyle({bottom: oldInnerBottom}); + effect.element.down().undoPositioned(); + } + }, arguments[1] || {}) + ); +} + +// Bug in opera makes the TD containing this element expand for a instance after finish +Effect.Squish = function(element) { + return new Effect.Scale(element, window.opera ? 1 : 0, { + restoreAfterFinish: true, + beforeSetup: function(effect) { + effect.element.makeClipping(); + }, + afterFinishInternal: function(effect) { + effect.element.hide().undoClipping(); + } + }); +} + +Effect.Grow = function(element) { + element = $(element); + var options = Object.extend({ + direction: 'center', + moveTransition: Effect.Transitions.sinoidal, + scaleTransition: Effect.Transitions.sinoidal, + opacityTransition: Effect.Transitions.full + }, arguments[1] || {}); + var oldStyle = { + top: element.style.top, + left: element.style.left, + height: element.style.height, + width: element.style.width, + opacity: element.getInlineOpacity() }; + + var dims = element.getDimensions(); + var initialMoveX, initialMoveY; + var moveX, moveY; + + switch (options.direction) { + case 'top-left': + initialMoveX = initialMoveY = moveX = moveY = 0; + break; + case 'top-right': + initialMoveX = dims.width; + initialMoveY = moveY = 0; + moveX = -dims.width; + break; + case 'bottom-left': + initialMoveX = moveX = 0; + initialMoveY = dims.height; + moveY = -dims.height; + break; + case 'bottom-right': + initialMoveX = dims.width; + initialMoveY = dims.height; + moveX = -dims.width; + moveY = -dims.height; + break; + case 'center': + initialMoveX = dims.width / 2; + initialMoveY = dims.height / 2; + moveX = -dims.width / 2; + moveY = -dims.height / 2; + break; + } + + return new Effect.Move(element, { + x: initialMoveX, + y: initialMoveY, + duration: 0.01, + beforeSetup: function(effect) { + effect.element.hide().makeClipping().makePositioned(); + }, + afterFinishInternal: function(effect) { + new Effect.Parallel( + [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }), + new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }), + new Effect.Scale(effect.element, 100, { + scaleMode: { originalHeight: dims.height, originalWidth: dims.width }, + sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true}) + ], Object.extend({ + beforeSetup: function(effect) { + effect.effects[0].element.setStyle({height: '0px'}).show(); + }, + afterFinishInternal: function(effect) { + effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle); + } + }, options) + ) + } + }); +} + +Effect.Shrink = function(element) { + element = $(element); + var options = Object.extend({ + direction: 'center', + moveTransition: Effect.Transitions.sinoidal, + scaleTransition: Effect.Transitions.sinoidal, + opacityTransition: Effect.Transitions.none + }, arguments[1] || {}); + var oldStyle = { + top: element.style.top, + left: element.style.left, + height: element.style.height, + width: element.style.width, + opacity: element.getInlineOpacity() }; + + var dims = element.getDimensions(); + var moveX, moveY; + + switch (options.direction) { + case 'top-left': + moveX = moveY = 0; + break; + case 'top-right': + moveX = dims.width; + moveY = 0; + break; + case 'bottom-left': + moveX = 0; + moveY = dims.height; + break; + case 'bottom-right': + moveX = dims.width; + moveY = dims.height; + break; + case 'center': + moveX = dims.width / 2; + moveY = dims.height / 2; + break; + } + + return new Effect.Parallel( + [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }), + new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}), + new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }) + ], Object.extend({ + beforeStartInternal: function(effect) { + effect.effects[0].element.makePositioned().makeClipping(); + }, + afterFinishInternal: function(effect) { + effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); } + }, options) + ); +} + +Effect.Pulsate = function(element) { + element = $(element); + var options = arguments[1] || {}; + var oldOpacity = element.getInlineOpacity(); + var transition = options.transition || Effect.Transitions.sinoidal; + var reverser = function(pos){ return transition(1-Effect.Transitions.pulse(pos, options.pulses)) }; + reverser.bind(transition); + return new Effect.Opacity(element, + Object.extend(Object.extend({ duration: 2.0, from: 0, + afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); } + }, options), {transition: reverser})); +} + +Effect.Fold = function(element) { + element = $(element); + var oldStyle = { + top: element.style.top, + left: element.style.left, + width: element.style.width, + height: element.style.height }; + element.makeClipping(); + return new Effect.Scale(element, 5, Object.extend({ + scaleContent: false, + scaleX: false, + afterFinishInternal: function(effect) { + new Effect.Scale(element, 1, { + scaleContent: false, + scaleY: false, + afterFinishInternal: function(effect) { + effect.element.hide().undoClipping().setStyle(oldStyle); + } }); + }}, arguments[1] || {})); +}; + +Effect.Morph = Class.create(); +Object.extend(Object.extend(Effect.Morph.prototype, Effect.Base.prototype), { + initialize: function(element) { + this.element = $(element); + if(!this.element) throw(Effect._elementDoesNotExistError); + var options = Object.extend({ + style: '' + }, arguments[1] || {}); + this.start(options); + }, + setup: function(){ + function parseColor(color){ + if(!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff'; + color = color.parseColor(); + return $R(0,2).map(function(i){ + return parseInt( color.slice(i*2+1,i*2+3), 16 ) + }); + } + this.transforms = this.options.style.parseStyle().map(function(property){ + var originalValue = this.element.getStyle(property[0]); + return $H({ + style: property[0], + originalValue: property[1].unit=='color' ? + parseColor(originalValue) : parseFloat(originalValue || 0), + targetValue: property[1].unit=='color' ? + parseColor(property[1].value) : property[1].value, + unit: property[1].unit + }); + }.bind(this)).reject(function(transform){ + return ( + (transform.originalValue == transform.targetValue) || + ( + transform.unit != 'color' && + (isNaN(transform.originalValue) || isNaN(transform.targetValue)) + ) + ) + }); + }, + update: function(position) { + var style = $H(), value = null; + this.transforms.each(function(transform){ + value = transform.unit=='color' ? + $R(0,2).inject('#',function(m,v,i){ + return m+(Math.round(transform.originalValue[i]+ + (transform.targetValue[i] - transform.originalValue[i])*position)).toColorPart() }) : + transform.originalValue + Math.round( + ((transform.targetValue - transform.originalValue) * position) * 1000)/1000 + transform.unit; + style[transform.style] = value; + }); + this.element.setStyle(style); + } +}); + +Effect.Transform = Class.create(); +Object.extend(Effect.Transform.prototype, { + initialize: function(tracks){ + this.tracks = []; + this.options = arguments[1] || {}; + this.addTracks(tracks); + }, + addTracks: function(tracks){ + tracks.each(function(track){ + var data = $H(track).values().first(); + this.tracks.push($H({ + ids: $H(track).keys().first(), + effect: Effect.Morph, + options: { style: data } + })); + }.bind(this)); + return this; + }, + play: function(){ + return new Effect.Parallel( + this.tracks.map(function(track){ + var elements = [$(track.ids) || $$(track.ids)].flatten(); + return elements.map(function(e){ return new track.effect(e, Object.extend({ sync:true }, track.options)) }); + }).flatten(), + this.options + ); + } +}); + +Element.CSS_PROPERTIES = ['azimuth', 'backgroundAttachment', 'backgroundColor', 'backgroundImage', + 'backgroundPosition', 'backgroundRepeat', 'borderBottomColor', 'borderBottomStyle', + 'borderBottomWidth', 'borderCollapse', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', + 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderSpacing', 'borderTopColor', + 'borderTopStyle', 'borderTopWidth', 'bottom', 'captionSide', 'clear', 'clip', 'color', 'content', + 'counterIncrement', 'counterReset', 'cssFloat', 'cueAfter', 'cueBefore', 'cursor', 'direction', + 'display', 'elevation', 'emptyCells', 'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', + 'fontStyle', 'fontVariant', 'fontWeight', 'height', 'left', 'letterSpacing', 'lineHeight', + 'listStyleImage', 'listStylePosition', 'listStyleType', 'marginBottom', 'marginLeft', 'marginRight', + 'marginTop', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'opacity', + 'orphans', 'outlineColor', 'outlineOffset', 'outlineStyle', 'outlineWidth', 'overflowX', 'overflowY', + 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'page', 'pageBreakAfter', 'pageBreakBefore', + 'pageBreakInside', 'pauseAfter', 'pauseBefore', 'pitch', 'pitchRange', 'position', 'quotes', + 'richness', 'right', 'size', 'speakHeader', 'speakNumeral', 'speakPunctuation', 'speechRate', 'stress', + 'tableLayout', 'textAlign', 'textDecoration', 'textIndent', 'textShadow', 'textTransform', 'top', + 'unicodeBidi', 'verticalAlign', 'visibility', 'voiceFamily', 'volume', 'whiteSpace', 'widows', + 'width', 'wordSpacing', 'zIndex']; + +Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; + +String.prototype.parseStyle = function(){ + var element = Element.extend(document.createElement('div')); + element.innerHTML = '

    '; + var style = element.down().style, styleRules = $H(); + + Element.CSS_PROPERTIES.each(function(property){ + if(style[property]) styleRules[property] = style[property]; + }); + + var result = $H(); + + styleRules.each(function(pair){ + var property = pair[0], value = pair[1], unit = null; + + if(value.parseColor('#zzzzzz') != '#zzzzzz') { + value = value.parseColor(); + unit = 'color'; + } else if(Element.CSS_LENGTH.test(value)) + var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/), + value = parseFloat(components[1]), unit = (components.length == 3) ? components[2] : null; + + result[property.underscore().dasherize()] = $H({ value:value, unit:unit }); + }.bind(this)); + + return result; +}; + +Element.morph = function(element, style) { + new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || {})); + return element; +}; + +['setOpacity','getOpacity','getInlineOpacity','forceRerendering','setContentZoom', + 'collectTextNodes','collectTextNodesIgnoreClass','morph'].each( + function(f) { Element.Methods[f] = Element[f]; } +); + +Element.Methods.visualEffect = function(element, effect, options) { + s = effect.gsub(/_/, '-').camelize(); + effect_class = s.charAt(0).toUpperCase() + s.substring(1); + new Effect[effect_class](element, options); + return $(element); +}; + +Element.addMethods(); \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/prototype.js b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/prototype.js new file mode 100644 index 00000000..50582217 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/javascripts/prototype.js @@ -0,0 +1,2515 @@ +/* Prototype JavaScript framework, version 1.5.0 + * (c) 2005-2007 Sam Stephenson + * + * Prototype is freely distributable under the terms of an MIT-style license. + * For details, see the Prototype web site: http://prototype.conio.net/ + * +/*--------------------------------------------------------------------------*/ + +var Prototype = { + Version: '1.5.0', + BrowserFeatures: { + XPath: !!document.evaluate + }, + + ScriptFragment: '(?:)((\n|\r|.)*?)(?:<\/script>)', + emptyFunction: function() {}, + K: function(x) { return x } +} + +var Class = { + create: function() { + return function() { + this.initialize.apply(this, arguments); + } + } +} + +var Abstract = new Object(); + +Object.extend = function(destination, source) { + for (var property in source) { + destination[property] = source[property]; + } + return destination; +} + +Object.extend(Object, { + inspect: function(object) { + try { + if (object === undefined) return 'undefined'; + if (object === null) return 'null'; + return object.inspect ? object.inspect() : object.toString(); + } catch (e) { + if (e instanceof RangeError) return '...'; + throw e; + } + }, + + keys: function(object) { + var keys = []; + for (var property in object) + keys.push(property); + return keys; + }, + + values: function(object) { + var values = []; + for (var property in object) + values.push(object[property]); + return values; + }, + + clone: function(object) { + return Object.extend({}, object); + } +}); + +Function.prototype.bind = function() { + var __method = this, args = $A(arguments), object = args.shift(); + return function() { + return __method.apply(object, args.concat($A(arguments))); + } +} + +Function.prototype.bindAsEventListener = function(object) { + var __method = this, args = $A(arguments), object = args.shift(); + return function(event) { + return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments))); + } +} + +Object.extend(Number.prototype, { + toColorPart: function() { + var digits = this.toString(16); + if (this < 16) return '0' + digits; + return digits; + }, + + succ: function() { + return this + 1; + }, + + times: function(iterator) { + $R(0, this, true).each(iterator); + return this; + } +}); + +var Try = { + these: function() { + var returnValue; + + for (var i = 0, length = arguments.length; i < length; i++) { + var lambda = arguments[i]; + try { + returnValue = lambda(); + break; + } catch (e) {} + } + + return returnValue; + } +} + +/*--------------------------------------------------------------------------*/ + +var PeriodicalExecuter = Class.create(); +PeriodicalExecuter.prototype = { + initialize: function(callback, frequency) { + this.callback = callback; + this.frequency = frequency; + this.currentlyExecuting = false; + + this.registerCallback(); + }, + + registerCallback: function() { + this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); + }, + + stop: function() { + if (!this.timer) return; + clearInterval(this.timer); + this.timer = null; + }, + + onTimerEvent: function() { + if (!this.currentlyExecuting) { + try { + this.currentlyExecuting = true; + this.callback(this); + } finally { + this.currentlyExecuting = false; + } + } + } +} +String.interpret = function(value){ + return value == null ? '' : String(value); +} + +Object.extend(String.prototype, { + gsub: function(pattern, replacement) { + var result = '', source = this, match; + replacement = arguments.callee.prepareReplacement(replacement); + + while (source.length > 0) { + if (match = source.match(pattern)) { + result += source.slice(0, match.index); + result += String.interpret(replacement(match)); + source = source.slice(match.index + match[0].length); + } else { + result += source, source = ''; + } + } + return result; + }, + + sub: function(pattern, replacement, count) { + replacement = this.gsub.prepareReplacement(replacement); + count = count === undefined ? 1 : count; + + return this.gsub(pattern, function(match) { + if (--count < 0) return match[0]; + return replacement(match); + }); + }, + + scan: function(pattern, iterator) { + this.gsub(pattern, iterator); + return this; + }, + + truncate: function(length, truncation) { + length = length || 30; + truncation = truncation === undefined ? '...' : truncation; + return this.length > length ? + this.slice(0, length - truncation.length) + truncation : this; + }, + + strip: function() { + return this.replace(/^\s+/, '').replace(/\s+$/, ''); + }, + + stripTags: function() { + return this.replace(/<\/?[^>]+>/gi, ''); + }, + + stripScripts: function() { + return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); + }, + + extractScripts: function() { + var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); + var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); + return (this.match(matchAll) || []).map(function(scriptTag) { + return (scriptTag.match(matchOne) || ['', ''])[1]; + }); + }, + + evalScripts: function() { + return this.extractScripts().map(function(script) { return eval(script) }); + }, + + escapeHTML: function() { + var div = document.createElement('div'); + var text = document.createTextNode(this); + div.appendChild(text); + return div.innerHTML; + }, + + unescapeHTML: function() { + var div = document.createElement('div'); + div.innerHTML = this.stripTags(); + return div.childNodes[0] ? (div.childNodes.length > 1 ? + $A(div.childNodes).inject('',function(memo,node){ return memo+node.nodeValue }) : + div.childNodes[0].nodeValue) : ''; + }, + + toQueryParams: function(separator) { + var match = this.strip().match(/([^?#]*)(#.*)?$/); + if (!match) return {}; + + return match[1].split(separator || '&').inject({}, function(hash, pair) { + if ((pair = pair.split('='))[0]) { + var name = decodeURIComponent(pair[0]); + var value = pair[1] ? decodeURIComponent(pair[1]) : undefined; + + if (hash[name] !== undefined) { + if (hash[name].constructor != Array) + hash[name] = [hash[name]]; + if (value) hash[name].push(value); + } + else hash[name] = value; + } + return hash; + }); + }, + + toArray: function() { + return this.split(''); + }, + + succ: function() { + return this.slice(0, this.length - 1) + + String.fromCharCode(this.charCodeAt(this.length - 1) + 1); + }, + + camelize: function() { + var parts = this.split('-'), len = parts.length; + if (len == 1) return parts[0]; + + var camelized = this.charAt(0) == '-' + ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) + : parts[0]; + + for (var i = 1; i < len; i++) + camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); + + return camelized; + }, + + capitalize: function(){ + return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); + }, + + underscore: function() { + return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase(); + }, + + dasherize: function() { + return this.gsub(/_/,'-'); + }, + + inspect: function(useDoubleQuotes) { + var escapedString = this.replace(/\\/g, '\\\\'); + if (useDoubleQuotes) + return '"' + escapedString.replace(/"/g, '\\"') + '"'; + else + return "'" + escapedString.replace(/'/g, '\\\'') + "'"; + } +}); + +String.prototype.gsub.prepareReplacement = function(replacement) { + if (typeof replacement == 'function') return replacement; + var template = new Template(replacement); + return function(match) { return template.evaluate(match) }; +} + +String.prototype.parseQuery = String.prototype.toQueryParams; + +var Template = Class.create(); +Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; +Template.prototype = { + initialize: function(template, pattern) { + this.template = template.toString(); + this.pattern = pattern || Template.Pattern; + }, + + evaluate: function(object) { + return this.template.gsub(this.pattern, function(match) { + var before = match[1]; + if (before == '\\') return match[2]; + return before + String.interpret(object[match[3]]); + }); + } +} + +var $break = new Object(); +var $continue = new Object(); + +var Enumerable = { + each: function(iterator) { + var index = 0; + try { + this._each(function(value) { + try { + iterator(value, index++); + } catch (e) { + if (e != $continue) throw e; + } + }); + } catch (e) { + if (e != $break) throw e; + } + return this; + }, + + eachSlice: function(number, iterator) { + var index = -number, slices = [], array = this.toArray(); + while ((index += number) < array.length) + slices.push(array.slice(index, index+number)); + return slices.map(iterator); + }, + + all: function(iterator) { + var result = true; + this.each(function(value, index) { + result = result && !!(iterator || Prototype.K)(value, index); + if (!result) throw $break; + }); + return result; + }, + + any: function(iterator) { + var result = false; + this.each(function(value, index) { + if (result = !!(iterator || Prototype.K)(value, index)) + throw $break; + }); + return result; + }, + + collect: function(iterator) { + var results = []; + this.each(function(value, index) { + results.push((iterator || Prototype.K)(value, index)); + }); + return results; + }, + + detect: function(iterator) { + var result; + this.each(function(value, index) { + if (iterator(value, index)) { + result = value; + throw $break; + } + }); + return result; + }, + + findAll: function(iterator) { + var results = []; + this.each(function(value, index) { + if (iterator(value, index)) + results.push(value); + }); + return results; + }, + + grep: function(pattern, iterator) { + var results = []; + this.each(function(value, index) { + var stringValue = value.toString(); + if (stringValue.match(pattern)) + results.push((iterator || Prototype.K)(value, index)); + }) + return results; + }, + + include: function(object) { + var found = false; + this.each(function(value) { + if (value == object) { + found = true; + throw $break; + } + }); + return found; + }, + + inGroupsOf: function(number, fillWith) { + fillWith = fillWith === undefined ? null : fillWith; + return this.eachSlice(number, function(slice) { + while(slice.length < number) slice.push(fillWith); + return slice; + }); + }, + + inject: function(memo, iterator) { + this.each(function(value, index) { + memo = iterator(memo, value, index); + }); + return memo; + }, + + invoke: function(method) { + var args = $A(arguments).slice(1); + return this.map(function(value) { + return value[method].apply(value, args); + }); + }, + + max: function(iterator) { + var result; + this.each(function(value, index) { + value = (iterator || Prototype.K)(value, index); + if (result == undefined || value >= result) + result = value; + }); + return result; + }, + + min: function(iterator) { + var result; + this.each(function(value, index) { + value = (iterator || Prototype.K)(value, index); + if (result == undefined || value < result) + result = value; + }); + return result; + }, + + partition: function(iterator) { + var trues = [], falses = []; + this.each(function(value, index) { + ((iterator || Prototype.K)(value, index) ? + trues : falses).push(value); + }); + return [trues, falses]; + }, + + pluck: function(property) { + var results = []; + this.each(function(value, index) { + results.push(value[property]); + }); + return results; + }, + + reject: function(iterator) { + var results = []; + this.each(function(value, index) { + if (!iterator(value, index)) + results.push(value); + }); + return results; + }, + + sortBy: function(iterator) { + return this.map(function(value, index) { + return {value: value, criteria: iterator(value, index)}; + }).sort(function(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }).pluck('value'); + }, + + toArray: function() { + return this.map(); + }, + + zip: function() { + var iterator = Prototype.K, args = $A(arguments); + if (typeof args.last() == 'function') + iterator = args.pop(); + + var collections = [this].concat(args).map($A); + return this.map(function(value, index) { + return iterator(collections.pluck(index)); + }); + }, + + size: function() { + return this.toArray().length; + }, + + inspect: function() { + return '#'; + } +} + +Object.extend(Enumerable, { + map: Enumerable.collect, + find: Enumerable.detect, + select: Enumerable.findAll, + member: Enumerable.include, + entries: Enumerable.toArray +}); +var $A = Array.from = function(iterable) { + if (!iterable) return []; + if (iterable.toArray) { + return iterable.toArray(); + } else { + var results = []; + for (var i = 0, length = iterable.length; i < length; i++) + results.push(iterable[i]); + return results; + } +} + +Object.extend(Array.prototype, Enumerable); + +if (!Array.prototype._reverse) + Array.prototype._reverse = Array.prototype.reverse; + +Object.extend(Array.prototype, { + _each: function(iterator) { + for (var i = 0, length = this.length; i < length; i++) + iterator(this[i]); + }, + + clear: function() { + this.length = 0; + return this; + }, + + first: function() { + return this[0]; + }, + + last: function() { + return this[this.length - 1]; + }, + + compact: function() { + return this.select(function(value) { + return value != null; + }); + }, + + flatten: function() { + return this.inject([], function(array, value) { + return array.concat(value && value.constructor == Array ? + value.flatten() : [value]); + }); + }, + + without: function() { + var values = $A(arguments); + return this.select(function(value) { + return !values.include(value); + }); + }, + + indexOf: function(object) { + for (var i = 0, length = this.length; i < length; i++) + if (this[i] == object) return i; + return -1; + }, + + reverse: function(inline) { + return (inline !== false ? this : this.toArray())._reverse(); + }, + + reduce: function() { + return this.length > 1 ? this : this[0]; + }, + + uniq: function() { + return this.inject([], function(array, value) { + return array.include(value) ? array : array.concat([value]); + }); + }, + + clone: function() { + return [].concat(this); + }, + + size: function() { + return this.length; + }, + + inspect: function() { + return '[' + this.map(Object.inspect).join(', ') + ']'; + } +}); + +Array.prototype.toArray = Array.prototype.clone; + +function $w(string){ + string = string.strip(); + return string ? string.split(/\s+/) : []; +} + +if(window.opera){ + Array.prototype.concat = function(){ + var array = []; + for(var i = 0, length = this.length; i < length; i++) array.push(this[i]); + for(var i = 0, length = arguments.length; i < length; i++) { + if(arguments[i].constructor == Array) { + for(var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) + array.push(arguments[i][j]); + } else { + array.push(arguments[i]); + } + } + return array; + } +} +var Hash = function(obj) { + Object.extend(this, obj || {}); +}; + +Object.extend(Hash, { + toQueryString: function(obj) { + var parts = []; + + this.prototype._each.call(obj, function(pair) { + if (!pair.key) return; + + if (pair.value && pair.value.constructor == Array) { + var values = pair.value.compact(); + if (values.length < 2) pair.value = values.reduce(); + else { + key = encodeURIComponent(pair.key); + values.each(function(value) { + value = value != undefined ? encodeURIComponent(value) : ''; + parts.push(key + '=' + encodeURIComponent(value)); + }); + return; + } + } + if (pair.value == undefined) pair[1] = ''; + parts.push(pair.map(encodeURIComponent).join('=')); + }); + + return parts.join('&'); + } +}); + +Object.extend(Hash.prototype, Enumerable); +Object.extend(Hash.prototype, { + _each: function(iterator) { + for (var key in this) { + var value = this[key]; + if (value && value == Hash.prototype[key]) continue; + + var pair = [key, value]; + pair.key = key; + pair.value = value; + iterator(pair); + } + }, + + keys: function() { + return this.pluck('key'); + }, + + values: function() { + return this.pluck('value'); + }, + + merge: function(hash) { + return $H(hash).inject(this, function(mergedHash, pair) { + mergedHash[pair.key] = pair.value; + return mergedHash; + }); + }, + + remove: function() { + var result; + for(var i = 0, length = arguments.length; i < length; i++) { + var value = this[arguments[i]]; + if (value !== undefined){ + if (result === undefined) result = value; + else { + if (result.constructor != Array) result = [result]; + result.push(value) + } + } + delete this[arguments[i]]; + } + return result; + }, + + toQueryString: function() { + return Hash.toQueryString(this); + }, + + inspect: function() { + return '#'; + } +}); + +function $H(object) { + if (object && object.constructor == Hash) return object; + return new Hash(object); +}; +ObjectRange = Class.create(); +Object.extend(ObjectRange.prototype, Enumerable); +Object.extend(ObjectRange.prototype, { + initialize: function(start, end, exclusive) { + this.start = start; + this.end = end; + this.exclusive = exclusive; + }, + + _each: function(iterator) { + var value = this.start; + while (this.include(value)) { + iterator(value); + value = value.succ(); + } + }, + + include: function(value) { + if (value < this.start) + return false; + if (this.exclusive) + return value < this.end; + return value <= this.end; + } +}); + +var $R = function(start, end, exclusive) { + return new ObjectRange(start, end, exclusive); +} + +var Ajax = { + getTransport: function() { + return Try.these( + function() {return new XMLHttpRequest()}, + function() {return new ActiveXObject('Msxml2.XMLHTTP')}, + function() {return new ActiveXObject('Microsoft.XMLHTTP')} + ) || false; + }, + + activeRequestCount: 0 +} + +Ajax.Responders = { + responders: [], + + _each: function(iterator) { + this.responders._each(iterator); + }, + + register: function(responder) { + if (!this.include(responder)) + this.responders.push(responder); + }, + + unregister: function(responder) { + this.responders = this.responders.without(responder); + }, + + dispatch: function(callback, request, transport, json) { + this.each(function(responder) { + if (typeof responder[callback] == 'function') { + try { + responder[callback].apply(responder, [request, transport, json]); + } catch (e) {} + } + }); + } +}; + +Object.extend(Ajax.Responders, Enumerable); + +Ajax.Responders.register({ + onCreate: function() { + Ajax.activeRequestCount++; + }, + onComplete: function() { + Ajax.activeRequestCount--; + } +}); + +Ajax.Base = function() {}; +Ajax.Base.prototype = { + setOptions: function(options) { + this.options = { + method: 'post', + asynchronous: true, + contentType: 'application/x-www-form-urlencoded', + encoding: 'UTF-8', + parameters: '' + } + Object.extend(this.options, options || {}); + + this.options.method = this.options.method.toLowerCase(); + if (typeof this.options.parameters == 'string') + this.options.parameters = this.options.parameters.toQueryParams(); + } +} + +Ajax.Request = Class.create(); +Ajax.Request.Events = + ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; + +Ajax.Request.prototype = Object.extend(new Ajax.Base(), { + _complete: false, + + initialize: function(url, options) { + this.transport = Ajax.getTransport(); + this.setOptions(options); + this.request(url); + }, + + request: function(url) { + this.url = url; + this.method = this.options.method; + var params = this.options.parameters; + + if (!['get', 'post'].include(this.method)) { + // simulate other verbs over post + params['_method'] = this.method; + this.method = 'post'; + } + + params = Hash.toQueryString(params); + if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_=' + + // when GET, append parameters to URL + if (this.method == 'get' && params) + this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params; + + try { + Ajax.Responders.dispatch('onCreate', this, this.transport); + + this.transport.open(this.method.toUpperCase(), this.url, + this.options.asynchronous); + + if (this.options.asynchronous) + setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10); + + this.transport.onreadystatechange = this.onStateChange.bind(this); + this.setRequestHeaders(); + + var body = this.method == 'post' ? (this.options.postBody || params) : null; + + this.transport.send(body); + + /* Force Firefox to handle ready state 4 for synchronous requests */ + if (!this.options.asynchronous && this.transport.overrideMimeType) + this.onStateChange(); + + } + catch (e) { + this.dispatchException(e); + } + }, + + onStateChange: function() { + var readyState = this.transport.readyState; + if (readyState > 1 && !((readyState == 4) && this._complete)) + this.respondToReadyState(this.transport.readyState); + }, + + setRequestHeaders: function() { + var headers = { + 'X-Requested-With': 'XMLHttpRequest', + 'X-Prototype-Version': Prototype.Version, + 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' + }; + + if (this.method == 'post') { + headers['Content-type'] = this.options.contentType + + (this.options.encoding ? '; charset=' + this.options.encoding : ''); + + /* Force "Connection: close" for older Mozilla browsers to work + * around a bug where XMLHttpRequest sends an incorrect + * Content-length header. See Mozilla Bugzilla #246651. + */ + if (this.transport.overrideMimeType && + (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) + headers['Connection'] = 'close'; + } + + // user-defined headers + if (typeof this.options.requestHeaders == 'object') { + var extras = this.options.requestHeaders; + + if (typeof extras.push == 'function') + for (var i = 0, length = extras.length; i < length; i += 2) + headers[extras[i]] = extras[i+1]; + else + $H(extras).each(function(pair) { headers[pair.key] = pair.value }); + } + + for (var name in headers) + this.transport.setRequestHeader(name, headers[name]); + }, + + success: function() { + return !this.transport.status + || (this.transport.status >= 200 && this.transport.status < 300); + }, + + respondToReadyState: function(readyState) { + var state = Ajax.Request.Events[readyState]; + var transport = this.transport, json = this.evalJSON(); + + if (state == 'Complete') { + try { + this._complete = true; + (this.options['on' + this.transport.status] + || this.options['on' + (this.success() ? 'Success' : 'Failure')] + || Prototype.emptyFunction)(transport, json); + } catch (e) { + this.dispatchException(e); + } + + if ((this.getHeader('Content-type') || 'text/javascript').strip(). + match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i)) + this.evalResponse(); + } + + try { + (this.options['on' + state] || Prototype.emptyFunction)(transport, json); + Ajax.Responders.dispatch('on' + state, this, transport, json); + } catch (e) { + this.dispatchException(e); + } + + if (state == 'Complete') { + // avoid memory leak in MSIE: clean up + this.transport.onreadystatechange = Prototype.emptyFunction; + } + }, + + getHeader: function(name) { + try { + return this.transport.getResponseHeader(name); + } catch (e) { return null } + }, + + evalJSON: function() { + try { + var json = this.getHeader('X-JSON'); + return json ? eval('(' + json + ')') : null; + } catch (e) { return null } + }, + + evalResponse: function() { + try { + return eval(this.transport.responseText); + } catch (e) { + this.dispatchException(e); + } + }, + + dispatchException: function(exception) { + (this.options.onException || Prototype.emptyFunction)(this, exception); + Ajax.Responders.dispatch('onException', this, exception); + } +}); + +Ajax.Updater = Class.create(); + +Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { + initialize: function(container, url, options) { + this.container = { + success: (container.success || container), + failure: (container.failure || (container.success ? null : container)) + } + + this.transport = Ajax.getTransport(); + this.setOptions(options); + + var onComplete = this.options.onComplete || Prototype.emptyFunction; + this.options.onComplete = (function(transport, param) { + this.updateContent(); + onComplete(transport, param); + }).bind(this); + + this.request(url); + }, + + updateContent: function() { + var receiver = this.container[this.success() ? 'success' : 'failure']; + var response = this.transport.responseText; + + if (!this.options.evalScripts) response = response.stripScripts(); + + if (receiver = $(receiver)) { + if (this.options.insertion) + new this.options.insertion(receiver, response); + else + receiver.update(response); + } + + if (this.success()) { + if (this.onComplete) + setTimeout(this.onComplete.bind(this), 10); + } + } +}); + +Ajax.PeriodicalUpdater = Class.create(); +Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), { + initialize: function(container, url, options) { + this.setOptions(options); + this.onComplete = this.options.onComplete; + + this.frequency = (this.options.frequency || 2); + this.decay = (this.options.decay || 1); + + this.updater = {}; + this.container = container; + this.url = url; + + this.start(); + }, + + start: function() { + this.options.onComplete = this.updateComplete.bind(this); + this.onTimerEvent(); + }, + + stop: function() { + this.updater.options.onComplete = undefined; + clearTimeout(this.timer); + (this.onComplete || Prototype.emptyFunction).apply(this, arguments); + }, + + updateComplete: function(request) { + if (this.options.decay) { + this.decay = (request.responseText == this.lastText ? + this.decay * this.options.decay : 1); + + this.lastText = request.responseText; + } + this.timer = setTimeout(this.onTimerEvent.bind(this), + this.decay * this.frequency * 1000); + }, + + onTimerEvent: function() { + this.updater = new Ajax.Updater(this.container, this.url, this.options); + } +}); +function $(element) { + if (arguments.length > 1) { + for (var i = 0, elements = [], length = arguments.length; i < length; i++) + elements.push($(arguments[i])); + return elements; + } + if (typeof element == 'string') + element = document.getElementById(element); + return Element.extend(element); +} + +if (Prototype.BrowserFeatures.XPath) { + document._getElementsByXPath = function(expression, parentElement) { + var results = []; + var query = document.evaluate(expression, $(parentElement) || document, + null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + for (var i = 0, length = query.snapshotLength; i < length; i++) + results.push(query.snapshotItem(i)); + return results; + }; +} + +document.getElementsByClassName = function(className, parentElement) { + if (Prototype.BrowserFeatures.XPath) { + var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]"; + return document._getElementsByXPath(q, parentElement); + } else { + var children = ($(parentElement) || document.body).getElementsByTagName('*'); + var elements = [], child; + for (var i = 0, length = children.length; i < length; i++) { + child = children[i]; + if (Element.hasClassName(child, className)) + elements.push(Element.extend(child)); + } + return elements; + } +}; + +/*--------------------------------------------------------------------------*/ + +if (!window.Element) + var Element = new Object(); + +Element.extend = function(element) { + if (!element || _nativeExtensions || element.nodeType == 3) return element; + + if (!element._extended && element.tagName && element != window) { + var methods = Object.clone(Element.Methods), cache = Element.extend.cache; + + if (element.tagName == 'FORM') + Object.extend(methods, Form.Methods); + if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName)) + Object.extend(methods, Form.Element.Methods); + + Object.extend(methods, Element.Methods.Simulated); + + for (var property in methods) { + var value = methods[property]; + if (typeof value == 'function' && !(property in element)) + element[property] = cache.findOrStore(value); + } + } + + element._extended = true; + return element; +}; + +Element.extend.cache = { + findOrStore: function(value) { + return this[value] = this[value] || function() { + return value.apply(null, [this].concat($A(arguments))); + } + } +}; + +Element.Methods = { + visible: function(element) { + return $(element).style.display != 'none'; + }, + + toggle: function(element) { + element = $(element); + Element[Element.visible(element) ? 'hide' : 'show'](element); + return element; + }, + + hide: function(element) { + $(element).style.display = 'none'; + return element; + }, + + show: function(element) { + $(element).style.display = ''; + return element; + }, + + remove: function(element) { + element = $(element); + element.parentNode.removeChild(element); + return element; + }, + + update: function(element, html) { + html = typeof html == 'undefined' ? '' : html.toString(); + $(element).innerHTML = html.stripScripts(); + setTimeout(function() {html.evalScripts()}, 10); + return element; + }, + + replace: function(element, html) { + element = $(element); + html = typeof html == 'undefined' ? '' : html.toString(); + if (element.outerHTML) { + element.outerHTML = html.stripScripts(); + } else { + var range = element.ownerDocument.createRange(); + range.selectNodeContents(element); + element.parentNode.replaceChild( + range.createContextualFragment(html.stripScripts()), element); + } + setTimeout(function() {html.evalScripts()}, 10); + return element; + }, + + inspect: function(element) { + element = $(element); + var result = '<' + element.tagName.toLowerCase(); + $H({'id': 'id', 'className': 'class'}).each(function(pair) { + var property = pair.first(), attribute = pair.last(); + var value = (element[property] || '').toString(); + if (value) result += ' ' + attribute + '=' + value.inspect(true); + }); + return result + '>'; + }, + + recursivelyCollect: function(element, property) { + element = $(element); + var elements = []; + while (element = element[property]) + if (element.nodeType == 1) + elements.push(Element.extend(element)); + return elements; + }, + + ancestors: function(element) { + return $(element).recursivelyCollect('parentNode'); + }, + + descendants: function(element) { + return $A($(element).getElementsByTagName('*')); + }, + + immediateDescendants: function(element) { + if (!(element = $(element).firstChild)) return []; + while (element && element.nodeType != 1) element = element.nextSibling; + if (element) return [element].concat($(element).nextSiblings()); + return []; + }, + + previousSiblings: function(element) { + return $(element).recursivelyCollect('previousSibling'); + }, + + nextSiblings: function(element) { + return $(element).recursivelyCollect('nextSibling'); + }, + + siblings: function(element) { + element = $(element); + return element.previousSiblings().reverse().concat(element.nextSiblings()); + }, + + match: function(element, selector) { + if (typeof selector == 'string') + selector = new Selector(selector); + return selector.match($(element)); + }, + + up: function(element, expression, index) { + return Selector.findElement($(element).ancestors(), expression, index); + }, + + down: function(element, expression, index) { + return Selector.findElement($(element).descendants(), expression, index); + }, + + previous: function(element, expression, index) { + return Selector.findElement($(element).previousSiblings(), expression, index); + }, + + next: function(element, expression, index) { + return Selector.findElement($(element).nextSiblings(), expression, index); + }, + + getElementsBySelector: function() { + var args = $A(arguments), element = $(args.shift()); + return Selector.findChildElements(element, args); + }, + + getElementsByClassName: function(element, className) { + return document.getElementsByClassName(className, element); + }, + + readAttribute: function(element, name) { + element = $(element); + if (document.all && !window.opera) { + var t = Element._attributeTranslations; + if (t.values[name]) return t.values[name](element, name); + if (t.names[name]) name = t.names[name]; + var attribute = element.attributes[name]; + if(attribute) return attribute.nodeValue; + } + return element.getAttribute(name); + }, + + getHeight: function(element) { + return $(element).getDimensions().height; + }, + + getWidth: function(element) { + return $(element).getDimensions().width; + }, + + classNames: function(element) { + return new Element.ClassNames(element); + }, + + hasClassName: function(element, className) { + if (!(element = $(element))) return; + var elementClassName = element.className; + if (elementClassName.length == 0) return false; + if (elementClassName == className || + elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) + return true; + return false; + }, + + addClassName: function(element, className) { + if (!(element = $(element))) return; + Element.classNames(element).add(className); + return element; + }, + + removeClassName: function(element, className) { + if (!(element = $(element))) return; + Element.classNames(element).remove(className); + return element; + }, + + toggleClassName: function(element, className) { + if (!(element = $(element))) return; + Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className); + return element; + }, + + observe: function() { + Event.observe.apply(Event, arguments); + return $A(arguments).first(); + }, + + stopObserving: function() { + Event.stopObserving.apply(Event, arguments); + return $A(arguments).first(); + }, + + // removes whitespace-only text node children + cleanWhitespace: function(element) { + element = $(element); + var node = element.firstChild; + while (node) { + var nextNode = node.nextSibling; + if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) + element.removeChild(node); + node = nextNode; + } + return element; + }, + + empty: function(element) { + return $(element).innerHTML.match(/^\s*$/); + }, + + descendantOf: function(element, ancestor) { + element = $(element), ancestor = $(ancestor); + while (element = element.parentNode) + if (element == ancestor) return true; + return false; + }, + + scrollTo: function(element) { + element = $(element); + var pos = Position.cumulativeOffset(element); + window.scrollTo(pos[0], pos[1]); + return element; + }, + + getStyle: function(element, style) { + element = $(element); + if (['float','cssFloat'].include(style)) + style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat'); + style = style.camelize(); + var value = element.style[style]; + if (!value) { + if (document.defaultView && document.defaultView.getComputedStyle) { + var css = document.defaultView.getComputedStyle(element, null); + value = css ? css[style] : null; + } else if (element.currentStyle) { + value = element.currentStyle[style]; + } + } + + if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none')) + value = element['offset'+style.capitalize()] + 'px'; + + if (window.opera && ['left', 'top', 'right', 'bottom'].include(style)) + if (Element.getStyle(element, 'position') == 'static') value = 'auto'; + if(style == 'opacity') { + if(value) return parseFloat(value); + if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) + if(value[1]) return parseFloat(value[1]) / 100; + return 1.0; + } + return value == 'auto' ? null : value; + }, + + setStyle: function(element, style) { + element = $(element); + for (var name in style) { + var value = style[name]; + if(name == 'opacity') { + if (value == 1) { + value = (/Gecko/.test(navigator.userAgent) && + !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0; + if(/MSIE/.test(navigator.userAgent) && !window.opera) + element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); + } else if(value == '') { + if(/MSIE/.test(navigator.userAgent) && !window.opera) + element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); + } else { + if(value < 0.00001) value = 0; + if(/MSIE/.test(navigator.userAgent) && !window.opera) + element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + + 'alpha(opacity='+value*100+')'; + } + } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat'; + element.style[name.camelize()] = value; + } + return element; + }, + + getDimensions: function(element) { + element = $(element); + var display = $(element).getStyle('display'); + if (display != 'none' && display != null) // Safari bug + return {width: element.offsetWidth, height: element.offsetHeight}; + + // All *Width and *Height properties give 0 on elements with display none, + // so enable the element temporarily + var els = element.style; + var originalVisibility = els.visibility; + var originalPosition = els.position; + var originalDisplay = els.display; + els.visibility = 'hidden'; + els.position = 'absolute'; + els.display = 'block'; + var originalWidth = element.clientWidth; + var originalHeight = element.clientHeight; + els.display = originalDisplay; + els.position = originalPosition; + els.visibility = originalVisibility; + return {width: originalWidth, height: originalHeight}; + }, + + makePositioned: function(element) { + element = $(element); + var pos = Element.getStyle(element, 'position'); + if (pos == 'static' || !pos) { + element._madePositioned = true; + element.style.position = 'relative'; + // Opera returns the offset relative to the positioning context, when an + // element is position relative but top and left have not been defined + if (window.opera) { + element.style.top = 0; + element.style.left = 0; + } + } + return element; + }, + + undoPositioned: function(element) { + element = $(element); + if (element._madePositioned) { + element._madePositioned = undefined; + element.style.position = + element.style.top = + element.style.left = + element.style.bottom = + element.style.right = ''; + } + return element; + }, + + makeClipping: function(element) { + element = $(element); + if (element._overflow) return element; + element._overflow = element.style.overflow || 'auto'; + if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden') + element.style.overflow = 'hidden'; + return element; + }, + + undoClipping: function(element) { + element = $(element); + if (!element._overflow) return element; + element.style.overflow = element._overflow == 'auto' ? '' : element._overflow; + element._overflow = null; + return element; + } +}; + +Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf}); + +Element._attributeTranslations = {}; + +Element._attributeTranslations.names = { + colspan: "colSpan", + rowspan: "rowSpan", + valign: "vAlign", + datetime: "dateTime", + accesskey: "accessKey", + tabindex: "tabIndex", + enctype: "encType", + maxlength: "maxLength", + readonly: "readOnly", + longdesc: "longDesc" +}; + +Element._attributeTranslations.values = { + _getAttr: function(element, attribute) { + return element.getAttribute(attribute, 2); + }, + + _flag: function(element, attribute) { + return $(element).hasAttribute(attribute) ? attribute : null; + }, + + style: function(element) { + return element.style.cssText.toLowerCase(); + }, + + title: function(element) { + var node = element.getAttributeNode('title'); + return node.specified ? node.nodeValue : null; + } +}; + +Object.extend(Element._attributeTranslations.values, { + href: Element._attributeTranslations.values._getAttr, + src: Element._attributeTranslations.values._getAttr, + disabled: Element._attributeTranslations.values._flag, + checked: Element._attributeTranslations.values._flag, + readonly: Element._attributeTranslations.values._flag, + multiple: Element._attributeTranslations.values._flag +}); + +Element.Methods.Simulated = { + hasAttribute: function(element, attribute) { + var t = Element._attributeTranslations; + attribute = t.names[attribute] || attribute; + return $(element).getAttributeNode(attribute).specified; + } +}; + +// IE is missing .innerHTML support for TABLE-related elements +if (document.all && !window.opera){ + Element.Methods.update = function(element, html) { + element = $(element); + html = typeof html == 'undefined' ? '' : html.toString(); + var tagName = element.tagName.toUpperCase(); + if (['THEAD','TBODY','TR','TD'].include(tagName)) { + var div = document.createElement('div'); + switch (tagName) { + case 'THEAD': + case 'TBODY': + div.innerHTML = '' + html.stripScripts() + '
    '; + depth = 2; + break; + case 'TR': + div.innerHTML = '' + html.stripScripts() + '
    '; + depth = 3; + break; + case 'TD': + div.innerHTML = '
    ' + html.stripScripts() + '
    '; + depth = 4; + } + $A(element.childNodes).each(function(node){ + element.removeChild(node) + }); + depth.times(function(){ div = div.firstChild }); + + $A(div.childNodes).each( + function(node){ element.appendChild(node) }); + } else { + element.innerHTML = html.stripScripts(); + } + setTimeout(function() {html.evalScripts()}, 10); + return element; + } +}; + +Object.extend(Element, Element.Methods); + +var _nativeExtensions = false; + +if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)) + ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) { + var className = 'HTML' + tag + 'Element'; + if(window[className]) return; + var klass = window[className] = {}; + klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; + }); + +Element.addMethods = function(methods) { + Object.extend(Element.Methods, methods || {}); + + function copy(methods, destination, onlyIfAbsent) { + onlyIfAbsent = onlyIfAbsent || false; + var cache = Element.extend.cache; + for (var property in methods) { + var value = methods[property]; + if (!onlyIfAbsent || !(property in destination)) + destination[property] = cache.findOrStore(value); + } + } + + if (typeof HTMLElement != 'undefined') { + copy(Element.Methods, HTMLElement.prototype); + copy(Element.Methods.Simulated, HTMLElement.prototype, true); + copy(Form.Methods, HTMLFormElement.prototype); + [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) { + copy(Form.Element.Methods, klass.prototype); + }); + _nativeExtensions = true; + } +} + +var Toggle = new Object(); +Toggle.display = Element.toggle; + +/*--------------------------------------------------------------------------*/ + +Abstract.Insertion = function(adjacency) { + this.adjacency = adjacency; +} + +Abstract.Insertion.prototype = { + initialize: function(element, content) { + this.element = $(element); + this.content = content.stripScripts(); + + if (this.adjacency && this.element.insertAdjacentHTML) { + try { + this.element.insertAdjacentHTML(this.adjacency, this.content); + } catch (e) { + var tagName = this.element.tagName.toUpperCase(); + if (['TBODY', 'TR'].include(tagName)) { + this.insertContent(this.contentFromAnonymousTable()); + } else { + throw e; + } + } + } else { + this.range = this.element.ownerDocument.createRange(); + if (this.initializeRange) this.initializeRange(); + this.insertContent([this.range.createContextualFragment(this.content)]); + } + + setTimeout(function() {content.evalScripts()}, 10); + }, + + contentFromAnonymousTable: function() { + var div = document.createElement('div'); + div.innerHTML = '' + this.content + '
    '; + return $A(div.childNodes[0].childNodes[0].childNodes); + } +} + +var Insertion = new Object(); + +Insertion.Before = Class.create(); +Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), { + initializeRange: function() { + this.range.setStartBefore(this.element); + }, + + insertContent: function(fragments) { + fragments.each((function(fragment) { + this.element.parentNode.insertBefore(fragment, this.element); + }).bind(this)); + } +}); + +Insertion.Top = Class.create(); +Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), { + initializeRange: function() { + this.range.selectNodeContents(this.element); + this.range.collapse(true); + }, + + insertContent: function(fragments) { + fragments.reverse(false).each((function(fragment) { + this.element.insertBefore(fragment, this.element.firstChild); + }).bind(this)); + } +}); + +Insertion.Bottom = Class.create(); +Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), { + initializeRange: function() { + this.range.selectNodeContents(this.element); + this.range.collapse(this.element); + }, + + insertContent: function(fragments) { + fragments.each((function(fragment) { + this.element.appendChild(fragment); + }).bind(this)); + } +}); + +Insertion.After = Class.create(); +Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), { + initializeRange: function() { + this.range.setStartAfter(this.element); + }, + + insertContent: function(fragments) { + fragments.each((function(fragment) { + this.element.parentNode.insertBefore(fragment, + this.element.nextSibling); + }).bind(this)); + } +}); + +/*--------------------------------------------------------------------------*/ + +Element.ClassNames = Class.create(); +Element.ClassNames.prototype = { + initialize: function(element) { + this.element = $(element); + }, + + _each: function(iterator) { + this.element.className.split(/\s+/).select(function(name) { + return name.length > 0; + })._each(iterator); + }, + + set: function(className) { + this.element.className = className; + }, + + add: function(classNameToAdd) { + if (this.include(classNameToAdd)) return; + this.set($A(this).concat(classNameToAdd).join(' ')); + }, + + remove: function(classNameToRemove) { + if (!this.include(classNameToRemove)) return; + this.set($A(this).without(classNameToRemove).join(' ')); + }, + + toString: function() { + return $A(this).join(' '); + } +}; + +Object.extend(Element.ClassNames.prototype, Enumerable); +var Selector = Class.create(); +Selector.prototype = { + initialize: function(expression) { + this.params = {classNames: []}; + this.expression = expression.toString().strip(); + this.parseExpression(); + this.compileMatcher(); + }, + + parseExpression: function() { + function abort(message) { throw 'Parse error in selector: ' + message; } + + if (this.expression == '') abort('empty expression'); + + var params = this.params, expr = this.expression, match, modifier, clause, rest; + while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) { + params.attributes = params.attributes || []; + params.attributes.push({name: match[2], operator: match[3], value: match[4] || match[5] || ''}); + expr = match[1]; + } + + if (expr == '*') return this.params.wildcard = true; + + while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)) { + modifier = match[1], clause = match[2], rest = match[3]; + switch (modifier) { + case '#': params.id = clause; break; + case '.': params.classNames.push(clause); break; + case '': + case undefined: params.tagName = clause.toUpperCase(); break; + default: abort(expr.inspect()); + } + expr = rest; + } + + if (expr.length > 0) abort(expr.inspect()); + }, + + buildMatchExpression: function() { + var params = this.params, conditions = [], clause; + + if (params.wildcard) + conditions.push('true'); + if (clause = params.id) + conditions.push('element.readAttribute("id") == ' + clause.inspect()); + if (clause = params.tagName) + conditions.push('element.tagName.toUpperCase() == ' + clause.inspect()); + if ((clause = params.classNames).length > 0) + for (var i = 0, length = clause.length; i < length; i++) + conditions.push('element.hasClassName(' + clause[i].inspect() + ')'); + if (clause = params.attributes) { + clause.each(function(attribute) { + var value = 'element.readAttribute(' + attribute.name.inspect() + ')'; + var splitValueBy = function(delimiter) { + return value + ' && ' + value + '.split(' + delimiter.inspect() + ')'; + } + + switch (attribute.operator) { + case '=': conditions.push(value + ' == ' + attribute.value.inspect()); break; + case '~=': conditions.push(splitValueBy(' ') + '.include(' + attribute.value.inspect() + ')'); break; + case '|=': conditions.push( + splitValueBy('-') + '.first().toUpperCase() == ' + attribute.value.toUpperCase().inspect() + ); break; + case '!=': conditions.push(value + ' != ' + attribute.value.inspect()); break; + case '': + case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break; + default: throw 'Unknown operator ' + attribute.operator + ' in selector'; + } + }); + } + + return conditions.join(' && '); + }, + + compileMatcher: function() { + this.match = new Function('element', 'if (!element.tagName) return false; \ + element = $(element); \ + return ' + this.buildMatchExpression()); + }, + + findElements: function(scope) { + var element; + + if (element = $(this.params.id)) + if (this.match(element)) + if (!scope || Element.childOf(element, scope)) + return [element]; + + scope = (scope || document).getElementsByTagName(this.params.tagName || '*'); + + var results = []; + for (var i = 0, length = scope.length; i < length; i++) + if (this.match(element = scope[i])) + results.push(Element.extend(element)); + + return results; + }, + + toString: function() { + return this.expression; + } +} + +Object.extend(Selector, { + matchElements: function(elements, expression) { + var selector = new Selector(expression); + return elements.select(selector.match.bind(selector)).map(Element.extend); + }, + + findElement: function(elements, expression, index) { + if (typeof expression == 'number') index = expression, expression = false; + return Selector.matchElements(elements, expression || '*')[index || 0]; + }, + + findChildElements: function(element, expressions) { + return expressions.map(function(expression) { + return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) { + var selector = new Selector(expr); + return results.inject([], function(elements, result) { + return elements.concat(selector.findElements(result || element)); + }); + }); + }).flatten(); + } +}); + +function $$() { + return Selector.findChildElements(document, $A(arguments)); +} +var Form = { + reset: function(form) { + $(form).reset(); + return form; + }, + + serializeElements: function(elements, getHash) { + var data = elements.inject({}, function(result, element) { + if (!element.disabled && element.name) { + var key = element.name, value = $(element).getValue(); + if (value != undefined) { + if (result[key]) { + if (result[key].constructor != Array) result[key] = [result[key]]; + result[key].push(value); + } + else result[key] = value; + } + } + return result; + }); + + return getHash ? data : Hash.toQueryString(data); + } +}; + +Form.Methods = { + serialize: function(form, getHash) { + return Form.serializeElements(Form.getElements(form), getHash); + }, + + getElements: function(form) { + return $A($(form).getElementsByTagName('*')).inject([], + function(elements, child) { + if (Form.Element.Serializers[child.tagName.toLowerCase()]) + elements.push(Element.extend(child)); + return elements; + } + ); + }, + + getInputs: function(form, typeName, name) { + form = $(form); + var inputs = form.getElementsByTagName('input'); + + if (!typeName && !name) return $A(inputs).map(Element.extend); + + for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) { + var input = inputs[i]; + if ((typeName && input.type != typeName) || (name && input.name != name)) + continue; + matchingInputs.push(Element.extend(input)); + } + + return matchingInputs; + }, + + disable: function(form) { + form = $(form); + form.getElements().each(function(element) { + element.blur(); + element.disabled = 'true'; + }); + return form; + }, + + enable: function(form) { + form = $(form); + form.getElements().each(function(element) { + element.disabled = ''; + }); + return form; + }, + + findFirstElement: function(form) { + return $(form).getElements().find(function(element) { + return element.type != 'hidden' && !element.disabled && + ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); + }); + }, + + focusFirstElement: function(form) { + form = $(form); + form.findFirstElement().activate(); + return form; + } +} + +Object.extend(Form, Form.Methods); + +/*--------------------------------------------------------------------------*/ + +Form.Element = { + focus: function(element) { + $(element).focus(); + return element; + }, + + select: function(element) { + $(element).select(); + return element; + } +} + +Form.Element.Methods = { + serialize: function(element) { + element = $(element); + if (!element.disabled && element.name) { + var value = element.getValue(); + if (value != undefined) { + var pair = {}; + pair[element.name] = value; + return Hash.toQueryString(pair); + } + } + return ''; + }, + + getValue: function(element) { + element = $(element); + var method = element.tagName.toLowerCase(); + return Form.Element.Serializers[method](element); + }, + + clear: function(element) { + $(element).value = ''; + return element; + }, + + present: function(element) { + return $(element).value != ''; + }, + + activate: function(element) { + element = $(element); + element.focus(); + if (element.select && ( element.tagName.toLowerCase() != 'input' || + !['button', 'reset', 'submit'].include(element.type) ) ) + element.select(); + return element; + }, + + disable: function(element) { + element = $(element); + element.disabled = true; + return element; + }, + + enable: function(element) { + element = $(element); + element.blur(); + element.disabled = false; + return element; + } +} + +Object.extend(Form.Element, Form.Element.Methods); +var Field = Form.Element; +var $F = Form.Element.getValue; + +/*--------------------------------------------------------------------------*/ + +Form.Element.Serializers = { + input: function(element) { + switch (element.type.toLowerCase()) { + case 'checkbox': + case 'radio': + return Form.Element.Serializers.inputSelector(element); + default: + return Form.Element.Serializers.textarea(element); + } + }, + + inputSelector: function(element) { + return element.checked ? element.value : null; + }, + + textarea: function(element) { + return element.value; + }, + + select: function(element) { + return this[element.type == 'select-one' ? + 'selectOne' : 'selectMany'](element); + }, + + selectOne: function(element) { + var index = element.selectedIndex; + return index >= 0 ? this.optionValue(element.options[index]) : null; + }, + + selectMany: function(element) { + var values, length = element.length; + if (!length) return null; + + for (var i = 0, values = []; i < length; i++) { + var opt = element.options[i]; + if (opt.selected) values.push(this.optionValue(opt)); + } + return values; + }, + + optionValue: function(opt) { + // extend element because hasAttribute may not be native + return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text; + } +} + +/*--------------------------------------------------------------------------*/ + +Abstract.TimedObserver = function() {} +Abstract.TimedObserver.prototype = { + initialize: function(element, frequency, callback) { + this.frequency = frequency; + this.element = $(element); + this.callback = callback; + + this.lastValue = this.getValue(); + this.registerCallback(); + }, + + registerCallback: function() { + setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); + }, + + onTimerEvent: function() { + var value = this.getValue(); + var changed = ('string' == typeof this.lastValue && 'string' == typeof value + ? this.lastValue != value : String(this.lastValue) != String(value)); + if (changed) { + this.callback(this.element, value); + this.lastValue = value; + } + } +} + +Form.Element.Observer = Class.create(); +Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { + getValue: function() { + return Form.Element.getValue(this.element); + } +}); + +Form.Observer = Class.create(); +Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { + getValue: function() { + return Form.serialize(this.element); + } +}); + +/*--------------------------------------------------------------------------*/ + +Abstract.EventObserver = function() {} +Abstract.EventObserver.prototype = { + initialize: function(element, callback) { + this.element = $(element); + this.callback = callback; + + this.lastValue = this.getValue(); + if (this.element.tagName.toLowerCase() == 'form') + this.registerFormCallbacks(); + else + this.registerCallback(this.element); + }, + + onElementEvent: function() { + var value = this.getValue(); + if (this.lastValue != value) { + this.callback(this.element, value); + this.lastValue = value; + } + }, + + registerFormCallbacks: function() { + Form.getElements(this.element).each(this.registerCallback.bind(this)); + }, + + registerCallback: function(element) { + if (element.type) { + switch (element.type.toLowerCase()) { + case 'checkbox': + case 'radio': + Event.observe(element, 'click', this.onElementEvent.bind(this)); + break; + default: + Event.observe(element, 'change', this.onElementEvent.bind(this)); + break; + } + } + } +} + +Form.Element.EventObserver = Class.create(); +Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { + getValue: function() { + return Form.Element.getValue(this.element); + } +}); + +Form.EventObserver = Class.create(); +Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { + getValue: function() { + return Form.serialize(this.element); + } +}); +if (!window.Event) { + var Event = new Object(); +} + +Object.extend(Event, { + KEY_BACKSPACE: 8, + KEY_TAB: 9, + KEY_RETURN: 13, + KEY_ESC: 27, + KEY_LEFT: 37, + KEY_UP: 38, + KEY_RIGHT: 39, + KEY_DOWN: 40, + KEY_DELETE: 46, + KEY_HOME: 36, + KEY_END: 35, + KEY_PAGEUP: 33, + KEY_PAGEDOWN: 34, + + element: function(event) { + return event.target || event.srcElement; + }, + + isLeftClick: function(event) { + return (((event.which) && (event.which == 1)) || + ((event.button) && (event.button == 1))); + }, + + pointerX: function(event) { + return event.pageX || (event.clientX + + (document.documentElement.scrollLeft || document.body.scrollLeft)); + }, + + pointerY: function(event) { + return event.pageY || (event.clientY + + (document.documentElement.scrollTop || document.body.scrollTop)); + }, + + stop: function(event) { + if (event.preventDefault) { + event.preventDefault(); + event.stopPropagation(); + } else { + event.returnValue = false; + event.cancelBubble = true; + } + }, + + // find the first node with the given tagName, starting from the + // node the event was triggered on; traverses the DOM upwards + findElement: function(event, tagName) { + var element = Event.element(event); + while (element.parentNode && (!element.tagName || + (element.tagName.toUpperCase() != tagName.toUpperCase()))) + element = element.parentNode; + return element; + }, + + observers: false, + + _observeAndCache: function(element, name, observer, useCapture) { + if (!this.observers) this.observers = []; + if (element.addEventListener) { + this.observers.push([element, name, observer, useCapture]); + element.addEventListener(name, observer, useCapture); + } else if (element.attachEvent) { + this.observers.push([element, name, observer, useCapture]); + element.attachEvent('on' + name, observer); + } + }, + + unloadCache: function() { + if (!Event.observers) return; + for (var i = 0, length = Event.observers.length; i < length; i++) { + Event.stopObserving.apply(this, Event.observers[i]); + Event.observers[i][0] = null; + } + Event.observers = false; + }, + + observe: function(element, name, observer, useCapture) { + element = $(element); + useCapture = useCapture || false; + + if (name == 'keypress' && + (navigator.appVersion.match(/Konqueror|Safari|KHTML/) + || element.attachEvent)) + name = 'keydown'; + + Event._observeAndCache(element, name, observer, useCapture); + }, + + stopObserving: function(element, name, observer, useCapture) { + element = $(element); + useCapture = useCapture || false; + + if (name == 'keypress' && + (navigator.appVersion.match(/Konqueror|Safari|KHTML/) + || element.detachEvent)) + name = 'keydown'; + + if (element.removeEventListener) { + element.removeEventListener(name, observer, useCapture); + } else if (element.detachEvent) { + try { + element.detachEvent('on' + name, observer); + } catch (e) {} + } + } +}); + +/* prevent memory leaks in IE */ +if (navigator.appVersion.match(/\bMSIE\b/)) + Event.observe(window, 'unload', Event.unloadCache, false); +var Position = { + // set to true if needed, warning: firefox performance problems + // NOT neeeded for page scrolling, only if draggable contained in + // scrollable elements + includeScrollOffsets: false, + + // must be called before calling withinIncludingScrolloffset, every time the + // page is scrolled + prepare: function() { + this.deltaX = window.pageXOffset + || document.documentElement.scrollLeft + || document.body.scrollLeft + || 0; + this.deltaY = window.pageYOffset + || document.documentElement.scrollTop + || document.body.scrollTop + || 0; + }, + + realOffset: function(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.scrollTop || 0; + valueL += element.scrollLeft || 0; + element = element.parentNode; + } while (element); + return [valueL, valueT]; + }, + + cumulativeOffset: function(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + } while (element); + return [valueL, valueT]; + }, + + positionedOffset: function(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + if (element) { + if(element.tagName=='BODY') break; + var p = Element.getStyle(element, 'position'); + if (p == 'relative' || p == 'absolute') break; + } + } while (element); + return [valueL, valueT]; + }, + + offsetParent: function(element) { + if (element.offsetParent) return element.offsetParent; + if (element == document.body) return element; + + while ((element = element.parentNode) && element != document.body) + if (Element.getStyle(element, 'position') != 'static') + return element; + + return document.body; + }, + + // caches x/y coordinate pair to use with overlap + within: function(element, x, y) { + if (this.includeScrollOffsets) + return this.withinIncludingScrolloffsets(element, x, y); + this.xcomp = x; + this.ycomp = y; + this.offset = this.cumulativeOffset(element); + + return (y >= this.offset[1] && + y < this.offset[1] + element.offsetHeight && + x >= this.offset[0] && + x < this.offset[0] + element.offsetWidth); + }, + + withinIncludingScrolloffsets: function(element, x, y) { + var offsetcache = this.realOffset(element); + + this.xcomp = x + offsetcache[0] - this.deltaX; + this.ycomp = y + offsetcache[1] - this.deltaY; + this.offset = this.cumulativeOffset(element); + + return (this.ycomp >= this.offset[1] && + this.ycomp < this.offset[1] + element.offsetHeight && + this.xcomp >= this.offset[0] && + this.xcomp < this.offset[0] + element.offsetWidth); + }, + + // within must be called directly before + overlap: function(mode, element) { + if (!mode) return 0; + if (mode == 'vertical') + return ((this.offset[1] + element.offsetHeight) - this.ycomp) / + element.offsetHeight; + if (mode == 'horizontal') + return ((this.offset[0] + element.offsetWidth) - this.xcomp) / + element.offsetWidth; + }, + + page: function(forElement) { + var valueT = 0, valueL = 0; + + var element = forElement; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + + // Safari fix + if (element.offsetParent==document.body) + if (Element.getStyle(element,'position')=='absolute') break; + + } while (element = element.offsetParent); + + element = forElement; + do { + if (!window.opera || element.tagName=='BODY') { + valueT -= element.scrollTop || 0; + valueL -= element.scrollLeft || 0; + } + } while (element = element.parentNode); + + return [valueL, valueT]; + }, + + clone: function(source, target) { + var options = Object.extend({ + setLeft: true, + setTop: true, + setWidth: true, + setHeight: true, + offsetTop: 0, + offsetLeft: 0 + }, arguments[2] || {}) + + // find page position of source + source = $(source); + var p = Position.page(source); + + // find coordinate system to use + target = $(target); + var delta = [0, 0]; + var parent = null; + // delta [0,0] will do fine with position: fixed elements, + // position:absolute needs offsetParent deltas + if (Element.getStyle(target,'position') == 'absolute') { + parent = Position.offsetParent(target); + delta = Position.page(parent); + } + + // correct by body offsets (fixes Safari) + if (parent == document.body) { + delta[0] -= document.body.offsetLeft; + delta[1] -= document.body.offsetTop; + } + + // set position + if(options.setLeft) target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; + if(options.setTop) target.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; + if(options.setWidth) target.style.width = source.offsetWidth + 'px'; + if(options.setHeight) target.style.height = source.offsetHeight + 'px'; + }, + + absolutize: function(element) { + element = $(element); + if (element.style.position == 'absolute') return; + Position.prepare(); + + var offsets = Position.positionedOffset(element); + var top = offsets[1]; + var left = offsets[0]; + var width = element.clientWidth; + var height = element.clientHeight; + + element._originalLeft = left - parseFloat(element.style.left || 0); + element._originalTop = top - parseFloat(element.style.top || 0); + element._originalWidth = element.style.width; + element._originalHeight = element.style.height; + + element.style.position = 'absolute'; + element.style.top = top + 'px'; + element.style.left = left + 'px'; + element.style.width = width + 'px'; + element.style.height = height + 'px'; + }, + + relativize: function(element) { + element = $(element); + if (element.style.position == 'relative') return; + Position.prepare(); + + element.style.position = 'relative'; + var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); + var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); + + element.style.top = top + 'px'; + element.style.left = left + 'px'; + element.style.height = element._originalHeight; + element.style.width = element._originalWidth; + } +} + +// Safari returns margins on body which is incorrect if the child is absolutely +// positioned. For performance reasons, redefine Position.cumulativeOffset for +// KHTML/WebKit only. +if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) { + Position.cumulativeOffset = function(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + if (element.offsetParent == document.body) + if (Element.getStyle(element, 'position') == 'absolute') break; + + element = element.offsetParent; + } while (element); + + return [valueL, valueT]; + } +} + +Element.addMethods(); \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/robots.txt b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/robots.txt new file mode 100644 index 00000000..4ab9e89f --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/stylesheets/scaffold.css b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/stylesheets/scaffold.css new file mode 100644 index 00000000..8f239a35 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/public/stylesheets/scaffold.css @@ -0,0 +1,74 @@ +body { background-color: #fff; color: #333; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { color: #000; } +a:visited { color: #666; } +a:hover { color: #fff; background-color:#000; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + +div.uploadStatus { + margin: 5px; +} + +div.progressBar { + margin: 5px; +} + +div.progressBar div.border { + background-color: #fff; + border: 1px solid grey; + width: 100%; +} + +div.progressBar div.background { + background-color: #333; + height: 18px; + width: 0%; +} + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/about b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/about new file mode 100755 index 00000000..7b07d46a --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/about @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/about' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/breakpointer b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/breakpointer new file mode 100755 index 00000000..64af76ed --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/breakpointer @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/breakpointer' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/console b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/console new file mode 100755 index 00000000..42f28f7d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/console @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/console' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/destroy b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/destroy new file mode 100755 index 00000000..fa0e6fcd --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/destroy @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/destroy' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/generate b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/generate new file mode 100755 index 00000000..ef976e09 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/generate @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/generate' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/benchmarker b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/benchmarker new file mode 100755 index 00000000..c842d35d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/benchmarker @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/performance/benchmarker' diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/profiler b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/profiler new file mode 100755 index 00000000..d855ac8b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/performance/profiler @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/performance/profiler' diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/plugin b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/plugin new file mode 100755 index 00000000..26ca64c0 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/plugin @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/plugin' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/inspector b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/inspector new file mode 100755 index 00000000..bf25ad86 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/inspector @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/inspector' diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/reaper b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/reaper new file mode 100755 index 00000000..c77f0453 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/reaper @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/reaper' diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/spawner b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/spawner new file mode 100755 index 00000000..7118f398 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/process/spawner @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/spawner' diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/runner b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/runner new file mode 100755 index 00000000..ccc30f9d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/runner @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/runner' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/server b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/server new file mode 100755 index 00000000..dfabcb88 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/script/server @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/server' \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parent_relationships.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parent_relationships.yml new file mode 100644 index 00000000..5bf02933 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parent_relationships.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parents.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parents.yml new file mode 100644 index 00000000..5bf02933 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/double_sti_parents.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/organic_substances.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/organic_substances.yml new file mode 100644 index 00000000..123ef537 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/organic_substances.yml @@ -0,0 +1,5 @@ +one: + type: Bone + +two: + type: Bone diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parent_relationships.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parent_relationships.yml new file mode 100644 index 00000000..5bf02933 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parent_relationships.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parents.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parents.yml new file mode 100644 index 00000000..5bf02933 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/single_sti_parents.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/sticks.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/sticks.yml new file mode 100644 index 00000000..157d7472 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/sticks.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + +two: + name: MyString diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/stones.yml b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/stones.yml new file mode 100644 index 00000000..157d7472 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/fixtures/stones.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + +two: + name: MyString diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/addresses_controller_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/addresses_controller_test.rb new file mode 100644 index 00000000..65284b5b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/addresses_controller_test.rb @@ -0,0 +1,57 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'addresses_controller' + +# Re-raise errors caught by the controller. +class AddressesController; def rescue_action(e) raise e end; end + +class AddressesControllerTest < Test::Unit::TestCase + fixtures :addresses + + def setup + @controller = AddressesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_should_get_index + get :index + assert_response :success + assert assigns(:addresses) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_address + assert_difference('Address.count') do + post :create, :address => { :country_id => 1, :user_id => 1, :state_id => 1} + end + + assert_redirected_to address_path(assigns(:address)) + end + + def test_should_show_address + get :show, :id => 1 + assert_response :success + end + + def test_should_get_edit + get :edit, :id => 1 + assert_response :success + end + + def test_should_update_address + put :update, :id => 1, :address => { } + assert_redirected_to address_path(assigns(:address)) + end + + def test_should_destroy_address + assert_difference('Address.count', -1) do + delete :destroy, :id => 1 + end + + assert_redirected_to addresses_path + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/bones_controller_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/bones_controller_test.rb new file mode 100644 index 00000000..fc0c7bd8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/bones_controller_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BonesControllerTest < ActionController::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/sellers_controller_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/sellers_controller_test.rb new file mode 100644 index 00000000..fb992e5d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/sellers_controller_test.rb @@ -0,0 +1,57 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'sellers_controller' + +# Re-raise errors caught by the controller. +class SellersController; def rescue_action(e) raise e end; end + +class SellersControllerTest < Test::Unit::TestCase + fixtures :sellers + + def setup + @controller = SellersController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_should_get_index + get :index + assert_response :success + assert assigns(:sellers) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_seller + assert_difference('Seller.count') do + post :create, :seller => { } + end + + assert_redirected_to seller_path(assigns(:seller)) + end + + def test_should_show_seller + get :show, :id => 1 + assert_response :success + end + + def test_should_get_edit + get :edit, :id => 1 + assert_response :success + end + + def test_should_update_seller + put :update, :id => 1, :seller => { } + assert_redirected_to seller_path(assigns(:seller)) + end + + def test_should_destroy_seller + assert_difference('Seller.count', -1) do + delete :destroy, :id => 1 + end + + assert_redirected_to sellers_path + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/states_controller_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/states_controller_test.rb new file mode 100644 index 00000000..2e93453b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/states_controller_test.rb @@ -0,0 +1,57 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'states_controller' + +# Re-raise errors caught by the controller. +class StatesController; def rescue_action(e) raise e end; end + +class StatesControllerTest < Test::Unit::TestCase + fixtures :states + + def setup + @controller = StatesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_should_get_index + get :index + assert_response :success + assert assigns(:states) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_state + assert_difference('State.count') do + post :create, :state => { } + end + + assert_redirected_to state_path(assigns(:state)) + end + + def test_should_show_state + get :show, :id => 1 + assert_response :success + end + + def test_should_get_edit + get :edit, :id => 1 + assert_response :success + end + + def test_should_update_state + put :update, :id => 1, :state => { } + assert_redirected_to state_path(assigns(:state)) + end + + def test_should_destroy_state + assert_difference('State.count', -1) do + delete :destroy, :id => 1 + end + + assert_redirected_to states_path + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/users_controller_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/users_controller_test.rb new file mode 100644 index 00000000..bc36751f --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/functional/users_controller_test.rb @@ -0,0 +1,57 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'users_controller' + +# Re-raise errors caught by the controller. +class UsersController; def rescue_action(e) raise e end; end + +class UsersControllerTest < Test::Unit::TestCase + fixtures :users + + def setup + @controller = UsersController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_should_get_index + get :index + assert_response :success + assert assigns(:users) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_user + assert_difference('User.count') do + post :create, :user => { } + end + + assert_redirected_to user_path(assigns(:user)) + end + + def test_should_show_user + get :show, :id => 1 + assert_response :success + end + + def test_should_get_edit + get :edit, :id => 1 + assert_response :success + end + + def test_should_update_user + put :update, :id => 1, :user => { } + assert_redirected_to user_path(assigns(:user)) + end + + def test_should_destroy_user + assert_difference('User.count', -1) do + delete :destroy, :id => 1 + end + + assert_redirected_to users_path + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/test_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/test_helper.rb new file mode 100644 index 00000000..773c49de --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/test_helper.rb @@ -0,0 +1,8 @@ +ENV["RAILS_ENV"] = "development" +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +require 'test_help' + +class Test::Unit::TestCase + self.use_transactional_fixtures = true + self.use_instantiated_fixtures = false +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/bone_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/bone_test.rb new file mode 100644 index 00000000..8afcb87b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/bone_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BoneTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_relationship_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_relationship_test.rb new file mode 100644 index 00000000..dc20e74d --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_relationship_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class DoubleStiParentRelationshipTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_test.rb new file mode 100644 index 00000000..154383a2 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/double_sti_parent_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class DoubleStiParentTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/organic_substance_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/organic_substance_test.rb new file mode 100644 index 00000000..af328b95 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/organic_substance_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class OrganicSubstanceTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_relationship_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_relationship_test.rb new file mode 100644 index 00000000..d5563fd8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_relationship_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class SingleStiParentRelationshipTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_test.rb new file mode 100644 index 00000000..70a00ecb --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/single_sti_parent_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class SingleStiParentTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stick_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stick_test.rb new file mode 100644 index 00000000..6729e0d6 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stick_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class StickTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stone_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stone_test.rb new file mode 100644 index 00000000..76b518d7 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/app/test/unit/stone_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class StoneTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/integration/server_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/integration/server_test.rb new file mode 100644 index 00000000..e53ea1aa --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/integration/server_test.rb @@ -0,0 +1,43 @@ + +require "#{File.dirname(__FILE__)}/../test_helper" +require 'open-uri' + +# Start the server + +class ServerTest < Test::Unit::TestCase + + PORT = 43040 + URL = "http://localhost:#{PORT}/" + + def setup + @pid = Process.fork do + Dir.chdir RAILS_ROOT do + # print "S" + exec("script/server -p #{PORT} &> #{LOG}") + end + end + sleep(5) + end + + def teardown + # Process.kill(9, @pid) doesn't work because Mongrel has double-forked itself away + `ps awx | grep #{PORT} | grep -v grep | awk '{print $1}'`.split("\n").each do |pid| + system("kill -9 #{pid}") + # print "K" + end + sleep(2) + @pid = nil + end + + def test_association_reloading + assert_match(/Bones: index/, open(URL + 'bones').read) + assert_match(/Bones: index/, open(URL + 'bones').read) + assert_match(/Bones: index/, open(URL + 'bones').read) + assert_match(/Bones: index/, open(URL + 'bones').read) + end + + def test_verify_autoload_gets_invoked_in_console + # XXX Probably can use script/runner to test this + end + +end \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/fish.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/fish.rb new file mode 100644 index 00000000..204642e9 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/fish.rb @@ -0,0 +1,5 @@ +class Aquatic::Fish < ActiveRecord::Base + # set_table_name "fish" + # attr_accessor :after_find_test, :after_initialize_test +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/pupils_whale.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/pupils_whale.rb new file mode 100644 index 00000000..ae4cbc18 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/pupils_whale.rb @@ -0,0 +1,7 @@ + +class Aquatic::PupilsWhale < ActiveRecord::Base + set_table_name "little_whale_pupils" + belongs_to :whale, :class_name => "Aquatic::Whale", :foreign_key => "whale_id" + belongs_to :aquatic_pupil, :polymorphic => true +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/whale.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/whale.rb new file mode 100644 index 00000000..0ca1b7fb --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/aquatic/whale.rb @@ -0,0 +1,15 @@ +# see http://dev.rubyonrails.org/ticket/5935 +module Aquatic; end +require 'aquatic/fish' +require 'aquatic/pupils_whale' + +class Aquatic::Whale < ActiveRecord::Base + # set_table_name "whales" + + has_many_polymorphs(:aquatic_pupils, :from => [:dogs, :"aquatic/fish"], + :through => "aquatic/pupils_whales") do + def a_method + :correct_block_result + end + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/beautiful_fight_relationship.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/beautiful_fight_relationship.rb new file mode 100644 index 00000000..b678c982 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/beautiful_fight_relationship.rb @@ -0,0 +1,26 @@ + +require 'extension_module' + +class BeautifulFightRelationship < ActiveRecord::Base + set_table_name 'keep_your_enemies_close' + + belongs_to :enemy, :polymorphic => true + belongs_to :protector, :polymorphic => true + # polymorphic relationships with column names different from the relationship name + # are not supported by Rails + + acts_as_double_polymorphic_join :enemies => [:dogs, :kittens, :frogs], + :protectors => [:wild_boars, :kittens, :"aquatic/fish", :dogs], + :enemies_extend => [ExtensionModule, proc {}], + :protectors_extend => proc { + def a_method + :correct_proc_result + end + }, + :join_extend => proc { + def a_method + :correct_join_result + end + } +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/canine.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/canine.rb new file mode 100644 index 00000000..b0010160 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/canine.rb @@ -0,0 +1,9 @@ +class Canine < ActiveRecord::Base + self.abstract_class = true + + def an_abstract_method + :correct_abstract_method_response + end + +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/cat.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/cat.rb new file mode 100644 index 00000000..0c99ff08 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/cat.rb @@ -0,0 +1,5 @@ +class Cat < ActiveRecord::Base + # STI base class + self.inheritance_column = 'cat_type' +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/dog.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/dog.rb new file mode 100644 index 00000000..7f027237 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/dog.rb @@ -0,0 +1,18 @@ + +require 'canine' + +class Dog < Canine + attr_accessor :after_find_test, :after_initialize_test + set_table_name "bow_wows" + + def after_find + @after_find_test = true +# puts "After find called on #{name}." + end + + def after_initialize + @after_initialize_test = true + end + +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/eaters_foodstuff.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/eaters_foodstuff.rb new file mode 100644 index 00000000..d904bb16 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/eaters_foodstuff.rb @@ -0,0 +1,10 @@ + +class EatersFoodstuff < ActiveRecord::Base + belongs_to :foodstuff, :class_name => "Petfood", :foreign_key => "foodstuff_id" + belongs_to :eater, :polymorphic => true + + def before_save + self.some_attribute = 3 + end +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/frog.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/frog.rb new file mode 100644 index 00000000..5a0f4658 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/frog.rb @@ -0,0 +1,4 @@ +class Frog < ActiveRecord::Base + +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/kitten.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/kitten.rb new file mode 100644 index 00000000..2a244c03 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/kitten.rb @@ -0,0 +1,3 @@ +class Kitten < Cat +# has_many :eaters_parents, :dependent => true, :as => 'eater' +end \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/parentship.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/parentship.rb new file mode 100644 index 00000000..e87b759b --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/parentship.rb @@ -0,0 +1,4 @@ +class Parentship < ActiveRecord::Base + belongs_to :parent, :class_name => "Person", :foreign_key => "parent_id" + belongs_to :kid, :polymorphic => true, :foreign_type => "child_type" +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/person.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/person.rb new file mode 100644 index 00000000..5d019829 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/person.rb @@ -0,0 +1,9 @@ +require 'parentship' +class Person < ActiveRecord::Base + has_many_polymorphs :kids, + :through => :parentships, + :from => [:people], + :as => :parent, + :polymorphic_type_key => "child_type", + :conditions => "people.age < 10" +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/petfood.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/petfood.rb new file mode 100644 index 00000000..df420ea8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/petfood.rb @@ -0,0 +1,39 @@ +# see http://dev.rubyonrails.org/ticket/5935 +require 'eaters_foodstuff' +require 'petfood' +require 'cat' +module Aquatic; end +require 'aquatic/fish' +require 'dog' +require 'wild_boar' +require 'kitten' +require 'tabby' +require 'extension_module' +require 'other_extension_module' + +class Petfood < ActiveRecord::Base + set_primary_key 'the_petfood_primary_key' + has_many_polymorphs :eaters, + :from => [:dogs, :petfoods, :wild_boars, :kittens, + :tabbies, :"aquatic/fish"], +# :dependent => :destroy, :destroy is now the default + :rename_individual_collections => true, + :as => :foodstuff, + :foreign_key => "foodstuff_id", + :ignore_duplicates => false, + :conditions => "NULL IS NULL", + :order => "eaters_foodstuffs.updated_at ASC", + :parent_order => "petfoods.the_petfood_primary_key DESC", + :parent_conditions => "petfoods.name IS NULL OR petfoods.name != 'Snausages'", + :extend => [ExtensionModule, OtherExtensionModule, proc {}], + :join_extend => proc { + def a_method + :correct_join_result + end + }, + :parent_extend => proc { + def a_method + :correct_parent_proc_result + end + } + end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/tabby.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/tabby.rb new file mode 100644 index 00000000..3cd0f994 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/tabby.rb @@ -0,0 +1,2 @@ +class Tabby < Cat +end \ No newline at end of file diff --git a/vendor/gems/has_many_polymorphs-2.13/test/models/wild_boar.rb b/vendor/gems/has_many_polymorphs-2.13/test/models/wild_boar.rb new file mode 100644 index 00000000..27d36a53 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/models/wild_boar.rb @@ -0,0 +1,3 @@ +class WildBoar < ActiveRecord::Base +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/modules/extension_module.rb b/vendor/gems/has_many_polymorphs-2.13/test/modules/extension_module.rb new file mode 100644 index 00000000..7cb4eff4 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/modules/extension_module.rb @@ -0,0 +1,9 @@ + +module ExtensionModule + def a_method + :correct_module_result + end + def self.a_method + :incorrect_module_result + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/modules/other_extension_module.rb b/vendor/gems/has_many_polymorphs-2.13/test/modules/other_extension_module.rb new file mode 100644 index 00000000..16313bd8 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/modules/other_extension_module.rb @@ -0,0 +1,9 @@ + +module OtherExtensionModule + def another_method + :correct_other_module_result + end + def self.another_method + :incorrect_other_module_result + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/patches/symlinked_plugins_1.2.6.diff b/vendor/gems/has_many_polymorphs-2.13/test/patches/symlinked_plugins_1.2.6.diff new file mode 100644 index 00000000..99e0df3e --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/patches/symlinked_plugins_1.2.6.diff @@ -0,0 +1,46 @@ +Index: /trunk/railties/lib/rails_generator/lookup.rb +=================================================================== +--- /trunk/railties/lib/rails_generator/lookup.rb (revision 4310) ++++ /trunk/railties/lib/rails_generator/lookup.rb (revision 6101) +@@ -101,5 +101,5 @@ + sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators") + sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators") +- sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/**/generators") ++ sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/generators") + end + sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") +Index: /trunk/railties/lib/tasks/rails.rb +=================================================================== +--- /trunk/railties/lib/tasks/rails.rb (revision 5469) ++++ /trunk/railties/lib/tasks/rails.rb (revision 6101) +@@ -6,3 +6,3 @@ + # Load any custom rakefile extensions + Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } +-Dir["#{RAILS_ROOT}/vendor/plugins/**/tasks/**/*.rake"].sort.each { |ext| load ext } ++Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext } +Index: /trunk/railties/lib/tasks/testing.rake +=================================================================== +--- /trunk/railties/lib/tasks/testing.rake (revision 5263) ++++ /trunk/railties/lib/tasks/testing.rake (revision 6101) +@@ -109,9 +109,9 @@ + t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb" + else +- t.pattern = 'vendor/plugins/**/test/**/*_test.rb' ++ t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb' + end + + t.verbose = true + end +- Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)" ++ Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)" + end +Index: /trunk/railties/CHANGELOG +=================================================================== +--- /trunk/railties/CHANGELOG (revision 6069) ++++ /trunk/railties/CHANGELOG (revision 6101) +@@ -1,3 +1,5 @@ + *SVN* ++ ++* Plugins may be symlinked in vendor/plugins. #4245 [brandon, progrium@gmail.com] + + * Resource generator depends on the model generator rather than duplicating it. #7269 [bscofield] diff --git a/vendor/gems/has_many_polymorphs-2.13/test/schema.rb b/vendor/gems/has_many_polymorphs-2.13/test/schema.rb new file mode 100644 index 00000000..39d869dc --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/schema.rb @@ -0,0 +1,87 @@ +ActiveRecord::Schema.define(:version => 0) do + create_table :petfoods, :force => true, :primary_key => :the_petfood_primary_key do |t| + t.column :name, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :bow_wows, :force => true do |t| + t.column :name, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :cats, :force => true do |t| + t.column :name, :string + t.column :cat_type, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :frogs, :force => true do |t| + t.column :name, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :wild_boars, :force => true do |t| + t.column :name, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :eaters_foodstuffs, :force => true do |t| + t.column :foodstuff_id, :integer + t.column :eater_id, :integer + t.column :some_attribute, :integer, :default => 0 + t.column :eater_type, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :fish, :force => true do |t| + t.column :name, :string + t.column :speed, :integer + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :whales, :force => true do |t| + t.column :name, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :little_whale_pupils, :force => true do |t| + t.column :whale_id, :integer + t.column :aquatic_pupil_id, :integer + t.column :aquatic_pupil_type, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :keep_your_enemies_close, :force => true do |t| + t.column :enemy_id, :integer + t.column :enemy_type, :string + t.column :protector_id, :integer + t.column :protector_type, :string + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :parentships, :force => true do |t| + t.column :parent_id, :integer + t.column :child_type, :string + t.column :kid_id, :integer + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + + create_table :people, :force => true do |t| + t.column :name, :string + t.column :age, :integer + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/setup.rb b/vendor/gems/has_many_polymorphs-2.13/test/setup.rb new file mode 100644 index 00000000..52535798 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/setup.rb @@ -0,0 +1,14 @@ + +# Setup integration system for the integration suite + +Dir.chdir "#{File.dirname(__FILE__)}/integration/app/" do + Dir.chdir "vendor/plugins" do + system("rm has_many_polymorphs; ln -s ../../../../../ has_many_polymorphs") + end + + system "rake db:drop --trace RAILS_GEM_VERSION=2.2.2 " + system "rake db:create --trace RAILS_GEM_VERSION=2.2.2 " + system "rake db:migrate --trace" + system "rake db:fixtures:load --trace" +end + diff --git a/vendor/gems/has_many_polymorphs-2.13/test/test_helper.rb b/vendor/gems/has_many_polymorphs-2.13/test/test_helper.rb new file mode 100644 index 00000000..363a6607 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/test_helper.rb @@ -0,0 +1,51 @@ + +$VERBOSE = nil +require 'rubygems' +require 'echoe' +require 'test/unit' +require 'multi_rails_init' +require 'ruby-debug' + +if defined? ENV['MULTIRAILS_RAILS_VERSION'] + ENV['RAILS_GEM_VERSION'] = ENV['MULTIRAILS_RAILS_VERSION'] +end + +Echoe.silence do + HERE = File.expand_path(File.dirname(__FILE__)) + $LOAD_PATH << HERE + # $LOAD_PATH << "#{HERE}/integration/app" +end + +LOG = "#{HERE}/integration/app/log/development.log" + +### For unit tests + +require 'integration/app/config/environment' +require 'test_help' + +ActiveSupport::Inflector.inflections {|i| i.irregular 'fish', 'fish' } + +$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path = HERE + "/fixtures") +$LOAD_PATH.unshift(HERE + "/models") +$LOAD_PATH.unshift(HERE + "/modules") + +class Test::Unit::TestCase + self.use_transactional_fixtures = !(ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false) + self.use_instantiated_fixtures = false +end + +Echoe.silence do + load(HERE + "/schema.rb") +end + +### For integration tests + +def truncate + system("> #{LOG}") +end + +def log + File.open(LOG, 'r') do |f| + f.read + end +end diff --git a/vendor/gems/has_many_polymorphs-2.13/test/unit/has_many_polymorphs_test.rb b/vendor/gems/has_many_polymorphs-2.13/test/unit/has_many_polymorphs_test.rb new file mode 100644 index 00000000..7f4b05a4 --- /dev/null +++ b/vendor/gems/has_many_polymorphs-2.13/test/unit/has_many_polymorphs_test.rb @@ -0,0 +1,714 @@ +require File.dirname(__FILE__) + '/../test_helper' + +require 'dog' +require 'wild_boar' +require 'frog' +require 'cat' +require 'kitten' +require 'aquatic/whale' +require 'aquatic/fish' +require 'aquatic/pupils_whale' +require 'beautiful_fight_relationship' + +class PolymorphTest < Test::Unit::TestCase + + set_fixture_class :bow_wows => Dog + set_fixture_class :keep_your_enemies_close => BeautifulFightRelationship + set_fixture_class :whales => Aquatic::Whale + set_fixture_class :fish => Aquatic::Fish + set_fixture_class :little_whale_pupils => Aquatic::PupilsWhale + + fixtures :cats, :bow_wows, :frogs, :wild_boars, :eaters_foodstuffs, :petfoods, + :fish, :whales, :little_whale_pupils, :keep_your_enemies_close, :people + + def setup + @association_error = ActiveRecord::Associations::PolymorphicError + @kibbles = Petfood.find(1) + @bits = Petfood.find(2) + @shamu = Aquatic::Whale.find(1) + @swimmy = Aquatic::Fish.find(1) + @rover = Dog.find(1) + @spot = Dog.find(2) + @puma = WildBoar.find(1) + @chloe = Kitten.find(1) + @alice = Kitten.find(2) + @toby = Tabby.find(3) + @froggy = Frog.find(1) + + @join_count = EatersFoodstuff.count + @kibbles_eaters_count = @kibbles.eaters.size + @bits_eaters_count = @bits.eaters.size + + @double_join_count = BeautifulFightRelationship.count + @alice_enemies_count = @alice.enemies.size + end + + def test_all_relationship_validities + # q = [] + # ObjectSpace.each_object(Class){|c| q << c if c.ancestors.include? ActiveRecord::Base } + # q.each{|c| puts "#{c.name}.reflect_on_all_associations.map(&:check_validity!)"} + Petfood.reflect_on_all_associations.map(&:check_validity!) + Tabby.reflect_on_all_associations.map(&:check_validity!) + Kitten.reflect_on_all_associations.map(&:check_validity!) + Dog.reflect_on_all_associations.map(&:check_validity!) + Canine.reflect_on_all_associations.map(&:check_validity!) + Aquatic::Fish.reflect_on_all_associations.map(&:check_validity!) + EatersFoodstuff.reflect_on_all_associations.map(&:check_validity!) + WildBoar.reflect_on_all_associations.map(&:check_validity!) + Frog.reflect_on_all_associations.map(&:check_validity!) + Cat.reflect_on_all_associations.map(&:check_validity!) + BeautifulFightRelationship.reflect_on_all_associations.map(&:check_validity!) + Person.reflect_on_all_associations.map(&:check_validity!) + Parentship.reflect_on_all_associations.map(&:check_validity!) + Aquatic::Whale.reflect_on_all_associations.map(&:check_validity!) + Aquatic::PupilsWhale.reflect_on_all_associations.map(&:check_validity!) + end + + def test_assignment + assert @kibbles.eaters.blank? + assert @kibbles.eaters.push(Cat.find_by_name('Chloe')) + assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count + + @kibbles.reload + assert_equal @kibbles_eaters_count, @kibbles.eaters.count + end + + def test_duplicate_assignment + # try to add a duplicate item when :ignore_duplicates is false + @kibbles.eaters.push(@alice) + assert @kibbles.eaters.include?(@alice) + @kibbles.eaters.push(@alice) + assert_equal @kibbles_eaters_count + 2, @kibbles.eaters.count + assert_equal @join_count + 2, EatersFoodstuff.count + end + + def test_create_and_push + assert @kibbles.eaters.push(@spot) + assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count + assert @kibbles.eaters << @rover + assert @kibbles.eaters << Kitten.create(:name => "Miranda") + assert_equal @kibbles_eaters_count += 2, @kibbles.eaters.length + + @kibbles.reload + assert_equal @kibbles_eaters_count, @kibbles.eaters.length + + # test that ids and new flags were set appropriately + assert_not_nil @kibbles.eaters[0].id + assert !@kibbles.eaters[1].new_record? + end + + def test_reload + assert @kibbles.reload + assert @kibbles.eaters.reload + end + + def test_add_join_record + assert_equal Kitten, @chloe.class + assert join = EatersFoodstuff.new(:foodstuff_id => @bits.id, :eater_id => @chloe.id, :eater_type => @chloe.class.name ) + assert join.save! + assert join.id + assert_equal @join_count + 1, EatersFoodstuff.count + + #assert_equal @bits_eaters_count, @bits.eaters.size # Doesn't behave this way on latest edge anymore + assert_equal @bits_eaters_count + 1, @bits.eaters.count # SQL + + # reload; is the new association there? + assert @bits.eaters.reload + assert @bits.eaters.include?(@chloe) + end + + def test_build_join_record_on_association + assert_equal Kitten, @chloe.class + assert join = @chloe.eaters_foodstuffs.build(:foodstuff => @bits) + # assert_equal join.eater_type, @chloe.class.name # will be STI parent type + assert join.save! + assert join.id + assert_equal @join_count + 1, EatersFoodstuff.count + + assert @bits.eaters.reload + assert @bits.eaters.include?(@chloe) + end + +# not supporting this, since has_many :through doesn't support it either +# def test_add_unsaved +# # add an unsaved item +# assert @bits.eaters << Kitten.new(:name => "Bridget") +# assert_nil Kitten.find_by_name("Bridget") +# assert_equal @bits_eaters_count + 1, @bits.eaters.count +# +# assert @bits.save +# @bits.reload +# assert_equal @bits_eaters_count + 1, @bits.eaters.count +# +# end + + def test_self_reference + assert @kibbles.eaters << @bits + assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count + assert @kibbles.eaters.include?(@bits) + @kibbles.reload + assert @kibbles.foodstuffs_of_eaters.blank? + + @bits.reload + assert @bits.foodstuffs_of_eaters.include?(@kibbles) + assert_equal [@kibbles], @bits.foodstuffs_of_eaters + end + + def test_remove + assert @kibbles.eaters << @chloe + @kibbles.reload + assert @kibbles.eaters.delete(@kibbles.eaters[0]) + assert_equal @kibbles_eaters_count, @kibbles.eaters.count + end + + def test_destroy + assert @kibbles.eaters.push(@chloe) + @kibbles.reload + assert @kibbles.eaters.length > 0 + assert @kibbles.eaters[0].destroy + @kibbles.reload + assert_equal @kibbles_eaters_count, @kibbles.eaters.count + end + + def test_clear + @kibbles.eaters << [@chloe, @spot, @rover] + @kibbles.reload + assert @kibbles.eaters.clear.blank? + assert @kibbles.eaters.blank? + @kibbles.reload + assert @kibbles.eaters.blank? + end + + def test_individual_collections + assert @kibbles.eaters.push(@chloe) + # check if individual collections work + assert_equal @kibbles.eater_kittens.length, 1 + assert @kibbles.eater_dogs + assert 1, @rover.eaters_foodstuffs.count + end + + def test_individual_collections_push + assert_equal [@chloe], (@kibbles.eater_kittens << @chloe) + @kibbles.reload + assert @kibbles.eaters.include?(@chloe) + assert @kibbles.eater_kittens.include?(@chloe) + assert !@kibbles.eater_dogs.include?(@chloe) + end + + def test_individual_collections_delete + @kibbles.eaters << [@chloe, @spot, @rover] + @kibbles.reload + assert_equal [@chloe], @kibbles.eater_kittens.delete(@chloe) + assert @kibbles.eater_kittens.empty? + @kibbles.eater_kittens.delete(@chloe) # what should this return? + + @kibbles.reload + assert @kibbles.eater_kittens.empty? + assert @kibbles.eater_dogs.include?(@spot) + end + + def test_individual_collections_clear + @kibbles.eaters << [@chloe, @spot, @rover] + @kibbles.reload + + assert_equal [], @kibbles.eater_kittens.clear + assert @kibbles.eater_kittens.empty? + assert_equal 2, @kibbles.eaters.size + + assert @kibbles.eater_kittens.empty? + assert_equal 2, @kibbles.eaters.size + assert !@kibbles.eater_kittens.include?(@chloe) + assert !@kibbles.eaters.include?(@chloe) + + @kibbles.reload + assert @kibbles.eater_kittens.empty? + assert_equal 2, @kibbles.eaters.size + assert !@kibbles.eater_kittens.include?(@chloe) + assert !@kibbles.eaters.include?(@chloe) + end + + def test_childrens_individual_collections + assert Cat.find_by_name('Chloe').eaters_foodstuffs + assert @kibbles.eaters_foodstuffs + end + + def test_self_referential_join_tables + # check that the self-reference join tables go the right ways + assert_equal @kibbles_eaters_count, @kibbles.eaters_foodstuffs.count + assert_equal @kibbles.eaters_foodstuffs.count, @kibbles.eaters_foodstuffs_as_child.count + end + + def test_dependent + assert @kibbles.eaters << @chloe + @kibbles.reload + + # delete ourself and see if :dependent was obeyed + dependent_rows = @kibbles.eaters_foodstuffs + assert_equal dependent_rows.length, @kibbles.eaters.count + @join_count = EatersFoodstuff.count + + @kibbles.destroy + assert_equal @join_count - dependent_rows.length, EatersFoodstuff.count + assert_equal 0, EatersFoodstuff.find(:all, :conditions => ['foodstuff_id = ?', 1] ).length + end + + def test_normal_callbacks + assert @rover.respond_to?(:after_initialize) + assert @rover.respond_to?(:after_find) + assert @rover.after_initialize_test + assert @rover.after_find_test + end + + def test_model_callbacks_not_overridden_by_plugin_callbacks + assert 0, @bits.eaters.count + assert @bits.eaters.push(@rover) + @bits.save + @bits2 = Petfood.find_by_name("Bits") + @bits.reload + assert rover = @bits2.eaters.select { |x| x.name == "Rover" }[0] + assert rover.after_initialize_test + assert rover.after_find_test + end + + def test_number_of_join_records + assert EatersFoodstuff.create(:foodstuff_id => 1, :eater_id => 1, :eater_type => "Cat") + @join_count = EatersFoodstuff.count + assert @join_count > 0 + end + + def test_number_of_regular_records + dogs = Dog.count + assert Dog.new(:name => "Auggie").save! + assert dogs + 1, Dog.count + end + + def test_attributes_come_through_when_child_has_underscore_in_table_name + join = EatersFoodstuff.new(:foodstuff_id => @bits.id, :eater_id => @puma.id, :eater_type => @puma.class.name) + join.save! + + @bits.eaters.reload + + assert_equal "Puma", @puma.name + assert_equal "Puma", @bits.eaters.first.name + end + + + def test_before_save_on_join_table_is_not_clobbered_by_sti_base_class_fix + assert @kibbles.eaters << @chloe + assert_equal 3, @kibbles.eaters_foodstuffs.first.some_attribute + end + + def test_sti_type_counts_are_correct + @kibbles.eaters << [@chloe, @alice, @toby] + assert_equal 2, @kibbles.eater_kittens.count + assert_equal 1, @kibbles.eater_tabbies.count + assert !@kibbles.respond_to?(:eater_cats) + end + + + def test_creating_namespaced_relationship + assert @shamu.aquatic_pupils.empty? + @shamu.aquatic_pupils << @swimmy + assert_equal 1, @shamu.aquatic_pupils.length + @shamu.reload + assert_equal 1, @shamu.aquatic_pupils.length + end + + def test_namespaced_polymorphic_collection + @shamu.aquatic_pupils << @swimmy + assert @shamu.aquatic_pupils.include?(@swimmy) + @shamu.reload + assert @shamu.aquatic_pupils.include?(@swimmy) + + @shamu.aquatic_pupils << @spot + assert @shamu.dogs.include?(@spot) + assert @shamu.aquatic_pupils.include?(@swimmy) + assert_equal @swimmy, @shamu.aquatic_fish.first + assert_equal 10, @shamu.aquatic_fish.first.speed + end + + def test_deleting_namespaced_relationship + @shamu.aquatic_pupils << @swimmy + @shamu.aquatic_pupils << @spot + + @shamu.reload + @shamu.aquatic_pupils.delete @spot + assert !@shamu.dogs.include?(@spot) + assert !@shamu.aquatic_pupils.include?(@spot) + assert_equal 1, @shamu.aquatic_pupils.length + end + + def test_unrenamed_parent_of_namespaced_child + @shamu.aquatic_pupils << @swimmy + assert_equal [@shamu], @swimmy.whales + end + + def test_empty_double_collections + assert @puma.enemies.empty? + assert @froggy.protectors.empty? + assert @alice.enemies.empty? + assert @spot.protectors.empty? + assert @alice.beautiful_fight_relationships_as_enemy.empty? + assert @alice.beautiful_fight_relationships_as_protector.empty? + assert @alice.beautiful_fight_relationships.empty? + end + + def test_double_collection_assignment + @alice.enemies << @spot + @alice.reload + @spot.reload + assert @spot.protectors.include?(@alice) + assert @alice.enemies.include?(@spot) + assert !@alice.protectors.include?(@alice) + assert_equal 1, @alice.beautiful_fight_relationships_as_protector.size + assert_equal 0, @alice.beautiful_fight_relationships_as_enemy.size + assert_equal 1, @alice.beautiful_fight_relationships.size + + # self reference + assert_equal 1, @alice.enemies.length + @alice.enemies.push @alice + assert @alice.enemies.include?(@alice) + assert_equal 2, @alice.enemies.length + @alice.reload + assert_equal 2, @alice.beautiful_fight_relationships_as_protector.size + assert_equal 1, @alice.beautiful_fight_relationships_as_enemy.size + assert_equal 3, @alice.beautiful_fight_relationships.size + end + + def test_double_collection_build_join_record_on_association + + join = @alice.beautiful_fight_relationships_as_protector.build(:enemy => @spot) + + assert_equal @alice.class.base_class.name, join.protector_type + assert_nothing_raised { join.save! } + + assert join.id + assert_equal @double_join_count + 1, BeautifulFightRelationship.count + + assert @alice.enemies.reload + assert @alice.enemies.include?(@spot) + end + + def test_double_dependency_injection +# breakpoint + end + + def test_double_collection_deletion + @alice.enemies << @spot + @alice.reload + assert @alice.enemies.include?(@spot) + @alice.enemies.delete(@spot) + assert !@alice.enemies.include?(@spot) + assert @alice.enemies.empty? + @alice.reload + assert !@alice.enemies.include?(@spot) + assert @alice.enemies.empty? + assert_equal 0, @alice.beautiful_fight_relationships.size + end + + def test_double_collection_deletion_from_opposite_side + @alice.protectors << @puma + @alice.reload + assert @alice.protectors.include?(@puma) + @alice.protectors.delete(@puma) + assert !@alice.protectors.include?(@puma) + assert @alice.protectors.empty? + @alice.reload + assert !@alice.protectors.include?(@puma) + assert @alice.protectors.empty? + assert_equal 0, @alice.beautiful_fight_relationships.size + end + + def test_individual_collections_created_for_double_relationship + assert @alice.dogs.empty? + @alice.enemies << @spot + + assert @alice.enemies.include?(@spot) + assert !@alice.kittens.include?(@alice) + + assert !@alice.dogs.include?(@spot) + @alice.reload + assert @alice.dogs.include?(@spot) + assert !WildBoar.find(@alice.id).dogs.include?(@spot) # make sure the parent type is checked + end + + def test_individual_collections_created_for_double_relationship_from_opposite_side + assert @alice.wild_boars.empty? + @alice.protectors << @puma + + assert @alice.protectors.include?(@puma) + assert !@alice.wild_boars.include?(@puma) + @alice.reload + assert @alice.wild_boars.include?(@puma) + + assert !Dog.find(@alice.id).wild_boars.include?(@puma) # make sure the parent type is checked + end + + def test_self_referential_individual_collections_created_for_double_relationship + @alice.enemies << @alice + @alice.reload + assert @alice.enemy_kittens.include?(@alice) + assert @alice.protector_kittens.include?(@alice) + assert @alice.kittens.include?(@alice) + assert_equal 2, @alice.kittens.size + + @alice.enemies << (@chloe = Kitten.find_by_name('Chloe')) + @alice.reload + assert @alice.enemy_kittens.include?(@chloe) + assert !@alice.protector_kittens.include?(@chloe) + assert @alice.kittens.include?(@chloe) + assert_equal 3, @alice.kittens.size + end + + def test_child_of_polymorphic_join_can_reach_parent + @alice.enemies << @spot + @alice.reload + assert @spot.protectors.include?(@alice) + end + + def test_double_collection_deletion_from_child_polymorphic_join + @alice.enemies << @spot + @spot.protectors.delete(@alice) + assert !@spot.protectors.include?(@alice) + @alice.reload + assert !@alice.enemies.include?(@spot) + BeautifulFightRelationship.create(:protector_id => 2, :protector_type => "Dog", :enemy_id => @spot.id, :enemy_type => @spot.class.name) + @alice.enemies << @spot + @spot.protectors.delete(@alice) + assert !@spot.protectors.include?(@alice) + end + + def test_collection_query_on_unsaved_record + assert Dog.new.enemies.empty? + assert Dog.new.foodstuffs_of_eaters.empty? + end + + def test_double_individual_collections_push + assert_equal [@chloe], (@spot.protector_kittens << @chloe) + @spot.reload + assert @spot.protectors.include?(@chloe) + assert @spot.protector_kittens.include?(@chloe) + assert !@spot.protector_dogs.include?(@chloe) + + assert_equal [@froggy], (@spot.frogs << @froggy) + @spot.reload + assert @spot.enemies.include?(@froggy) + assert @spot.frogs.include?(@froggy) + assert !@spot.enemy_dogs.include?(@froggy) + end + + def test_double_individual_collections_delete + @spot.protectors << [@chloe, @puma] + @spot.reload + assert_equal [@chloe], @spot.protector_kittens.delete(@chloe) + assert @spot.protector_kittens.empty? + @spot.protector_kittens.delete(@chloe) # again, unclear what .delete should return + + @spot.reload + assert @spot.protector_kittens.empty? + assert @spot.wild_boars.include?(@puma) + end + + def test_double_individual_collections_clear + @spot.protectors << [@chloe, @puma, @alice] + @spot.reload + assert_equal [], @spot.protector_kittens.clear + assert @spot.protector_kittens.empty? + assert_equal 1, @spot.protectors.size + @spot.reload + assert @spot.protector_kittens.empty? + assert_equal 1, @spot.protectors.size + assert !@spot.protector_kittens.include?(@chloe) + assert !@spot.protectors.include?(@chloe) + assert !@spot.protector_kittens.include?(@alice) + assert !@spot.protectors.include?(@alice) + assert @spot.protectors.include?(@puma) + assert @spot.wild_boars.include?(@puma) + end + + def test_single_extensions + assert_equal :correct_block_result, @shamu.aquatic_pupils.a_method + @kibbles.eaters.push(@alice) + @kibbles.eaters.push(@spot) + assert_equal :correct_join_result, @kibbles.eaters_foodstuffs.a_method + assert_equal :correct_module_result, @kibbles.eaters.a_method + assert_equal :correct_other_module_result, @kibbles.eaters.another_method + @kibbles.eaters.each do |eater| + assert_equal :correct_join_result, eater.eaters_foodstuffs.a_method + end + assert_equal :correct_parent_proc_result, @kibbles.foodstuffs_of_eaters.a_method + assert_equal :correct_parent_proc_result, @kibbles.eaters.first.foodstuffs_of_eaters.a_method + end + + def test_double_extensions + assert_equal :correct_proc_result, @spot.protectors.a_method + assert_equal :correct_module_result, @spot.enemies.a_method + assert_equal :correct_join_result, @spot.beautiful_fight_relationships_as_enemy.a_method + assert_equal :correct_join_result, @spot.beautiful_fight_relationships_as_protector.a_method + assert_equal :correct_join_result, @froggy.beautiful_fight_relationships.a_method + assert_equal :correct_join_result, @froggy.beautiful_fight_relationships_as_enemy.a_method + assert_raises(NoMethodError) {@froggy.beautiful_fight_relationships_as_protector.a_method} + end + + def test_pluralization_checks + assert_raises(@association_error) { + eval "class SomeModel < ActiveRecord::Base + has_many_polymorphs :polymorphs, :from => [:dog, :cats] + end" } + assert_raises(@association_error) { + eval "class SomeModel < ActiveRecord::Base + has_many_polymorphs :polymorph, :from => [:dogs, :cats] + end" } + assert_raises(@association_error) { + eval "class SomeModel < ActiveRecord::Base + acts_as_double_polymorphic_join :polymorph => [:dogs, :cats], :unimorphs => [:dogs, :cats] + end" } + end + + def test_error_message_on_namespaced_targets + assert_raises(@association_error) { + eval "class SomeModel < ActiveRecord::Base + has_many_polymorphs :polymorphs, :from => [:fish] + end" } + end + + def test_single_custom_finders + [@kibbles, @alice, @puma, @spot, @bits].each {|record| @kibbles.eaters << record; sleep 1} # XXX yeah i know + assert_equal @kibbles.eaters, @kibbles.eaters.find(:all, :order => "eaters_foodstuffs.created_at ASC") + assert_equal @kibbles.eaters.reverse, @kibbles.eaters.find(:all, :order => "eaters_foodstuffs.created_at DESC") + if (ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false) + assert_equal @kibbles.eaters.sort_by(&:created_at), @kibbles.eaters.find(:all, :order => "IFNULL(bow_wows.created_at,(IFNULL(petfoods.created_at,(IFNULL(wild_boars.created_at,(IFNULL(cats.created_at,fish.created_at))))))) ASC") + end + assert_equal @kibbles.eaters.select{|x| x.is_a? Petfood}, @kibbles.eater_petfoods.find(:all, :order => "eaters_foodstuffs.created_at ASC") + end + + def test_double_custom_finders + @spot.protectors << [@chloe, @puma, @alice] + assert_equal [@chloe], @spot.protectors.find(:all, :conditions => ["cats.name = ?", @chloe.name], :limit => 1) + assert_equal [], @spot.protectors.find(:all, :conditions => ["cats.name = ?", @chloe.name], :limit => 1, :offset => 1) + assert_equal 2, @spot.protectors.find(:all, :limit => 100, :offset => 1).size + end + + def test_single_custom_finder_parameters_carry_to_individual_relationships + # XXX test nullout here + end + + def test_double_custom_finder_parameters_carry_to_individual_relationships + # XXX test nullout here + end + + def test_include_doesnt_fail + assert_nothing_raised do + @spot.protectors.find(:all, :include => :wild_boars) + end + end + + def test_abstract_method + assert_equal :correct_abstract_method_response, @spot.an_abstract_method + end + + def test_missing_target_should_raise + @kibbles.eaters << [@kibbles, @alice, @puma, @spot, @bits] + @spot.destroy_without_callbacks + assert_raises(@association_error) { @kibbles.eaters.reload } +# assert_raises(@association_error) { @kibbles.eater_dogs.reload } # bah AR + end + + def test_lazy_loading_is_lazy + # XXX + end + + def test_push_with_skip_duplicates_false_doesnt_load_target + # Loading kibbles locally again because setup calls .size which loads target + kibbles = Petfood.find(1) + assert !kibbles.eaters.loaded? + assert !(kibbles.eater_dogs << Dog.create!(:name => "Mongy")).loaded? + assert !kibbles.eaters.loaded? + end + + def test_association_foreign_key_is_sane + assert_equal "eater_id", Petfood.reflect_on_association(:eaters).association_foreign_key + end + + def test_reflection_instance_methods_are_sane + assert_equal EatersFoodstuff, Petfood.reflect_on_association(:eaters).klass + assert_equal EatersFoodstuff.name, Petfood.reflect_on_association(:eaters).class_name + end + + def test_parent_order + @alice.foodstuffs_of_eaters << Petfood.find(:all, :order => "the_petfood_primary_key ASC") + @alice.reload #not necessary + assert_equal [2,1], @alice.foodstuffs_of_eaters.map(&:id) + end + + def test_parent_conditions + @kibbles.eaters << @alice + assert_equal [@alice], @kibbles.eaters + + @snausages = Petfood.create(:name => 'Snausages') + @snausages.eaters << @alice + assert_equal [@alice], @snausages.eaters + + assert_equal [@kibbles], @alice.foodstuffs_of_eaters + end + + def test_self_referential_hmp_with_conditions + p = Person.find(:first) + kid = Person.create(:name => "Tim", :age => 3) + p.kids << kid + + kid.reload; p.reload + + # assert_equal [p], kid.parents + # assert Rails.has_one? Bug + # non-standard foreign_type key is not set properly when you are the polymorphic interface of a has_many going to a :through + + assert_equal [kid], p.kids + assert_equal [kid], p.people + end + +# def test_polymorphic_include +# @kibbles.eaters << [@kibbles, @alice, @puma, @spot, @bits] +# assert @kibbles.eaters.include?(@kibbles.eaters_foodstuffs.find(:all, :include => :eater).first.eater) +# end +# +# def test_double_polymorphic_include +# end +# +# def test_single_child_include +# end +# +# def test_double_child_include +# end +# +# def test_single_include_from_parent +# end +# +# def test_double_include_from_parent +# end +# +# def test_meta_referential_single_include +# end +# +# def test_meta_referential_double_include +# end +# +# def test_meta_referential_single_include +# end +# +# def test_meta_referential_single_double_multi_include +# end +# +# def test_dont_ignore_duplicates +# end +# +# def test_ignore_duplicates +# end +# +# def test_tagging_system_generator +# end +# +# def test_tagging_system_library +# end + +end diff --git a/vendor/gems/rack-1.1.0/.specification b/vendor/gems/rack-1.1.0/.specification new file mode 100644 index 00000000..ef892653 --- /dev/null +++ b/vendor/gems/rack-1.1.0/.specification @@ -0,0 +1,314 @@ +--- !ruby/object:Gem::Specification +name: rack +version: !ruby/object:Gem::Version + hash: 19 + prerelease: false + segments: + - 1 + - 1 + - 0 + version: 1.1.0 +platform: ruby +authors: +- Christian Neukirchen +autorequire: +bindir: bin +cert_chain: [] + +date: 2010-01-04 00:00:00 +01:00 +default_executable: rackup +dependencies: +- !ruby/object:Gem::Dependency + name: test-spec + prerelease: false + requirement: &id001 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id001 +- !ruby/object:Gem::Dependency + name: camping + prerelease: false + requirement: &id002 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id002 +- !ruby/object:Gem::Dependency + name: fcgi + prerelease: false + requirement: &id003 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id003 +- !ruby/object:Gem::Dependency + name: memcache-client + prerelease: false + requirement: &id004 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id004 +- !ruby/object:Gem::Dependency + name: mongrel + prerelease: false + requirement: &id005 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id005 +- !ruby/object:Gem::Dependency + name: thin + prerelease: false + requirement: &id006 !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" + type: :development + version_requirements: *id006 +description: | + Rack provides minimal, modular and adaptable interface for developing + web applications in Ruby. By wrapping HTTP requests and responses in + the simplest way possible, it unifies and distills the API for web + servers, web frameworks, and software in between (the so-called + middleware) into a single method call. + + Also see http://rack.rubyforge.org. + +email: chneukirchen@gmail.com +executables: +- rackup +extensions: [] + +extra_rdoc_files: +- README +- SPEC +- KNOWN-ISSUES +files: +- bin/rackup +- contrib/rack_logo.svg +- example/lobster.ru +- example/protectedlobster.rb +- example/protectedlobster.ru +- lib/rack/adapter/camping.rb +- lib/rack/auth/abstract/handler.rb +- lib/rack/auth/abstract/request.rb +- lib/rack/auth/basic.rb +- lib/rack/auth/digest/md5.rb +- lib/rack/auth/digest/nonce.rb +- lib/rack/auth/digest/params.rb +- lib/rack/auth/digest/request.rb +- lib/rack/builder.rb +- lib/rack/cascade.rb +- lib/rack/chunked.rb +- lib/rack/commonlogger.rb +- lib/rack/conditionalget.rb +- lib/rack/config.rb +- lib/rack/content_length.rb +- lib/rack/content_type.rb +- lib/rack/deflater.rb +- lib/rack/directory.rb +- lib/rack/etag.rb +- lib/rack/file.rb +- lib/rack/handler/cgi.rb +- lib/rack/handler/evented_mongrel.rb +- lib/rack/handler/fastcgi.rb +- lib/rack/handler/lsws.rb +- lib/rack/handler/mongrel.rb +- lib/rack/handler/scgi.rb +- lib/rack/handler/swiftiplied_mongrel.rb +- lib/rack/handler/thin.rb +- lib/rack/handler/webrick.rb +- lib/rack/handler.rb +- lib/rack/head.rb +- lib/rack/lint.rb +- lib/rack/lobster.rb +- lib/rack/lock.rb +- lib/rack/logger.rb +- lib/rack/methodoverride.rb +- lib/rack/mime.rb +- lib/rack/mock.rb +- lib/rack/nulllogger.rb +- lib/rack/recursive.rb +- lib/rack/reloader.rb +- lib/rack/request.rb +- lib/rack/response.rb +- lib/rack/rewindable_input.rb +- lib/rack/runtime.rb +- lib/rack/sendfile.rb +- lib/rack/server.rb +- lib/rack/session/abstract/id.rb +- lib/rack/session/cookie.rb +- lib/rack/session/memcache.rb +- lib/rack/session/pool.rb +- lib/rack/showexceptions.rb +- lib/rack/showstatus.rb +- lib/rack/static.rb +- lib/rack/urlmap.rb +- lib/rack/utils.rb +- lib/rack.rb +- COPYING +- KNOWN-ISSUES +- rack.gemspec +- RDOX +- README +- SPEC +- test/spec_rack_auth_basic.rb +- test/spec_rack_auth_digest.rb +- test/spec_rack_builder.rb +- test/spec_rack_camping.rb +- test/spec_rack_cascade.rb +- test/spec_rack_cgi.rb +- test/spec_rack_chunked.rb +- test/spec_rack_commonlogger.rb +- test/spec_rack_conditionalget.rb +- test/spec_rack_config.rb +- test/spec_rack_content_length.rb +- test/spec_rack_content_type.rb +- test/spec_rack_deflater.rb +- test/spec_rack_directory.rb +- test/spec_rack_etag.rb +- test/spec_rack_fastcgi.rb +- test/spec_rack_file.rb +- test/spec_rack_handler.rb +- test/spec_rack_head.rb +- test/spec_rack_lint.rb +- test/spec_rack_lobster.rb +- test/spec_rack_lock.rb +- test/spec_rack_logger.rb +- test/spec_rack_methodoverride.rb +- test/spec_rack_mock.rb +- test/spec_rack_mongrel.rb +- test/spec_rack_nulllogger.rb +- test/spec_rack_recursive.rb +- test/spec_rack_request.rb +- test/spec_rack_response.rb +- test/spec_rack_rewindable_input.rb +- test/spec_rack_runtime.rb +- test/spec_rack_sendfile.rb +- test/spec_rack_session_cookie.rb +- test/spec_rack_session_memcache.rb +- test/spec_rack_session_pool.rb +- test/spec_rack_showexceptions.rb +- test/spec_rack_showstatus.rb +- test/spec_rack_static.rb +- test/spec_rack_thin.rb +- test/spec_rack_urlmap.rb +- test/spec_rack_utils.rb +- test/spec_rack_webrick.rb +- test/spec_rackup.rb +has_rdoc: true +homepage: http://rack.rubyforge.org +licenses: [] + +post_install_message: +rdoc_options: [] + +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +required_rubygems_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +requirements: [] + +rubyforge_project: rack +rubygems_version: 1.3.7 +signing_key: +specification_version: 3 +summary: a modular Ruby webserver interface +test_files: +- test/spec_rack_auth_basic.rb +- test/spec_rack_auth_digest.rb +- test/spec_rack_builder.rb +- test/spec_rack_camping.rb +- test/spec_rack_cascade.rb +- test/spec_rack_cgi.rb +- test/spec_rack_chunked.rb +- test/spec_rack_commonlogger.rb +- test/spec_rack_conditionalget.rb +- test/spec_rack_config.rb +- test/spec_rack_content_length.rb +- test/spec_rack_content_type.rb +- test/spec_rack_deflater.rb +- test/spec_rack_directory.rb +- test/spec_rack_etag.rb +- test/spec_rack_fastcgi.rb +- test/spec_rack_file.rb +- test/spec_rack_handler.rb +- test/spec_rack_head.rb +- test/spec_rack_lint.rb +- test/spec_rack_lobster.rb +- test/spec_rack_lock.rb +- test/spec_rack_logger.rb +- test/spec_rack_methodoverride.rb +- test/spec_rack_mock.rb +- test/spec_rack_mongrel.rb +- test/spec_rack_nulllogger.rb +- test/spec_rack_recursive.rb +- test/spec_rack_request.rb +- test/spec_rack_response.rb +- test/spec_rack_rewindable_input.rb +- test/spec_rack_runtime.rb +- test/spec_rack_sendfile.rb +- test/spec_rack_session_cookie.rb +- test/spec_rack_session_memcache.rb +- test/spec_rack_session_pool.rb +- test/spec_rack_showexceptions.rb +- test/spec_rack_showstatus.rb +- test/spec_rack_static.rb +- test/spec_rack_thin.rb +- test/spec_rack_urlmap.rb +- test/spec_rack_utils.rb +- test/spec_rack_webrick.rb +- test/spec_rackup.rb diff --git a/vendor/gems/rack-1.1.0/COPYING b/vendor/gems/rack-1.1.0/COPYING new file mode 100644 index 00000000..83b390bc --- /dev/null +++ b/vendor/gems/rack-1.1.0/COPYING @@ -0,0 +1,18 @@ +Copyright (c) 2007, 2008, 2009, 2010 Christian Neukirchen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gems/rack-1.1.0/KNOWN-ISSUES b/vendor/gems/rack-1.1.0/KNOWN-ISSUES new file mode 100644 index 00000000..a1af5dc1 --- /dev/null +++ b/vendor/gems/rack-1.1.0/KNOWN-ISSUES @@ -0,0 +1,21 @@ += Known issues with Rack and Web servers + +* Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your + FastCGI app at "/". This can be fixed by using this middleware: + + class LighttpdScriptNameFix + def initialize(app) + @app = app + end + + def call(env) + env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s + env["SCRIPT_NAME"] = "" + @app.call(env) + end + end + + Of course, use this only when your app runs at "/". + + Since lighttpd 1.4.23, you also can use the "fix-root-scriptname" flag + in fastcgi.server. diff --git a/vendor/gems/rack-1.1.0/RDOX b/vendor/gems/rack-1.1.0/RDOX new file mode 100644 index 00000000..e69de29b diff --git a/vendor/gems/rack-1.1.0/README b/vendor/gems/rack-1.1.0/README new file mode 100644 index 00000000..777b12d3 --- /dev/null +++ b/vendor/gems/rack-1.1.0/README @@ -0,0 +1,399 @@ += Rack, a modular Ruby webserver interface + +Rack provides a minimal, modular and adaptable interface for developing +web applications in Ruby. By wrapping HTTP requests and responses in +the simplest way possible, it unifies and distills the API for web +servers, web frameworks, and software in between (the so-called +middleware) into a single method call. + +The exact details of this are described in the Rack specification, +which all Rack applications should conform to. + +== Specification changes in this release + +With Rack 1.1, the Rack specification (found in SPEC) changed in the +following backward-incompatible ways. + +* Rack::VERSION has been pushed to [1,1]. +* rack.logger is now specified. +* The SPEC now allows subclasses of the required types. +* rack.input has to be opened in binary mode. + +== Supported web servers + +The included *handlers* connect all kinds of web servers to Rack: +* Mongrel +* EventedMongrel +* SwiftipliedMongrel +* WEBrick +* FCGI +* CGI +* SCGI +* LiteSpeed +* Thin + +These web servers include Rack handlers in their distributions: +* Ebb +* Fuzed +* Glassfish v3 +* Phusion Passenger (which is mod_rack for Apache and for nginx) +* Rainbows! +* Unicorn +* Zbatery + +Any valid Rack app will run the same on all these handlers, without +changing anything. + +== Supported web frameworks + +The included *adapters* connect Rack with existing Ruby web frameworks: +* Camping + +These frameworks include Rack adapters in their distributions: +* Camping +* Coset +* Halcyon +* Mack +* Maveric +* Merb +* Racktools::SimpleApplication +* Ramaze +* Ruby on Rails +* Rum +* Sinatra +* Sin +* Vintage +* Waves +* Wee +* ... and many others. + +Current links to these projects can be found at +http://wiki.ramaze.net/Home#other-frameworks + +== Available middleware + +Between the server and the framework, Rack can be customized to your +applications needs using middleware, for example: +* Rack::URLMap, to route to multiple applications inside the same process. +* Rack::CommonLogger, for creating Apache-style logfiles. +* Rack::ShowException, for catching unhandled exceptions and + presenting them in a nice and helpful way with clickable backtrace. +* Rack::File, for serving static files. +* ...many others! + +All these components use the same interface, which is described in +detail in the Rack specification. These optional components can be +used in any way you wish. + +== Convenience + +If you want to develop outside of existing frameworks, implement your +own ones, or develop middleware, Rack provides many helpers to create +Rack applications quickly and without doing the same web stuff all +over: +* Rack::Request, which also provides query string parsing and + multipart handling. +* Rack::Response, for convenient generation of HTTP replies and + cookie handling. +* Rack::MockRequest and Rack::MockResponse for efficient and quick + testing of Rack application without real HTTP round-trips. + +== rack-contrib + +The plethora of useful middleware created the need for a project that +collects fresh Rack middleware. rack-contrib includes a variety of +add-on components for Rack and it is easy to contribute new modules. + +* http://github.com/rack/rack-contrib + +== rackup + +rackup is a useful tool for running Rack applications, which uses the +Rack::Builder DSL to configure middleware and build up applications +easily. + +rackup automatically figures out the environment it is run in, and +runs your application as FastCGI, CGI, or standalone with Mongrel or +WEBrick---all from the same configuration. + +== Quick start + +Try the lobster! + +Either with the embedded WEBrick starter: + + ruby -Ilib lib/rack/lobster.rb + +Or with rackup: + + bin/rackup -Ilib example/lobster.ru + +By default, the lobster is found at http://localhost:9292. + +== Installing with RubyGems + +A Gem of Rack is available at gemcutter.org. You can install it with: + + gem install rack + +I also provide a local mirror of the gems (and development snapshots) +at my site: + + gem install rack --source http://chneukirchen.org/releases/gems/ + +== Running the tests + +Testing Rack requires the test/spec testing framework: + + gem install test-spec + +There are two rake-based test tasks: + + rake test tests all the fast tests (no Handlers or Adapters) + rake fulltest runs all the tests + +The fast testsuite has no dependencies outside of the core Ruby +installation and test-spec. + +To run the test suite completely, you need: + + * camping + * fcgi + * memcache-client + * mongrel + * thin + +The full set of tests test FCGI access with lighttpd (on port +9203) so you will need lighttpd installed as well as the FCGI +libraries and the fcgi gem: + +Download and install lighttpd: + + http://www.lighttpd.net/download + +Installing the FCGI libraries: + + curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz + tar xzvf fcgi-2.4.0.tar.gz + cd fcgi-2.4.0 + ./configure --prefix=/usr/local + make + sudo make install + cd .. + +Installing the Ruby fcgi gem: + + gem install fcgi + +Furthermore, to test Memcache sessions, you need memcached (will be +run on port 11211) and memcache-client installed. + +== History + +* March 3rd, 2007: First public release 0.1. + +* May 16th, 2007: Second public release 0.2. + * HTTP Basic authentication. + * Cookie Sessions. + * Static file handler. + * Improved Rack::Request. + * Improved Rack::Response. + * Added Rack::ShowStatus, for better default error messages. + * Bug fixes in the Camping adapter. + * Removed Rails adapter, was too alpha. + +* February 26th, 2008: Third public release 0.3. + * LiteSpeed handler, by Adrian Madrid. + * SCGI handler, by Jeremy Evans. + * Pool sessions, by blink. + * OpenID authentication, by blink. + * :Port and :File options for opening FastCGI sockets, by blink. + * Last-Modified HTTP header for Rack::File, by blink. + * Rack::Builder#use now accepts blocks, by Corey Jewett. + (See example/protectedlobster.ru) + * HTTP status 201 can contain a Content-Type and a body now. + * Many bugfixes, especially related to Cookie handling. + +* August 21st, 2008: Fourth public release 0.4. + * New middleware, Rack::Deflater, by Christoffer Sawicki. + * OpenID authentication now needs ruby-openid 2. + * New Memcache sessions, by blink. + * Explicit EventedMongrel handler, by Joshua Peek + * Rack::Reloader is not loaded in rackup development mode. + * rackup can daemonize with -D. + * Many bugfixes, especially for pool sessions, URLMap, thread safety + and tempfile handling. + * Improved tests. + * Rack moved to Git. + +* January 6th, 2009: Fifth public release 0.9. + * Rack is now managed by the Rack Core Team. + * Rack::Lint is stricter and follows the HTTP RFCs more closely. + * Added ConditionalGet middleware. + * Added ContentLength middleware. + * Added Deflater middleware. + * Added Head middleware. + * Added MethodOverride middleware. + * Rack::Mime now provides popular MIME-types and their extension. + * Mongrel Header now streams. + * Added Thin handler. + * Official support for swiftiplied Mongrel. + * Secure cookies. + * Made HeaderHash case-preserving. + * Many bugfixes and small improvements. + +* January 9th, 2009: Sixth public release 0.9.1. + * Fix directory traversal exploits in Rack::File and Rack::Directory. + +* April 25th, 2009: Seventh public release 1.0.0. + * SPEC change: Rack::VERSION has been pushed to [1,0]. + * SPEC change: header values must be Strings now, split on "\n". + * SPEC change: Content-Length can be missing, in this case chunked transfer + encoding is used. + * SPEC change: rack.input must be rewindable and support reading into + a buffer, wrap with Rack::RewindableInput if it isn't. + * SPEC change: rack.session is now specified. + * SPEC change: Bodies can now additionally respond to #to_path with + a filename to be served. + * NOTE: String bodies break in 1.9, use an Array consisting of a + single String instead. + * New middleware Rack::Lock. + * New middleware Rack::ContentType. + * Rack::Reloader has been rewritten. + * Major update to Rack::Auth::OpenID. + * Support for nested parameter parsing in Rack::Response. + * Support for redirects in Rack::Response. + * HttpOnly cookie support in Rack::Response. + * The Rakefile has been rewritten. + * Many bugfixes and small improvements. + +* October 18th, 2009: Eighth public release 1.0.1. + * Bump remainder of rack.versions. + * Support the pure Ruby FCGI implementation. + * Fix for form names containing "=": split first then unescape components + * Fixes the handling of the filename parameter with semicolons in names. + * Add anchor to nested params parsing regexp to prevent stack overflows + * Use more compatible gzip write api instead of "<<". + * Make sure that Reloader doesn't break when executed via ruby -e + * Make sure WEBrick respects the :Host option + * Many Ruby 1.9 fixes. + +* January 3rd, 2009: Ninth public release 1.1.0. + * Moved Auth::OpenID to rack-contrib. + * SPEC change that relaxes Lint slightly to allow subclasses of the + required types + * SPEC change to document rack.input binary mode in greator detail + * SPEC define optional rack.logger specification + * File servers support X-Cascade header + * Imported Config middleware + * Imported ETag middleware + * Imported Runtime middleware + * Imported Sendfile middleware + * New Logger and NullLogger middlewares + * Added mime type for .ogv and .manifest. + * Don't squeeze PATH_INFO slashes + * Use Content-Type to determine POST params parsing + * Update Rack::Utils::HTTP_STATUS_CODES hash + * Add status code lookup utility + * Response should call #to_i on the status + * Add Request#user_agent + * Request#host knows about forwared host + * Return an empty string for Request#host if HTTP_HOST and + SERVER_NAME are both missing + * Allow MockRequest to accept hash params + * Optimizations to HeaderHash + * Refactored rackup into Rack::Server + * Added Utils.build_nested_query to complement Utils.parse_nested_query + * Added Utils::Multipart.build_multipart to complement + Utils::Multipart.parse_multipart + * Extracted set and delete cookie helpers into Utils so they can be + used outside Response + * Extract parse_query and parse_multipart in Request so subclasses + can change their behavior + * Enforce binary encoding in RewindableInput + * Set correct external_encoding for handlers that don't use RewindableInput + +== Contact + +Please post bugs, suggestions and patches to +the bug tracker at . + +Mailing list archives are available at +. + +Git repository (send Git patches to the mailing list): +* http://github.com/rack/rack +* http://git.vuxu.org/cgi-bin/gitweb.cgi?p=rack.git + +You are also welcome to join the #rack channel on irc.freenode.net. + +== Thanks + +The Rack Core Team, consisting of + +* Christian Neukirchen (chneukirchen) +* James Tucker (raggi) +* Josh Peek (josh) +* Michael Fellinger (manveru) +* Ryan Tomayko (rtomayko) +* Scytrin dai Kinthra (scytrin) + +would like to thank: + +* Adrian Madrid, for the LiteSpeed handler. +* Christoffer Sawicki, for the first Rails adapter and Rack::Deflater. +* Tim Fletcher, for the HTTP authentication code. +* Luc Heinrich for the Cookie sessions, the static file handler and bugfixes. +* Armin Ronacher, for the logo and racktools. +* Aredridel, Ben Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, + Tom Robinson, Phil Hagelberg, S. Brent Faulkner, Bosko Milekic, + Daniel Rodríguez Troitiño, Genki Takiuchi, Geoffrey Grosenbach, + Julien Sanchez, Kamal Fariz Mahyuddin, Masayoshi Takahashi, Patrick + Aljordm, Mig, and Kazuhiro Nishiyama for bug fixing and other + improvements. +* Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support + and API improvements. +* Yehuda Katz and Carl Lerche for refactoring rackup. +* Brian Candler, for Rack::ContentType. +* Graham Batty, for improved handler loading. +* Stephen Bannasch, for bug reports and documentation. +* Gary Wright, for proposing a better Rack::Response interface. +* Jonathan Buch, for improvements regarding Rack::Response. +* Armin Röhrl, for tracking down bugs in the Cookie generator. +* Alexander Kellett for testing the Gem and reviewing the announcement. +* Marcus Rückert, for help with configuring and debugging lighttpd. +* The WSGI team for the well-done and documented work they've done and + Rack builds up on. +* All bug reporters and patch contributers not mentioned above. + +== Copyright + +Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +== Links + +Rack:: +Rack's Rubyforge project:: +Official Rack repositories:: +Rack Lighthouse Bug Tracking:: +rack-devel mailing list:: + +Christian Neukirchen:: + diff --git a/vendor/gems/rack-1.1.0/SPEC b/vendor/gems/rack-1.1.0/SPEC new file mode 100644 index 00000000..d2260cbe --- /dev/null +++ b/vendor/gems/rack-1.1.0/SPEC @@ -0,0 +1,171 @@ +This specification aims to formalize the Rack protocol. You +can (and should) use Rack::Lint to enforce it. +When you develop middleware, be sure to add a Lint before and +after to catch all mistakes. += Rack applications +A Rack application is an Ruby object (not a class) that +responds to +call+. +It takes exactly one argument, the *environment* +and returns an Array of exactly three values: +The *status*, +the *headers*, +and the *body*. +== The Environment +The environment must be an true instance of Hash (no +subclassing allowed) that includes CGI-like headers. +The application is free to modify the environment. +The environment is required to include these variables +(adopted from PEP333), except when they'd be empty, but see +below. +REQUEST_METHOD:: The HTTP request method, such as + "GET" or "POST". This cannot ever + be an empty string, and so is + always required. +SCRIPT_NAME:: The initial portion of the request + URL's "path" that corresponds to the + application object, so that the + application knows its virtual + "location". This may be an empty + string, if the application corresponds + to the "root" of the server. +PATH_INFO:: The remainder of the request URL's + "path", designating the virtual + "location" of the request's target + within the application. This may be an + empty string, if the request URL targets + the application root and does not have a + trailing slash. This value may be + percent-encoded when I originating from + a URL. +QUERY_STRING:: The portion of the request URL that + follows the ?, if any. May be + empty, but is always required! +SERVER_NAME, SERVER_PORT:: When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required. +HTTP_ Variables:: Variables corresponding to the + client-supplied HTTP request + headers (i.e., variables whose + names begin with HTTP_). The + presence or absence of these + variables should correspond with + the presence or absence of the + appropriate HTTP header in the + request. +In addition to this, the Rack environment must include these +Rack-specific variables: +rack.version:: The Array [1,1], representing this version of Rack. +rack.url_scheme:: +http+ or +https+, depending on the request URL. +rack.input:: See below, the input stream. +rack.errors:: See below, the error stream. +rack.multithread:: true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. +rack.multiprocess:: true if an equivalent application object may be simultaneously invoked by another process, false otherwise. +rack.run_once:: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). +Additional environment specifications have approved to +standardized middleware APIs. None of these are required to +be implemented by the server. +rack.session:: A hash like interface for storing request session data. + The store must implement: + store(key, value) (aliased as []=); + fetch(key, default = nil) (aliased as []); + delete(key); + clear; +rack.logger:: A common object interface for logging messages. + The object must implement: + info(message, &block) + debug(message, &block) + warn(message, &block) + error(message, &block) + fatal(message, &block) +The server or the application can store their own data in the +environment, too. The keys must contain at least one dot, +and should be prefixed uniquely. The prefix rack. +is reserved for use with the Rack core distribution and other +accepted specifications and must not be used otherwise. +The environment must not contain the keys +HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH +(use the versions without HTTP_). +The CGI keys (named without a period) must have String values. +There are the following restrictions: +* rack.version must be an array of Integers. +* rack.url_scheme must either be +http+ or +https+. +* There must be a valid input stream in rack.input. +* There must be a valid error stream in rack.errors. +* The REQUEST_METHOD must be a valid token. +* The SCRIPT_NAME, if non-empty, must start with / +* The PATH_INFO, if non-empty, must start with / +* The CONTENT_LENGTH, if given, must consist of digits only. +* One of SCRIPT_NAME or PATH_INFO must be + set. PATH_INFO should be / if + SCRIPT_NAME is empty. + SCRIPT_NAME never should be /, but instead be empty. +=== The Input Stream +The input stream is an IO-like object which contains the raw HTTP +POST data. +When applicable, its external encoding must be "ASCII-8BIT" and it +must be opened in binary mode, for Ruby 1.9 compatibility. +The input stream must respond to +gets+, +each+, +read+ and +rewind+. +* +gets+ must be called without arguments and return a string, + or +nil+ on EOF. +* +read+ behaves like IO#read. Its signature is read([length, [buffer]]). + If given, +length+ must be an non-negative Integer (>= 0) or +nil+, and +buffer+ must + be a String and may not be nil. If +length+ is given and not nil, then this method + reads at most +length+ bytes from the input stream. If +length+ is not given or nil, + then this method reads all data until EOF. + When EOF is reached, this method returns nil if +length+ is given and not nil, or "" + if +length+ is not given or is nil. + If +buffer+ is given, then the read data will be placed into +buffer+ instead of a + newly created String object. +* +each+ must be called without arguments and only yield Strings. +* +rewind+ must be called without arguments. It rewinds the input + stream back to the beginning. It must not raise Errno::ESPIPE: + that is, it may not be a pipe or a socket. Therefore, handler + developers must buffer the input data into some rewindable object + if the underlying input stream is not rewindable. +* +close+ must never be called on the input stream. +=== The Error Stream +The error stream must respond to +puts+, +write+ and +flush+. +* +puts+ must be called with a single argument that responds to +to_s+. +* +write+ must be called with a single argument that is a String. +* +flush+ must be called without arguments and must be called + in order to make the error appear for sure. +* +close+ must never be called on the error stream. +== The Response +=== The Status +This is an HTTP status. When parsed as integer (+to_i+), it must be +greater than or equal to 100. +=== The Headers +The header must respond to +each+, and yield values of key and value. +The header keys must be Strings. +The header must not contain a +Status+ key, +contain keys with : or newlines in their name, +contain keys names that end in - or _, +but only contain keys that consist of +letters, digits, _ or - and start with a letter. +The values of the header must be Strings, +consisting of lines (for multiple header values, e.g. multiple +Set-Cookie values) seperated by "\n". +The lines must not contain characters below 037. +=== The Content-Type +There must be a Content-Type, except when the ++Status+ is 1xx, 204 or 304, in which case there must be none +given. +=== The Content-Length +There must not be a Content-Length header when the ++Status+ is 1xx, 204 or 304. +=== The Body +The Body must respond to +each+ +and must only yield String values. +The Body itself should not be an instance of String, as this will +break in Ruby 1.9. +If the Body responds to +close+, it will be called after iteration. +If the Body responds to +to_path+, it must return a String +identifying the location of a file whose contents are identical +to that produced by calling +each+; this may be used by the +server as an alternative, possibly more efficient way to +transport the response. +The Body commonly is an Array of Strings, the application +instance itself, or a File-like object. +== Thanks +Some parts of this specification are adopted from PEP333: Python +Web Server Gateway Interface +v1.0 (http://www.python.org/dev/peps/pep-0333/). I'd like to thank +everyone involved in that effort. diff --git a/vendor/gems/rack-1.1.0/bin/rackup b/vendor/gems/rack-1.1.0/bin/rackup new file mode 100755 index 00000000..ad94af4b --- /dev/null +++ b/vendor/gems/rack-1.1.0/bin/rackup @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require "rack" +Rack::Server.start diff --git a/vendor/gems/rack-1.1.0/contrib/rack_logo.svg b/vendor/gems/rack-1.1.0/contrib/rack_logo.svg new file mode 100644 index 00000000..905dcd32 --- /dev/null +++ b/vendor/gems/rack-1.1.0/contrib/rack_logo.svg @@ -0,0 +1,111 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/vendor/gems/rack-1.1.0/example/lobster.ru b/vendor/gems/rack-1.1.0/example/lobster.ru new file mode 100644 index 00000000..cc7ffcae --- /dev/null +++ b/vendor/gems/rack-1.1.0/example/lobster.ru @@ -0,0 +1,4 @@ +require 'rack/lobster' + +use Rack::ShowExceptions +run Rack::Lobster.new diff --git a/vendor/gems/rack-1.1.0/example/protectedlobster.rb b/vendor/gems/rack-1.1.0/example/protectedlobster.rb new file mode 100644 index 00000000..108b9d05 --- /dev/null +++ b/vendor/gems/rack-1.1.0/example/protectedlobster.rb @@ -0,0 +1,14 @@ +require 'rack' +require 'rack/lobster' + +lobster = Rack::Lobster.new + +protected_lobster = Rack::Auth::Basic.new(lobster) do |username, password| + 'secret' == password +end + +protected_lobster.realm = 'Lobster 2.0' + +pretty_protected_lobster = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_lobster)) + +Rack::Handler::WEBrick.run pretty_protected_lobster, :Port => 9292 diff --git a/vendor/gems/rack-1.1.0/example/protectedlobster.ru b/vendor/gems/rack-1.1.0/example/protectedlobster.ru new file mode 100644 index 00000000..b0da62f0 --- /dev/null +++ b/vendor/gems/rack-1.1.0/example/protectedlobster.ru @@ -0,0 +1,8 @@ +require 'rack/lobster' + +use Rack::ShowExceptions +use Rack::Auth::Basic, "Lobster 2.0" do |username, password| + 'secret' == password +end + +run Rack::Lobster.new diff --git a/vendor/gems/rack-1.1.0/lib/rack.rb b/vendor/gems/rack-1.1.0/lib/rack.rb new file mode 100644 index 00000000..c118fc07 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack.rb @@ -0,0 +1,92 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen +# +# Rack is freely distributable under the terms of an MIT-style license. +# See COPYING or http://www.opensource.org/licenses/mit-license.php. + +# The Rack main module, serving as a namespace for all core Rack +# modules and classes. +# +# All modules meant for use in your application are autoloaded here, +# so it should be enough just to require rack.rb in your code. + +module Rack + # The Rack protocol version number implemented. + VERSION = [1,1] + + # Return the Rack protocol version as a dotted string. + def self.version + VERSION.join(".") + end + + # Return the Rack release as a dotted string. + def self.release + "1.1" + end + + autoload :Builder, "rack/builder" + autoload :Cascade, "rack/cascade" + autoload :Chunked, "rack/chunked" + autoload :CommonLogger, "rack/commonlogger" + autoload :ConditionalGet, "rack/conditionalget" + autoload :Config, "rack/config" + autoload :ContentLength, "rack/content_length" + autoload :ContentType, "rack/content_type" + autoload :ETag, "rack/etag" + autoload :File, "rack/file" + autoload :Deflater, "rack/deflater" + autoload :Directory, "rack/directory" + autoload :ForwardRequest, "rack/recursive" + autoload :Handler, "rack/handler" + autoload :Head, "rack/head" + autoload :Lint, "rack/lint" + autoload :Lock, "rack/lock" + autoload :Logger, "rack/logger" + autoload :MethodOverride, "rack/methodoverride" + autoload :Mime, "rack/mime" + autoload :NullLogger, "rack/nulllogger" + autoload :Recursive, "rack/recursive" + autoload :Reloader, "rack/reloader" + autoload :Runtime, "rack/runtime" + autoload :Sendfile, "rack/sendfile" + autoload :Server, "rack/server" + autoload :ShowExceptions, "rack/showexceptions" + autoload :ShowStatus, "rack/showstatus" + autoload :Static, "rack/static" + autoload :URLMap, "rack/urlmap" + autoload :Utils, "rack/utils" + + autoload :MockRequest, "rack/mock" + autoload :MockResponse, "rack/mock" + + autoload :Request, "rack/request" + autoload :Response, "rack/response" + + module Auth + autoload :Basic, "rack/auth/basic" + autoload :AbstractRequest, "rack/auth/abstract/request" + autoload :AbstractHandler, "rack/auth/abstract/handler" + module Digest + autoload :MD5, "rack/auth/digest/md5" + autoload :Nonce, "rack/auth/digest/nonce" + autoload :Params, "rack/auth/digest/params" + autoload :Request, "rack/auth/digest/request" + end + end + + module Session + autoload :Cookie, "rack/session/cookie" + autoload :Pool, "rack/session/pool" + autoload :Memcache, "rack/session/memcache" + end + + # *Adapters* connect Rack with third party web frameworks. + # + # Rack includes an adapter for Camping, see README for other + # frameworks supporting Rack in their code bases. + # + # Refer to the submodules for framework-specific calling details. + + module Adapter + autoload :Camping, "rack/adapter/camping" + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/adapter/camping.rb b/vendor/gems/rack-1.1.0/lib/rack/adapter/camping.rb new file mode 100644 index 00000000..63bc787f --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/adapter/camping.rb @@ -0,0 +1,22 @@ +module Rack + module Adapter + class Camping + def initialize(app) + @app = app + end + + def call(env) + env["PATH_INFO"] ||= "" + env["SCRIPT_NAME"] ||= "" + controller = @app.run(env['rack.input'], env) + h = controller.headers + h.each_pair do |k,v| + if v.kind_of? URI + h[k] = v.to_s + end + end + [controller.status, controller.headers, [controller.body.to_s]] + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/handler.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/handler.rb new file mode 100644 index 00000000..214df629 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/handler.rb @@ -0,0 +1,37 @@ +module Rack + module Auth + # Rack::Auth::AbstractHandler implements common authentication functionality. + # + # +realm+ should be set for all handlers. + + class AbstractHandler + + attr_accessor :realm + + def initialize(app, realm=nil, &authenticator) + @app, @realm, @authenticator = app, realm, authenticator + end + + + private + + def unauthorized(www_authenticate = challenge) + return [ 401, + { 'Content-Type' => 'text/plain', + 'Content-Length' => '0', + 'WWW-Authenticate' => www_authenticate.to_s }, + [] + ] + end + + def bad_request + return [ 400, + { 'Content-Type' => 'text/plain', + 'Content-Length' => '0' }, + [] + ] + end + + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/request.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/request.rb new file mode 100644 index 00000000..1d9ccec6 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/abstract/request.rb @@ -0,0 +1,37 @@ +module Rack + module Auth + class AbstractRequest + + def initialize(env) + @env = env + end + + def provided? + !authorization_key.nil? + end + + def parts + @parts ||= @env[authorization_key].split(' ', 2) + end + + def scheme + @scheme ||= parts.first.downcase.to_sym + end + + def params + @params ||= parts.last + end + + + private + + AUTHORIZATION_KEYS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION'] + + def authorization_key + @authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.has_key?(key) } + end + + end + + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb new file mode 100644 index 00000000..95572246 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb @@ -0,0 +1,58 @@ +require 'rack/auth/abstract/handler' +require 'rack/auth/abstract/request' + +module Rack + module Auth + # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617. + # + # Initialize with the Rack application that you want protecting, + # and a block that checks if a username and password pair are valid. + # + # See also: example/protectedlobster.rb + + class Basic < AbstractHandler + + def call(env) + auth = Basic::Request.new(env) + + return unauthorized unless auth.provided? + + return bad_request unless auth.basic? + + if valid?(auth) + env['REMOTE_USER'] = auth.username + + return @app.call(env) + end + + unauthorized + end + + + private + + def challenge + 'Basic realm="%s"' % realm + end + + def valid?(auth) + @authenticator.call(*auth.credentials) + end + + class Request < Auth::AbstractRequest + def basic? + :basic == scheme + end + + def credentials + @credentials ||= params.unpack("m*").first.split(/:/, 2) + end + + def username + credentials.first + end + end + + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/digest/md5.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/md5.rb new file mode 100644 index 00000000..e579dc96 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/md5.rb @@ -0,0 +1,124 @@ +require 'rack/auth/abstract/handler' +require 'rack/auth/digest/request' +require 'rack/auth/digest/params' +require 'rack/auth/digest/nonce' +require 'digest/md5' + +module Rack + module Auth + module Digest + # Rack::Auth::Digest::MD5 implements the MD5 algorithm version of + # HTTP Digest Authentication, as per RFC 2617. + # + # Initialize with the [Rack] application that you want protecting, + # and a block that looks up a plaintext password for a given username. + # + # +opaque+ needs to be set to a constant base64/hexadecimal string. + # + class MD5 < AbstractHandler + + attr_accessor :opaque + + attr_writer :passwords_hashed + + def initialize(*args) + super + @passwords_hashed = nil + end + + def passwords_hashed? + !!@passwords_hashed + end + + def call(env) + auth = Request.new(env) + + unless auth.provided? + return unauthorized + end + + if !auth.digest? || !auth.correct_uri? || !valid_qop?(auth) + return bad_request + end + + if valid?(auth) + if auth.nonce.stale? + return unauthorized(challenge(:stale => true)) + else + env['REMOTE_USER'] = auth.username + + return @app.call(env) + end + end + + unauthorized + end + + + private + + QOP = 'auth'.freeze + + def params(hash = {}) + Params.new do |params| + params['realm'] = realm + params['nonce'] = Nonce.new.to_s + params['opaque'] = H(opaque) + params['qop'] = QOP + + hash.each { |k, v| params[k] = v } + end + end + + def challenge(hash = {}) + "Digest #{params(hash)}" + end + + def valid?(auth) + valid_opaque?(auth) && valid_nonce?(auth) && valid_digest?(auth) + end + + def valid_qop?(auth) + QOP == auth.qop + end + + def valid_opaque?(auth) + H(opaque) == auth.opaque + end + + def valid_nonce?(auth) + auth.nonce.valid? + end + + def valid_digest?(auth) + digest(auth, @authenticator.call(auth.username)) == auth.response + end + + def md5(data) + ::Digest::MD5.hexdigest(data) + end + + alias :H :md5 + + def KD(secret, data) + H([secret, data] * ':') + end + + def A1(auth, password) + [ auth.username, auth.realm, password ] * ':' + end + + def A2(auth) + [ auth.method, auth.uri ] * ':' + end + + def digest(auth, password) + password_hash = passwords_hashed? ? password : H(A1(auth, password)) + + KD(password_hash, [ auth.nonce, auth.nc, auth.cnonce, QOP, H(A2(auth)) ] * ':') + end + + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/digest/nonce.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/nonce.rb new file mode 100644 index 00000000..dbe109f2 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/nonce.rb @@ -0,0 +1,51 @@ +require 'digest/md5' + +module Rack + module Auth + module Digest + # Rack::Auth::Digest::Nonce is the default nonce generator for the + # Rack::Auth::Digest::MD5 authentication handler. + # + # +private_key+ needs to set to a constant string. + # + # +time_limit+ can be optionally set to an integer (number of seconds), + # to limit the validity of the generated nonces. + + class Nonce + + class << self + attr_accessor :private_key, :time_limit + end + + def self.parse(string) + new(*string.unpack("m*").first.split(' ', 2)) + end + + def initialize(timestamp = Time.now, given_digest = nil) + @timestamp, @given_digest = timestamp.to_i, given_digest + end + + def to_s + [([ @timestamp, digest ] * ' ')].pack("m*").strip + end + + def digest + ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':') + end + + def valid? + digest == @given_digest + end + + def stale? + !self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit + end + + def fresh? + !stale? + end + + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/digest/params.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/params.rb new file mode 100644 index 00000000..730e2efd --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/params.rb @@ -0,0 +1,55 @@ +module Rack + module Auth + module Digest + class Params < Hash + + def self.parse(str) + split_header_value(str).inject(new) do |header, param| + k, v = param.split('=', 2) + header[k] = dequote(v) + header + end + end + + def self.dequote(str) # From WEBrick::HTTPUtils + ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup + ret.gsub!(/\\(.)/, "\\1") + ret + end + + def self.split_header_value(str) + str.scan( /(\w+\=(?:"[^\"]+"|[^,]+))/n ).collect{ |v| v[0] } + end + + def initialize + super + + yield self if block_given? + end + + def [](k) + super k.to_s + end + + def []=(k, v) + super k.to_s, v.to_s + end + + UNQUOTED = ['qop', 'nc', 'stale'] + + def to_s + inject([]) do |parts, (k, v)| + parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v)) + parts + end.join(', ') + end + + def quote(str) # From WEBrick::HTTPUtils + '"' << str.gsub(/[\\\"]/o, "\\\1") << '"' + end + + end + end + end +end + diff --git a/vendor/gems/rack-1.1.0/lib/rack/auth/digest/request.rb b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/request.rb new file mode 100644 index 00000000..a8aa3bf9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/auth/digest/request.rb @@ -0,0 +1,40 @@ +require 'rack/auth/abstract/request' +require 'rack/auth/digest/params' +require 'rack/auth/digest/nonce' + +module Rack + module Auth + module Digest + class Request < Auth::AbstractRequest + + def method + @env['rack.methodoverride.original_method'] || @env['REQUEST_METHOD'] + end + + def digest? + :digest == scheme + end + + def correct_uri? + (@env['SCRIPT_NAME'].to_s + @env['PATH_INFO'].to_s) == uri + end + + def nonce + @nonce ||= Nonce.parse(params['nonce']) + end + + def params + @params ||= Params.parse(parts.last) + end + + def method_missing(sym) + if params.has_key? key = sym.to_s + return params[key] + end + super + end + + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/builder.rb b/vendor/gems/rack-1.1.0/lib/rack/builder.rb new file mode 100644 index 00000000..530f0aaf --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/builder.rb @@ -0,0 +1,80 @@ +module Rack + # Rack::Builder implements a small DSL to iteratively construct Rack + # applications. + # + # Example: + # + # app = Rack::Builder.new { + # use Rack::CommonLogger + # use Rack::ShowExceptions + # map "/lobster" do + # use Rack::Lint + # run Rack::Lobster.new + # end + # } + # + # Or + # + # app = Rack::Builder.app do + # use Rack::CommonLogger + # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] } + # end + # + # +use+ adds a middleware to the stack, +run+ dispatches to an application. + # You can use +map+ to construct a Rack::URLMap in a convenient way. + + class Builder + def self.parse_file(config, opts = Server::Options.new) + options = {} + if config =~ /\.ru$/ + cfgfile = ::File.read(config) + if cfgfile[/^#\\(.*)/] && opts + options = opts.parse! $1.split(/\s+/) + end + cfgfile.sub!(/^__END__\n.*/, '') + app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", + TOPLEVEL_BINDING, config + else + require config + app = Object.const_get(::File.basename(config, '.rb').capitalize) + end + return app, options + end + + def initialize(&block) + @ins = [] + instance_eval(&block) if block_given? + end + + def self.app(&block) + self.new(&block).to_app + end + + def use(middleware, *args, &block) + @ins << lambda { |app| middleware.new(app, *args, &block) } + end + + def run(app) + @ins << app #lambda { |nothing| app } + end + + def map(path, &block) + if @ins.last.kind_of? Hash + @ins.last[path] = self.class.new(&block).to_app + else + @ins << {} + map(path, &block) + end + end + + def to_app + @ins[-1] = Rack::URLMap.new(@ins.last) if Hash === @ins.last + inner_app = @ins.last + @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) } + end + + def call(env) + to_app.call(env) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/cascade.rb b/vendor/gems/rack-1.1.0/lib/rack/cascade.rb new file mode 100644 index 00000000..14c3e54d --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/cascade.rb @@ -0,0 +1,41 @@ +module Rack + # Rack::Cascade tries an request on several apps, and returns the + # first response that is not 404 (or in a list of configurable + # status codes). + + class Cascade + NotFound = [404, {}, []] + + attr_reader :apps + + def initialize(apps, catch=404) + @apps = []; @has_app = {} + apps.each { |app| add app } + + @catch = {} + [*catch].each { |status| @catch[status] = true } + end + + def call(env) + result = NotFound + + @apps.each do |app| + result = app.call(env) + break unless @catch.include?(result[0].to_i) + end + + result + end + + def add app + @has_app[app] = true + @apps << app + end + + def include? app + @has_app.include? app + end + + alias_method :<<, :add + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/chunked.rb b/vendor/gems/rack-1.1.0/lib/rack/chunked.rb new file mode 100644 index 00000000..dddf9694 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/chunked.rb @@ -0,0 +1,49 @@ +require 'rack/utils' + +module Rack + + # Middleware that applies chunked transfer encoding to response bodies + # when the response does not include a Content-Length header. + class Chunked + include Rack::Utils + + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + headers = HeaderHash.new(headers) + + if env['HTTP_VERSION'] == 'HTTP/1.0' || + STATUS_WITH_NO_ENTITY_BODY.include?(status) || + headers['Content-Length'] || + headers['Transfer-Encoding'] + [status, headers, body] + else + dup.chunk(status, headers, body) + end + end + + def chunk(status, headers, body) + @body = body + headers.delete('Content-Length') + headers['Transfer-Encoding'] = 'chunked' + [status, headers, self] + end + + def each + term = "\r\n" + @body.each do |chunk| + size = bytesize(chunk) + next if size == 0 + yield [size.to_s(16), term, chunk, term].join + end + yield ["0", term, "", term].join + end + + def close + @body.close if @body.respond_to?(:close) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/commonlogger.rb b/vendor/gems/rack-1.1.0/lib/rack/commonlogger.rb new file mode 100644 index 00000000..1edc9b83 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/commonlogger.rb @@ -0,0 +1,49 @@ +module Rack + # Rack::CommonLogger forwards every request to an +app+ given, and + # logs a line in the Apache common log format to the +logger+, or + # rack.errors by default. + class CommonLogger + # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common + # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 - + # %{%s - %s [%s] "%s %s%s %s" %d %s\n} % + FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n} + + def initialize(app, logger=nil) + @app = app + @logger = logger + end + + def call(env) + began_at = Time.now + status, header, body = @app.call(env) + header = Utils::HeaderHash.new(header) + log(env, status, header, began_at) + [status, header, body] + end + + private + + def log(env, status, header, began_at) + now = Time.now + length = extract_content_length(header) + + logger = @logger || env['rack.errors'] + logger.write FORMAT % [ + env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-", + env["REMOTE_USER"] || "-", + now.strftime("%d/%b/%Y %H:%M:%S"), + env["REQUEST_METHOD"], + env["PATH_INFO"], + env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"], + env["HTTP_VERSION"], + status.to_s[0..3], + length, + now - began_at ] + end + + def extract_content_length(headers) + value = headers['Content-Length'] or return '-' + value.to_s == '0' ? '-' : value + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/conditionalget.rb b/vendor/gems/rack-1.1.0/lib/rack/conditionalget.rb new file mode 100644 index 00000000..046ebdb0 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/conditionalget.rb @@ -0,0 +1,47 @@ +require 'rack/utils' + +module Rack + + # Middleware that enables conditional GET using If-None-Match and + # If-Modified-Since. The application should set either or both of the + # Last-Modified or Etag response headers according to RFC 2616. When + # either of the conditions is met, the response body is set to be zero + # length and the response status is set to 304 Not Modified. + # + # Applications that defer response body generation until the body's each + # message is received will avoid response body generation completely when + # a conditional GET matches. + # + # Adapted from Michael Klishin's Merb implementation: + # http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb + class ConditionalGet + def initialize(app) + @app = app + end + + def call(env) + return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD']) + + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + if etag_matches?(env, headers) || modified_since?(env, headers) + status = 304 + headers.delete('Content-Type') + headers.delete('Content-Length') + body = [] + end + [status, headers, body] + end + + private + def etag_matches?(env, headers) + etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH'] + end + + def modified_since?(env, headers) + last_modified = headers['Last-Modified'] and + last_modified == env['HTTP_IF_MODIFIED_SINCE'] + end + end + +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/config.rb b/vendor/gems/rack-1.1.0/lib/rack/config.rb new file mode 100644 index 00000000..c6d446c0 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/config.rb @@ -0,0 +1,15 @@ +module Rack + # Rack::Config modifies the environment using the block given during + # initialization. + class Config + def initialize(app, &block) + @app = app + @block = block + end + + def call(env) + @block.call(env) + @app.call(env) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/content_length.rb b/vendor/gems/rack-1.1.0/lib/rack/content_length.rb new file mode 100644 index 00000000..1e56d438 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/content_length.rb @@ -0,0 +1,29 @@ +require 'rack/utils' + +module Rack + # Sets the Content-Length header on responses with fixed-length bodies. + class ContentLength + include Rack::Utils + + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + headers = HeaderHash.new(headers) + + if !STATUS_WITH_NO_ENTITY_BODY.include?(status) && + !headers['Content-Length'] && + !headers['Transfer-Encoding'] && + (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) + + body = [body] if body.respond_to?(:to_str) # rack 0.4 compat + length = body.to_ary.inject(0) { |len, part| len + bytesize(part) } + headers['Content-Length'] = length.to_s + end + + [status, headers, body] + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/content_type.rb b/vendor/gems/rack-1.1.0/lib/rack/content_type.rb new file mode 100644 index 00000000..874c28cd --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/content_type.rb @@ -0,0 +1,23 @@ +require 'rack/utils' + +module Rack + + # Sets the Content-Type header on responses which don't have one. + # + # Builder Usage: + # use Rack::ContentType, "text/plain" + # + # When no content type argument is provided, "text/html" is assumed. + class ContentType + def initialize(app, content_type = "text/html") + @app, @content_type = app, content_type + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + headers['Content-Type'] ||= @content_type + [status, headers, body] + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/deflater.rb b/vendor/gems/rack-1.1.0/lib/rack/deflater.rb new file mode 100644 index 00000000..ad0f5316 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/deflater.rb @@ -0,0 +1,96 @@ +require "zlib" +require "stringio" +require "time" # for Time.httpdate +require 'rack/utils' + +module Rack + class Deflater + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + + # Skip compressing empty entity body responses and responses with + # no-transform set. + if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) || + headers['Cache-Control'].to_s =~ /\bno-transform\b/ + return [status, headers, body] + end + + request = Request.new(env) + + encoding = Utils.select_best_encoding(%w(gzip deflate identity), + request.accept_encoding) + + # Set the Vary HTTP header. + vary = headers["Vary"].to_s.split(",").map { |v| v.strip } + unless vary.include?("*") || vary.include?("Accept-Encoding") + headers["Vary"] = vary.push("Accept-Encoding").join(",") + end + + case encoding + when "gzip" + headers['Content-Encoding'] = "gzip" + headers.delete('Content-Length') + mtime = headers.key?("Last-Modified") ? + Time.httpdate(headers["Last-Modified"]) : Time.now + [status, headers, GzipStream.new(body, mtime)] + when "deflate" + headers['Content-Encoding'] = "deflate" + headers.delete('Content-Length') + [status, headers, DeflateStream.new(body)] + when "identity" + [status, headers, body] + when nil + message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found." + [406, {"Content-Type" => "text/plain", "Content-Length" => message.length.to_s}, [message]] + end + end + + class GzipStream + def initialize(body, mtime) + @body = body + @mtime = mtime + end + + def each(&block) + @writer = block + gzip =::Zlib::GzipWriter.new(self) + gzip.mtime = @mtime + @body.each { |part| gzip.write(part) } + @body.close if @body.respond_to?(:close) + gzip.close + @writer = nil + end + + def write(data) + @writer.call(data) + end + end + + class DeflateStream + DEFLATE_ARGS = [ + Zlib::DEFAULT_COMPRESSION, + # drop the zlib header which causes both Safari and IE to choke + -Zlib::MAX_WBITS, + Zlib::DEF_MEM_LEVEL, + Zlib::DEFAULT_STRATEGY + ] + + def initialize(body) + @body = body + end + + def each + deflater = ::Zlib::Deflate.new(*DEFLATE_ARGS) + @body.each { |part| yield deflater.deflate(part) } + @body.close if @body.respond_to?(:close) + yield deflater.finish + nil + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/directory.rb b/vendor/gems/rack-1.1.0/lib/rack/directory.rb new file mode 100644 index 00000000..927ac0c9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/directory.rb @@ -0,0 +1,157 @@ +require 'time' +require 'rack/utils' +require 'rack/mime' + +module Rack + # Rack::Directory serves entries below the +root+ given, according to the + # path info of the Rack request. If a directory is found, the file's contents + # will be presented in an html based index. If a file is found, the env will + # be passed to the specified +app+. + # + # If +app+ is not specified, a Rack::File of the same +root+ will be used. + + class Directory + DIR_FILE = "%s%s%s%s" + DIR_PAGE = <<-PAGE + + %s + + + +

    %s

    +
    + + + + + + + +%s +
    NameSizeTypeLast Modified
    +
    + + PAGE + + attr_reader :files + attr_accessor :root, :path + + def initialize(root, app=nil) + @root = F.expand_path(root) + @app = app || Rack::File.new(@root) + end + + def call(env) + dup._call(env) + end + + F = ::File + + def _call(env) + @env = env + @script_name = env['SCRIPT_NAME'] + @path_info = Utils.unescape(env['PATH_INFO']) + + if forbidden = check_forbidden + forbidden + else + @path = F.join(@root, @path_info) + list_path + end + end + + def check_forbidden + return unless @path_info.include? ".." + + body = "Forbidden\n" + size = Rack::Utils.bytesize(body) + return [403, {"Content-Type" => "text/plain", + "Content-Length" => size.to_s, + "X-Cascade" => "pass"}, [body]] + end + + def list_directory + @files = [['../','Parent Directory','','','']] + glob = F.join(@path, '*') + + Dir[glob].sort.each do |node| + stat = stat(node) + next unless stat + basename = F.basename(node) + ext = F.extname(node) + + url = F.join(@script_name, @path_info, basename) + size = stat.size + type = stat.directory? ? 'directory' : Mime.mime_type(ext) + size = stat.directory? ? '-' : filesize_format(size) + mtime = stat.mtime.httpdate + url << '/' if stat.directory? + basename << '/' if stat.directory? + + @files << [ url, basename, size, type, mtime ] + end + + return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ] + end + + def stat(node, max = 10) + F.stat(node) + rescue Errno::ENOENT, Errno::ELOOP + return nil + end + + # TODO: add correct response if not readable, not sure if 404 is the best + # option + def list_path + @stat = F.stat(@path) + + if @stat.readable? + return @app.call(@env) if @stat.file? + return list_directory if @stat.directory? + else + raise Errno::ENOENT, 'No such file or directory' + end + + rescue Errno::ENOENT, Errno::ELOOP + return entity_not_found + end + + def entity_not_found + body = "Entity not found: #{@path_info}\n" + size = Rack::Utils.bytesize(body) + return [404, {"Content-Type" => "text/plain", + "Content-Length" => size.to_s, + "X-Cascade" => "pass"}, [body]] + end + + def each + show_path = @path.sub(/^#{@root}/,'') + files = @files.map{|f| DIR_FILE % f }*"\n" + page = DIR_PAGE % [ show_path, show_path , files ] + page.each_line{|l| yield l } + end + + # Stolen from Ramaze + + FILESIZE_FORMAT = [ + ['%.1fT', 1 << 40], + ['%.1fG', 1 << 30], + ['%.1fM', 1 << 20], + ['%.1fK', 1 << 10], + ] + + def filesize_format(int) + FILESIZE_FORMAT.each do |format, size| + return format % (int.to_f / size) if int >= size + end + + int.to_s + 'B' + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/etag.rb b/vendor/gems/rack-1.1.0/lib/rack/etag.rb new file mode 100644 index 00000000..06dbc6aa --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/etag.rb @@ -0,0 +1,23 @@ +require 'digest/md5' + +module Rack + # Automatically sets the ETag header on all String bodies + class ETag + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + + if !headers.has_key?('ETag') + parts = [] + body.each { |part| parts << part.to_s } + headers['ETag'] = %("#{Digest::MD5.hexdigest(parts.join(""))}") + [status, headers, parts] + else + [status, headers, body] + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/file.rb b/vendor/gems/rack-1.1.0/lib/rack/file.rb new file mode 100644 index 00000000..14af7b3b --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/file.rb @@ -0,0 +1,90 @@ +require 'time' +require 'rack/utils' +require 'rack/mime' + +module Rack + # Rack::File serves files below the +root+ given, according to the + # path info of the Rack request. + # + # Handlers can detect if bodies are a Rack::File, and use mechanisms + # like sendfile on the +path+. + + class File + attr_accessor :root + attr_accessor :path + + alias :to_path :path + + def initialize(root) + @root = root + end + + def call(env) + dup._call(env) + end + + F = ::File + + def _call(env) + @path_info = Utils.unescape(env["PATH_INFO"]) + return forbidden if @path_info.include? ".." + + @path = F.join(@root, @path_info) + + begin + if F.file?(@path) && F.readable?(@path) + serving + else + raise Errno::EPERM + end + rescue SystemCallError + not_found + end + end + + def forbidden + body = "Forbidden\n" + [403, {"Content-Type" => "text/plain", + "Content-Length" => body.size.to_s, + "X-Cascade" => "pass"}, + [body]] + end + + # NOTE: + # We check via File::size? whether this file provides size info + # via stat (e.g. /proc files often don't), otherwise we have to + # figure it out by reading the whole file into memory. And while + # we're at it we also use this as body then. + + def serving + if size = F.size?(@path) + body = self + else + body = [F.read(@path)] + size = Utils.bytesize(body.first) + end + + [200, { + "Last-Modified" => F.mtime(@path).httpdate, + "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'), + "Content-Length" => size.to_s + }, body] + end + + def not_found + body = "File not found: #{@path_info}\n" + [404, {"Content-Type" => "text/plain", + "Content-Length" => body.size.to_s, + "X-Cascade" => "pass"}, + [body]] + end + + def each + F.open(@path, "rb") { |file| + while part = file.read(8192) + yield part + end + } + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler.rb b/vendor/gems/rack-1.1.0/lib/rack/handler.rb new file mode 100644 index 00000000..3c09883e --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler.rb @@ -0,0 +1,88 @@ +module Rack + # *Handlers* connect web servers with Rack. + # + # Rack includes Handlers for Mongrel, WEBrick, FastCGI, CGI, SCGI + # and LiteSpeed. + # + # Handlers usually are activated by calling MyHandler.run(myapp). + # A second optional hash can be passed to include server-specific + # configuration. + module Handler + def self.get(server) + return unless server + server = server.to_s + + if klass = @handlers[server] + obj = Object + klass.split("::").each { |x| obj = obj.const_get(x) } + obj + else + try_require('rack/handler', server) + const_get(server) + end + end + + def self.default(options = {}) + # Guess. + if ENV.include?("PHP_FCGI_CHILDREN") + # We already speak FastCGI + options.delete :File + options.delete :Port + + Rack::Handler::FastCGI + elsif ENV.include?("REQUEST_METHOD") + Rack::Handler::CGI + else + begin + Rack::Handler::Mongrel + rescue LoadError => e + Rack::Handler::WEBrick + end + end + end + + # Transforms server-name constants to their canonical form as filenames, + # then tries to require them but silences the LoadError if not found + # + # Naming convention: + # + # Foo # => 'foo' + # FooBar # => 'foo_bar.rb' + # FooBAR # => 'foobar.rb' + # FOObar # => 'foobar.rb' + # FOOBAR # => 'foobar.rb' + # FooBarBaz # => 'foo_bar_baz.rb' + def self.try_require(prefix, const_name) + file = const_name.gsub(/^[A-Z]+/) { |pre| pre.downcase }. + gsub(/[A-Z]+[^A-Z]/, '_\&').downcase + + require(::File.join(prefix, file)) + rescue LoadError + end + + def self.register(server, klass) + @handlers ||= {} + @handlers[server] = klass + end + + autoload :CGI, "rack/handler/cgi" + autoload :FastCGI, "rack/handler/fastcgi" + autoload :Mongrel, "rack/handler/mongrel" + autoload :EventedMongrel, "rack/handler/evented_mongrel" + autoload :SwiftipliedMongrel, "rack/handler/swiftiplied_mongrel" + autoload :WEBrick, "rack/handler/webrick" + autoload :LSWS, "rack/handler/lsws" + autoload :SCGI, "rack/handler/scgi" + autoload :Thin, "rack/handler/thin" + + register 'cgi', 'Rack::Handler::CGI' + register 'fastcgi', 'Rack::Handler::FastCGI' + register 'mongrel', 'Rack::Handler::Mongrel' + register 'emongrel', 'Rack::Handler::EventedMongrel' + register 'smongrel', 'Rack::Handler::SwiftipliedMongrel' + register 'webrick', 'Rack::Handler::WEBrick' + register 'lsws', 'Rack::Handler::LSWS' + register 'scgi', 'Rack::Handler::SCGI' + register 'thin', 'Rack::Handler::Thin' + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/cgi.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/cgi.rb new file mode 100644 index 00000000..c6903f15 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/cgi.rb @@ -0,0 +1,61 @@ +require 'rack/content_length' + +module Rack + module Handler + class CGI + def self.run(app, options=nil) + serve app + end + + def self.serve(app) + app = ContentLength.new(app) + + env = ENV.to_hash + env.delete "HTTP_CONTENT_LENGTH" + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + env.update({"rack.version" => [1,1], + "rack.input" => $stdin, + "rack.errors" => $stderr, + + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => true, + + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + }) + + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + + status, headers, body = app.call(env) + begin + send_headers status, headers + send_body body + ensure + body.close if body.respond_to? :close + end + end + + def self.send_headers(status, headers) + STDOUT.print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.split("\n").each { |v| + STDOUT.print "#{k}: #{v}\r\n" + } + } + STDOUT.print "\r\n" + STDOUT.flush + end + + def self.send_body(body) + body.each { |part| + STDOUT.print part + STDOUT.flush + } + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/evented_mongrel.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/evented_mongrel.rb new file mode 100644 index 00000000..0f5cbf72 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/evented_mongrel.rb @@ -0,0 +1,8 @@ +require 'swiftcore/evented_mongrel' + +module Rack + module Handler + class EventedMongrel < Handler::Mongrel + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/fastcgi.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/fastcgi.rb new file mode 100644 index 00000000..b992a5f4 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/fastcgi.rb @@ -0,0 +1,89 @@ +require 'fcgi' +require 'socket' +require 'rack/content_length' +require 'rack/rewindable_input' + +if defined? FCGI::Stream + class FCGI::Stream + alias _rack_read_without_buffer read + + def read(n, buffer=nil) + buf = _rack_read_without_buffer n + buffer.replace(buf.to_s) if buffer + buf + end + end +end + +module Rack + module Handler + class FastCGI + def self.run(app, options={}) + file = options[:File] and STDIN.reopen(UNIXServer.new(file)) + port = options[:Port] and STDIN.reopen(TCPServer.new(port)) + FCGI.each { |request| + serve request, app + } + end + + def self.serve(request, app) + app = Rack::ContentLength.new(app) + + env = request.env + env.delete "HTTP_CONTENT_LENGTH" + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + rack_input = RewindableInput.new(request.in) + + env.update({"rack.version" => [1,1], + "rack.input" => rack_input, + "rack.errors" => request.err, + + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" + }) + + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == "" + env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == "" + + begin + status, headers, body = app.call(env) + begin + send_headers request.out, status, headers + send_body request.out, body + ensure + body.close if body.respond_to? :close + end + ensure + rack_input.close + request.finish + end + end + + def self.send_headers(out, status, headers) + out.print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.split("\n").each { |v| + out.print "#{k}: #{v}\r\n" + } + } + out.print "\r\n" + out.flush + end + + def self.send_body(out, body) + body.each { |part| + out.print part + out.flush + } + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/lsws.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/lsws.rb new file mode 100644 index 00000000..eabc0bc9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/lsws.rb @@ -0,0 +1,63 @@ +require 'lsapi' +require 'rack/content_length' +require 'rack/rewindable_input' + +module Rack + module Handler + class LSWS + def self.run(app, options=nil) + while LSAPI.accept != nil + serve app + end + end + def self.serve(app) + app = Rack::ContentLength.new(app) + + env = ENV.to_hash + env.delete "HTTP_CONTENT_LENGTH" + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + rack_input = RewindableInput.new($stdin.read.to_s) + + env.update( + "rack.version" => [1,1], + "rack.input" => rack_input, + "rack.errors" => $stderr, + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => false, + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + ) + + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + status, headers, body = app.call(env) + begin + send_headers status, headers + send_body body + ensure + body.close if body.respond_to? :close + end + ensure + rack_input.close + end + def self.send_headers(status, headers) + print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.split("\n").each { |v| + print "#{k}: #{v}\r\n" + } + } + print "\r\n" + STDOUT.flush + end + def self.send_body(body) + body.each { |part| + print part + STDOUT.flush + } + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/mongrel.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/mongrel.rb new file mode 100644 index 00000000..b6b775ea --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/mongrel.rb @@ -0,0 +1,90 @@ +require 'mongrel' +require 'stringio' +require 'rack/content_length' +require 'rack/chunked' + +module Rack + module Handler + class Mongrel < ::Mongrel::HttpHandler + def self.run(app, options={}) + server = ::Mongrel::HttpServer.new( + options[:Host] || '0.0.0.0', + options[:Port] || 8080, + options[:num_processors] || 950, + options[:throttle] || 0, + options[:timeout] || 60) + # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods. + # Use is similar to #run, replacing the app argument with a hash of + # { path=>app, ... } or an instance of Rack::URLMap. + if options[:map] + if app.is_a? Hash + app.each do |path, appl| + path = '/'+path unless path[0] == ?/ + server.register(path, Rack::Handler::Mongrel.new(appl)) + end + elsif app.is_a? URLMap + app.instance_variable_get(:@mapping).each do |(host, path, appl)| + next if !host.nil? && !options[:Host].nil? && options[:Host] != host + path = '/'+path unless path[0] == ?/ + server.register(path, Rack::Handler::Mongrel.new(appl)) + end + else + raise ArgumentError, "first argument should be a Hash or URLMap" + end + else + server.register('/', Rack::Handler::Mongrel.new(app)) + end + yield server if block_given? + server.run.join + end + + def initialize(app) + @app = Rack::Chunked.new(Rack::ContentLength.new(app)) + end + + def process(request, response) + env = {}.replace(request.params) + env.delete "HTTP_CONTENT_TYPE" + env.delete "HTTP_CONTENT_LENGTH" + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + rack_input = request.body || StringIO.new('') + rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) + + env.update({"rack.version" => [1,1], + "rack.input" => rack_input, + "rack.errors" => $stderr, + + "rack.multithread" => true, + "rack.multiprocess" => false, # ??? + "rack.run_once" => false, + + "rack.url_scheme" => "http", + }) + env["QUERY_STRING"] ||= "" + + status, headers, body = @app.call(env) + + begin + response.status = status.to_i + response.send_status(nil) + + headers.each { |k, vs| + vs.split("\n").each { |v| + response.header[k] = v + } + } + response.send_header + + body.each { |part| + response.write part + response.socket.flush + } + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/scgi.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/scgi.rb new file mode 100644 index 00000000..79a6b2bd --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/scgi.rb @@ -0,0 +1,62 @@ +require 'scgi' +require 'stringio' +require 'rack/content_length' +require 'rack/chunked' + +module Rack + module Handler + class SCGI < ::SCGI::Processor + attr_accessor :app + + def self.run(app, options=nil) + new(options.merge(:app=>app, + :host=>options[:Host], + :port=>options[:Port], + :socket=>options[:Socket])).listen + end + + def initialize(settings = {}) + @app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app])) + @log = Object.new + def @log.info(*args); end + def @log.error(*args); end + super(settings) + end + + def process_request(request, input_body, socket) + env = {}.replace(request) + env.delete "HTTP_CONTENT_TYPE" + env.delete "HTTP_CONTENT_LENGTH" + env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2) + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["PATH_INFO"] = env["REQUEST_PATH"] + env["QUERY_STRING"] ||= "" + env["SCRIPT_NAME"] = "" + + rack_input = StringIO.new(input_body) + rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) + + env.update({"rack.version" => [1,1], + "rack.input" => rack_input, + "rack.errors" => $stderr, + "rack.multithread" => true, + "rack.multiprocess" => true, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" + }) + status, headers, body = app.call(env) + begin + socket.write("Status: #{status}\r\n") + headers.each do |k, vs| + vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")} + end + socket.write("\r\n") + body.each {|s| socket.write(s)} + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/swiftiplied_mongrel.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/swiftiplied_mongrel.rb new file mode 100644 index 00000000..4bafd0b9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/swiftiplied_mongrel.rb @@ -0,0 +1,8 @@ +require 'swiftcore/swiftiplied_mongrel' + +module Rack + module Handler + class SwiftipliedMongrel < Handler::Mongrel + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/thin.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/thin.rb new file mode 100644 index 00000000..3d4fedff --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/thin.rb @@ -0,0 +1,18 @@ +require "thin" +require "rack/content_length" +require "rack/chunked" + +module Rack + module Handler + class Thin + def self.run(app, options={}) + app = Rack::Chunked.new(Rack::ContentLength.new(app)) + server = ::Thin::Server.new(options[:Host] || '0.0.0.0', + options[:Port] || 8080, + app) + yield server if block_given? + server.start + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/handler/webrick.rb b/vendor/gems/rack-1.1.0/lib/rack/handler/webrick.rb new file mode 100644 index 00000000..8d7f5724 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/handler/webrick.rb @@ -0,0 +1,69 @@ +require 'webrick' +require 'stringio' +require 'rack/content_length' + +module Rack + module Handler + class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet + def self.run(app, options={}) + options[:BindAddress] = options.delete(:Host) if options[:Host] + server = ::WEBrick::HTTPServer.new(options) + server.mount "/", Rack::Handler::WEBrick, app + trap(:INT) { server.shutdown } + yield server if block_given? + server.start + end + + def initialize(server, app) + super server + @app = Rack::ContentLength.new(app) + end + + def service(req, res) + env = req.meta_vars + env.delete_if { |k, v| v.nil? } + + rack_input = StringIO.new(req.body.to_s) + rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) + + env.update({"rack.version" => [1,1], + "rack.input" => rack_input, + "rack.errors" => $stderr, + + "rack.multithread" => true, + "rack.multiprocess" => false, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + }) + + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["QUERY_STRING"] ||= "" + env["REQUEST_PATH"] ||= "/" + unless env["PATH_INFO"] == "" + path, n = req.request_uri.path, env["SCRIPT_NAME"].length + env["PATH_INFO"] = path[n, path.length-n] + end + + status, headers, body = @app.call(env) + begin + res.status = status.to_i + headers.each { |k, vs| + if k.downcase == "set-cookie" + res.cookies.concat vs.split("\n") + else + vs.split("\n").each { |v| + res[k] = v + } + end + } + body.each { |part| + res.body << part + } + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/head.rb b/vendor/gems/rack-1.1.0/lib/rack/head.rb new file mode 100644 index 00000000..deab822a --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/head.rb @@ -0,0 +1,19 @@ +module Rack + +class Head + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + + if env["REQUEST_METHOD"] == "HEAD" + [status, headers, []] + else + [status, headers, body] + end + end +end + +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/lint.rb b/vendor/gems/rack-1.1.0/lib/rack/lint.rb new file mode 100644 index 00000000..534375b9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/lint.rb @@ -0,0 +1,575 @@ +require 'rack/utils' + +module Rack + # Rack::Lint validates your application and the requests and + # responses according to the Rack spec. + + class Lint + def initialize(app) + @app = app + end + + # :stopdoc: + + class LintError < RuntimeError; end + module Assertion + def assert(message, &block) + unless block.call + raise LintError, message + end + end + end + include Assertion + + ## This specification aims to formalize the Rack protocol. You + ## can (and should) use Rack::Lint to enforce it. + ## + ## When you develop middleware, be sure to add a Lint before and + ## after to catch all mistakes. + + ## = Rack applications + + ## A Rack application is an Ruby object (not a class) that + ## responds to +call+. + def call(env=nil) + dup._call(env) + end + + def _call(env) + ## It takes exactly one argument, the *environment* + assert("No env given") { env } + check_env env + + env['rack.input'] = InputWrapper.new(env['rack.input']) + env['rack.errors'] = ErrorWrapper.new(env['rack.errors']) + + ## and returns an Array of exactly three values: + status, headers, @body = @app.call(env) + ## The *status*, + check_status status + ## the *headers*, + check_headers headers + ## and the *body*. + check_content_type status, headers + check_content_length status, headers, env + [status, headers, self] + end + + ## == The Environment + def check_env(env) + ## The environment must be an true instance of Hash (no + ## subclassing allowed) that includes CGI-like headers. + ## The application is free to modify the environment. + assert("env #{env.inspect} is not a Hash, but #{env.class}") { + env.kind_of? Hash + } + + ## + ## The environment is required to include these variables + ## (adopted from PEP333), except when they'd be empty, but see + ## below. + + ## REQUEST_METHOD:: The HTTP request method, such as + ## "GET" or "POST". This cannot ever + ## be an empty string, and so is + ## always required. + + ## SCRIPT_NAME:: The initial portion of the request + ## URL's "path" that corresponds to the + ## application object, so that the + ## application knows its virtual + ## "location". This may be an empty + ## string, if the application corresponds + ## to the "root" of the server. + + ## PATH_INFO:: The remainder of the request URL's + ## "path", designating the virtual + ## "location" of the request's target + ## within the application. This may be an + ## empty string, if the request URL targets + ## the application root and does not have a + ## trailing slash. This value may be + ## percent-encoded when I originating from + ## a URL. + + ## QUERY_STRING:: The portion of the request URL that + ## follows the ?, if any. May be + ## empty, but is always required! + + ## SERVER_NAME, SERVER_PORT:: When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required. + + ## HTTP_ Variables:: Variables corresponding to the + ## client-supplied HTTP request + ## headers (i.e., variables whose + ## names begin with HTTP_). The + ## presence or absence of these + ## variables should correspond with + ## the presence or absence of the + ## appropriate HTTP header in the + ## request. + + ## In addition to this, the Rack environment must include these + ## Rack-specific variables: + + ## rack.version:: The Array [1,1], representing this version of Rack. + ## rack.url_scheme:: +http+ or +https+, depending on the request URL. + ## rack.input:: See below, the input stream. + ## rack.errors:: See below, the error stream. + ## rack.multithread:: true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. + ## rack.multiprocess:: true if an equivalent application object may be simultaneously invoked by another process, false otherwise. + ## rack.run_once:: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). + ## + + ## Additional environment specifications have approved to + ## standardized middleware APIs. None of these are required to + ## be implemented by the server. + + ## rack.session:: A hash like interface for storing request session data. + ## The store must implement: + if session = env['rack.session'] + ## store(key, value) (aliased as []=); + assert("session #{session.inspect} must respond to store and []=") { + session.respond_to?(:store) && session.respond_to?(:[]=) + } + + ## fetch(key, default = nil) (aliased as []); + assert("session #{session.inspect} must respond to fetch and []") { + session.respond_to?(:fetch) && session.respond_to?(:[]) + } + + ## delete(key); + assert("session #{session.inspect} must respond to delete") { + session.respond_to?(:delete) + } + + ## clear; + assert("session #{session.inspect} must respond to clear") { + session.respond_to?(:clear) + } + end + + ## rack.logger:: A common object interface for logging messages. + ## The object must implement: + if logger = env['rack.logger'] + ## info(message, &block) + assert("logger #{logger.inspect} must respond to info") { + logger.respond_to?(:info) + } + + ## debug(message, &block) + assert("logger #{logger.inspect} must respond to debug") { + logger.respond_to?(:debug) + } + + ## warn(message, &block) + assert("logger #{logger.inspect} must respond to warn") { + logger.respond_to?(:warn) + } + + ## error(message, &block) + assert("logger #{logger.inspect} must respond to error") { + logger.respond_to?(:error) + } + + ## fatal(message, &block) + assert("logger #{logger.inspect} must respond to fatal") { + logger.respond_to?(:fatal) + } + end + + ## The server or the application can store their own data in the + ## environment, too. The keys must contain at least one dot, + ## and should be prefixed uniquely. The prefix rack. + ## is reserved for use with the Rack core distribution and other + ## accepted specifications and must not be used otherwise. + ## + + %w[REQUEST_METHOD SERVER_NAME SERVER_PORT + QUERY_STRING + rack.version rack.input rack.errors + rack.multithread rack.multiprocess rack.run_once].each { |header| + assert("env missing required key #{header}") { env.include? header } + } + + ## The environment must not contain the keys + ## HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH + ## (use the versions without HTTP_). + %w[HTTP_CONTENT_TYPE HTTP_CONTENT_LENGTH].each { |header| + assert("env contains #{header}, must use #{header[5,-1]}") { + not env.include? header + } + } + + ## The CGI keys (named without a period) must have String values. + env.each { |key, value| + next if key.include? "." # Skip extensions + assert("env variable #{key} has non-string value #{value.inspect}") { + value.kind_of? String + } + } + + ## + ## There are the following restrictions: + + ## * rack.version must be an array of Integers. + assert("rack.version must be an Array, was #{env["rack.version"].class}") { + env["rack.version"].kind_of? Array + } + ## * rack.url_scheme must either be +http+ or +https+. + assert("rack.url_scheme unknown: #{env["rack.url_scheme"].inspect}") { + %w[http https].include? env["rack.url_scheme"] + } + + ## * There must be a valid input stream in rack.input. + check_input env["rack.input"] + ## * There must be a valid error stream in rack.errors. + check_error env["rack.errors"] + + ## * The REQUEST_METHOD must be a valid token. + assert("REQUEST_METHOD unknown: #{env["REQUEST_METHOD"]}") { + env["REQUEST_METHOD"] =~ /\A[0-9A-Za-z!\#$%&'*+.^_`|~-]+\z/ + } + + ## * The SCRIPT_NAME, if non-empty, must start with / + assert("SCRIPT_NAME must start with /") { + !env.include?("SCRIPT_NAME") || + env["SCRIPT_NAME"] == "" || + env["SCRIPT_NAME"] =~ /\A\// + } + ## * The PATH_INFO, if non-empty, must start with / + assert("PATH_INFO must start with /") { + !env.include?("PATH_INFO") || + env["PATH_INFO"] == "" || + env["PATH_INFO"] =~ /\A\// + } + ## * The CONTENT_LENGTH, if given, must consist of digits only. + assert("Invalid CONTENT_LENGTH: #{env["CONTENT_LENGTH"]}") { + !env.include?("CONTENT_LENGTH") || env["CONTENT_LENGTH"] =~ /\A\d+\z/ + } + + ## * One of SCRIPT_NAME or PATH_INFO must be + ## set. PATH_INFO should be / if + ## SCRIPT_NAME is empty. + assert("One of SCRIPT_NAME or PATH_INFO must be set (make PATH_INFO '/' if SCRIPT_NAME is empty)") { + env["SCRIPT_NAME"] || env["PATH_INFO"] + } + ## SCRIPT_NAME never should be /, but instead be empty. + assert("SCRIPT_NAME cannot be '/', make it '' and PATH_INFO '/'") { + env["SCRIPT_NAME"] != "/" + } + end + + ## === The Input Stream + ## + ## The input stream is an IO-like object which contains the raw HTTP + ## POST data. + def check_input(input) + ## When applicable, its external encoding must be "ASCII-8BIT" and it + ## must be opened in binary mode, for Ruby 1.9 compatibility. + assert("rack.input #{input} does not have ASCII-8BIT as its external encoding") { + input.external_encoding.name == "ASCII-8BIT" + } if input.respond_to?(:external_encoding) + assert("rack.input #{input} is not opened in binary mode") { + input.binmode? + } if input.respond_to?(:binmode?) + + ## The input stream must respond to +gets+, +each+, +read+ and +rewind+. + [:gets, :each, :read, :rewind].each { |method| + assert("rack.input #{input} does not respond to ##{method}") { + input.respond_to? method + } + } + end + + class InputWrapper + include Assertion + + def initialize(input) + @input = input + end + + def size + @input.size + end + + ## * +gets+ must be called without arguments and return a string, + ## or +nil+ on EOF. + def gets(*args) + assert("rack.input#gets called with arguments") { args.size == 0 } + v = @input.gets + assert("rack.input#gets didn't return a String") { + v.nil? or v.kind_of? String + } + v + end + + ## * +read+ behaves like IO#read. Its signature is read([length, [buffer]]). + ## If given, +length+ must be an non-negative Integer (>= 0) or +nil+, and +buffer+ must + ## be a String and may not be nil. If +length+ is given and not nil, then this method + ## reads at most +length+ bytes from the input stream. If +length+ is not given or nil, + ## then this method reads all data until EOF. + ## When EOF is reached, this method returns nil if +length+ is given and not nil, or "" + ## if +length+ is not given or is nil. + ## If +buffer+ is given, then the read data will be placed into +buffer+ instead of a + ## newly created String object. + def read(*args) + assert("rack.input#read called with too many arguments") { + args.size <= 2 + } + if args.size >= 1 + assert("rack.input#read called with non-integer and non-nil length") { + args.first.kind_of?(Integer) || args.first.nil? + } + assert("rack.input#read called with a negative length") { + args.first.nil? || args.first >= 0 + } + end + if args.size >= 2 + assert("rack.input#read called with non-String buffer") { + args[1].kind_of?(String) + } + end + + v = @input.read(*args) + + assert("rack.input#read didn't return nil or a String") { + v.nil? or v.kind_of? String + } + if args[0].nil? + assert("rack.input#read(nil) returned nil on EOF") { + !v.nil? + } + end + + v + end + + ## * +each+ must be called without arguments and only yield Strings. + def each(*args) + assert("rack.input#each called with arguments") { args.size == 0 } + @input.each { |line| + assert("rack.input#each didn't yield a String") { + line.kind_of? String + } + yield line + } + end + + ## * +rewind+ must be called without arguments. It rewinds the input + ## stream back to the beginning. It must not raise Errno::ESPIPE: + ## that is, it may not be a pipe or a socket. Therefore, handler + ## developers must buffer the input data into some rewindable object + ## if the underlying input stream is not rewindable. + def rewind(*args) + assert("rack.input#rewind called with arguments") { args.size == 0 } + assert("rack.input#rewind raised Errno::ESPIPE") { + begin + @input.rewind + true + rescue Errno::ESPIPE + false + end + } + end + + ## * +close+ must never be called on the input stream. + def close(*args) + assert("rack.input#close must not be called") { false } + end + end + + ## === The Error Stream + def check_error(error) + ## The error stream must respond to +puts+, +write+ and +flush+. + [:puts, :write, :flush].each { |method| + assert("rack.error #{error} does not respond to ##{method}") { + error.respond_to? method + } + } + end + + class ErrorWrapper + include Assertion + + def initialize(error) + @error = error + end + + ## * +puts+ must be called with a single argument that responds to +to_s+. + def puts(str) + @error.puts str + end + + ## * +write+ must be called with a single argument that is a String. + def write(str) + assert("rack.errors#write not called with a String") { str.kind_of? String } + @error.write str + end + + ## * +flush+ must be called without arguments and must be called + ## in order to make the error appear for sure. + def flush + @error.flush + end + + ## * +close+ must never be called on the error stream. + def close(*args) + assert("rack.errors#close must not be called") { false } + end + end + + ## == The Response + + ## === The Status + def check_status(status) + ## This is an HTTP status. When parsed as integer (+to_i+), it must be + ## greater than or equal to 100. + assert("Status must be >=100 seen as integer") { status.to_i >= 100 } + end + + ## === The Headers + def check_headers(header) + ## The header must respond to +each+, and yield values of key and value. + assert("headers object should respond to #each, but doesn't (got #{header.class} as headers)") { + header.respond_to? :each + } + header.each { |key, value| + ## The header keys must be Strings. + assert("header key must be a string, was #{key.class}") { + key.kind_of? String + } + ## The header must not contain a +Status+ key, + assert("header must not contain Status") { key.downcase != "status" } + ## contain keys with : or newlines in their name, + assert("header names must not contain : or \\n") { key !~ /[:\n]/ } + ## contain keys names that end in - or _, + assert("header names must not end in - or _") { key !~ /[-_]\z/ } + ## but only contain keys that consist of + ## letters, digits, _ or - and start with a letter. + assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ } + + ## The values of the header must be Strings, + assert("a header value must be a String, but the value of " + + "'#{key}' is a #{value.class}") { value.kind_of? String } + ## consisting of lines (for multiple header values, e.g. multiple + ## Set-Cookie values) seperated by "\n". + value.split("\n").each { |item| + ## The lines must not contain characters below 037. + assert("invalid header value #{key}: #{item.inspect}") { + item !~ /[\000-\037]/ + } + } + } + end + + ## === The Content-Type + def check_content_type(status, headers) + headers.each { |key, value| + ## There must be a Content-Type, except when the + ## +Status+ is 1xx, 204 or 304, in which case there must be none + ## given. + if key.downcase == "content-type" + assert("Content-Type header found in #{status} response, not allowed") { + not Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + return + end + } + assert("No Content-Type header found") { + Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + end + + ## === The Content-Length + def check_content_length(status, headers, env) + headers.each { |key, value| + if key.downcase == 'content-length' + ## There must not be a Content-Length header when the + ## +Status+ is 1xx, 204 or 304. + assert("Content-Length header found in #{status} response, not allowed") { + not Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + + bytes = 0 + string_body = true + + if @body.respond_to?(:to_ary) + @body.each { |part| + unless part.kind_of?(String) + string_body = false + break + end + + bytes += Rack::Utils.bytesize(part) + } + + if env["REQUEST_METHOD"] == "HEAD" + assert("Response body was given for HEAD request, but should be empty") { + bytes == 0 + } + else + if string_body + assert("Content-Length header was #{value}, but should be #{bytes}") { + value == bytes.to_s + } + end + end + end + + return + end + } + end + + ## === The Body + def each + @closed = false + ## The Body must respond to +each+ + @body.each { |part| + ## and must only yield String values. + assert("Body yielded non-string value #{part.inspect}") { + part.kind_of? String + } + yield part + } + ## + ## The Body itself should not be an instance of String, as this will + ## break in Ruby 1.9. + ## + ## If the Body responds to +close+, it will be called after iteration. + # XXX howto: assert("Body has not been closed") { @closed } + + + ## + ## If the Body responds to +to_path+, it must return a String + ## identifying the location of a file whose contents are identical + ## to that produced by calling +each+; this may be used by the + ## server as an alternative, possibly more efficient way to + ## transport the response. + + if @body.respond_to?(:to_path) + assert("The file identified by body.to_path does not exist") { + ::File.exist? @body.to_path + } + end + + ## + ## The Body commonly is an Array of Strings, the application + ## instance itself, or a File-like object. + end + + def close + @closed = true + @body.close if @body.respond_to?(:close) + end + + # :startdoc: + + end +end + +## == Thanks +## Some parts of this specification are adopted from PEP333: Python +## Web Server Gateway Interface +## v1.0 (http://www.python.org/dev/peps/pep-0333/). I'd like to thank +## everyone involved in that effort. diff --git a/vendor/gems/rack-1.1.0/lib/rack/lobster.rb b/vendor/gems/rack-1.1.0/lib/rack/lobster.rb new file mode 100644 index 00000000..f63f419a --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/lobster.rb @@ -0,0 +1,65 @@ +require 'zlib' + +require 'rack/request' +require 'rack/response' + +module Rack + # Paste has a Pony, Rack has a Lobster! + class Lobster + LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 + P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 + t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ + I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0]) + + LambdaLobster = lambda { |env| + if env["QUERY_STRING"].include?("flip") + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?" + else + lobster = LobsterString + href = "?flip" + end + + content = ["Lobstericious!", + "
    ", lobster, "
    ", + "flip!"] + length = content.inject(0) { |a,e| a+e.size }.to_s + [200, {"Content-Type" => "text/html", "Content-Length" => length}, content] + } + + def call(env) + req = Request.new(env) + if req.GET["flip"] == "left" + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?flip=right" + elsif req.GET["flip"] == "crash" + raise "Lobster crashed" + else + lobster = LobsterString + href = "?flip=left" + end + + res = Response.new + res.write "Lobstericious!" + res.write "
    "
    +      res.write lobster
    +      res.write "
    " + res.write "

    flip!

    " + res.write "

    crash!

    " + res.finish + end + + end +end + +if $0 == __FILE__ + require 'rack' + require 'rack/showexceptions' + Rack::Handler::WEBrick.run \ + Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)), + :Port => 9292 +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/lock.rb b/vendor/gems/rack-1.1.0/lib/rack/lock.rb new file mode 100644 index 00000000..93238528 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/lock.rb @@ -0,0 +1,16 @@ +module Rack + class Lock + FLAG = 'rack.multithread'.freeze + + def initialize(app, lock = Mutex.new) + @app, @lock = app, lock + end + + def call(env) + old, env[FLAG] = env[FLAG], false + @lock.synchronize { @app.call(env) } + ensure + env[FLAG] = old + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/logger.rb b/vendor/gems/rack-1.1.0/lib/rack/logger.rb new file mode 100644 index 00000000..d67d8ce2 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/logger.rb @@ -0,0 +1,20 @@ +require 'logger' + +module Rack + # Sets up rack.logger to write to rack.errors stream + class Logger + def initialize(app, level = ::Logger::INFO) + @app, @level = app, level + end + + def call(env) + logger = ::Logger.new(env['rack.errors']) + logger.level = @level + + env['rack.logger'] = logger + @app.call(env) + ensure + logger.close + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/methodoverride.rb b/vendor/gems/rack-1.1.0/lib/rack/methodoverride.rb new file mode 100644 index 00000000..0eed29f4 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/methodoverride.rb @@ -0,0 +1,27 @@ +module Rack + class MethodOverride + HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) + + METHOD_OVERRIDE_PARAM_KEY = "_method".freeze + HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze + + def initialize(app) + @app = app + end + + def call(env) + if env["REQUEST_METHOD"] == "POST" + req = Request.new(env) + method = req.POST[METHOD_OVERRIDE_PARAM_KEY] || + env[HTTP_METHOD_OVERRIDE_HEADER] + method = method.to_s.upcase + if HTTP_METHODS.include?(method) + env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"] + env["REQUEST_METHOD"] = method + end + end + + @app.call(env) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/mime.rb b/vendor/gems/rack-1.1.0/lib/rack/mime.rb new file mode 100644 index 00000000..1414d19a --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/mime.rb @@ -0,0 +1,206 @@ +module Rack + module Mime + # Returns String with mime type if found, otherwise use +fallback+. + # +ext+ should be filename extension in the '.ext' format that + # File.extname(file) returns. + # +fallback+ may be any object + # + # Also see the documentation for MIME_TYPES + # + # Usage: + # Rack::Mime.mime_type('.foo') + # + # This is a shortcut for: + # Rack::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream') + + def mime_type(ext, fallback='application/octet-stream') + MIME_TYPES.fetch(ext.to_s.downcase, fallback) + end + module_function :mime_type + + # List of most common mime-types, selected various sources + # according to their usefulness in a webserving scope for Ruby + # users. + # + # To amend this list with your local mime.types list you can use: + # + # require 'webrick/httputils' + # list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types') + # Rack::Mime::MIME_TYPES.merge!(list) + # + # To add the list mongrel provides, use: + # + # require 'mongrel/handlers' + # Rack::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES) + + MIME_TYPES = { + ".3gp" => "video/3gpp", + ".a" => "application/octet-stream", + ".ai" => "application/postscript", + ".aif" => "audio/x-aiff", + ".aiff" => "audio/x-aiff", + ".asc" => "application/pgp-signature", + ".asf" => "video/x-ms-asf", + ".asm" => "text/x-asm", + ".asx" => "video/x-ms-asf", + ".atom" => "application/atom+xml", + ".au" => "audio/basic", + ".avi" => "video/x-msvideo", + ".bat" => "application/x-msdownload", + ".bin" => "application/octet-stream", + ".bmp" => "image/bmp", + ".bz2" => "application/x-bzip2", + ".c" => "text/x-c", + ".cab" => "application/vnd.ms-cab-compressed", + ".cc" => "text/x-c", + ".chm" => "application/vnd.ms-htmlhelp", + ".class" => "application/octet-stream", + ".com" => "application/x-msdownload", + ".conf" => "text/plain", + ".cpp" => "text/x-c", + ".crt" => "application/x-x509-ca-cert", + ".css" => "text/css", + ".csv" => "text/csv", + ".cxx" => "text/x-c", + ".deb" => "application/x-debian-package", + ".der" => "application/x-x509-ca-cert", + ".diff" => "text/x-diff", + ".djv" => "image/vnd.djvu", + ".djvu" => "image/vnd.djvu", + ".dll" => "application/x-msdownload", + ".dmg" => "application/octet-stream", + ".doc" => "application/msword", + ".dot" => "application/msword", + ".dtd" => "application/xml-dtd", + ".dvi" => "application/x-dvi", + ".ear" => "application/java-archive", + ".eml" => "message/rfc822", + ".eps" => "application/postscript", + ".exe" => "application/x-msdownload", + ".f" => "text/x-fortran", + ".f77" => "text/x-fortran", + ".f90" => "text/x-fortran", + ".flv" => "video/x-flv", + ".for" => "text/x-fortran", + ".gem" => "application/octet-stream", + ".gemspec" => "text/x-script.ruby", + ".gif" => "image/gif", + ".gz" => "application/x-gzip", + ".h" => "text/x-c", + ".hh" => "text/x-c", + ".htm" => "text/html", + ".html" => "text/html", + ".ico" => "image/vnd.microsoft.icon", + ".ics" => "text/calendar", + ".ifb" => "text/calendar", + ".iso" => "application/octet-stream", + ".jar" => "application/java-archive", + ".java" => "text/x-java-source", + ".jnlp" => "application/x-java-jnlp-file", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".js" => "application/javascript", + ".json" => "application/json", + ".log" => "text/plain", + ".m3u" => "audio/x-mpegurl", + ".m4v" => "video/mp4", + ".man" => "text/troff", + ".manifest"=> "text/cache-manifest", + ".mathml" => "application/mathml+xml", + ".mbox" => "application/mbox", + ".mdoc" => "text/troff", + ".me" => "text/troff", + ".mid" => "audio/midi", + ".midi" => "audio/midi", + ".mime" => "message/rfc822", + ".mml" => "application/mathml+xml", + ".mng" => "video/x-mng", + ".mov" => "video/quicktime", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mp4v" => "video/mp4", + ".mpeg" => "video/mpeg", + ".mpg" => "video/mpeg", + ".ms" => "text/troff", + ".msi" => "application/x-msdownload", + ".odp" => "application/vnd.oasis.opendocument.presentation", + ".ods" => "application/vnd.oasis.opendocument.spreadsheet", + ".odt" => "application/vnd.oasis.opendocument.text", + ".ogg" => "application/ogg", + ".ogv" => "video/ogg", + ".p" => "text/x-pascal", + ".pas" => "text/x-pascal", + ".pbm" => "image/x-portable-bitmap", + ".pdf" => "application/pdf", + ".pem" => "application/x-x509-ca-cert", + ".pgm" => "image/x-portable-graymap", + ".pgp" => "application/pgp-encrypted", + ".pkg" => "application/octet-stream", + ".pl" => "text/x-script.perl", + ".pm" => "text/x-script.perl-module", + ".png" => "image/png", + ".pnm" => "image/x-portable-anymap", + ".ppm" => "image/x-portable-pixmap", + ".pps" => "application/vnd.ms-powerpoint", + ".ppt" => "application/vnd.ms-powerpoint", + ".ps" => "application/postscript", + ".psd" => "image/vnd.adobe.photoshop", + ".py" => "text/x-script.python", + ".qt" => "video/quicktime", + ".ra" => "audio/x-pn-realaudio", + ".rake" => "text/x-script.ruby", + ".ram" => "audio/x-pn-realaudio", + ".rar" => "application/x-rar-compressed", + ".rb" => "text/x-script.ruby", + ".rdf" => "application/rdf+xml", + ".roff" => "text/troff", + ".rpm" => "application/x-redhat-package-manager", + ".rss" => "application/rss+xml", + ".rtf" => "application/rtf", + ".ru" => "text/x-script.ruby", + ".s" => "text/x-asm", + ".sgm" => "text/sgml", + ".sgml" => "text/sgml", + ".sh" => "application/x-sh", + ".sig" => "application/pgp-signature", + ".snd" => "audio/basic", + ".so" => "application/octet-stream", + ".svg" => "image/svg+xml", + ".svgz" => "image/svg+xml", + ".swf" => "application/x-shockwave-flash", + ".t" => "text/troff", + ".tar" => "application/x-tar", + ".tbz" => "application/x-bzip-compressed-tar", + ".tcl" => "application/x-tcl", + ".tex" => "application/x-tex", + ".texi" => "application/x-texinfo", + ".texinfo" => "application/x-texinfo", + ".text" => "text/plain", + ".tif" => "image/tiff", + ".tiff" => "image/tiff", + ".torrent" => "application/x-bittorrent", + ".tr" => "text/troff", + ".txt" => "text/plain", + ".vcf" => "text/x-vcard", + ".vcs" => "text/x-vcalendar", + ".vrml" => "model/vrml", + ".war" => "application/java-archive", + ".wav" => "audio/x-wav", + ".wma" => "audio/x-ms-wma", + ".wmv" => "video/x-ms-wmv", + ".wmx" => "video/x-ms-wmx", + ".wrl" => "model/vrml", + ".wsdl" => "application/wsdl+xml", + ".xbm" => "image/x-xbitmap", + ".xhtml" => "application/xhtml+xml", + ".xls" => "application/vnd.ms-excel", + ".xml" => "application/xml", + ".xpm" => "image/x-xpixmap", + ".xsl" => "application/xml", + ".xslt" => "application/xslt+xml", + ".yaml" => "text/yaml", + ".yml" => "text/yaml", + ".zip" => "application/zip", + } + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/mock.rb b/vendor/gems/rack-1.1.0/lib/rack/mock.rb new file mode 100644 index 00000000..23ecba17 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/mock.rb @@ -0,0 +1,189 @@ +require 'uri' +require 'stringio' +require 'rack/lint' +require 'rack/utils' +require 'rack/response' + +module Rack + # Rack::MockRequest helps testing your Rack application without + # actually using HTTP. + # + # After performing a request on a URL with get/post/put/delete, it + # returns a MockResponse with useful helper methods for effective + # testing. + # + # You can pass a hash with additional configuration to the + # get/post/put/delete. + # :input:: A String or IO-like to be used as rack.input. + # :fatal:: Raise a FatalWarning if the app writes to rack.errors. + # :lint:: If true, wrap the application in a Rack::Lint. + + class MockRequest + class FatalWarning < RuntimeError + end + + class FatalWarner + def puts(warning) + raise FatalWarning, warning + end + + def write(warning) + raise FatalWarning, warning + end + + def flush + end + + def string + "" + end + end + + DEFAULT_ENV = { + "rack.version" => [1,1], + "rack.input" => StringIO.new, + "rack.errors" => StringIO.new, + "rack.multithread" => true, + "rack.multiprocess" => true, + "rack.run_once" => false, + } + + def initialize(app) + @app = app + end + + def get(uri, opts={}) request("GET", uri, opts) end + def post(uri, opts={}) request("POST", uri, opts) end + def put(uri, opts={}) request("PUT", uri, opts) end + def delete(uri, opts={}) request("DELETE", uri, opts) end + + def request(method="GET", uri="", opts={}) + env = self.class.env_for(uri, opts.merge(:method => method)) + + if opts[:lint] + app = Rack::Lint.new(@app) + else + app = @app + end + + errors = env["rack.errors"] + MockResponse.new(*(app.call(env) + [errors])) + end + + # Return the Rack environment used for a request to +uri+. + def self.env_for(uri="", opts={}) + uri = URI(uri) + uri.path = "/#{uri.path}" unless uri.path[0] == ?/ + + env = DEFAULT_ENV.dup + + env["REQUEST_METHOD"] = opts[:method] ? opts[:method].to_s.upcase : "GET" + env["SERVER_NAME"] = uri.host || "example.org" + env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80" + env["QUERY_STRING"] = uri.query.to_s + env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path + env["rack.url_scheme"] = uri.scheme || "http" + env["HTTPS"] = env["rack.url_scheme"] == "https" ? "on" : "off" + + env["SCRIPT_NAME"] = opts[:script_name] || "" + + if opts[:fatal] + env["rack.errors"] = FatalWarner.new + else + env["rack.errors"] = StringIO.new + end + + if params = opts[:params] + if env["REQUEST_METHOD"] == "GET" + params = Utils.parse_nested_query(params) if params.is_a?(String) + params.update(Utils.parse_nested_query(env["QUERY_STRING"])) + env["QUERY_STRING"] = Utils.build_nested_query(params) + elsif !opts.has_key?(:input) + opts["CONTENT_TYPE"] = "application/x-www-form-urlencoded" + if params.is_a?(Hash) + if data = Utils::Multipart.build_multipart(params) + opts[:input] = data + opts["CONTENT_LENGTH"] ||= data.length.to_s + opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Utils::Multipart::MULTIPART_BOUNDARY}" + else + opts[:input] = Utils.build_nested_query(params) + end + else + opts[:input] = params + end + end + end + + empty_str = "" + empty_str.force_encoding("ASCII-8BIT") if empty_str.respond_to? :force_encoding + opts[:input] ||= empty_str + if String === opts[:input] + rack_input = StringIO.new(opts[:input]) + else + rack_input = opts[:input] + end + + rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) + env['rack.input'] = rack_input + + env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s + + opts.each { |field, value| + env[field] = value if String === field + } + + env + end + end + + # Rack::MockResponse provides useful helpers for testing your apps. + # Usually, you don't create the MockResponse on your own, but use + # MockRequest. + + class MockResponse + def initialize(status, headers, body, errors=StringIO.new("")) + @status = status.to_i + + @original_headers = headers + @headers = Rack::Utils::HeaderHash.new + headers.each { |field, values| + @headers[field] = values + @headers[field] = "" if values.empty? + } + + @body = "" + body.each { |part| @body << part } + + @errors = errors.string if errors.respond_to?(:string) + end + + # Status + attr_reader :status + + # Headers + attr_reader :headers, :original_headers + + def [](field) + headers[field] + end + + + # Body + attr_reader :body + + def =~(other) + @body =~ other + end + + def match(other) + @body.match other + end + + + # Errors + attr_accessor :errors + + + include Response::Helpers + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb b/vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb new file mode 100644 index 00000000..77fb637d --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb @@ -0,0 +1,18 @@ +module Rack + class NullLogger + def initialize(app) + @app = app + end + + def call(env) + env['rack.logger'] = self + @app.call(env) + end + + def info(progname = nil, &block); end + def debug(progname = nil, &block); end + def warn(progname = nil, &block); end + def error(progname = nil, &block); end + def fatal(progname = nil, &block); end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/recursive.rb b/vendor/gems/rack-1.1.0/lib/rack/recursive.rb new file mode 100644 index 00000000..bf8b9659 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/recursive.rb @@ -0,0 +1,57 @@ +require 'uri' + +module Rack + # Rack::ForwardRequest gets caught by Rack::Recursive and redirects + # the current request to the app at +url+. + # + # raise ForwardRequest.new("/not-found") + # + + class ForwardRequest < Exception + attr_reader :url, :env + + def initialize(url, env={}) + @url = URI(url) + @env = env + + @env["PATH_INFO"] = @url.path + @env["QUERY_STRING"] = @url.query if @url.query + @env["HTTP_HOST"] = @url.host if @url.host + @env["HTTP_PORT"] = @url.port if @url.port + @env["rack.url_scheme"] = @url.scheme if @url.scheme + + super "forwarding to #{url}" + end + end + + # Rack::Recursive allows applications called down the chain to + # include data from other applications (by using + # rack['rack.recursive.include'][...] or raise a + # ForwardRequest to redirect internally. + + class Recursive + def initialize(app) + @app = app + end + + def call(env) + @script_name = env["SCRIPT_NAME"] + @app.call(env.merge('rack.recursive.include' => method(:include))) + rescue ForwardRequest => req + call(env.merge(req.env)) + end + + def include(env, path) + unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ || + path[@script_name.size].nil?) + raise ArgumentError, "can only include below #{@script_name}, not #{path}" + end + + env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name, + "REQUEST_METHOD" => "GET", + "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "", + "rack.input" => StringIO.new("")) + @app.call(env) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/reloader.rb b/vendor/gems/rack-1.1.0/lib/rack/reloader.rb new file mode 100644 index 00000000..a06de23a --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/reloader.rb @@ -0,0 +1,109 @@ +# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com +# Rack::Reloader is subject to the terms of an MIT-style license. +# See COPYING or http://www.opensource.org/licenses/mit-license.php. + +require 'pathname' + +module Rack + + # High performant source reloader + # + # This class acts as Rack middleware. + # + # What makes it especially suited for use in a production environment is that + # any file will only be checked once and there will only be made one system + # call stat(2). + # + # Please note that this will not reload files in the background, it does so + # only when actively called. + # + # It is performing a check/reload cycle at the start of every request, but + # also respects a cool down time, during which nothing will be done. + class Reloader + def initialize(app, cooldown = 10, backend = Stat) + @app = app + @cooldown = cooldown + @last = (Time.now - cooldown) + @cache = {} + @mtimes = {} + + extend backend + end + + def call(env) + if @cooldown and Time.now > @last + @cooldown + if Thread.list.size > 1 + Thread.exclusive{ reload! } + else + reload! + end + + @last = Time.now + end + + @app.call(env) + end + + def reload!(stderr = $stderr) + rotation do |file, mtime| + previous_mtime = @mtimes[file] ||= mtime + safe_load(file, mtime, stderr) if mtime > previous_mtime + end + end + + # A safe Kernel::load, issuing the hooks depending on the results + def safe_load(file, mtime, stderr = $stderr) + load(file) + stderr.puts "#{self.class}: reloaded `#{file}'" + file + rescue LoadError, SyntaxError => ex + stderr.puts ex + ensure + @mtimes[file] = mtime + end + + module Stat + def rotation + files = [$0, *$LOADED_FEATURES].uniq + paths = ['./', *$LOAD_PATH].uniq + + files.map{|file| + next if file =~ /\.(so|bundle)$/ # cannot reload compiled files + + found, stat = figure_path(file, paths) + next unless found && stat && mtime = stat.mtime + + @cache[file] = found + + yield(found, mtime) + }.compact + end + + # Takes a relative or absolute +file+ name, a couple possible +paths+ that + # the +file+ might reside in. Returns the full path and File::Stat for the + # path. + def figure_path(file, paths) + found = @cache[file] + found = file if !found and Pathname.new(file).absolute? + found, stat = safe_stat(found) + return found, stat if found + + paths.find do |possible_path| + path = ::File.join(possible_path, file) + found, stat = safe_stat(path) + return ::File.expand_path(found), stat if found + end + + return false, false + end + + def safe_stat(file) + return unless file + stat = ::File.stat(file) + return file, stat if stat.file? + rescue Errno::ENOENT, Errno::ENOTDIR + @cache.delete(file) and false + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/request.rb b/vendor/gems/rack-1.1.0/lib/rack/request.rb new file mode 100644 index 00000000..b3de1ce4 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/request.rb @@ -0,0 +1,271 @@ +require 'rack/utils' + +module Rack + # Rack::Request provides a convenient interface to a Rack + # environment. It is stateless, the environment +env+ passed to the + # constructor will be directly modified. + # + # req = Rack::Request.new(env) + # req.post? + # req.params["data"] + # + # The environment hash passed will store a reference to the Request object + # instantiated so that it will only instantiate if an instance of the Request + # object doesn't already exist. + + class Request + # The environment of the request. + attr_reader :env + + def initialize(env) + @env = env + end + + def body; @env["rack.input"] end + def scheme; @env["rack.url_scheme"] end + def script_name; @env["SCRIPT_NAME"].to_s end + def path_info; @env["PATH_INFO"].to_s end + def port; @env["SERVER_PORT"].to_i end + def request_method; @env["REQUEST_METHOD"] end + def query_string; @env["QUERY_STRING"].to_s end + def content_length; @env['CONTENT_LENGTH'] end + def content_type; @env['CONTENT_TYPE'] end + def session; @env['rack.session'] ||= {} end + def session_options; @env['rack.session.options'] ||= {} end + def logger; @env['rack.logger'] end + + # The media type (type/subtype) portion of the CONTENT_TYPE header + # without any media type parameters. e.g., when CONTENT_TYPE is + # "text/plain;charset=utf-8", the media-type is "text/plain". + # + # For more information on the use of media types in HTTP, see: + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 + def media_type + content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase + end + + # The media type parameters provided in CONTENT_TYPE as a Hash, or + # an empty Hash if no CONTENT_TYPE or media-type parameters were + # provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8", + # this method responds with the following Hash: + # { 'charset' => 'utf-8' } + def media_type_params + return {} if content_type.nil? + content_type.split(/\s*[;,]\s*/)[1..-1]. + collect { |s| s.split('=', 2) }. + inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } + end + + # The character set of the request body if a "charset" media type + # parameter was given, or nil if no "charset" was specified. Note + # that, per RFC2616, text/* media types that specify no explicit + # charset are to be considered ISO-8859-1. + def content_charset + media_type_params['charset'] + end + + def host_with_port + if forwarded = @env["HTTP_X_FORWARDED_HOST"] + forwarded.split(/,\s?/).last + else + @env['HTTP_HOST'] || "#{@env['SERVER_NAME'] || @env['SERVER_ADDR']}:#{@env['SERVER_PORT']}" + end + end + + def host + # Remove port number. + host_with_port.to_s.gsub(/:\d+\z/, '') + end + + def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end + def path_info=(s); @env["PATH_INFO"] = s.to_s end + + def get?; request_method == "GET" end + def post?; request_method == "POST" end + def put?; request_method == "PUT" end + def delete?; request_method == "DELETE" end + def head?; request_method == "HEAD" end + + # The set of form-data media-types. Requests that do not indicate + # one of the media types presents in this list will not be eligible + # for form-data / param parsing. + FORM_DATA_MEDIA_TYPES = [ + 'application/x-www-form-urlencoded', + 'multipart/form-data' + ] + + # The set of media-types. Requests that do not indicate + # one of the media types presents in this list will not be eligible + # for param parsing like soap attachments or generic multiparts + PARSEABLE_DATA_MEDIA_TYPES = [ + 'multipart/related', + 'multipart/mixed' + ] + + # Determine whether the request body contains form-data by checking + # the request Content-Type for one of the media-types: + # "application/x-www-form-urlencoded" or "multipart/form-data". The + # list of form-data media types can be modified through the + # +FORM_DATA_MEDIA_TYPES+ array. + # + # A request body is also assumed to contain form-data when no + # Content-Type header is provided and the request_method is POST. + def form_data? + type = media_type + meth = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'] + (meth == 'POST' && type.nil?) || FORM_DATA_MEDIA_TYPES.include?(type) + end + + # Determine whether the request body contains data by checking + # the request media_type against registered parse-data media-types + def parseable_data? + PARSEABLE_DATA_MEDIA_TYPES.include?(media_type) + end + + # Returns the data recieved in the query string. + def GET + if @env["rack.request.query_string"] == query_string + @env["rack.request.query_hash"] + else + @env["rack.request.query_string"] = query_string + @env["rack.request.query_hash"] = parse_query(query_string) + end + end + + # Returns the data recieved in the request body. + # + # This method support both application/x-www-form-urlencoded and + # multipart/form-data. + def POST + if @env["rack.input"].nil? + raise "Missing rack.input" + elsif @env["rack.request.form_input"].eql? @env["rack.input"] + @env["rack.request.form_hash"] + elsif form_data? || parseable_data? + @env["rack.request.form_input"] = @env["rack.input"] + unless @env["rack.request.form_hash"] = parse_multipart(env) + form_vars = @env["rack.input"].read + + # Fix for Safari Ajax postings that always append \0 + form_vars.sub!(/\0\z/, '') + + @env["rack.request.form_vars"] = form_vars + @env["rack.request.form_hash"] = parse_query(form_vars) + + @env["rack.input"].rewind + end + @env["rack.request.form_hash"] + else + {} + end + end + + # The union of GET and POST data. + def params + self.GET.update(self.POST) + rescue EOFError => e + self.GET + end + + # shortcut for request.params[key] + def [](key) + params[key.to_s] + end + + # shortcut for request.params[key] = value + def []=(key, value) + params[key.to_s] = value + end + + # like Hash#values_at + def values_at(*keys) + keys.map{|key| params[key] } + end + + # the referer of the client or '/' + def referer + @env['HTTP_REFERER'] || '/' + end + alias referrer referer + + def user_agent + @env['HTTP_USER_AGENT'] + end + + def cookies + return {} unless @env["HTTP_COOKIE"] + + if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] + @env["rack.request.cookie_hash"] + else + @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"] + # According to RFC 2109: + # If multiple cookies satisfy the criteria above, they are ordered in + # the Cookie header such that those with more specific Path attributes + # precede those with less specific. Ordering with respect to other + # attributes (e.g., Domain) is unspecified. + @env["rack.request.cookie_hash"] = + Utils.parse_query(@env["rack.request.cookie_string"], ';,').inject({}) {|h,(k,v)| + h[k] = Array === v ? v.first : v + h + } + end + end + + def xhr? + @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" + end + + # Tries to return a remake of the original request URL as a string. + def url + url = scheme + "://" + url << host + + if scheme == "https" && port != 443 || + scheme == "http" && port != 80 + url << ":#{port}" + end + + url << fullpath + + url + end + + def path + script_name + path_info + end + + def fullpath + query_string.empty? ? path : "#{path}?#{query_string}" + end + + def accept_encoding + @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part| + m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick + + if m + [m[1], (m[2] || 1.0).to_f] + else + raise "Invalid value for Accept-Encoding: #{part.inspect}" + end + end + end + + def ip + if addr = @env['HTTP_X_FORWARDED_FOR'] + addr.split(',').last.strip + else + @env['REMOTE_ADDR'] + end + end + + protected + def parse_query(qs) + Utils.parse_nested_query(qs) + end + + def parse_multipart(env) + Utils::Multipart.parse_multipart(env) + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/response.rb b/vendor/gems/rack-1.1.0/lib/rack/response.rb new file mode 100644 index 00000000..a7f9bf2b --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/response.rb @@ -0,0 +1,149 @@ +require 'rack/request' +require 'rack/utils' + +module Rack + # Rack::Response provides a convenient interface to create a Rack + # response. + # + # It allows setting of headers and cookies, and provides useful + # defaults (a OK response containing HTML). + # + # You can use Response#write to iteratively generate your response, + # but note that this is buffered by Rack::Response until you call + # +finish+. +finish+ however can take a block inside which calls to + # +write+ are syncronous with the Rack response. + # + # Your application's +call+ should end returning Response#finish. + + class Response + attr_accessor :length + + def initialize(body=[], status=200, header={}, &block) + @status = status.to_i + @header = Utils::HeaderHash.new({"Content-Type" => "text/html"}. + merge(header)) + + @writer = lambda { |x| @body << x } + @block = nil + @length = 0 + + @body = [] + + if body.respond_to? :to_str + write body.to_str + elsif body.respond_to?(:each) + body.each { |part| + write part.to_s + } + else + raise TypeError, "stringable or iterable required" + end + + yield self if block_given? + end + + attr_reader :header + attr_accessor :status, :body + + def [](key) + header[key] + end + + def []=(key, value) + header[key] = value + end + + def set_cookie(key, value) + Utils.set_cookie_header!(header, key, value) + end + + def delete_cookie(key, value={}) + Utils.delete_cookie_header!(header, key, value) + end + + def redirect(target, status=302) + self.status = status + self["Location"] = target + end + + def finish(&block) + @block = block + + if [204, 304].include?(status.to_i) + header.delete "Content-Type" + [status.to_i, header, []] + else + [status.to_i, header, self] + end + end + alias to_a finish # For *response + + def each(&callback) + @body.each(&callback) + @writer = callback + @block.call(self) if @block + end + + # Append to body and update Content-Length. + # + # NOTE: Do not mix #write and direct #body access! + # + def write(str) + s = str.to_s + @length += Rack::Utils.bytesize(s) + @writer.call s + + header["Content-Length"] = @length.to_s + str + end + + def close + body.close if body.respond_to?(:close) + end + + def empty? + @block == nil && @body.empty? + end + + alias headers header + + module Helpers + def invalid?; @status < 100 || @status >= 600; end + + def informational?; @status >= 100 && @status < 200; end + def successful?; @status >= 200 && @status < 300; end + def redirection?; @status >= 300 && @status < 400; end + def client_error?; @status >= 400 && @status < 500; end + def server_error?; @status >= 500 && @status < 600; end + + def ok?; @status == 200; end + def forbidden?; @status == 403; end + def not_found?; @status == 404; end + + def redirect?; [301, 302, 303, 307].include? @status; end + def empty?; [201, 204, 304].include? @status; end + + # Headers + attr_reader :headers, :original_headers + + def include?(header) + !!headers[header] + end + + def content_type + headers["Content-Type"] + end + + def content_length + cl = headers["Content-Length"] + cl ? cl.to_i : cl + end + + def location + headers["Location"] + end + end + + include Helpers + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/rewindable_input.rb b/vendor/gems/rack-1.1.0/lib/rack/rewindable_input.rb new file mode 100644 index 00000000..accd96be --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/rewindable_input.rb @@ -0,0 +1,100 @@ +require 'tempfile' + +module Rack + # Class which can make any IO object rewindable, including non-rewindable ones. It does + # this by buffering the data into a tempfile, which is rewindable. + # + # rack.input is required to be rewindable, so if your input stream IO is non-rewindable + # by nature (e.g. a pipe or a socket) then you can wrap it in an object of this class + # to easily make it rewindable. + # + # Don't forget to call #close when you're done. This frees up temporary resources that + # RewindableInput uses, though it does *not* close the original IO object. + class RewindableInput + def initialize(io) + @io = io + @rewindable_io = nil + @unlinked = false + end + + def gets + make_rewindable unless @rewindable_io + @rewindable_io.gets + end + + def read(*args) + make_rewindable unless @rewindable_io + @rewindable_io.read(*args) + end + + def each(&block) + make_rewindable unless @rewindable_io + @rewindable_io.each(&block) + end + + def rewind + make_rewindable unless @rewindable_io + @rewindable_io.rewind + end + + # Closes this RewindableInput object without closing the originally + # wrapped IO oject. Cleans up any temporary resources that this RewindableInput + # has created. + # + # This method may be called multiple times. It does nothing on subsequent calls. + def close + if @rewindable_io + if @unlinked + @rewindable_io.close + else + @rewindable_io.close! + end + @rewindable_io = nil + end + end + + private + + # Ruby's Tempfile class has a bug. Subclass it and fix it. + class Tempfile < ::Tempfile + def _close + @tmpfile.close if @tmpfile + @data[1] = nil if @data + @tmpfile = nil + end + end + + def make_rewindable + # Buffer all data into a tempfile. Since this tempfile is private to this + # RewindableInput object, we chmod it so that nobody else can read or write + # it. On POSIX filesystems we also unlink the file so that it doesn't + # even have a file entry on the filesystem anymore, though we can still + # access it because we have the file handle open. + @rewindable_io = Tempfile.new('RackRewindableInput') + @rewindable_io.chmod(0000) + @rewindable_io.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding) + @rewindable_io.binmode + if filesystem_has_posix_semantics? + @rewindable_io.unlink + @unlinked = true + end + + buffer = "" + while @io.read(1024 * 4, buffer) + entire_buffer_written_out = false + while !entire_buffer_written_out + written = @rewindable_io.write(buffer) + entire_buffer_written_out = written == buffer.size + if !entire_buffer_written_out + buffer.slice!(0 .. written - 1) + end + end + end + @rewindable_io.rewind + end + + def filesystem_has_posix_semantics? + RUBY_PLATFORM !~ /(mswin|mingw|cygwin|java)/ + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/runtime.rb b/vendor/gems/rack-1.1.0/lib/rack/runtime.rb new file mode 100644 index 00000000..1bd411fd --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/runtime.rb @@ -0,0 +1,27 @@ +module Rack + # Sets an "X-Runtime" response header, indicating the response + # time of the request, in seconds + # + # You can put it right before the application to see the processing + # time, or before all the other middlewares to include time for them, + # too. + class Runtime + def initialize(app, name = nil) + @app = app + @header_name = "X-Runtime" + @header_name << "-#{name}" if name + end + + def call(env) + start_time = Time.now + status, headers, body = @app.call(env) + request_time = Time.now - start_time + + if !headers.has_key?(@header_name) + headers[@header_name] = "%0.6f" % request_time + end + + [status, headers, body] + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/sendfile.rb b/vendor/gems/rack-1.1.0/lib/rack/sendfile.rb new file mode 100644 index 00000000..4fa82946 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/sendfile.rb @@ -0,0 +1,142 @@ +require 'rack/file' + +module Rack + class File #:nodoc: + alias :to_path :path + end + + # = Sendfile + # + # The Sendfile middleware intercepts responses whose body is being + # served from a file and replaces it with a server specific X-Sendfile + # header. The web server is then responsible for writing the file contents + # to the client. This can dramatically reduce the amount of work required + # by the Ruby backend and takes advantage of the web servers optimized file + # delivery code. + # + # In order to take advantage of this middleware, the response body must + # respond to +to_path+ and the request must include an X-Sendfile-Type + # header. Rack::File and other components implement +to_path+ so there's + # rarely anything you need to do in your application. The X-Sendfile-Type + # header is typically set in your web servers configuration. The following + # sections attempt to document + # + # === Nginx + # + # Nginx supports the X-Accel-Redirect header. This is similar to X-Sendfile + # but requires parts of the filesystem to be mapped into a private URL + # hierarachy. + # + # The following example shows the Nginx configuration required to create + # a private "/files/" area, enable X-Accel-Redirect, and pass the special + # X-Sendfile-Type and X-Accel-Mapping headers to the backend: + # + # location /files/ { + # internal; + # alias /var/www/; + # } + # + # location / { + # proxy_redirect false; + # + # proxy_set_header Host $host; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # + # proxy_set_header X-Sendfile-Type X-Accel-Redirect + # proxy_set_header X-Accel-Mapping /files/=/var/www/; + # + # proxy_pass http://127.0.0.1:8080/; + # } + # + # Note that the X-Sendfile-Type header must be set exactly as shown above. The + # X-Accel-Mapping header should specify the name of the private URL pattern, + # followed by an equals sign (=), followed by the location on the file system + # that it maps to. The middleware performs a simple substitution on the + # resulting path. + # + # See Also: http://wiki.codemongers.com/NginxXSendfile + # + # === lighttpd + # + # Lighttpd has supported some variation of the X-Sendfile header for some + # time, although only recent version support X-Sendfile in a reverse proxy + # configuration. + # + # $HTTP["host"] == "example.com" { + # proxy-core.protocol = "http" + # proxy-core.balancer = "round-robin" + # proxy-core.backends = ( + # "127.0.0.1:8000", + # "127.0.0.1:8001", + # ... + # ) + # + # proxy-core.allow-x-sendfile = "enable" + # proxy-core.rewrite-request = ( + # "X-Sendfile-Type" => (".*" => "X-Sendfile") + # ) + # } + # + # See Also: http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModProxyCore + # + # === Apache + # + # X-Sendfile is supported under Apache 2.x using a separate module: + # + # http://tn123.ath.cx/mod_xsendfile/ + # + # Once the module is compiled and installed, you can enable it using + # XSendFile config directive: + # + # RequestHeader Set X-Sendfile-Type X-Sendfile + # ProxyPassReverse / http://localhost:8001/ + # XSendFile on + + class Sendfile + F = ::File + + def initialize(app, variation=nil) + @app = app + @variation = variation + end + + def call(env) + status, headers, body = @app.call(env) + if body.respond_to?(:to_path) + case type = variation(env) + when 'X-Accel-Redirect' + path = F.expand_path(body.to_path) + if url = map_accel_path(env, path) + headers[type] = url + body = [] + else + env['rack.errors'] << "X-Accel-Mapping header missing" + end + when 'X-Sendfile', 'X-Lighttpd-Send-File' + path = F.expand_path(body.to_path) + headers[type] = path + body = [] + when '', nil + else + env['rack.errors'] << "Unknown x-sendfile variation: '#{variation}'.\n" + end + end + [status, headers, body] + end + + private + def variation(env) + @variation || + env['sendfile.type'] || + env['HTTP_X_SENDFILE_TYPE'] + end + + def map_accel_path(env, file) + if mapping = env['HTTP_X_ACCEL_MAPPING'] + internal, external = mapping.split('=', 2).map{ |p| p.strip } + file.sub(/^#{internal}/i, external) + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/server.rb b/vendor/gems/rack-1.1.0/lib/rack/server.rb new file mode 100644 index 00000000..2bb20aae --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/server.rb @@ -0,0 +1,212 @@ +require 'optparse' + +module Rack + class Server + class Options + def parse!(args) + options = {} + opt_parser = OptionParser.new("", 24, ' ') do |opts| + opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]" + + opts.separator "" + opts.separator "Ruby options:" + + lineno = 1 + opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line| + eval line, TOPLEVEL_BINDING, "-e", lineno + lineno += 1 + } + + opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") { + options[:debug] = true + } + opts.on("-w", "--warn", "turn warnings on for your script") { + options[:warn] = true + } + + opts.on("-I", "--include PATH", + "specify $LOAD_PATH (may be used more than once)") { |path| + options[:include] = path.split(":") + } + + opts.on("-r", "--require LIBRARY", + "require the library, before executing your script") { |library| + options[:require] = library + } + + opts.separator "" + opts.separator "Rack options:" + opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s| + options[:server] = s + } + + opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host| + options[:Host] = host + } + + opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port| + options[:Port] = port + } + + opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e| + options[:environment] = e + } + + opts.on("-D", "--daemonize", "run daemonized in the background") { |d| + options[:daemonize] = d ? true : false + } + + opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f| + options[:pid] = f + } + + opts.separator "" + opts.separator "Common options:" + + opts.on_tail("-h", "--help", "Show this message") do + puts opts + exit + end + + opts.on_tail("--version", "Show version") do + puts "Rack #{Rack.version}" + exit + end + end + opt_parser.parse! args + options[:config] = args.last if args.last + options + end + end + + def self.start + new.start + end + + attr_accessor :options + + def initialize(options = nil) + @options = options + end + + def options + @options ||= parse_options(ARGV) + end + + def default_options + { + :environment => "development", + :pid => nil, + :Port => 9292, + :Host => "0.0.0.0", + :AccessLog => [], + :config => "config.ru" + } + end + + def app + @app ||= begin + if !::File.exist? options[:config] + abort "configuration #{options[:config]} not found" + end + + app, options = Rack::Builder.parse_file(self.options[:config], opt_parser) + self.options.merge! options + app + end + end + + def self.middleware + @middleware ||= begin + m = Hash.new {|h,k| h[k] = []} + m["deployment"].concat [lambda {|server| server.server =~ /CGI/ ? nil : [Rack::CommonLogger, $stderr] }] + m["development"].concat m["deployment"] + [[Rack::ShowExceptions], [Rack::Lint]] + m + end + end + + def middleware + self.class.middleware + end + + def start + if options[:debug] + $DEBUG = true + require 'pp' + p options[:server] + pp wrapped_app + pp app + end + + if options[:warn] + $-w = true + end + + if includes = options[:include] + $LOAD_PATH.unshift *includes + end + + if library = options[:require] + require library + end + + daemonize_app if options[:daemonize] + write_pid if options[:pid] + server.run wrapped_app, options + end + + def server + @_server ||= Rack::Handler.get(options[:server]) || Rack::Handler.default + end + + private + def parse_options(args) + options = default_options + + # Don't evaluate CGI ISINDEX parameters. + # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html + args.clear if ENV.include?("REQUEST_METHOD") + + options.merge! opt_parser.parse! args + options + end + + def opt_parser + Options.new + end + + def build_app(app) + middleware[options[:environment]].reverse_each do |middleware| + middleware = middleware.call(self) if middleware.respond_to?(:call) + next unless middleware + klass = middleware.shift + app = klass.new(app, *middleware) + end + app + end + + def wrapped_app + @wrapped_app ||= build_app app + end + + def daemonize_app + if RUBY_VERSION < "1.9" + exit if fork + Process.setsid + exit if fork + Dir.chdir "/" + ::File.umask 0000 + STDIN.reopen "/dev/null" + STDOUT.reopen "/dev/null", "a" + STDERR.reopen "/dev/null", "a" + else + Process.daemon + end + end + + def write_pid + ::File.open(options[:pid], 'w'){ |f| f.write("#{Process.pid}") } + at_exit { ::File.delete(options[:pid]) if ::File.exist?(options[:pid]) } + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/session/abstract/id.rb b/vendor/gems/rack-1.1.0/lib/rack/session/abstract/id.rb new file mode 100644 index 00000000..98746705 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/session/abstract/id.rb @@ -0,0 +1,140 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net +# bugrep: Andreas Zehnder + +require 'time' +require 'rack/request' +require 'rack/response' + +module Rack + + module Session + + module Abstract + + # ID sets up a basic framework for implementing an id based sessioning + # service. Cookies sent to the client for maintaining sessions will only + # contain an id reference. Only #get_session and #set_session are + # required to be overwritten. + # + # All parameters are optional. + # * :key determines the name of the cookie, by default it is + # 'rack.session' + # * :path, :domain, :expire_after, :secure, and :httponly set the related + # cookie options as by Rack::Response#add_cookie + # * :defer will not set a cookie in the response. + # * :renew (implementation dependent) will prompt the generation of a new + # session id, and migration of data to be referenced at the new id. If + # :defer is set, it will be overridden and the cookie will be set. + # * :sidbits sets the number of bits in length that a generated session + # id will be. + # + # These options can be set on a per request basis, at the location of + # env['rack.session.options']. Additionally the id of the session can be + # found within the options hash at the key :id. It is highly not + # recommended to change its value. + # + # Is Rack::Utils::Context compatible. + + class ID + DEFAULT_OPTIONS = { + :path => '/', + :domain => nil, + :expire_after => nil, + :secure => false, + :httponly => true, + :defer => false, + :renew => false, + :sidbits => 128 + } + + attr_reader :key, :default_options + def initialize(app, options={}) + @app = app + @key = options[:key] || "rack.session" + @default_options = self.class::DEFAULT_OPTIONS.merge(options) + end + + def call(env) + context(env) + end + + def context(env, app=@app) + load_session(env) + status, headers, body = app.call(env) + commit_session(env, status, headers, body) + end + + private + + # Generate a new session id using Ruby #rand. The size of the + # session id is controlled by the :sidbits option. + # Monkey patch this to use custom methods for session id generation. + + def generate_sid + "%0#{@default_options[:sidbits] / 4}x" % + rand(2**@default_options[:sidbits] - 1) + end + + # Extracts the session id from provided cookies and passes it and the + # environment to #get_session. It then sets the resulting session into + # 'rack.session', and places options and session metadata into + # 'rack.session.options'. + + def load_session(env) + request = Rack::Request.new(env) + session_id = request.cookies[@key] + + begin + session_id, session = get_session(env, session_id) + env['rack.session'] = session + rescue + env['rack.session'] = Hash.new + end + + env['rack.session.options'] = @default_options. + merge(:id => session_id) + end + + # Acquires the session from the environment and the session id from + # the session options and passes them to #set_session. If successful + # and the :defer option is not true, a cookie will be added to the + # response with the session's id. + + def commit_session(env, status, headers, body) + session = env['rack.session'] + options = env['rack.session.options'] + session_id = options[:id] + + if not session_id = set_session(env, session_id, session, options) + env["rack.errors"].puts("Warning! #{self.class.name} failed to save session. Content dropped.") + elsif options[:defer] and not options[:renew] + env["rack.errors"].puts("Defering cookie for #{session_id}") if $VERBOSE + else + cookie = Hash.new + cookie[:value] = session_id + cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil? + Utils.set_cookie_header!(headers, @key, cookie.merge(options)) + end + + [status, headers, body] + end + + # All thread safety and session retrival proceedures should occur here. + # Should return [session_id, session]. + # If nil is provided as the session id, generation of a new valid id + # should occur within. + + def get_session(env, sid) + raise '#get_session not implemented.' + end + + # All thread safety and session storage proceedures should occur here. + # Should return true or false dependant on whether or not the session + # was saved or not. + def set_session(env, sid, session, options) + raise '#set_session not implemented.' + end + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/session/cookie.rb b/vendor/gems/rack-1.1.0/lib/rack/session/cookie.rb new file mode 100644 index 00000000..240e6c8d --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/session/cookie.rb @@ -0,0 +1,90 @@ +require 'openssl' +require 'rack/request' +require 'rack/response' + +module Rack + + module Session + + # Rack::Session::Cookie provides simple cookie based session management. + # The session is a Ruby Hash stored as base64 encoded marshalled data + # set to :key (default: rack.session). + # When the secret key is set, cookie data is checked for data integrity. + # + # Example: + # + # use Rack::Session::Cookie, :key => 'rack.session', + # :domain => 'foo.com', + # :path => '/', + # :expire_after => 2592000, + # :secret => 'change_me' + # + # All parameters are optional. + + class Cookie + + def initialize(app, options={}) + @app = app + @key = options[:key] || "rack.session" + @secret = options[:secret] + @default_options = {:domain => nil, + :path => "/", + :expire_after => nil}.merge(options) + end + + def call(env) + load_session(env) + status, headers, body = @app.call(env) + commit_session(env, status, headers, body) + end + + private + + def load_session(env) + request = Rack::Request.new(env) + session_data = request.cookies[@key] + + if @secret && session_data + session_data, digest = session_data.split("--") + session_data = nil unless digest == generate_hmac(session_data) + end + + begin + session_data = session_data.unpack("m*").first + session_data = Marshal.load(session_data) + env["rack.session"] = session_data + rescue + env["rack.session"] = Hash.new + end + + env["rack.session.options"] = @default_options.dup + end + + def commit_session(env, status, headers, body) + session_data = Marshal.dump(env["rack.session"]) + session_data = [session_data].pack("m*") + + if @secret + session_data = "#{session_data}--#{generate_hmac(session_data)}" + end + + if session_data.size > (4096 - @key.size) + env["rack.errors"].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.") + else + options = env["rack.session.options"] + cookie = Hash.new + cookie[:value] = session_data + cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil? + Utils.set_cookie_header!(headers, @key, cookie.merge(options)) + end + + [status, headers, body] + end + + def generate_hmac(data) + OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, @secret, data) + end + + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/session/memcache.rb b/vendor/gems/rack-1.1.0/lib/rack/session/memcache.rb new file mode 100644 index 00000000..44629da3 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/session/memcache.rb @@ -0,0 +1,119 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net + +require 'rack/session/abstract/id' +require 'memcache' + +module Rack + module Session + # Rack::Session::Memcache provides simple cookie based session management. + # Session data is stored in memcached. The corresponding session key is + # maintained in the cookie. + # You may treat Session::Memcache as you would Session::Pool with the + # following caveats. + # + # * Setting :expire_after to 0 would note to the Memcache server to hang + # onto the session data until it would drop it according to it's own + # specifications. However, the cookie sent to the client would expire + # immediately. + # + # Note that memcache does drop data before it may be listed to expire. For + # a full description of behaviour, please see memcache's documentation. + + class Memcache < Abstract::ID + attr_reader :mutex, :pool + DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge \ + :namespace => 'rack:session', + :memcache_server => 'localhost:11211' + + def initialize(app, options={}) + super + + @mutex = Mutex.new + mserv = @default_options[:memcache_server] + mopts = @default_options. + reject{|k,v| MemCache::DEFAULT_OPTIONS.include? k } + @pool = MemCache.new mserv, mopts + unless @pool.active? and @pool.servers.any?{|c| c.alive? } + raise 'No memcache servers' + end + end + + def generate_sid + loop do + sid = super + break sid unless @pool.get(sid, true) + end + end + + def get_session(env, session_id) + @mutex.lock if env['rack.multithread'] + unless session_id and session = @pool.get(session_id) + session_id, session = generate_sid, {} + unless /^STORED/ =~ @pool.add(session_id, session) + raise "Session collision on '#{session_id.inspect}'" + end + end + session.instance_variable_set '@old', @pool.get(session_id, true) + return [session_id, session] + rescue MemCache::MemCacheError, Errno::ECONNREFUSED + # MemCache server cannot be contacted + warn "#{self} is unable to find memcached server." + warn $!.inspect + return [ nil, {} ] + ensure + @mutex.unlock if @mutex.locked? + end + + def set_session(env, session_id, new_session, options) + expiry = options[:expire_after] + expiry = expiry.nil? ? 0 : expiry + 1 + + @mutex.lock if env['rack.multithread'] + if options[:renew] or options[:drop] + @pool.delete session_id + return false if options[:drop] + session_id = generate_sid + @pool.add session_id, {} # so we don't worry about cache miss on #set + end + + session = @pool.get(session_id) || {} + old_session = new_session.instance_variable_get '@old' + old_session = old_session ? Marshal.load(old_session) : {} + + unless Hash === old_session and Hash === new_session + env['rack.errors']. + puts 'Bad old_session or new_session sessions provided.' + else # merge sessions + # alterations are either update or delete, making as few changes as + # possible to prevent possible issues. + + # removed keys + delete = old_session.keys - new_session.keys + if $VERBOSE and not delete.empty? + env['rack.errors']. + puts "//@#{session_id}: delete #{delete*','}" + end + delete.each{|k| session.delete k } + + # added or altered keys + update = new_session.keys. + select{|k| new_session[k] != old_session[k] } + if $VERBOSE and not update.empty? + env['rack.errors'].puts "//@#{session_id}: update #{update*','}" + end + update.each{|k| session[k] = new_session[k] } + end + + @pool.set session_id, session, expiry + return session_id + rescue MemCache::MemCacheError, Errno::ECONNREFUSED + # MemCache server cannot be contacted + warn "#{self} is unable to find memcached server." + warn $!.inspect + return false + ensure + @mutex.unlock if @mutex.locked? + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/session/pool.rb b/vendor/gems/rack-1.1.0/lib/rack/session/pool.rb new file mode 100644 index 00000000..b3f8bd72 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/session/pool.rb @@ -0,0 +1,100 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net +# THANKS: +# apeiros, for session id generation, expiry setup, and threadiness +# sergio, threadiness and bugreps + +require 'rack/session/abstract/id' +require 'thread' + +module Rack + module Session + # Rack::Session::Pool provides simple cookie based session management. + # Session data is stored in a hash held by @pool. + # In the context of a multithreaded environment, sessions being + # committed to the pool is done in a merging manner. + # + # The :drop option is available in rack.session.options if you wish to + # explicitly remove the session from the session cache. + # + # Example: + # myapp = MyRackApp.new + # sessioned = Rack::Session::Pool.new(myapp, + # :domain => 'foo.com', + # :expire_after => 2592000 + # ) + # Rack::Handler::WEBrick.run sessioned + + class Pool < Abstract::ID + attr_reader :mutex, :pool + DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :drop => false + + def initialize(app, options={}) + super + @pool = Hash.new + @mutex = Mutex.new + end + + def generate_sid + loop do + sid = super + break sid unless @pool.key? sid + end + end + + def get_session(env, sid) + session = @pool[sid] if sid + @mutex.lock if env['rack.multithread'] + unless sid and session + env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil? + session = {} + sid = generate_sid + @pool.store sid, session + end + session.instance_variable_set('@old', {}.merge(session)) + return [sid, session] + ensure + @mutex.unlock if env['rack.multithread'] + end + + def set_session(env, session_id, new_session, options) + @mutex.lock if env['rack.multithread'] + session = @pool[session_id] + if options[:renew] or options[:drop] + @pool.delete session_id + return false if options[:drop] + session_id = generate_sid + @pool.store session_id, 0 + end + old_session = new_session.instance_variable_get('@old') || {} + session = merge_sessions session_id, old_session, new_session, session + @pool.store session_id, session + return session_id + rescue + warn "#{new_session.inspect} has been lost." + warn $!.inspect + ensure + @mutex.unlock if env['rack.multithread'] + end + + private + + def merge_sessions sid, old, new, cur=nil + cur ||= {} + unless Hash === old and Hash === new + warn 'Bad old or new sessions provided.' + return cur + end + + delete = old.keys - new.keys + warn "//@#{sid}: dropping #{delete*','}" if $DEBUG and not delete.empty? + delete.each{|k| cur.delete k } + + update = new.keys.select{|k| new[k] != old[k] } + warn "//@#{sid}: updating #{update*','}" if $DEBUG and not update.empty? + update.each{|k| cur[k] = new[k] } + + cur + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/showexceptions.rb b/vendor/gems/rack-1.1.0/lib/rack/showexceptions.rb new file mode 100644 index 00000000..697bc41f --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/showexceptions.rb @@ -0,0 +1,349 @@ +require 'ostruct' +require 'erb' +require 'rack/request' +require 'rack/utils' + +module Rack + # Rack::ShowExceptions catches all exceptions raised from the app it + # wraps. It shows a useful backtrace with the sourcefile and + # clickable context, the whole Rack environment and the request + # data. + # + # Be careful when you use this on public-facing sites as it could + # reveal information helpful to attackers. + + class ShowExceptions + CONTEXT = 7 + + def initialize(app) + @app = app + @template = ERB.new(TEMPLATE) + end + + def call(env) + @app.call(env) + rescue StandardError, LoadError, SyntaxError => e + backtrace = pretty(env, e) + [500, + {"Content-Type" => "text/html", + "Content-Length" => backtrace.join.size.to_s}, + backtrace] + end + + def pretty(env, exception) + req = Rack::Request.new(env) + path = (req.script_name + req.path_info).squeeze("/") + + frames = exception.backtrace.map { |line| + frame = OpenStruct.new + if line =~ /(.*?):(\d+)(:in `(.*)')?/ + frame.filename = $1 + frame.lineno = $2.to_i + frame.function = $4 + + begin + lineno = frame.lineno-1 + lines = ::File.readlines(frame.filename) + frame.pre_context_lineno = [lineno-CONTEXT, 0].max + frame.pre_context = lines[frame.pre_context_lineno...lineno] + frame.context_line = lines[lineno].chomp + frame.post_context_lineno = [lineno+CONTEXT, lines.size].min + frame.post_context = lines[lineno+1..frame.post_context_lineno] + rescue + end + + frame + else + nil + end + }.compact + + env["rack.errors"].puts "#{exception.class}: #{exception.message}" + env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l } + env["rack.errors"].flush + + [@template.result(binding)] + end + + def h(obj) # :nodoc: + case obj + when String + Utils.escape_html(obj) + else + Utils.escape_html(obj.inspect) + end + end + + # :stopdoc: + +# adapted from Django +# Copyright (c) 2005, the Lawrence Journal-World +# Used under the modified BSD license: +# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 +TEMPLATE = <<'HTML' + + + + + + <%=h exception.class %> at <%=h path %> + + + + + +
    +

    <%=h exception.class %> at <%=h path %>

    +

    <%=h exception.message %>

    + + + + + + +
    Ruby<%=h frames.first.filename %>: in <%=h frames.first.function %>, line <%=h frames.first.lineno %>
    Web<%=h req.request_method %> <%=h(req.host + path)%>
    + +

    Jump to:

    + +
    + +
    +

    Traceback (innermost first)

    +
      +<% frames.each { |frame| %> +
    • + <%=h frame.filename %>: in <%=h frame.function %> + + <% if frame.context_line %> +
      + <% if frame.pre_context %> +
        + <% frame.pre_context.each { |line| %> +
      1. <%=h line %>
      2. + <% } %> +
      + <% end %> + +
        +
      1. <%=h frame.context_line %>...
      + + <% if frame.post_context %> +
        + <% frame.post_context.each { |line| %> +
      1. <%=h line %>
      2. + <% } %> +
      + <% end %> +
      + <% end %> +
    • +<% } %> +
    +
    + +
    +

    Request information

    + +

    GET

    + <% unless req.GET.empty? %> + + + + + + + + + <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
    VariableValue
    <%=h key %>
    <%=h val.inspect %>
    + <% else %> +

    No GET data.

    + <% end %> + +

    POST

    + <% unless req.POST.empty? %> + + + + + + + + + <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
    VariableValue
    <%=h key %>
    <%=h val.inspect %>
    + <% else %> +

    No POST data.

    + <% end %> + + + + <% unless req.cookies.empty? %> + + + + + + + + + <% req.cookies.each { |key, val| %> + + + + + <% } %> + +
    VariableValue
    <%=h key %>
    <%=h val.inspect %>
    + <% else %> +

    No cookie data.

    + <% end %> + +

    Rack ENV

    + + + + + + + + + <% env.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
    VariableValue
    <%=h key %>
    <%=h val %>
    + +
    + +
    +

    + You're seeing this error because you use Rack::ShowExceptions. +

    +
    + + + +HTML + + # :startdoc: + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/showstatus.rb b/vendor/gems/rack-1.1.0/lib/rack/showstatus.rb new file mode 100644 index 00000000..28258c7c --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/showstatus.rb @@ -0,0 +1,106 @@ +require 'erb' +require 'rack/request' +require 'rack/utils' + +module Rack + # Rack::ShowStatus catches all empty responses the app it wraps and + # replaces them with a site explaining the error. + # + # Additional details can be put into rack.showstatus.detail + # and will be shown as HTML. If such details exist, the error page + # is always rendered, even if the reply was not empty. + + class ShowStatus + def initialize(app) + @app = app + @template = ERB.new(TEMPLATE) + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + empty = headers['Content-Length'].to_i <= 0 + + # client or server error, or explicit message + if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"] + req = Rack::Request.new(env) + message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s + detail = env["rack.showstatus.detail"] || message + body = @template.result(binding) + size = Rack::Utils.bytesize(body) + [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]] + else + [status, headers, body] + end + end + + def h(obj) # :nodoc: + case obj + when String + Utils.escape_html(obj) + else + Utils.escape_html(obj.inspect) + end + end + + # :stopdoc: + +# adapted from Django +# Copyright (c) 2005, the Lawrence Journal-World +# Used under the modified BSD license: +# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 +TEMPLATE = <<'HTML' + + + + + <%=h message %> at <%=h req.script_name + req.path_info %> + + + + +
    +

    <%=h message %> (<%= status.to_i %>)

    + + + + + + + + + +
    Request Method:<%=h req.request_method %>
    Request URL:<%=h req.url %>
    +
    +
    +

    <%= detail %>

    +
    + +
    +

    + You're seeing this error because you use Rack::ShowStatus. +

    +
    + + +HTML + + # :startdoc: + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/static.rb b/vendor/gems/rack-1.1.0/lib/rack/static.rb new file mode 100644 index 00000000..168e8f83 --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/static.rb @@ -0,0 +1,38 @@ +module Rack + + # The Rack::Static middleware intercepts requests for static files + # (javascript files, images, stylesheets, etc) based on the url prefixes + # passed in the options, and serves them using a Rack::File object. This + # allows a Rack stack to serve both static and dynamic content. + # + # Examples: + # use Rack::Static, :urls => ["/media"] + # will serve all requests beginning with /media from the "media" folder + # located in the current directory (ie media/*). + # + # use Rack::Static, :urls => ["/css", "/images"], :root => "public" + # will serve all requests beginning with /css or /images from the folder + # "public" in the current directory (ie public/css/* and public/images/*) + + class Static + + def initialize(app, options={}) + @app = app + @urls = options[:urls] || ["/favicon.ico"] + root = options[:root] || Dir.pwd + @file_server = Rack::File.new(root) + end + + def call(env) + path = env["PATH_INFO"] + can_serve = @urls.any? { |url| path.index(url) == 0 } + + if can_serve + @file_server.call(env) + else + @app.call(env) + end + end + + end +end diff --git a/vendor/gems/rack-1.1.0/lib/rack/urlmap.rb b/vendor/gems/rack-1.1.0/lib/rack/urlmap.rb new file mode 100644 index 00000000..b699d35b --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/urlmap.rb @@ -0,0 +1,56 @@ +module Rack + # Rack::URLMap takes a hash mapping urls or paths to apps, and + # dispatches accordingly. Support for HTTP/1.1 host names exists if + # the URLs start with http:// or https://. + # + # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part + # relevant for dispatch is in the SCRIPT_NAME, and the rest in the + # PATH_INFO. This should be taken care of when you need to + # reconstruct the URL in order to create links. + # + # URLMap dispatches in such a way that the longest paths are tried + # first, since they are most specific. + + class URLMap + def initialize(map = {}) + remap(map) + end + + def remap(map) + @mapping = map.map { |location, app| + if location =~ %r{\Ahttps?://(.*?)(/.*)} + host, location = $1, $2 + else + host = nil + end + + unless location[0] == ?/ + raise ArgumentError, "paths need to start with /" + end + location = location.chomp('/') + match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)", nil, 'n') + + [host, location, match, app] + }.sort_by { |(h, l, m, a)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first + end + + def call(env) + path = env["PATH_INFO"].to_s + script_name = env['SCRIPT_NAME'] + hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT') + @mapping.each { |host, location, match, app| + next unless (hHost == host || sName == host \ + || (host.nil? && (hHost == sName || hHost == sName+':'+sPort))) + next unless path =~ match && rest = $1 + next unless rest.empty? || rest[0] == ?/ + + return app.call( + env.merge( + 'SCRIPT_NAME' => (script_name + location), + 'PATH_INFO' => rest)) + } + [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]] + end + end +end + diff --git a/vendor/gems/rack-1.1.0/lib/rack/utils.rb b/vendor/gems/rack-1.1.0/lib/rack/utils.rb new file mode 100644 index 00000000..68fd6ace --- /dev/null +++ b/vendor/gems/rack-1.1.0/lib/rack/utils.rb @@ -0,0 +1,620 @@ +# -*- encoding: binary -*- + +require 'set' +require 'tempfile' + +module Rack + # Rack::Utils contains a grab-bag of useful methods for writing web + # applications adopted from all kinds of Ruby libraries. + + module Utils + # Performs URI escaping so that you can construct proper + # query strings faster. Use this rather than the cgi.rb + # version since it's faster. (Stolen from Camping). + def escape(s) + s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) { + '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase + }.tr(' ', '+') + end + module_function :escape + + # Unescapes a URI escaped string. (Stolen from Camping). + def unescape(s) + s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){ + [$1.delete('%')].pack('H*') + } + end + module_function :unescape + + DEFAULT_SEP = /[&;] */n + + # Stolen from Mongrel, with some small modifications: + # Parses a query string by breaking it up at the '&' + # and ';' characters. You can also use this to parse + # cookies by changing the characters used in the second + # parameter (which defaults to '&;'). + def parse_query(qs, d = nil) + params = {} + + (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p| + k, v = p.split('=', 2).map { |x| unescape(x) } + if v =~ /^("|')(.*)\1$/ + v = $2.gsub('\\'+$1, $1) + end + if cur = params[k] + if cur.class == Array + params[k] << v + else + params[k] = [cur, v] + end + else + params[k] = v + end + end + + return params + end + module_function :parse_query + + def parse_nested_query(qs, d = nil) + params = {} + + (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p| + k, v = unescape(p).split('=', 2) + normalize_params(params, k, v) + end + + return params + end + module_function :parse_nested_query + + def normalize_params(params, name, v = nil) + if v and v =~ /^("|')(.*)\1$/ + v = $2.gsub('\\'+$1, $1) + end + name =~ %r(\A[\[\]]*([^\[\]]+)\]*) + k = $1 || '' + after = $' || '' + + return if k.empty? + + if after == "" + params[k] = v + elsif after == "[]" + params[k] ||= [] + raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) + params[k] << v + elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$) + child_key = $1 + params[k] ||= [] + raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) + if params[k].last.is_a?(Hash) && !params[k].last.key?(child_key) + normalize_params(params[k].last, child_key, v) + else + params[k] << normalize_params({}, child_key, v) + end + else + params[k] ||= {} + raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Hash) + params[k] = normalize_params(params[k], after, v) + end + + return params + end + module_function :normalize_params + + def build_query(params) + params.map { |k, v| + if v.class == Array + build_query(v.map { |x| [k, x] }) + else + "#{escape(k)}=#{escape(v)}" + end + }.join("&") + end + module_function :build_query + + def build_nested_query(value, prefix = nil) + case value + when Array + value.map { |v| + build_nested_query(v, "#{prefix}[]") + }.join("&") + when Hash + value.map { |k, v| + build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k)) + }.join("&") + when String + raise ArgumentError, "value must be a Hash" if prefix.nil? + "#{prefix}=#{escape(value)}" + else + prefix + end + end + module_function :build_nested_query + + # Escape ampersands, brackets and quotes to their HTML/XML entities. + def escape_html(string) + string.to_s.gsub("&", "&"). + gsub("<", "<"). + gsub(">", ">"). + gsub("'", "'"). + gsub('"', """) + end + module_function :escape_html + + def select_best_encoding(available_encodings, accept_encoding) + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + + expanded_accept_encoding = + accept_encoding.map { |m, q| + if m == "*" + (available_encodings - accept_encoding.map { |m2, _| m2 }).map { |m2| [m2, q] } + else + [[m, q]] + end + }.inject([]) { |mem, list| + mem + list + } + + encoding_candidates = expanded_accept_encoding.sort_by { |_, q| -q }.map { |m, _| m } + + unless encoding_candidates.include?("identity") + encoding_candidates.push("identity") + end + + expanded_accept_encoding.find_all { |m, q| + q == 0.0 + }.each { |m, _| + encoding_candidates.delete(m) + } + + return (encoding_candidates & available_encodings)[0] + end + module_function :select_best_encoding + + def set_cookie_header!(header, key, value) + case value + when Hash + domain = "; domain=" + value[:domain] if value[:domain] + path = "; path=" + value[:path] if value[:path] + # According to RFC 2109, we need dashes here. + # N.B.: cgi.rb uses spaces... + expires = "; expires=" + value[:expires].clone.gmtime. + strftime("%a, %d-%b-%Y %H:%M:%S GMT") if value[:expires] + secure = "; secure" if value[:secure] + httponly = "; HttpOnly" if value[:httponly] + value = value[:value] + end + value = [value] unless Array === value + cookie = escape(key) + "=" + + value.map { |v| escape v }.join("&") + + "#{domain}#{path}#{expires}#{secure}#{httponly}" + + case header["Set-Cookie"] + when Array + header["Set-Cookie"] << cookie + when String + header["Set-Cookie"] = [header["Set-Cookie"], cookie] + when nil + header["Set-Cookie"] = cookie + end + + nil + end + module_function :set_cookie_header! + + def delete_cookie_header!(header, key, value = {}) + unless Array === header["Set-Cookie"] + header["Set-Cookie"] = [header["Set-Cookie"]].compact + end + + header["Set-Cookie"].reject! { |cookie| + cookie =~ /\A#{escape(key)}=/ + } + + set_cookie_header!(header, key, + {:value => '', :path => nil, :domain => nil, + :expires => Time.at(0) }.merge(value)) + + nil + end + module_function :delete_cookie_header! + + # Return the bytesize of String; uses String#length under Ruby 1.8 and + # String#bytesize under 1.9. + if ''.respond_to?(:bytesize) + def bytesize(string) + string.bytesize + end + else + def bytesize(string) + string.size + end + end + module_function :bytesize + + # Context allows the use of a compatible middleware at different points + # in a request handling stack. A compatible middleware must define + # #context which should take the arguments env and app. The first of which + # would be the request environment. The second of which would be the rack + # application that the request would be forwarded to. + class Context + attr_reader :for, :app + + def initialize(app_f, app_r) + raise 'running context does not respond to #context' unless app_f.respond_to? :context + @for, @app = app_f, app_r + end + + def call(env) + @for.context(env, @app) + end + + def recontext(app) + self.class.new(@for, app) + end + + def context(env, app=@app) + recontext(app).call(env) + end + end + + # A case-insensitive Hash that preserves the original case of a + # header when set. + class HeaderHash < Hash + def self.new(hash={}) + HeaderHash === hash ? hash : super(hash) + end + + def initialize(hash={}) + super() + @names = {} + hash.each { |k, v| self[k] = v } + end + + def each + super do |k, v| + yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v) + end + end + + def to_hash + inject({}) do |hash, (k,v)| + if v.respond_to? :to_ary + hash[k] = v.to_ary.join("\n") + else + hash[k] = v + end + hash + end + end + + def [](k) + super(@names[k] ||= @names[k.downcase]) + end + + def []=(k, v) + delete k + @names[k] = @names[k.downcase] = k + super k, v + end + + def delete(k) + canonical = k.downcase + result = super @names.delete(canonical) + @names.delete_if { |name,| name.downcase == canonical } + result + end + + def include?(k) + @names.include?(k) || @names.include?(k.downcase) + end + + alias_method :has_key?, :include? + alias_method :member?, :include? + alias_method :key?, :include? + + def merge!(other) + other.each { |k, v| self[k] = v } + self + end + + def merge(other) + hash = dup + hash.merge! other + end + + def replace(other) + clear + other.each { |k, v| self[k] = v } + self + end + end + + # Every standard HTTP code mapped to the appropriate message. + # Generated with: + # curl -s http://www.iana.org/assignments/http-status-codes | \ + # ruby -ane 'm = /^(\d{3}) +(\S[^\[(]+)/.match($_) and + # puts " #{m[1]} => \x27#{m[2].strip}x27,"' + HTTP_STATUS_CODES = { + 100 => 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', + 226 => 'IM Used', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 306 => 'Reserved', + 307 => 'Temporary Redirect', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', + 423 => 'Locked', + 424 => 'Failed Dependency', + 426 => 'Upgrade Required', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates', + 507 => 'Insufficient Storage', + 510 => 'Not Extended', + } + + # Responses with HTTP status codes that should not have an entity body + STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 304) + + SYMBOL_TO_STATUS_CODE = HTTP_STATUS_CODES.inject({}) { |hash, (code, message)| + hash[message.downcase.gsub(/\s|-/, '_').to_sym] = code + hash + } + + def status_code(status) + if status.is_a?(Symbol) + SYMBOL_TO_STATUS_CODE[status] || 500 + else + status.to_i + end + end + module_function :status_code + + # A multipart form data parser, adapted from IOWA. + # + # Usually, Rack::Request#POST takes care of calling this. + + module Multipart + class UploadedFile + # The filename, *not* including the path, of the "uploaded" file + attr_reader :original_filename + + # The content type of the "uploaded" file + attr_accessor :content_type + + def initialize(path, content_type = "text/plain", binary = false) + raise "#{path} file does not exist" unless ::File.exist?(path) + @content_type = content_type + @original_filename = ::File.basename(path) + @tempfile = Tempfile.new(@original_filename) + @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding) + @tempfile.binmode if binary + FileUtils.copy_file(path, @tempfile.path) + end + + def path + @tempfile.path + end + alias_method :local_path, :path + + def method_missing(method_name, *args, &block) #:nodoc: + @tempfile.__send__(method_name, *args, &block) + end + end + + EOL = "\r\n" + MULTIPART_BOUNDARY = "AaB03x" + + def self.parse_multipart(env) + unless env['CONTENT_TYPE'] =~ + %r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|n + nil + else + boundary = "--#{$1}" + + params = {} + buf = "" + content_length = env['CONTENT_LENGTH'].to_i + input = env['rack.input'] + input.rewind + + boundary_size = Utils.bytesize(boundary) + EOL.size + bufsize = 16384 + + content_length -= boundary_size + + read_buffer = '' + + status = input.read(boundary_size, read_buffer) + raise EOFError, "bad content body" unless status == boundary + EOL + + rx = /(?:#{EOL})?#{Regexp.quote boundary}(#{EOL}|--)/n + + loop { + head = nil + body = '' + filename = content_type = name = nil + + until head && buf =~ rx + if !head && i = buf.index(EOL+EOL) + head = buf.slice!(0, i+2) # First \r\n + buf.slice!(0, 2) # Second \r\n + + filename = head[/Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/ni, 1] + content_type = head[/Content-Type: (.*)#{EOL}/ni, 1] + name = head[/Content-Disposition:.*\s+name="?([^\";]*)"?/ni, 1] || head[/Content-ID:\s*([^#{EOL}]*)/ni, 1] + + if content_type || filename + body = Tempfile.new("RackMultipart") + body.binmode if body.respond_to?(:binmode) + end + + next + end + + # Save the read body part. + if head && (boundary_size+4 < buf.size) + body << buf.slice!(0, buf.size - (boundary_size+4)) + end + + c = input.read(bufsize < content_length ? bufsize : content_length, read_buffer) + raise EOFError, "bad content body" if c.nil? || c.empty? + buf << c + content_length -= c.size + end + + # Save the rest. + if i = buf.index(rx) + body << buf.slice!(0, i) + buf.slice!(0, boundary_size+2) + + content_length = -1 if $1 == "--" + end + + if filename == "" + # filename is blank which means no file has been selected + data = nil + elsif filename + body.rewind + + # Take the basename of the upload's original filename. + # This handles the full Windows paths given by Internet Explorer + # (and perhaps other broken user agents) without affecting + # those which give the lone filename. + filename =~ /^(?:.*[:\\\/])?(.*)/m + filename = $1 + + data = {:filename => filename, :type => content_type, + :name => name, :tempfile => body, :head => head} + elsif !filename && content_type + body.rewind + + # Generic multipart cases, not coming from a form + data = {:type => content_type, + :name => name, :tempfile => body, :head => head} + else + data = body + end + + Utils.normalize_params(params, name, data) unless data.nil? + + # break if we're at the end of a buffer, but not if it is the end of a field + break if (buf.empty? && $1 != EOL) || content_length == -1 + } + + input.rewind + + params + end + end + + def self.build_multipart(params, first = true) + if first + unless params.is_a?(Hash) + raise ArgumentError, "value must be a Hash" + end + + multipart = false + query = lambda { |value| + case value + when Array + value.each(&query) + when Hash + value.values.each(&query) + when UploadedFile + multipart = true + end + } + params.values.each(&query) + return nil unless multipart + end + + flattened_params = Hash.new + + params.each do |key, value| + k = first ? key.to_s : "[#{key}]" + + case value + when Array + value.map { |v| + build_multipart(v, false).each { |subkey, subvalue| + flattened_params["#{k}[]#{subkey}"] = subvalue + } + } + when Hash + build_multipart(value, false).each { |subkey, subvalue| + flattened_params[k + subkey] = subvalue + } + else + flattened_params[k] = value + end + end + + if first + flattened_params.map { |name, file| + if file.respond_to?(:original_filename) + ::File.open(file.path, "rb") do |f| + f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding) +<<-EOF +--#{MULTIPART_BOUNDARY}\r +Content-Disposition: form-data; name="#{name}"; filename="#{Utils.escape(file.original_filename)}"\r +Content-Type: #{file.content_type}\r +Content-Length: #{::File.stat(file.path).size}\r +\r +#{f.read}\r +EOF + end + else +<<-EOF +--#{MULTIPART_BOUNDARY}\r +Content-Disposition: form-data; name="#{name}"\r +\r +#{file}\r +EOF + end + }.join + "--#{MULTIPART_BOUNDARY}--\r" + else + flattened_params + end + end + end + end +end diff --git a/vendor/gems/rack-1.1.0/rack.gemspec b/vendor/gems/rack-1.1.0/rack.gemspec new file mode 100644 index 00000000..e28b9bb2 --- /dev/null +++ b/vendor/gems/rack-1.1.0/rack.gemspec @@ -0,0 +1,38 @@ +Gem::Specification.new do |s| + s.name = "rack" + s.version = "1.1.0" + s.platform = Gem::Platform::RUBY + s.summary = "a modular Ruby webserver interface" + + s.description = <<-EOF +Rack provides minimal, modular and adaptable interface for developing +web applications in Ruby. By wrapping HTTP requests and responses in +the simplest way possible, it unifies and distills the API for web +servers, web frameworks, and software in between (the so-called +middleware) into a single method call. + +Also see http://rack.rubyforge.org. +EOF + + s.files = Dir['{bin/*,contrib/*,example/*,lib/**/*}'] + + %w(COPYING KNOWN-ISSUES rack.gemspec RDOX README SPEC) + s.bindir = 'bin' + s.executables << 'rackup' + s.require_path = 'lib' + s.has_rdoc = true + s.extra_rdoc_files = ['README', 'SPEC', 'KNOWN-ISSUES'] + s.test_files = Dir['test/{test,spec}_*.rb'] + + s.author = 'Christian Neukirchen' + s.email = 'chneukirchen@gmail.com' + s.homepage = 'http://rack.rubyforge.org' + s.rubyforge_project = 'rack' + + s.add_development_dependency 'test-spec' + + s.add_development_dependency 'camping' + s.add_development_dependency 'fcgi' + s.add_development_dependency 'memcache-client' + s.add_development_dependency 'mongrel' + s.add_development_dependency 'thin' +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_auth_basic.rb b/vendor/gems/rack-1.1.0/test/spec_rack_auth_basic.rb new file mode 100644 index 00000000..0176efc8 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_auth_basic.rb @@ -0,0 +1,73 @@ +require 'test/spec' + +require 'rack/auth/basic' +require 'rack/mock' + +context 'Rack::Auth::Basic' do + + def realm + 'WallysWorld' + end + + def unprotected_app + lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] } + end + + def protected_app + app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username } + app.realm = realm + app + end + + setup do + @request = Rack::MockRequest.new(protected_app) + end + + def request_with_basic_auth(username, password, &block) + request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block + end + + def request(headers = {}) + yield @request.get('/', headers) + end + + def assert_basic_auth_challenge(response) + response.should.be.a.client_error + response.status.should.equal 401 + response.should.include 'WWW-Authenticate' + response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/ + response.body.should.be.empty + end + + specify 'should challenge correctly when no credentials are specified' do + request do |response| + assert_basic_auth_challenge response + end + end + + specify 'should rechallenge if incorrect credentials are specified' do + request_with_basic_auth 'joe', 'password' do |response| + assert_basic_auth_challenge response + end + end + + specify 'should return application output if correct credentials are specified' do + request_with_basic_auth 'Boss', 'password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Boss' + end + end + + specify 'should return 400 Bad Request if different auth scheme used' do + request 'HTTP_AUTHORIZATION' => 'Digest params' do |response| + response.should.be.a.client_error + response.status.should.equal 400 + response.should.not.include 'WWW-Authenticate' + end + end + + specify 'realm as optional constructor arg' do + app = Rack::Auth::Basic.new(unprotected_app, realm) { true } + assert_equal realm, app.realm + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_auth_digest.rb b/vendor/gems/rack-1.1.0/test/spec_rack_auth_digest.rb new file mode 100644 index 00000000..a980acc8 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_auth_digest.rb @@ -0,0 +1,226 @@ +require 'test/spec' + +require 'rack/auth/digest/md5' +require 'rack/mock' + +context 'Rack::Auth::Digest::MD5' do + + def realm + 'WallysWorld' + end + + def unprotected_app + lambda do |env| + [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] + end + end + + def protected_app + app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username| + { 'Alice' => 'correct-password' }[username] + end + app.realm = realm + app.opaque = 'this-should-be-secret' + app + end + + def protected_app_with_hashed_passwords + app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username| + username == 'Alice' ? Digest::MD5.hexdigest("Alice:#{realm}:correct-password") : nil + end + app.realm = realm + app.opaque = 'this-should-be-secret' + app.passwords_hashed = true + app + end + + def partially_protected_app + Rack::URLMap.new({ + '/' => unprotected_app, + '/protected' => protected_app + }) + end + + def protected_app_with_method_override + Rack::MethodOverride.new(protected_app) + end + + setup do + @request = Rack::MockRequest.new(protected_app) + end + + def request(method, path, headers = {}, &block) + response = @request.request(method, path, headers) + block.call(response) if block + return response + end + + class MockDigestRequest + def initialize(params) + @params = params + end + def method_missing(sym) + if @params.has_key? k = sym.to_s + return @params[k] + end + super + end + def method + @params['method'] + end + def response(password) + Rack::Auth::Digest::MD5.new(nil).send :digest, self, password + end + end + + def request_with_digest_auth(method, path, username, password, options = {}, &block) + request_options = {} + request_options[:input] = options.delete(:input) if options.include? :input + + response = request(method, path, request_options) + + return response unless response.status == 401 + + if wait = options.delete(:wait) + sleep wait + end + + challenge = response['WWW-Authenticate'].split(' ', 2).last + + params = Rack::Auth::Digest::Params.parse(challenge) + + params['username'] = username + params['nc'] = '00000001' + params['cnonce'] = 'nonsensenonce' + params['uri'] = path + + params['method'] = method + + params.update options + + params['response'] = MockDigestRequest.new(params).response(password) + + request(method, path, request_options.merge('HTTP_AUTHORIZATION' => "Digest #{params}"), &block) + end + + def assert_digest_auth_challenge(response) + response.should.be.a.client_error + response.status.should.equal 401 + response.should.include 'WWW-Authenticate' + response.headers['WWW-Authenticate'].should =~ /^Digest / + response.body.should.be.empty + end + + def assert_bad_request(response) + response.should.be.a.client_error + response.status.should.equal 400 + response.should.not.include 'WWW-Authenticate' + end + + specify 'should challenge when no credentials are specified' do + request 'GET', '/' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should return application output if correct credentials given' do + request_with_digest_auth 'GET', '/', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should return application output if correct credentials given (hashed passwords)' do + @request = Rack::MockRequest.new(protected_app_with_hashed_passwords) + + request_with_digest_auth 'GET', '/', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should rechallenge if incorrect username given' do + request_with_digest_auth 'GET', '/', 'Bob', 'correct-password' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should rechallenge if incorrect password given' do + request_with_digest_auth 'GET', '/', 'Alice', 'wrong-password' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should rechallenge with stale parameter if nonce is stale' do + begin + Rack::Auth::Digest::Nonce.time_limit = 1 + + request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', :wait => 2 do |response| + assert_digest_auth_challenge response + response.headers['WWW-Authenticate'].should =~ /\bstale=true\b/ + end + ensure + Rack::Auth::Digest::Nonce.time_limit = nil + end + end + + specify 'should return 400 Bad Request if incorrect qop given' do + request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', 'qop' => 'auth-int' do |response| + assert_bad_request response + end + end + + specify 'should return 400 Bad Request if incorrect uri given' do + request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', 'uri' => '/foo' do |response| + assert_bad_request response + end + end + + specify 'should return 400 Bad Request if different auth scheme used' do + request 'GET', '/', 'HTTP_AUTHORIZATION' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' do |response| + assert_bad_request response + end + end + + specify 'should not require credentials for unprotected path' do + @request = Rack::MockRequest.new(partially_protected_app) + request 'GET', '/' do |response| + response.should.be.ok + end + end + + specify 'should challenge when no credentials are specified for protected path' do + @request = Rack::MockRequest.new(partially_protected_app) + request 'GET', '/protected' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should return application output if correct credentials given for protected path' do + @request = Rack::MockRequest.new(partially_protected_app) + request_with_digest_auth 'GET', '/protected', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should return application output if correct credentials given for POST' do + request_with_digest_auth 'POST', '/', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should return application output if correct credentials given for PUT (using method override of POST)' do + @request = Rack::MockRequest.new(protected_app_with_method_override) + request_with_digest_auth 'POST', '/', 'Alice', 'correct-password', :input => "_method=put" do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'realm as optional constructor arg' do + app = Rack::Auth::Digest::MD5.new(unprotected_app, realm) { true } + assert_equal realm, app.realm + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_builder.rb b/vendor/gems/rack-1.1.0/test/spec_rack_builder.rb new file mode 100644 index 00000000..3fad9810 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_builder.rb @@ -0,0 +1,84 @@ +require 'test/spec' + +require 'rack/builder' +require 'rack/mock' +require 'rack/showexceptions' +require 'rack/auth/basic' + +context "Rack::Builder" do + specify "chains apps by default" do + app = Rack::Builder.new do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end.to_app + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "has implicit #to_app" do + app = Rack::Builder.new do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "supports blocks on use" do + app = Rack::Builder.new do + use Rack::ShowExceptions + use Rack::Auth::Basic do |username, password| + 'secret' == password + end + + run lambda { |env| [200, {}, ['Hi Boss']] } + end + + response = Rack::MockRequest.new(app).get("/") + response.should.be.client_error + response.status.should.equal 401 + + # with auth... + response = Rack::MockRequest.new(app).get("/", + 'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*")) + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Boss' + end + + specify "has explicit #to_app" do + app = Rack::Builder.app do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "apps are initialized once" do + app = Rack::Builder.new do + class AppClass + def initialize + @called = 0 + end + def call(env) + raise "bzzzt" if @called > 0 + @called += 1 + [200, {'Content-Type' => 'text/plain'}, ['OK']] + end + end + + use Rack::ShowExceptions + run AppClass.new + end + + Rack::MockRequest.new(app).get("/").status.should.equal 200 + Rack::MockRequest.new(app).get("/").should.be.server_error + end + +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_camping.rb b/vendor/gems/rack-1.1.0/test/spec_rack_camping.rb new file mode 100644 index 00000000..bed11710 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_camping.rb @@ -0,0 +1,51 @@ +require 'test/spec' +require 'stringio' +require 'uri' + +begin + require 'rack/mock' + + $-w, w = nil, $-w # yuck + require 'camping' + require 'rack/adapter/camping' + + Camping.goes :CampApp + module CampApp + module Controllers + class HW < R('/') + def get + @headers["X-Served-By"] = URI("http://rack.rubyforge.org") + "Camping works!" + end + + def post + "Data: #{input.foo}" + end + end + end + end + $-w = w + + context "Rack::Adapter::Camping" do + specify "works with GET" do + res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). + get("/") + + res.should.be.ok + res["Content-Type"].should.equal "text/html" + res["X-Served-By"].should.equal "http://rack.rubyforge.org" + + res.body.should.equal "Camping works!" + end + + specify "works with POST" do + res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). + post("/", :input => "foo=bar") + + res.should.be.ok + res.body.should.equal "Data: bar" + end + end +rescue LoadError + $stderr.puts "Skipping Rack::Adapter::Camping tests (Camping is required). `gem install camping` and try again." +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_cascade.rb b/vendor/gems/rack-1.1.0/test/spec_rack_cascade.rb new file mode 100644 index 00000000..cf3c29b4 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_cascade.rb @@ -0,0 +1,48 @@ +require 'test/spec' + +require 'rack/cascade' +require 'rack/mock' + +require 'rack/urlmap' +require 'rack/file' + +context "Rack::Cascade" do + docroot = File.expand_path(File.dirname(__FILE__)) + app1 = Rack::File.new(docroot) + + app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" }) + + app3 = Rack::URLMap.new("/foo" => lambda { |env| + [200, { "Content-Type" => "text/plain"}, [""]]}) + + specify "should dispatch onward on 404 by default" do + cascade = Rack::Cascade.new([app1, app2, app3]) + Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok + Rack::MockRequest.new(cascade).get("/foo").should.be.ok + Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found + Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden + end + + specify "should dispatch onward on whatever is passed" do + cascade = Rack::Cascade.new([app1, app2, app3], [404, 403]) + Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found + end + + specify "should return 404 if empty" do + Rack::MockRequest.new(Rack::Cascade.new([])).get('/').should.be.not_found + end + + specify "should append new app" do + cascade = Rack::Cascade.new([], [404, 403]) + Rack::MockRequest.new(cascade).get('/').should.be.not_found + cascade << app2 + Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found + Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found + cascade << app1 + Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok + Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden + Rack::MockRequest.new(cascade).get('/foo').should.be.not_found + cascade << app3 + Rack::MockRequest.new(cascade).get('/foo').should.be.ok + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb b/vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb new file mode 100644 index 00000000..59500cd7 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb @@ -0,0 +1,89 @@ +require 'test/spec' +require 'testrequest' + +context "Rack::Handler::CGI" do + include TestRequest::Helpers + + setup do + @host = '0.0.0.0' + @port = 9203 + end + + # Keep this first. + specify "startup" do + $pid = fork { + Dir.chdir(File.join(File.dirname(__FILE__), "..", "test", "cgi")) + exec "lighttpd -D -f lighttpd.conf" + } + end + + specify "should respond" do + sleep 1 + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a lighttpd" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /lighttpd/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal @port.to_s + response["SERVER_NAME"].should =~ @host + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [1,1] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be true + response["rack.run_once"].should.be true + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + # Keep this last. + specify "shutdown" do + Process.kill 15, $pid + Process.wait($pid).should.equal $pid + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_chunked.rb b/vendor/gems/rack-1.1.0/test/spec_rack_chunked.rb new file mode 100644 index 00000000..39eea482 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_chunked.rb @@ -0,0 +1,62 @@ +require 'rack/mock' +require 'rack/chunked' +require 'rack/utils' + +context "Rack::Chunked" do + + before do + @env = Rack::MockRequest. + env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET') + end + + specify 'chunks responses with no Content-Length' do + app = lambda { |env| [200, {}, ['Hello', ' ', 'World!']] } + response = Rack::MockResponse.new(*Rack::Chunked.new(app).call(@env)) + response.headers.should.not.include 'Content-Length' + response.headers['Transfer-Encoding'].should.equal 'chunked' + response.body.should.equal "5\r\nHello\r\n1\r\n \r\n6\r\nWorld!\r\n0\r\n\r\n" + end + + specify 'chunks empty bodies properly' do + app = lambda { |env| [200, {}, []] } + response = Rack::MockResponse.new(*Rack::Chunked.new(app).call(@env)) + response.headers.should.not.include 'Content-Length' + response.headers['Transfer-Encoding'].should.equal 'chunked' + response.body.should.equal "0\r\n\r\n" + end + + specify 'does not modify response when Content-Length header present' do + app = lambda { |env| [200, {'Content-Length'=>'12'}, ['Hello', ' ', 'World!']] } + status, headers, body = Rack::Chunked.new(app).call(@env) + status.should.equal 200 + headers.should.not.include 'Transfer-Encoding' + headers.should.include 'Content-Length' + body.join.should.equal 'Hello World!' + end + + specify 'does not modify response when client is HTTP/1.0' do + app = lambda { |env| [200, {}, ['Hello', ' ', 'World!']] } + @env['HTTP_VERSION'] = 'HTTP/1.0' + status, headers, body = Rack::Chunked.new(app).call(@env) + status.should.equal 200 + headers.should.not.include 'Transfer-Encoding' + body.join.should.equal 'Hello World!' + end + + specify 'does not modify response when Transfer-Encoding header already present' do + app = lambda { |env| [200, {'Transfer-Encoding' => 'identity'}, ['Hello', ' ', 'World!']] } + status, headers, body = Rack::Chunked.new(app).call(@env) + status.should.equal 200 + headers['Transfer-Encoding'].should.equal 'identity' + body.join.should.equal 'Hello World!' + end + + [100, 204, 304].each do |status_code| + specify "does not modify response when status code is #{status_code}" do + app = lambda { |env| [status_code, {}, []] } + status, headers, body = Rack::Chunked.new(app).call(@env) + status.should.equal status_code + headers.should.not.include 'Transfer-Encoding' + end + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_commonlogger.rb b/vendor/gems/rack-1.1.0/test/spec_rack_commonlogger.rb new file mode 100644 index 00000000..46a72e86 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_commonlogger.rb @@ -0,0 +1,61 @@ +require 'test/spec' +require 'stringio' + +require 'rack/commonlogger' +require 'rack/lobster' +require 'rack/mock' + +context "Rack::CommonLogger" do + app = lambda { |env| + [200, + {"Content-Type" => "text/html", "Content-Length" => length.to_s}, + [obj]]} + app_without_length = lambda { |env| + [200, + {"Content-Type" => "text/html"}, + []]} + app_with_zero_length = lambda { |env| + [200, + {"Content-Type" => "text/html", "Content-Length" => "0"}, + []]} + + specify "should log to rack.errors by default" do + res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/") + + res.errors.should.not.be.empty + res.errors.should =~ /"GET \/ " 200 #{length} / + end + + specify "should log to anything with +write+" do + log = StringIO.new + res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/") + + log.string.should =~ /"GET \/ " 200 #{length} / + end + + specify "should log - content length if header is missing" do + res = Rack::MockRequest.new(Rack::CommonLogger.new(app_without_length)).get("/") + + res.errors.should.not.be.empty + res.errors.should =~ /"GET \/ " 200 - / + end + + specify "should log - content length if header is zero" do + res = Rack::MockRequest.new(Rack::CommonLogger.new(app_with_zero_length)).get("/") + + res.errors.should.not.be.empty + res.errors.should =~ /"GET \/ " 200 - / + end + + def length + self.class.length + end + + def self.length + 123 + end + + def self.obj + "hello world" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_conditionalget.rb b/vendor/gems/rack-1.1.0/test/spec_rack_conditionalget.rb new file mode 100644 index 00000000..ca34cc92 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_conditionalget.rb @@ -0,0 +1,41 @@ +require 'test/spec' +require 'time' + +require 'rack/mock' +require 'rack/conditionalget' + +context "Rack::ConditionalGet" do + specify "should set a 304 status and truncate body when If-Modified-Since hits" do + timestamp = Time.now.httpdate + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Last-Modified'=>timestamp}, ['TEST']] }) + + response = Rack::MockRequest.new(app). + get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp) + + response.status.should.equal 304 + response.body.should.be.empty + end + + specify "should set a 304 status and truncate body when If-None-Match hits" do + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Etag'=>'1234'}, ['TEST']] }) + + response = Rack::MockRequest.new(app). + get("/", 'HTTP_IF_NONE_MATCH' => '1234') + + response.status.should.equal 304 + response.body.should.be.empty + end + + specify "should not affect non-GET/HEAD requests" do + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Etag'=>'1234'}, ['TEST']] }) + + response = Rack::MockRequest.new(app). + post("/", 'HTTP_IF_NONE_MATCH' => '1234') + + response.status.should.equal 200 + response.body.should.equal 'TEST' + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_config.rb b/vendor/gems/rack-1.1.0/test/spec_rack_config.rb new file mode 100644 index 00000000..a508ea4b --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_config.rb @@ -0,0 +1,24 @@ +require 'test/spec' +require 'rack/mock' +require 'rack/builder' +require 'rack/content_length' +require 'rack/config' + +context "Rack::Config" do + + specify "should accept a block that modifies the environment" do + app = Rack::Builder.new do + use Rack::Lint + use Rack::ContentLength + use Rack::Config do |env| + env['greeting'] = 'hello' + end + run lambda { |env| + [200, {'Content-Type' => 'text/plain'}, [env['greeting'] || '']] + } + end + response = Rack::MockRequest.new(app).get('/') + response.body.should.equal('hello') + end + +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_content_length.rb b/vendor/gems/rack-1.1.0/test/spec_rack_content_length.rb new file mode 100644 index 00000000..7db9345f --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_content_length.rb @@ -0,0 +1,43 @@ +require 'rack/mock' +require 'rack/content_length' + +context "Rack::ContentLength" do + specify "sets Content-Length on String bodies if none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '13' + end + + specify "sets Content-Length on Array bodies if none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '13' + end + + specify "does not set Content-Length on variable length bodies" do + body = lambda { "Hello World!" } + def body.each ; yield call ; end + + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.be.nil + end + + specify "does not change Content-Length if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '1' + end + + specify "does not set Content-Length on 304 responses" do + app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal nil + end + + specify "does not set Content-Length when Transfer-Encoding is chunked" do + app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal nil + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_content_type.rb b/vendor/gems/rack-1.1.0/test/spec_rack_content_type.rb new file mode 100644 index 00000000..9975b94d --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_content_type.rb @@ -0,0 +1,30 @@ +require 'rack/mock' +require 'rack/content_type' + +context "Rack::ContentType" do + specify "sets Content-Type to default text/html if none is set" do + app = lambda { |env| [200, {}, "Hello, World!"] } + status, headers, body = Rack::ContentType.new(app).call({}) + headers['Content-Type'].should.equal 'text/html' + end + + specify "sets Content-Type to chosen default if none is set" do + app = lambda { |env| [200, {}, "Hello, World!"] } + status, headers, body = + Rack::ContentType.new(app, 'application/octet-stream').call({}) + headers['Content-Type'].should.equal 'application/octet-stream' + end + + specify "does not change Content-Type if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] } + status, headers, body = Rack::ContentType.new(app).call({}) + headers['Content-Type'].should.equal 'foo/bar' + end + + specify "case insensitive detection of Content-Type" do + app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] } + status, headers, body = Rack::ContentType.new(app).call({}) + headers.to_a.select { |k,v| k.downcase == "content-type" }. + should.equal [["CONTENT-Type","foo/bar"]] + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_deflater.rb b/vendor/gems/rack-1.1.0/test/spec_rack_deflater.rb new file mode 100644 index 00000000..c9bb3189 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_deflater.rb @@ -0,0 +1,127 @@ +require 'test/spec' + +require 'rack/mock' +require 'rack/deflater' +require 'stringio' +require 'time' # for Time#httpdate + +context "Rack::Deflater" do + def build_response(status, body, accept_encoding, headers = {}) + body = [body] if body.respond_to? :to_str + app = lambda { |env| [status, {}, body] } + request = Rack::MockRequest.env_for("", headers.merge("HTTP_ACCEPT_ENCODING" => accept_encoding)) + response = Rack::Deflater.new(app).call(request) + + return response + end + + specify "should be able to deflate bodies that respond to each" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "deflate") + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "deflate", + "Vary" => "Accept-Encoding" + }) + buf = '' + response[2].each { |part| buf << part } + buf.should.equal("K\313\317OJ,\002\000") + end + + # TODO: This is really just a special case of the above... + specify "should be able to deflate String bodies" do + response = build_response(200, "Hello world!", "deflate") + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "deflate", + "Vary" => "Accept-Encoding" + }) + buf = '' + response[2].each { |part| buf << part } + buf.should.equal("\363H\315\311\311W(\317/\312IQ\004\000") + end + + specify "should be able to gzip bodies that respond to each" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "gzip") + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "gzip", + "Vary" => "Accept-Encoding", + }) + + buf = '' + response[2].each { |part| buf << part } + io = StringIO.new(buf) + gz = Zlib::GzipReader.new(io) + gz.read.should.equal("foobar") + gz.close + end + + specify "should be able to fallback to no deflation" do + response = build_response(200, "Hello world!", "superzip") + + response[0].should.equal(200) + response[1].should.equal({ "Vary" => "Accept-Encoding" }) + response[2].should.equal(["Hello world!"]) + end + + specify "should be able to skip when there is no response entity body" do + response = build_response(304, [], "gzip") + + response[0].should.equal(304) + response[1].should.equal({}) + response[2].should.equal([]) + end + + specify "should handle the lack of an acceptable encoding" do + response1 = build_response(200, "Hello world!", "identity;q=0", "PATH_INFO" => "/") + response1[0].should.equal(406) + response1[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "71"}) + response1[2].should.equal(["An acceptable encoding for the requested resource / could not be found."]) + + response2 = build_response(200, "Hello world!", "identity;q=0", "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/bar") + response2[0].should.equal(406) + response2[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "78"}) + response2[2].should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."]) + end + + specify "should handle gzip response with Last-Modified header" do + last_modified = Time.now.httpdate + + app = lambda { |env| [200, { "Last-Modified" => last_modified }, ["Hello World!"]] } + request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip") + response = Rack::Deflater.new(app).call(request) + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "gzip", + "Vary" => "Accept-Encoding", + "Last-Modified" => last_modified + }) + + buf = '' + response[2].each { |part| buf << part } + io = StringIO.new(buf) + gz = Zlib::GzipReader.new(io) + gz.read.should.equal("Hello World!") + gz.close + end + + specify "should do nothing when no-transform Cache-Control directive present" do + app = lambda { |env| [200, {'Cache-Control' => 'no-transform'}, ['Hello World!']] } + request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip") + response = Rack::Deflater.new(app).call(request) + + response[0].should.equal(200) + response[1].should.not.include "Content-Encoding" + response[2].join.should.equal("Hello World!") + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_directory.rb b/vendor/gems/rack-1.1.0/test/spec_rack_directory.rb new file mode 100644 index 00000000..d255c91d --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_directory.rb @@ -0,0 +1,61 @@ +require 'test/spec' + +require 'rack/directory' +require 'rack/lint' + +require 'rack/mock' + +context "Rack::Directory" do + DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT + FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] } + app = Rack::Directory.new DOCROOT, FILE_CATCH + + specify "serves directory indices" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/") + + res.should.be.ok + res.should =~ // + end + + specify "passes to app if file found" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/test") + + res.should.be.ok + res.should =~ /passed!/ + end + + specify "serves uri with URL encoded filenames" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/%63%67%69/") # "/cgi/test" + + res.should.be.ok + res.should =~ // + + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/%74%65%73%74") # "/cgi/test" + + res.should.be.ok + res.should =~ /passed!/ + end + + specify "does not allow directory traversal" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/../test") + + res.should.be.forbidden + + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/%2E%2E/test") + + res.should.be.forbidden + end + + specify "404s if it can't find the file" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/blubb") + + res.should.be.not_found + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_etag.rb b/vendor/gems/rack-1.1.0/test/spec_rack_etag.rb new file mode 100644 index 00000000..73cd31ac --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_etag.rb @@ -0,0 +1,17 @@ +require 'test/spec' +require 'rack/mock' +require 'rack/etag' + +context "Rack::ETag" do + specify "sets ETag if none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] } + response = Rack::ETag.new(app).call({}) + response[1]['ETag'].should.equal "\"65a8e27d8879283831b664bd8b7f0ad4\"" + end + + specify "does not change ETag if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'ETag' => '"abc"'}, ["Hello, World!"]] } + response = Rack::ETag.new(app).call({}) + response[1]['ETag'].should.equal "\"abc\"" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_fastcgi.rb b/vendor/gems/rack-1.1.0/test/spec_rack_fastcgi.rb new file mode 100644 index 00000000..1ae55ace --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_fastcgi.rb @@ -0,0 +1,89 @@ +require 'test/spec' +require 'testrequest' + +context "Rack::Handler::FastCGI" do + include TestRequest::Helpers + + setup do + @host = '0.0.0.0' + @port = 9203 + end + + # Keep this first. + specify "startup" do + $pid = fork { + Dir.chdir(File.join(File.dirname(__FILE__), "..", "test", "cgi")) + exec "lighttpd -D -f lighttpd.conf" + } + end + + specify "should respond" do + sleep 1 + lambda { + GET("/test.fcgi") + }.should.not.raise + end + + specify "should be a lighttpd" do + GET("/test.fcgi") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /lighttpd/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal @port.to_s + response["SERVER_NAME"].should =~ @host + end + + specify "should have rack headers" do + GET("/test.fcgi") + response["rack.version"].should.equal [1,1] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be true + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test.fcgi") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test.fcgi/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test.fcgi", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test.fcgi?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + # Keep this last. + specify "shutdown" do + Process.kill 15, $pid + Process.wait($pid).should.equal $pid + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_file.rb b/vendor/gems/rack-1.1.0/test/spec_rack_file.rb new file mode 100644 index 00000000..0a2f8ee8 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_file.rb @@ -0,0 +1,75 @@ +require 'test/spec' + +require 'rack/file' +require 'rack/lint' + +require 'rack/mock' + +context "Rack::File" do + DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT + + specify "serves files" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/test") + + res.should.be.ok + res.should =~ /ruby/ + end + + specify "sets Last-Modified header" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/test") + + path = File.join(DOCROOT, "/cgi/test") + + res.should.be.ok + res["Last-Modified"].should.equal File.mtime(path).httpdate + end + + specify "serves files with URL encoded filenames" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/%74%65%73%74") # "/cgi/test" + + res.should.be.ok + res.should =~ /ruby/ + end + + specify "does not allow directory traversal" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/../test") + + res.should.be.forbidden + end + + specify "does not allow directory traversal with encoded periods" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/%2E%2E/README") + + res.should.be.forbidden + end + + specify "404s if it can't find the file" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/blubb") + + res.should.be.not_found + end + + specify "detects SystemCallErrors" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi") + + res.should.be.not_found + end + + specify "returns bodies that respond to #to_path" do + env = Rack::MockRequest.env_for("/cgi/test") + status, headers, body = Rack::File.new(DOCROOT).call(env) + + path = File.join(DOCROOT, "/cgi/test") + + status.should.equal 200 + body.should.respond_to :to_path + body.to_path.should.equal path + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_handler.rb b/vendor/gems/rack-1.1.0/test/spec_rack_handler.rb new file mode 100644 index 00000000..fcf19b78 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_handler.rb @@ -0,0 +1,43 @@ +require 'test/spec' + +require 'rack/handler' + +class Rack::Handler::Lobster; end +class RockLobster; end + +context "Rack::Handler" do + specify "has registered default handlers" do + Rack::Handler.get('cgi').should.equal Rack::Handler::CGI + Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI + Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel + Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick + end + + specify "handler that doesn't exist should raise a NameError" do + lambda { + Rack::Handler.get('boom') + }.should.raise(NameError) + end + + specify "should get unregistered, but already required, handler by name" do + Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster + end + + specify "should register custom handler" do + Rack::Handler.register('rock_lobster', 'RockLobster') + Rack::Handler.get('rock_lobster').should.equal RockLobster + end + + specify "should not need registration for properly coded handlers even if not already required" do + begin + $:.push "test/unregistered_handler" + Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered + lambda { + Rack::Handler.get('UnRegistered') + }.should.raise(NameError) + Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne + ensure + $:.delete "test/unregistered_handler" + end + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_head.rb b/vendor/gems/rack-1.1.0/test/spec_rack_head.rb new file mode 100644 index 00000000..48d3f81f --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_head.rb @@ -0,0 +1,30 @@ +require 'rack/head' +require 'rack/mock' + +context "Rack::Head" do + def test_response(headers = {}) + app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] } + request = Rack::MockRequest.env_for("/", headers) + response = Rack::Head.new(app).call(request) + + return response + end + + specify "passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do + %w[GET POST PUT DELETE OPTIONS TRACE].each do |type| + resp = test_response("REQUEST_METHOD" => type) + + resp[0].should.equal(200) + resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) + resp[2].should.equal(["foo"]) + end + end + + specify "removes body from HEAD requests" do + resp = test_response("REQUEST_METHOD" => "HEAD") + + resp[0].should.equal(200) + resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) + resp[2].should.equal([]) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_lint.rb b/vendor/gems/rack-1.1.0/test/spec_rack_lint.rb new file mode 100644 index 00000000..bbf75c17 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_lint.rb @@ -0,0 +1,528 @@ +require 'test/spec' +require 'stringio' + +require 'rack/lint' +require 'rack/mock' + +context "Rack::Lint" do + def env(*args) + Rack::MockRequest.env_for("/", *args) + end + + specify "passes valid request" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] + }).call(env({})) + }.should.not.raise + end + + specify "notices fatal errors" do + lambda { Rack::Lint.new(nil).call }.should.raise(Rack::Lint::LintError). + message.should.match(/No env given/) + end + + specify "notices environment errors" do + lambda { Rack::Lint.new(nil).call 5 }.should.raise(Rack::Lint::LintError). + message.should.match(/not a Hash/) + + lambda { + e = env + e.delete("REQUEST_METHOD") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/missing required key REQUEST_METHOD/) + + lambda { + e = env + e.delete("SERVER_NAME") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/missing required key SERVER_NAME/) + + + lambda { + Rack::Lint.new(nil).call(env("HTTP_CONTENT_TYPE" => "text/plain")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/contains HTTP_CONTENT_TYPE/) + + lambda { + Rack::Lint.new(nil).call(env("HTTP_CONTENT_LENGTH" => "42")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/contains HTTP_CONTENT_LENGTH/) + + lambda { + Rack::Lint.new(nil).call(env("FOO" => Object.new)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/non-string value/) + + lambda { + Rack::Lint.new(nil).call(env("rack.version" => "0.2")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be an Array/) + + lambda { + Rack::Lint.new(nil).call(env("rack.url_scheme" => "gopher")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/url_scheme unknown/) + + lambda { + Rack::Lint.new(nil).call(env("rack.session" => [])) + }.should.raise(Rack::Lint::LintError). + message.should.equal("session [] must respond to store and []=") + + lambda { + Rack::Lint.new(nil).call(env("rack.logger" => [])) + }.should.raise(Rack::Lint::LintError). + message.should.equal("logger [] must respond to info") + + lambda { + Rack::Lint.new(nil).call(env("REQUEST_METHOD" => "FUCKUP?")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/REQUEST_METHOD/) + + lambda { + Rack::Lint.new(nil).call(env("SCRIPT_NAME" => "howdy")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must start with/) + + lambda { + Rack::Lint.new(nil).call(env("PATH_INFO" => "../foo")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must start with/) + + lambda { + Rack::Lint.new(nil).call(env("CONTENT_LENGTH" => "xcii")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Invalid CONTENT_LENGTH/) + + lambda { + e = env + e.delete("PATH_INFO") + e.delete("SCRIPT_NAME") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/One of .* must be set/) + + lambda { + Rack::Lint.new(nil).call(env("SCRIPT_NAME" => "/")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/cannot be .* make it ''/) + end + + specify "notices input errors" do + lambda { + Rack::Lint.new(nil).call(env("rack.input" => "")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/does not respond to #gets/) + + lambda { + input = Object.new + def input.binmode? + false + end + Rack::Lint.new(nil).call(env("rack.input" => input)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/is not opened in binary mode/) + + lambda { + input = Object.new + def input.external_encoding + result = Object.new + def result.name + "US-ASCII" + end + result + end + Rack::Lint.new(nil).call(env("rack.input" => input)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/does not have ASCII-8BIT as its external encoding/) + end + + specify "notices error errors" do + lambda { + Rack::Lint.new(nil).call(env("rack.errors" => "")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/does not respond to #puts/) + end + + specify "notices status errors" do + lambda { + Rack::Lint.new(lambda { |env| + ["cc", {}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be >=100 seen as integer/) + + lambda { + Rack::Lint.new(lambda { |env| + [42, {}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be >=100 seen as integer/) + end + + specify "notices header errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, Object.new, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("headers object should respond to #each, but doesn't (got Object as headers)") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {true=>false}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("header key must be a string, was TrueClass") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Status" => "404"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not contain Status/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-Type:" => "text/plain"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not contain :/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-" => "text/plain"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not end/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"..%%quark%%.." => "text/plain"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("invalid header name: ..%%quark%%..") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo" => Object.new}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("a header value must be a String, but the value of 'Foo' is a Object") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo" => [1, 2, 3]}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("a header value must be a String, but the value of 'Foo' is a Array") + + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo-Bar" => "text\000plain"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/invalid header/) + + # line ends (010) should be allowed in header values. + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo-Bar" => "one\ntwo\nthree", "Content-Length" => "0", "Content-Type" => "text/plain" }, []] + }).call(env({})) + }.should.not.raise(Rack::Lint::LintError) + end + + specify "notices content-type errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/No Content-Type/) + + [100, 101, 204, 304].each do |status| + lambda { + Rack::Lint.new(lambda { |env| + [status, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Type header found/) + end + end + + specify "notices content-length errors" do + [100, 101, 204, 304].each do |status| + lambda { + Rack::Lint.new(lambda { |env| + [status, {"Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Length header found/) + end + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain", "Content-Length" => "1"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Length header was 1, but should be 0/) + end + + specify "notices body errors" do + lambda { + status, header, body = Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain","Content-length" => "3"}, [1,2,3]] + }).call(env({})) + body.each { |part| } + }.should.raise(Rack::Lint::LintError). + message.should.match(/yielded non-string/) + end + + specify "notices input handling errors" do + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].gets("\r\n") + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/gets called with arguments/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(1, 2, 3) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with too many arguments/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read("foo") + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with non-integer and non-nil length/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(-1) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with a negative length/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(nil, nil) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with non-String buffer/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(nil, 1) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with non-String buffer/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].rewind(0) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/rewind called with arguments/) + + weirdio = Object.new + class << weirdio + def gets + 42 + end + + def read + 23 + end + + def each + yield 23 + yield 42 + end + + def rewind + raise Errno::ESPIPE, "Errno::ESPIPE" + end + end + + eof_weirdio = Object.new + class << eof_weirdio + def gets + nil + end + + def read(*args) + nil + end + + def each + end + + def rewind + end + end + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].gets + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/gets didn't return a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].each { |x| } + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/each didn't yield a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read didn't return nil or a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env("rack.input" => eof_weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read\(nil\) returned nil on EOF/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].rewind + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/rewind raised Errno::ESPIPE/) + + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].close + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/close must not be called/) + end + + specify "notices error handling errors" do + lambda { + Rack::Lint.new(lambda { |env| + env["rack.errors"].write(42) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/write not called with a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.errors"].close + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/close must not be called/) + end + + specify "notices HEAD errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, []] + }).call(env({"REQUEST_METHOD" => "HEAD"})) + }.should.not.raise + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] + }).call(env({"REQUEST_METHOD" => "HEAD"})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/body was given for HEAD/) + end + + specify "passes valid read calls" do + hello_str = "hello world" + hello_str.force_encoding("ASCII-8BIT") if hello_str.respond_to? :force_encoding + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(0) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(1) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(nil) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(nil, '') + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read(1, '') + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, []] + }).call(env({"rack.input" => StringIO.new(hello_str)})) + }.should.not.raise(Rack::Lint::LintError) + end +end + +context "Rack::Lint::InputWrapper" do + specify "delegates :size to underlying IO object" do + class IOMock + def size + 101 + end + end + + wrapper = Rack::Lint::InputWrapper.new(IOMock.new) + wrapper.size.should == 101 + end + + specify "delegates :rewind to underlying IO object" do + io = StringIO.new("123") + wrapper = Rack::Lint::InputWrapper.new(io) + wrapper.read.should.equal "123" + wrapper.read.should.equal "" + wrapper.rewind + wrapper.read.should.equal "123" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_lobster.rb b/vendor/gems/rack-1.1.0/test/spec_rack_lobster.rb new file mode 100644 index 00000000..7be267a2 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_lobster.rb @@ -0,0 +1,45 @@ +require 'test/spec' + +require 'rack/lobster' +require 'rack/mock' + +context "Rack::Lobster::LambdaLobster" do + specify "should be a single lambda" do + Rack::Lobster::LambdaLobster.should.be.kind_of Proc + end + + specify "should look like a lobster" do + res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/") + res.should.be.ok + res.body.should.include "(,(,,(,,,(" + res.body.should.include "?flip" + end + + specify "should be flippable" do + res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/?flip") + res.should.be.ok + res.body.should.include "(,,,(,,(,(" + end +end + +context "Rack::Lobster" do + specify "should look like a lobster" do + res = Rack::MockRequest.new(Rack::Lobster.new).get("/") + res.should.be.ok + res.body.should.include "(,(,,(,,,(" + res.body.should.include "?flip" + res.body.should.include "crash" + end + + specify "should be flippable" do + res = Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=left") + res.should.be.ok + res.body.should.include "(,,,(,,(,(" + end + + specify "should provide crashing for testing purposes" do + lambda { + Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=crash") + }.should.raise + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_lock.rb b/vendor/gems/rack-1.1.0/test/spec_rack_lock.rb new file mode 100644 index 00000000..18af2b23 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_lock.rb @@ -0,0 +1,38 @@ +require 'test/spec' + +require 'rack/mock' +require 'rack/lock' + +context "Rack::Lock" do + class Lock + attr_reader :synchronized + + def initialize + @synchronized = false + end + + def synchronize + @synchronized = true + yield + end + end + + specify "should call synchronize on lock" do + lock = Lock.new + env = Rack::MockRequest.env_for("/") + app = Rack::Lock.new(lambda { |env| }, lock) + lock.synchronized.should.equal false + app.call(env) + lock.synchronized.should.equal true + end + + specify "should set multithread flag to false" do + app = Rack::Lock.new(lambda { |env| env['rack.multithread'] }) + app.call(Rack::MockRequest.env_for("/")).should.equal false + end + + specify "should reset original multithread flag when exiting lock" do + app = Rack::Lock.new(lambda { |env| env }) + app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_logger.rb b/vendor/gems/rack-1.1.0/test/spec_rack_logger.rb new file mode 100644 index 00000000..d55b9c77 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_logger.rb @@ -0,0 +1,21 @@ +require 'rack/logger' +require 'rack/lint' +require 'stringio' + +context "Rack::Logger" do + specify "logs to rack.errors" do + app = lambda { |env| + log = env['rack.logger'] + log.debug("Created logger") + log.info("Program started") + log.warn("Nothing to do!") + + [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] + } + + errors = StringIO.new + Rack::Logger.new(app).call({'rack.errors' => errors}) + errors.string.should.match "INFO -- : Program started" + errors.string.should.match "WARN -- : Nothing to do" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_methodoverride.rb b/vendor/gems/rack-1.1.0/test/spec_rack_methodoverride.rb new file mode 100644 index 00000000..57452394 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_methodoverride.rb @@ -0,0 +1,60 @@ +require 'test/spec' + +require 'rack/mock' +require 'rack/methodoverride' +require 'stringio' + +context "Rack::MethodOverride" do + specify "should not affect GET requests" do + env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "GET" + end + + specify "_method parameter should modify REQUEST_METHOD for POST requests" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "PUT" + end + + specify "X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests" do + env = Rack::MockRequest.env_for("/", + :method => "POST", + "HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT" + ) + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "PUT" + end + + specify "should not modify REQUEST_METHOD if the method is unknown" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "POST" + end + + specify "should not modify REQUEST_METHOD when _method is nil" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "POST" + end + + specify "should store the original REQUEST_METHOD prior to overriding" do + env = Rack::MockRequest.env_for("/", + :method => "POST", + :input => "_method=options") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["rack.methodoverride.original_method"].should.equal "POST" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_mock.rb b/vendor/gems/rack-1.1.0/test/spec_rack_mock.rb new file mode 100644 index 00000000..a03bedc2 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_mock.rb @@ -0,0 +1,243 @@ +require 'yaml' +require 'rack/mock' +require 'rack/request' +require 'rack/response' + +app = lambda { |env| + req = Rack::Request.new(env) + + env["mock.postdata"] = env["rack.input"].read + if req.GET["error"] + env["rack.errors"].puts req.GET["error"] + env["rack.errors"].flush + end + + Rack::Response.new(env.to_yaml, + req.GET["status"] || 200, + "Content-Type" => "text/yaml").finish +} + +context "Rack::MockRequest" do + specify "should return a MockResponse" do + res = Rack::MockRequest.new(app).get("") + res.should.be.kind_of Rack::MockResponse + end + + specify "should be able to only return the environment" do + env = Rack::MockRequest.env_for("") + env.should.be.kind_of Hash + env.should.include "rack.version" + end + + specify "should provide sensible defaults" do + res = Rack::MockRequest.new(app).request + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "example.org" + env["SERVER_PORT"].should.equal "80" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/" + env["SCRIPT_NAME"].should.equal "" + env["rack.url_scheme"].should.equal "http" + env["mock.postdata"].should.be.empty + end + + specify "should allow GET/POST/PUT/DELETE" do + res = Rack::MockRequest.new(app).get("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + + res = Rack::MockRequest.new(app).post("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "POST" + + res = Rack::MockRequest.new(app).put("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "PUT" + + res = Rack::MockRequest.new(app).delete("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "DELETE" + + Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"]. + should.equal "OPTIONS" + end + + specify "should set content length" do + env = Rack::MockRequest.env_for("/", :input => "foo") + env["CONTENT_LENGTH"].should.equal "3" + end + + specify "should allow posting" do + res = Rack::MockRequest.new(app).get("", :input => "foo") + env = YAML.load(res.body) + env["mock.postdata"].should.equal "foo" + + res = Rack::MockRequest.new(app).post("", :input => StringIO.new("foo")) + env = YAML.load(res.body) + env["mock.postdata"].should.equal "foo" + end + + specify "should use all parts of an URL" do + res = Rack::MockRequest.new(app). + get("https://bla.example.org:9292/meh/foo?bar") + res.should.be.kind_of Rack::MockResponse + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "bla.example.org" + env["SERVER_PORT"].should.equal "9292" + env["QUERY_STRING"].should.equal "bar" + env["PATH_INFO"].should.equal "/meh/foo" + env["rack.url_scheme"].should.equal "https" + end + + specify "should set SSL port and HTTP flag on when using https" do + res = Rack::MockRequest.new(app). + get("https://example.org/foo") + res.should.be.kind_of Rack::MockResponse + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "example.org" + env["SERVER_PORT"].should.equal "443" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/foo" + env["rack.url_scheme"].should.equal "https" + env["HTTPS"].should.equal "on" + end + + specify "should prepend slash to uri path" do + res = Rack::MockRequest.new(app). + get("foo") + res.should.be.kind_of Rack::MockResponse + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "example.org" + env["SERVER_PORT"].should.equal "80" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/foo" + env["rack.url_scheme"].should.equal "http" + end + + specify "should properly convert method name to an uppercase string" do + res = Rack::MockRequest.new(app).request(:get) + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + end + + specify "should accept params and build query string for GET requests" do + res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}}) + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["QUERY_STRING"].should.match "baz=2" + env["QUERY_STRING"].should.match "foo[bar]=1" + env["PATH_INFO"].should.equal "/foo" + env["mock.postdata"].should.equal "" + end + + specify "should accept raw input in params for GET requests" do + res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["QUERY_STRING"].should.match "baz=2" + env["QUERY_STRING"].should.match "foo[bar]=1" + env["PATH_INFO"].should.equal "/foo" + env["mock.postdata"].should.equal "" + end + + specify "should accept params and build url encoded params for POST requests" do + res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}}) + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "POST" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/foo" + env["CONTENT_TYPE"].should.equal "application/x-www-form-urlencoded" + env["mock.postdata"].should.equal "foo[bar]=1" + end + + specify "should accept raw input in params for POST requests" do + res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "POST" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/foo" + env["CONTENT_TYPE"].should.equal "application/x-www-form-urlencoded" + env["mock.postdata"].should.equal "foo[bar]=1" + end + + specify "should accept params and build multipart encoded params for POST requests" do + files = Rack::Utils::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt")) + res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files }) + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "POST" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/foo" + env["CONTENT_TYPE"].should.equal "multipart/form-data; boundary=AaB03x" + env["mock.postdata"].length.should.equal 206 + end + + specify "should behave valid according to the Rack spec" do + lambda { + res = Rack::MockRequest.new(app). + get("https://bla.example.org:9292/meh/foo?bar", :lint => true) + }.should.not.raise(Rack::Lint::LintError) + end +end + +context "Rack::MockResponse" do + specify "should provide access to the HTTP status" do + res = Rack::MockRequest.new(app).get("") + res.should.be.successful + res.should.be.ok + + res = Rack::MockRequest.new(app).get("/?status=404") + res.should.not.be.successful + res.should.be.client_error + res.should.be.not_found + + res = Rack::MockRequest.new(app).get("/?status=501") + res.should.not.be.successful + res.should.be.server_error + + res = Rack::MockRequest.new(app).get("/?status=307") + res.should.be.redirect + + res = Rack::MockRequest.new(app).get("/?status=201", :lint => true) + res.should.be.empty + end + + specify "should provide access to the HTTP headers" do + res = Rack::MockRequest.new(app).get("") + res.should.include "Content-Type" + res.headers["Content-Type"].should.equal "text/yaml" + res.original_headers["Content-Type"].should.equal "text/yaml" + res["Content-Type"].should.equal "text/yaml" + res.content_type.should.equal "text/yaml" + res.content_length.should.be 414 # needs change often. + res.location.should.be.nil + end + + specify "should provide access to the HTTP body" do + res = Rack::MockRequest.new(app).get("") + res.body.should =~ /rack/ + res.should =~ /rack/ + res.should.match(/rack/) + res.should.satisfy { |r| r.match(/rack/) } + end + + specify "should provide access to the Rack errors" do + res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true) + res.should.be.ok + res.errors.should.not.be.empty + res.errors.should.include "foo" + end + + specify "should optionally make Rack errors fatal" do + lambda { + Rack::MockRequest.new(app).get("/?error=foo", :fatal => true) + }.should.raise(Rack::MockRequest::FatalWarning) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_mongrel.rb b/vendor/gems/rack-1.1.0/test/spec_rack_mongrel.rb new file mode 100644 index 00000000..4b386891 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_mongrel.rb @@ -0,0 +1,189 @@ +require 'test/spec' + +begin +require 'rack/handler/mongrel' +require 'rack/urlmap' +require 'rack/lint' +require 'testrequest' +require 'timeout' + +Thread.abort_on_exception = true +$tcp_defer_accept_opts = nil +$tcp_cork_opts = nil + +context "Rack::Handler::Mongrel" do + include TestRequest::Helpers + + setup do + server = Mongrel::HttpServer.new(@host='0.0.0.0', @port=9201) + server.register('/test', + Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new))) + server.register('/stream', + Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest))) + @acc = server.run + end + + specify "should respond" do + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a Mongrel" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /Mongrel/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9201" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [1,1] + response["rack.multithread"].should.be true + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test" + response["PATH_INFO"].should.be.equal "" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test/foo" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + specify "should provide a .run" do + block_ran = false + Thread.new { + Rack::Handler::Mongrel.run(lambda {}, {:Port => 9211}) { |server| + server.should.be.kind_of Mongrel::HttpServer + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a hash" do + block_ran = false + Thread.new { + map = {'/'=>lambda{},'/foo'=>lambda{}} + Rack::Handler::Mongrel.run(map, :map => true, :Port => 9221) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.size.should.be 2 + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.should.include '/' + server.classifier.uris.should.include '/foo' + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a urlmap" do + block_ran = false + Thread.new { + map = Rack::URLMap.new({'/'=>lambda{},'/bar'=>lambda{}}) + Rack::Handler::Mongrel.run(map, {:map => true, :Port => 9231}) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.size.should.be 2 + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.should.include '/' + server.classifier.uris.should.include '/bar' + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a urlmap restricting by host" do + block_ran = false + Thread.new { + map = Rack::URLMap.new({ + '/' => lambda{}, + '/foo' => lambda{}, + '/bar' => lambda{}, + 'http://localhost/' => lambda{}, + 'http://localhost/bar' => lambda{}, + 'http://falsehost/arf' => lambda{}, + 'http://falsehost/qux' => lambda{} + }) + opt = {:map => true, :Port => 9241, :Host => 'localhost'} + Rack::Handler::Mongrel.run(map, opt) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.should.include '/' + server.classifier.handler_map['/'].size.should.be 2 + server.classifier.uris.should.include '/foo' + server.classifier.handler_map['/foo'].size.should.be 1 + server.classifier.uris.should.include '/bar' + server.classifier.handler_map['/bar'].size.should.be 2 + server.classifier.uris.should.not.include '/qux' + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.size.should.be 3 + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should stream #each part of the response" do + body = '' + begin + Timeout.timeout(1) do + Net::HTTP.start(@host, @port) do |http| + get = Net::HTTP::Get.new('/stream') + http.request(get) do |response| + response.read_body { |part| body << part } + end + end + end + rescue Timeout::Error + end + body.should.not.be.empty + end + + teardown do + @acc.raise Mongrel::StopServer + end +end + +rescue LoadError + $stderr.puts "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again." +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_nulllogger.rb b/vendor/gems/rack-1.1.0/test/spec_rack_nulllogger.rb new file mode 100644 index 00000000..b3c2bc9c --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_nulllogger.rb @@ -0,0 +1,13 @@ +require 'rack/nulllogger' +require 'rack/lint' +require 'rack/mock' + +context "Rack::NullLogger" do + specify "acks as a nop logger" do + app = lambda { |env| + env['rack.logger'].warn "b00m" + [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] + } + Rack::NullLogger.new(app).call({}) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_recursive.rb b/vendor/gems/rack-1.1.0/test/spec_rack_recursive.rb new file mode 100644 index 00000000..afc1a0d9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_recursive.rb @@ -0,0 +1,77 @@ +require 'test/spec' + +require 'rack/recursive' +require 'rack/urlmap' +require 'rack/response' +require 'rack/mock' + +context "Rack::Recursive" do + setup do + + @app1 = lambda { |env| + res = Rack::Response.new + res["X-Path-Info"] = env["PATH_INFO"] + res["X-Query-String"] = env["QUERY_STRING"] + res.finish do |res| + res.write "App1" + end + } + + @app2 = lambda { |env| + Rack::Response.new.finish do |res| + res.write "App2" + _, _, body = env['rack.recursive.include'].call(env, "/app1") + body.each { |b| + res.write b + } + end + } + + @app3 = lambda { |env| + raise Rack::ForwardRequest.new("/app1") + } + + @app4 = lambda { |env| + raise Rack::ForwardRequest.new("http://example.org/app1/quux?meh") + } + + end + + specify "should allow for subrequests" do + res = Rack::MockRequest.new(Rack::Recursive.new( + Rack::URLMap.new("/app1" => @app1, + "/app2" => @app2))). + get("/app2") + + res.should.be.ok + res.body.should.equal "App2App1" + end + + specify "should raise error on requests not below the app" do + app = Rack::URLMap.new("/app1" => @app1, + "/app" => Rack::Recursive.new( + Rack::URLMap.new("/1" => @app1, + "/2" => @app2))) + + lambda { + Rack::MockRequest.new(app).get("/app/2") + }.should.raise(ArgumentError). + message.should =~ /can only include below/ + end + + specify "should support forwarding" do + app = Rack::Recursive.new(Rack::URLMap.new("/app1" => @app1, + "/app3" => @app3, + "/app4" => @app4)) + + res = Rack::MockRequest.new(app).get("/app3") + res.should.be.ok + res.body.should.equal "App1" + + res = Rack::MockRequest.new(app).get("/app4") + res.should.be.ok + res.body.should.equal "App1" + res["X-Path-Info"].should.equal "/quux" + res["X-Query-String"].should.equal "meh" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_request.rb b/vendor/gems/rack-1.1.0/test/spec_rack_request.rb new file mode 100644 index 00000000..fcdeb484 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_request.rb @@ -0,0 +1,545 @@ +require 'test/spec' +require 'stringio' + +require 'rack/request' +require 'rack/mock' + +context "Rack::Request" do + specify "wraps the rack variables" do + req = Rack::Request.new(Rack::MockRequest.env_for("http://example.com:8080/")) + + req.body.should.respond_to? :gets + req.scheme.should.equal "http" + req.request_method.should.equal "GET" + + req.should.be.get + req.should.not.be.post + req.should.not.be.put + req.should.not.be.delete + req.should.not.be.head + + req.script_name.should.equal "" + req.path_info.should.equal "/" + req.query_string.should.equal "" + + req.host.should.equal "example.com" + req.port.should.equal 8080 + + req.content_length.should.equal "0" + req.content_type.should.be.nil + end + + specify "can figure out the correct host" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "www2.example.org") + req.host.should.equal "www2.example.org" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org", "SERVER_PORT" => "9292") + req.host.should.equal "example.org" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org:9292") + req.host.should.equal "example.org" + + env = Rack::MockRequest.env_for("/", "SERVER_ADDR" => "192.168.1.1", "SERVER_PORT" => "9292") + env.delete("SERVER_NAME") + req = Rack::Request.new(env) + req.host.should.equal "192.168.1.1" + + env = Rack::MockRequest.env_for("/") + env.delete("SERVER_NAME") + req = Rack::Request.new(env) + req.host.should.equal "" + end + + specify "can parse the query string" do + req = Rack::Request.new(Rack::MockRequest.env_for("/?foo=bar&quux=bla")) + req.query_string.should.equal "foo=bar&quux=bla" + req.GET.should.equal "foo" => "bar", "quux" => "bla" + req.POST.should.be.empty + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "raises if rack.input is missing" do + req = Rack::Request.new({}) + lambda { req.POST }.should.raise(RuntimeError) + end + + specify "can parse POST data when method is POST and no Content-Type given" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", + "REQUEST_METHOD" => 'POST', + :input => "foo=bar&quux=bla") + req.content_type.should.be.nil + req.media_type.should.be.nil + req.query_string.should.equal "foo=quux" + req.GET.should.equal "foo" => "quux" + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "can parse POST data with explicit content type regardless of method" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => "foo=bar&quux=bla") + req.content_type.should.equal 'application/x-www-form-urlencoded;foo=bar' + req.media_type.should.equal 'application/x-www-form-urlencoded' + req.media_type_params['foo'].should.equal 'bar' + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "does not parse POST data when media type is not form-data" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", + "REQUEST_METHOD" => 'POST', + "CONTENT_TYPE" => 'text/plain;charset=utf-8', + :input => "foo=bar&quux=bla") + req.content_type.should.equal 'text/plain;charset=utf-8' + req.media_type.should.equal 'text/plain' + req.media_type_params['charset'].should.equal 'utf-8' + req.POST.should.be.empty + req.params.should.equal "foo" => "quux" + req.body.read.should.equal "foo=bar&quux=bla" + end + + specify "can parse POST data on PUT when media type is form-data" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", + "REQUEST_METHOD" => 'PUT', + "CONTENT_TYPE" => 'application/x-www-form-urlencoded', + :input => "foo=bar&quux=bla") + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.body.read.should.equal "foo=bar&quux=bla" + end + + specify "rewinds input after parsing POST data" do + input = StringIO.new("foo=bar&quux=bla") + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => input) + req.params.should.equal "foo" => "bar", "quux" => "bla" + input.read.should.equal "foo=bar&quux=bla" + end + + specify "cleans up Safari's ajax POST body" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + 'REQUEST_METHOD' => 'POST', :input => "foo=bar&quux=bla\0") + req.POST.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "can get value by key from params with #[]" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=quux") + req['foo'].should.equal 'quux' + req[:foo].should.equal 'quux' + end + + specify "can set value to key on params with #[]=" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=duh") + req['foo'].should.equal 'duh' + req[:foo].should.equal 'duh' + req.params.should.equal 'foo' => 'duh' + + req['foo'] = 'bar' + req.params.should.equal 'foo' => 'bar' + req['foo'].should.equal 'bar' + req[:foo].should.equal 'bar' + + req[:foo] = 'jaz' + req.params.should.equal 'foo' => 'jaz' + req['foo'].should.equal 'jaz' + req[:foo].should.equal 'jaz' + end + + specify "values_at answers values by keys in order given" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=baz&wun=der&bar=ful") + req.values_at('foo').should.equal ['baz'] + req.values_at('foo', 'wun').should.equal ['baz', 'der'] + req.values_at('bar', 'foo', 'wun').should.equal ['ful', 'baz', 'der'] + end + + specify "referrer should be extracted correct" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_REFERER" => "/some/path") + req.referer.should.equal "/some/path" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/") + req.referer.should.equal "/" + end + + specify "user agent should be extracted correct" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_USER_AGENT" => "Mozilla/4.0 (compatible)") + req.user_agent.should.equal "Mozilla/4.0 (compatible)" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/") + req.user_agent.should.equal nil + end + + specify "can cache, but invalidates the cache" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", + "CONTENT_TYPE" => "application/x-www-form-urlencoded", + :input => "foo=bar&quux=bla") + req.GET.should.equal "foo" => "quux" + req.GET.should.equal "foo" => "quux" + req.env["QUERY_STRING"] = "bla=foo" + req.GET.should.equal "bla" => "foo" + req.GET.should.equal "bla" => "foo" + + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.env["rack.input"] = StringIO.new("foo=bla&quux=bar") + req.POST.should.equal "foo" => "bla", "quux" => "bar" + req.POST.should.equal "foo" => "bla", "quux" => "bar" + end + + specify "can figure out if called via XHR" do + req = Rack::Request.new(Rack::MockRequest.env_for("")) + req.should.not.be.xhr + + req = Rack::Request.new \ + Rack::MockRequest.env_for("", "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest") + req.should.be.xhr + end + + specify "can parse cookies" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("", "HTTP_COOKIE" => "foo=bar;quux=h&m") + req.cookies.should.equal "foo" => "bar", "quux" => "h&m" + req.cookies.should.equal "foo" => "bar", "quux" => "h&m" + req.env.delete("HTTP_COOKIE") + req.cookies.should.equal({}) + end + + specify "parses cookies according to RFC 2109" do + req = Rack::Request.new \ + Rack::MockRequest.env_for('', 'HTTP_COOKIE' => 'foo=bar;foo=car') + req.cookies.should.equal 'foo' => 'bar' + end + + specify "provides setters" do + req = Rack::Request.new(e=Rack::MockRequest.env_for("")) + req.script_name.should.equal "" + req.script_name = "/foo" + req.script_name.should.equal "/foo" + e["SCRIPT_NAME"].should.equal "/foo" + + req.path_info.should.equal "/" + req.path_info = "/foo" + req.path_info.should.equal "/foo" + e["PATH_INFO"].should.equal "/foo" + end + + specify "provides the original env" do + req = Rack::Request.new(e=Rack::MockRequest.env_for("")) + req.env.should.be e + end + + specify "can restore the URL" do + Rack::Request.new(Rack::MockRequest.env_for("")).url. + should.equal "http://example.org/" + Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).url. + should.equal "http://example.org/foo/" + Rack::Request.new(Rack::MockRequest.env_for("/foo")).url. + should.equal "http://example.org/foo" + Rack::Request.new(Rack::MockRequest.env_for("?foo")).url. + should.equal "http://example.org/?foo" + Rack::Request.new(Rack::MockRequest.env_for("http://example.org:8080/")).url. + should.equal "http://example.org:8080/" + Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).url. + should.equal "https://example.org/" + + Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).url. + should.equal "https://example.com:8080/foo?foo" + end + + specify "can restore the full path" do + Rack::Request.new(Rack::MockRequest.env_for("")).fullpath. + should.equal "/" + Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).fullpath. + should.equal "/foo/" + Rack::Request.new(Rack::MockRequest.env_for("/foo")).fullpath. + should.equal "/foo" + Rack::Request.new(Rack::MockRequest.env_for("?foo")).fullpath. + should.equal "/?foo" + Rack::Request.new(Rack::MockRequest.env_for("http://example.org:8080/")).fullpath. + should.equal "/" + Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).fullpath. + should.equal "/" + + Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).fullpath. + should.equal "/foo?foo" + end + + specify "can handle multiple media type parameters" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'text/plain; foo=BAR,baz=bizzle dizzle;BLING=bam') + req.should.not.be.form_data + req.media_type_params.should.include 'foo' + req.media_type_params['foo'].should.equal 'BAR' + req.media_type_params.should.include 'baz' + req.media_type_params['baz'].should.equal 'bizzle dizzle' + req.media_type_params.should.not.include 'BLING' + req.media_type_params.should.include 'bling' + req.media_type_params['bling'].should.equal 'bam' + end + + specify "can parse multipart form data" do + # Adapted from RFC 1867. + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + req.POST.should.include "fileupload" + req.POST.should.include "reply" + + req.should.be.form_data + req.content_length.should.equal input.size + req.media_type.should.equal 'multipart/form-data' + req.media_type_params.should.include 'boundary' + req.media_type_params['boundary'].should.equal 'AaB03x' + + req.POST["reply"].should.equal "yes" + + f = req.POST["fileupload"] + f.should.be.kind_of Hash + f[:type].should.equal "image/jpeg" + f[:filename].should.equal "dj.jpg" + f.should.include :tempfile + f[:tempfile].size.should.equal 76 + end + + specify "can parse big multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + req.POST["huge"][:tempfile].size.should.equal 32768 + req.POST["mean"][:tempfile].size.should.equal 10 + req.POST["mean"][:tempfile].read.should.equal "--AaB03xha" + end + + specify "can detect invalid multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + end + + specify "shouldn't try to interpret binary as utf8" do + begin + original_kcode = $KCODE + $KCODE='UTF8' + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda{req.POST}.should.not.raise(EOFError) + req.POST["fileupload"][:tempfile].size.should.equal 4 + ensure + $KCODE = original_kcode + end + end + + + specify "should work around buggy 1.8.* Tempfile equality" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => rack_input) + + lambda {req.POST}.should.not.raise + lambda {req.POST}.should.blaming("input re-processed!").not.raise + end + + specify "does conform to the Rack spec" do + app = lambda { |env| + content = Rack::Request.new(env).POST["file"].inspect + size = content.respond_to?(:bytesize) ? content.bytesize : content.size + [200, {"Content-Type" => "text/html", "Content-Length" => size.to_s}, [content]] + } + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size.to_s, "rack.input" => StringIO.new(input) + + res.should.be.ok + end + + specify "should parse Accept-Encoding correctly" do + parser = lambda do |x| + Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => x)).accept_encoding + end + + parser.call(nil).should.equal([]) + + parser.call("compress, gzip").should.equal([["compress", 1.0], ["gzip", 1.0]]) + parser.call("").should.equal([]) + parser.call("*").should.equal([["*", 1.0]]) + parser.call("compress;q=0.5, gzip;q=1.0").should.equal([["compress", 0.5], ["gzip", 1.0]]) + parser.call("gzip;q=1.0, identity; q=0.5, *;q=0").should.equal([["gzip", 1.0], ["identity", 0.5], ["*", 0] ]) + + lambda { parser.call("gzip ; q=1.0") }.should.raise(RuntimeError) + end + + specify 'should provide ip information' do + app = lambda { |env| + request = Rack::Request.new(env) + response = Rack::Response.new + response.write request.ip + response.finish + } + + mock = Rack::MockRequest.new(Rack::Lint.new(app)) + res = mock.get '/', 'REMOTE_ADDR' => '123.123.123.123' + res.body.should.equal '123.123.123.123' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234' + + res.body.should.equal '234.234.234.234' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234,212.212.212.212' + + res.body.should.equal '212.212.212.212' + end + + class MyRequest < Rack::Request + def params + {:foo => "bar"} + end + end + + specify "should allow subclass request to be instantiated after parent request" do + env = Rack::MockRequest.env_for("/?foo=bar") + + req1 = Rack::Request.new(env) + req1.GET.should.equal "foo" => "bar" + req1.params.should.equal "foo" => "bar" + + req2 = MyRequest.new(env) + req2.GET.should.equal "foo" => "bar" + req2.params.should.equal :foo => "bar" + end + + specify "should allow parent request to be instantiated after subclass request" do + env = Rack::MockRequest.env_for("/?foo=bar") + + req1 = MyRequest.new(env) + req1.GET.should.equal "foo" => "bar" + req1.params.should.equal :foo => "bar" + + req2 = Rack::Request.new(env) + req2.GET.should.equal "foo" => "bar" + req2.params.should.equal "foo" => "bar" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_response.rb b/vendor/gems/rack-1.1.0/test/spec_rack_response.rb new file mode 100644 index 00000000..7989013d --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_response.rb @@ -0,0 +1,221 @@ +require 'test/spec' +require 'set' + +require 'rack/response' + +context "Rack::Response" do + specify "has sensible default values" do + response = Rack::Response.new + status, header, body = response.finish + status.should.equal 200 + header.should.equal "Content-Type" => "text/html" + body.each { |part| + part.should.equal "" + } + + response = Rack::Response.new + status, header, body = *response + status.should.equal 200 + header.should.equal "Content-Type" => "text/html" + body.each { |part| + part.should.equal "" + } + end + + specify "can be written to" do + response = Rack::Response.new + + status, header, body = response.finish do + response.write "foo" + response.write "bar" + response.write "baz" + end + + parts = [] + body.each { |part| parts << part } + + parts.should.equal ["foo", "bar", "baz"] + end + + specify "can set and read headers" do + response = Rack::Response.new + response["Content-Type"].should.equal "text/html" + response["Content-Type"] = "text/plain" + response["Content-Type"].should.equal "text/plain" + end + + specify "can set cookies" do + response = Rack::Response.new + + response.set_cookie "foo", "bar" + response["Set-Cookie"].should.equal "foo=bar" + response.set_cookie "foo2", "bar2" + response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2"] + response.set_cookie "foo3", "bar3" + response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2", "foo3=bar3"] + end + + specify "formats the Cookie expiration date accordingly to RFC 2109" do + response = Rack::Response.new + + response.set_cookie "foo", {:value => "bar", :expires => Time.now+10} + response["Set-Cookie"].should.match( + /expires=..., \d\d-...-\d\d\d\d \d\d:\d\d:\d\d .../) + end + + specify "can set secure cookies" do + response = Rack::Response.new + response.set_cookie "foo", {:value => "bar", :secure => true} + response["Set-Cookie"].should.equal "foo=bar; secure" + end + + specify "can set http only cookies" do + response = Rack::Response.new + response.set_cookie "foo", {:value => "bar", :httponly => true} + response["Set-Cookie"].should.equal "foo=bar; HttpOnly" + end + + specify "can delete cookies" do + response = Rack::Response.new + response.set_cookie "foo", "bar" + response.set_cookie "foo2", "bar2" + response.delete_cookie "foo" + response["Set-Cookie"].should.equal ["foo2=bar2", + "foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT"] + end + + specify "can do redirects" do + response = Rack::Response.new + response.redirect "/foo" + status, header, body = response.finish + + status.should.equal 302 + header["Location"].should.equal "/foo" + + response = Rack::Response.new + response.redirect "/foo", 307 + status, header, body = response.finish + + status.should.equal 307 + end + + specify "has a useful constructor" do + r = Rack::Response.new("foo") + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foo" + + r = Rack::Response.new(["foo", "bar"]) + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foobar" + + r = Rack::Response.new(["foo", "bar"].to_set) + r.write "foo" + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foobarfoo" + + r = Rack::Response.new([], 500) + r.status.should.equal 500 + + r = Rack::Response.new([], "200 OK") + r.status.should.equal 200 + end + + specify "has a constructor that can take a block" do + r = Rack::Response.new { |res| + res.status = 404 + res.write "foo" + } + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foo" + status.should.equal 404 + end + + specify "doesn't return invalid responses" do + r = Rack::Response.new(["foo", "bar"], 204) + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.be.empty + header["Content-Type"].should.equal nil + + lambda { + Rack::Response.new(Object.new) + }.should.raise(TypeError). + message.should =~ /stringable or iterable required/ + end + + specify "knows if it's empty" do + r = Rack::Response.new + r.should.be.empty + r.write "foo" + r.should.not.be.empty + + r = Rack::Response.new + r.should.be.empty + r.finish + r.should.be.empty + + r = Rack::Response.new + r.should.be.empty + r.finish { } + r.should.not.be.empty + end + + specify "should provide access to the HTTP status" do + res = Rack::Response.new + res.status = 200 + res.should.be.successful + res.should.be.ok + + res.status = 404 + res.should.not.be.successful + res.should.be.client_error + res.should.be.not_found + + res.status = 501 + res.should.not.be.successful + res.should.be.server_error + + res.status = 307 + res.should.be.redirect + end + + specify "should provide access to the HTTP headers" do + res = Rack::Response.new + res["Content-Type"] = "text/yaml" + + res.should.include "Content-Type" + res.headers["Content-Type"].should.equal "text/yaml" + res["Content-Type"].should.equal "text/yaml" + res.content_type.should.equal "text/yaml" + res.content_length.should.be.nil + res.location.should.be.nil + end + + specify "does not add or change Content-Length when #finish()ing" do + res = Rack::Response.new + res.status = 200 + res.finish + res.headers["Content-Length"].should.be.nil + + res = Rack::Response.new + res.status = 200 + res.headers["Content-Length"] = "10" + res.finish + res.headers["Content-Length"].should.equal "10" + end + + specify "updates Content-Length when body appended to using #write" do + res = Rack::Response.new + res.status = 200 + res.headers["Content-Length"].should.be.nil + res.write "Hi" + res.headers["Content-Length"].should.equal "2" + res.write " there" + res.headers["Content-Length"].should.equal "8" + end + +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_rewindable_input.rb b/vendor/gems/rack-1.1.0/test/spec_rack_rewindable_input.rb new file mode 100644 index 00000000..78bebfc9 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_rewindable_input.rb @@ -0,0 +1,118 @@ +require 'test/spec' +require 'stringio' +require 'rack/rewindable_input' + +shared_context "a rewindable IO object" do + setup do + @rio = Rack::RewindableInput.new(@io) + end + + teardown do + @rio.close + end + + specify "should be able to handle to read()" do + @rio.read.should.equal "hello world" + end + + specify "should be able to handle to read(nil)" do + @rio.read(nil).should.equal "hello world" + end + + specify "should be able to handle to read(length)" do + @rio.read(1).should.equal "h" + end + + specify "should be able to handle to read(length, buffer)" do + buffer = "" + result = @rio.read(1, buffer) + result.should.equal "h" + result.object_id.should.equal buffer.object_id + end + + specify "should be able to handle to read(nil, buffer)" do + buffer = "" + result = @rio.read(nil, buffer) + result.should.equal "hello world" + result.object_id.should.equal buffer.object_id + end + + specify "should rewind to the beginning when #rewind is called" do + @rio.read(1) + @rio.rewind + @rio.read.should.equal "hello world" + end + + specify "should be able to handle gets" do + @rio.gets.should == "hello world" + end + + specify "should be able to handle each" do + array = [] + @rio.each do |data| + array << data + end + array.should.equal(["hello world"]) + end + + specify "should not buffer into a Tempfile if no data has been read yet" do + @rio.instance_variable_get(:@rewindable_io).should.be.nil + end + + specify "should buffer into a Tempfile when data has been consumed for the first time" do + @rio.read(1) + tempfile = @rio.instance_variable_get(:@rewindable_io) + tempfile.should.not.be.nil + @rio.read(1) + tempfile2 = @rio.instance_variable_get(:@rewindable_io) + tempfile2.should.equal tempfile + end + + specify "should close the underlying tempfile upon calling #close" do + @rio.read(1) + tempfile = @rio.instance_variable_get(:@rewindable_io) + @rio.close + tempfile.should.be.closed + end + + specify "should be possibel to call #close when no data has been buffered yet" do + @rio.close + end + + specify "should be possible to call #close multiple times" do + @rio.close + @rio.close + end +end + +context "Rack::RewindableInput" do + context "given an IO object that is already rewindable" do + setup do + @io = StringIO.new("hello world") + end + + it_should_behave_like "a rewindable IO object" + end + + context "given an IO object that is not rewindable" do + setup do + @io = StringIO.new("hello world") + @io.instance_eval do + undef :rewind + end + end + + it_should_behave_like "a rewindable IO object" + end + + context "given an IO object whose rewind method raises Errno::ESPIPE" do + setup do + @io = StringIO.new("hello world") + def @io.rewind + raise Errno::ESPIPE, "You can't rewind this!" + end + end + + it_should_behave_like "a rewindable IO object" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_runtime.rb b/vendor/gems/rack-1.1.0/test/spec_rack_runtime.rb new file mode 100644 index 00000000..62d80956 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_runtime.rb @@ -0,0 +1,35 @@ +require 'test/spec' +require 'rack/mock' +require 'rack/runtime' + +context "Rack::Runtime" do + specify "sets X-Runtime is none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::Runtime.new(app).call({}) + response[1]['X-Runtime'].should =~ /[\d\.]+/ + end + + specify "does not set the X-Runtime if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain', "X-Runtime" => "foobar"}, "Hello, World!"] } + response = Rack::Runtime.new(app).call({}) + response[1]['X-Runtime'].should == "foobar" + end + + specify "should allow a suffix to be set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::Runtime.new(app, "Test").call({}) + response[1]['X-Runtime-Test'].should =~ /[\d\.]+/ + end + + specify "should allow multiple timers to be set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + runtime1 = Rack::Runtime.new(app, "App") + runtime2 = Rack::Runtime.new(runtime1, "All") + response = runtime2.call({}) + + response[1]['X-Runtime-App'].should =~ /[\d\.]+/ + response[1]['X-Runtime-All'].should =~ /[\d\.]+/ + + Float(response[1]['X-Runtime-All']).should > Float(response[1]['X-Runtime-App']) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_sendfile.rb b/vendor/gems/rack-1.1.0/test/spec_rack_sendfile.rb new file mode 100644 index 00000000..8cfe2017 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_sendfile.rb @@ -0,0 +1,86 @@ +require 'test/spec' +require 'rack/mock' +require 'rack/sendfile' + +context "Rack::File" do + specify "should respond to #to_path" do + Rack::File.new(Dir.pwd).should.respond_to :to_path + end +end + +context "Rack::Sendfile" do + def sendfile_body + res = ['Hello World'] + def res.to_path ; "/tmp/hello.txt" ; end + res + end + + def simple_app(body=sendfile_body) + lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] } + end + + def sendfile_app(body=sendfile_body) + Rack::Sendfile.new(simple_app(body)) + end + + setup do + @request = Rack::MockRequest.new(sendfile_app) + end + + def request(headers={}) + yield @request.get('/', headers) + end + + specify "does nothing when no X-Sendfile-Type header present" do + request do |response| + response.should.be.ok + response.body.should.equal 'Hello World' + response.headers.should.not.include 'X-Sendfile' + end + end + + specify "sets X-Sendfile response header and discards body" do + request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response| + response.should.be.ok + response.body.should.be.empty + response.headers['X-Sendfile'].should.equal '/tmp/hello.txt' + end + end + + specify "sets X-Lighttpd-Send-File response header and discards body" do + request 'HTTP_X_SENDFILE_TYPE' => 'X-Lighttpd-Send-File' do |response| + response.should.be.ok + response.body.should.be.empty + response.headers['X-Lighttpd-Send-File'].should.equal '/tmp/hello.txt' + end + end + + specify "sets X-Accel-Redirect response header and discards body" do + headers = { + 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect', + 'HTTP_X_ACCEL_MAPPING' => '/tmp/=/foo/bar/' + } + request headers do |response| + response.should.be.ok + response.body.should.be.empty + response.headers['X-Accel-Redirect'].should.equal '/foo/bar/hello.txt' + end + end + + specify 'writes to rack.error when no X-Accel-Mapping is specified' do + request 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect' do |response| + response.should.be.ok + response.body.should.equal 'Hello World' + response.headers.should.not.include 'X-Accel-Redirect' + response.errors.should.include 'X-Accel-Mapping' + end + end + + specify 'does nothing when body does not respond to #to_path' do + @request = Rack::MockRequest.new(sendfile_app(['Not a file...'])) + request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response| + response.body.should.equal 'Not a file...' + response.headers.should.not.include 'X-Sendfile' + end + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_session_cookie.rb b/vendor/gems/rack-1.1.0/test/spec_rack_session_cookie.rb new file mode 100644 index 00000000..fba3f83b --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_session_cookie.rb @@ -0,0 +1,73 @@ +require 'test/spec' + +require 'rack/session/cookie' +require 'rack/mock' +require 'rack/response' + +context "Rack::Session::Cookie" do + incrementor = lambda { |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + specify "creates a new cookie" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/") + res["Set-Cookie"].should.match("rack.session=") + res.body.should.equal '{"counter"=>1}' + end + + specify "loads from a cookie" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "survives broken cookies" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => "rack.session=blarghfasel") + res.body.should.equal '{"counter"=>1}' + end + + bigcookie = lambda { |env| + env["rack.session"]["cookie"] = "big" * 3000 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + specify "barks on too big cookies" do + lambda { + Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)). + get("/", :fatal => true) + }.should.raise(Rack::MockRequest::FatalWarning) + end + + specify "loads from a cookie wih integrity hash" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "ignores tampered with session cookies" do + app = Rack::Session::Cookie.new(incrementor, :secret => 'test') + response1 = Rack::MockRequest.new(app).get("/") + _, digest = response1["Set-Cookie"].split("--") + tampered_with_cookie = "hackerman-was-here" + "--" + digest + response2 = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => + tampered_with_cookie) + + # The tampered-with cookie is ignored, so we get back an identical Set-Cookie + response2["Set-Cookie"].should.equal(response1["Set-Cookie"]) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_session_memcache.rb b/vendor/gems/rack-1.1.0/test/spec_rack_session_memcache.rb new file mode 100644 index 00000000..faac796e --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_session_memcache.rb @@ -0,0 +1,273 @@ +require 'test/spec' + +begin + require 'rack/session/memcache' + require 'rack/mock' + require 'rack/response' + require 'thread' + + context "Rack::Session::Memcache" do + session_key = Rack::Session::Memcache::DEFAULT_OPTIONS[:key] + session_match = /#{session_key}=([0-9a-fA-F]+);/ + incrementor = lambda do |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + end + drop_session = proc do |env| + env['rack.session.options'][:drop] = true + incrementor.call(env) + end + renew_session = proc do |env| + env['rack.session.options'][:renew] = true + incrementor.call(env) + end + defer_session = proc do |env| + env['rack.session.options'][:defer] = true + incrementor.call(env) + end + + specify "faults on no connection" do + if RUBY_VERSION < "1.9" + lambda do + Rack::Session::Memcache.new incrementor, :memcache_server => 'nosuchserver' + end.should.raise + else + lambda do + Rack::Session::Memcache.new incrementor, :memcache_server => 'nosuchserver' + end.should.raise ArgumentError + end + end + + specify "connect to existing server" do + test_pool = MemCache.new incrementor, :namespace => 'test:rack:session' + end + + specify "creates a new cookie" do + pool = Rack::Session::Memcache.new(incrementor) + res = Rack::MockRequest.new(pool).get("/") + res["Set-Cookie"].should.match("#{session_key}=") + res.body.should.equal '{"counter"=>1}' + end + + specify "determines session from a cookie" do + pool = Rack::Session::Memcache.new(incrementor) + req = Rack::MockRequest.new(pool) + res = req.get("/") + cookie = res["Set-Cookie"] + req.get("/", "HTTP_COOKIE" => cookie). + body.should.equal '{"counter"=>2}' + req.get("/", "HTTP_COOKIE" => cookie). + body.should.equal '{"counter"=>3}' + end + + specify "survives nonexistant cookies" do + bad_cookie = "rack.session=blarghfasel" + pool = Rack::Session::Memcache.new(incrementor) + res = Rack::MockRequest.new(pool). + get("/", "HTTP_COOKIE" => bad_cookie) + res.body.should.equal '{"counter"=>1}' + cookie = res["Set-Cookie"][session_match] + cookie.should.not.match(/#{bad_cookie}/) + end + + specify "maintains freshness" do + pool = Rack::Session::Memcache.new(incrementor, :expire_after => 3) + res = Rack::MockRequest.new(pool).get('/') + res.body.should.include '"counter"=>1' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.equal cookie + res.body.should.include '"counter"=>2' + puts 'Sleeping to expire session' if $DEBUG + sleep 4 + res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.not.equal cookie + res.body.should.include '"counter"=>1' + end + + specify "deletes cookies with :drop option" do + pool = Rack::Session::Memcache.new(incrementor) + req = Rack::MockRequest.new(pool) + drop = Rack::Utils::Context.new(pool, drop_session) + dreq = Rack::MockRequest.new(drop) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + + res2 = dreq.get("/", "HTTP_COOKIE" => cookie) + res2["Set-Cookie"].should.equal nil + res2.body.should.equal '{"counter"=>3}' + + res3 = req.get("/", "HTTP_COOKIE" => cookie) + res3["Set-Cookie"][session_match].should.not.equal session + res3.body.should.equal '{"counter"=>1}' + end + + specify "provides new session id with :renew option" do + pool = Rack::Session::Memcache.new(incrementor) + req = Rack::MockRequest.new(pool) + renew = Rack::Utils::Context.new(pool, renew_session) + rreq = Rack::MockRequest.new(renew) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + + res2 = rreq.get("/", "HTTP_COOKIE" => cookie) + new_cookie = res2["Set-Cookie"] + new_session = new_cookie[session_match] + new_session.should.not.equal session + res2.body.should.equal '{"counter"=>3}' + + res3 = req.get("/", "HTTP_COOKIE" => new_cookie) + res3["Set-Cookie"][session_match].should.equal new_session + res3.body.should.equal '{"counter"=>4}' + end + + specify "omits cookie with :defer option" do + pool = Rack::Session::Memcache.new(incrementor) + req = Rack::MockRequest.new(pool) + defer = Rack::Utils::Context.new(pool, defer_session) + dreq = Rack::MockRequest.new(defer) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + + res2 = dreq.get("/", "HTTP_COOKIE" => cookie) + res2["Set-Cookie"].should.equal nil + res2.body.should.equal '{"counter"=>3}' + + res3 = req.get("/", "HTTP_COOKIE" => cookie) + res3["Set-Cookie"][session_match].should.equal session + res3.body.should.equal '{"counter"=>4}' + end + + specify "deep hashes are correctly updated" do + store = nil + hash_check = proc do |env| + session = env['rack.session'] + unless session.include? 'test' + session.update :a => :b, :c => { :d => :e }, + :f => { :g => { :h => :i} }, 'test' => true + else + session[:f][:g][:h] = :j + end + [200, {}, session.inspect] + end + pool = Rack::Session::Memcache.new(hash_check) + req = Rack::MockRequest.new(pool) + + res0 = req.get("/") + session_id = (cookie = res0["Set-Cookie"])[session_match, 1] + ses0 = pool.pool.get(session_id, true) + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + ses1 = pool.pool.get(session_id, true) + + ses1.should.not.equal ses0 + end + + # anyone know how to do this better? + specify "multithread: should cleanly merge sessions" do + next unless $DEBUG + warn 'Running multithread test for Session::Memcache' + pool = Rack::Session::Memcache.new(incrementor) + req = Rack::MockRequest.new(pool) + + res = req.get('/') + res.body.should.equal '{"counter"=>1}' + cookie = res["Set-Cookie"] + session_id = cookie[session_match, 1] + + delta_incrementor = lambda do |env| + # emulate disconjoinment of threading + env['rack.session'] = env['rack.session'].dup + Thread.stop + env['rack.session'][(Time.now.usec*rand).to_i] = true + incrementor.call(env) + end + tses = Rack::Utils::Context.new pool, delta_incrementor + treq = Rack::MockRequest.new(tses) + tnum = rand(7).to_i+5 + r = Array.new(tnum) do + Thread.new(treq) do |run| + run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) + end + end.reverse.map{|t| t.run.join.value } + r.each do |request| + request['Set-Cookie'].should.equal cookie + request.body.should.include '"counter"=>2' + end + + session = pool.pool.get(session_id) + session.size.should.be tnum+1 # counter + session['counter'].should.be 2 # meeeh + + tnum = rand(7).to_i+5 + r = Array.new(tnum) do |i| + delta_time = proc do |env| + env['rack.session'][i] = Time.now + Thread.stop + env['rack.session'] = env['rack.session'].dup + env['rack.session'][i] -= Time.now + incrementor.call(env) + end + app = Rack::Utils::Context.new pool, time_delta + req = Rack::MockRequest.new app + Thread.new(req) do |run| + run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) + end + end.reverse.map{|t| t.run.join.value } + r.each do |request| + request['Set-Cookie'].should.equal cookie + request.body.should.include '"counter"=>3' + end + + session = pool.pool.get(session_id) + session.size.should.be tnum+1 + session['counter'].should.be 3 + + drop_counter = proc do |env| + env['rack.session'].delete 'counter' + env['rack.session']['foo'] = 'bar' + [200, {'Content-Type'=>'text/plain'}, env['rack.session'].inspect] + end + tses = Rack::Utils::Context.new pool, drop_counter + treq = Rack::MockRequest.new(tses) + tnum = rand(7).to_i+5 + r = Array.new(tnum) do + Thread.new(treq) do |run| + run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) + end + end.reverse.map{|t| t.run.join.value } + r.each do |request| + request['Set-Cookie'].should.equal cookie + request.body.should.include '"foo"=>"bar"' + end + + session = pool.pool.get(session_id) + session.size.should.be r.size+1 + session['counter'].should.be.nil? + session['foo'].should.equal 'bar' + end + end +rescue RuntimeError + $stderr.puts "Skipping Rack::Session::Memcache tests. Start memcached and try again." +rescue LoadError + $stderr.puts "Skipping Rack::Session::Memcache tests (Memcache is required). `gem install memcache-client` and try again." +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_session_pool.rb b/vendor/gems/rack-1.1.0/test/spec_rack_session_pool.rb new file mode 100644 index 00000000..6be382ec --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_session_pool.rb @@ -0,0 +1,172 @@ +require 'test/spec' + +require 'rack/session/pool' +require 'rack/mock' +require 'rack/response' +require 'thread' + +context "Rack::Session::Pool" do + session_key = Rack::Session::Pool::DEFAULT_OPTIONS[:key] + session_match = /#{session_key}=[0-9a-fA-F]+;/ + incrementor = lambda do |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + end + drop_session = proc do |env| + env['rack.session.options'][:drop] = true + incrementor.call(env) + end + renew_session = proc do |env| + env['rack.session.options'][:renew] = true + incrementor.call(env) + end + defer_session = proc do |env| + env['rack.session.options'][:defer] = true + incrementor.call(env) + end + + specify "creates a new cookie" do + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool).get("/") + res["Set-Cookie"].should.match session_match + res.body.should.equal '{"counter"=>1}' + end + + specify "determines session from a cookie" do + pool = Rack::Session::Pool.new(incrementor) + req = Rack::MockRequest.new(pool) + cookie = req.get("/")["Set-Cookie"] + req.get("/", "HTTP_COOKIE" => cookie). + body.should.equal '{"counter"=>2}' + req.get("/", "HTTP_COOKIE" => cookie). + body.should.equal '{"counter"=>3}' + end + + specify "survives nonexistant cookies" do + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool). + get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel") + res.body.should.equal '{"counter"=>1}' + end + + specify "deletes cookies with :drop option" do + pool = Rack::Session::Pool.new(incrementor) + req = Rack::MockRequest.new(pool) + drop = Rack::Utils::Context.new(pool, drop_session) + dreq = Rack::MockRequest.new(drop) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + pool.pool.size.should.be 1 + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + pool.pool.size.should.be 1 + + res2 = dreq.get("/", "HTTP_COOKIE" => cookie) + res2["Set-Cookie"].should.equal nil + res2.body.should.equal '{"counter"=>3}' + pool.pool.size.should.be 0 + + res3 = req.get("/", "HTTP_COOKIE" => cookie) + res3["Set-Cookie"][session_match].should.not.equal session + res3.body.should.equal '{"counter"=>1}' + pool.pool.size.should.be 1 + end + + specify "provides new session id with :renew option" do + pool = Rack::Session::Pool.new(incrementor) + req = Rack::MockRequest.new(pool) + renew = Rack::Utils::Context.new(pool, renew_session) + rreq = Rack::MockRequest.new(renew) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + pool.pool.size.should.be 1 + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + pool.pool.size.should.be 1 + + res2 = rreq.get("/", "HTTP_COOKIE" => cookie) + new_cookie = res2["Set-Cookie"] + new_session = new_cookie[session_match] + new_session.should.not.equal session + res2.body.should.equal '{"counter"=>3}' + pool.pool.size.should.be 1 + + res3 = req.get("/", "HTTP_COOKIE" => new_cookie) + res3["Set-Cookie"][session_match].should.equal new_session + res3.body.should.equal '{"counter"=>4}' + pool.pool.size.should.be 1 + end + + specify "omits cookie with :defer option" do + pool = Rack::Session::Pool.new(incrementor) + req = Rack::MockRequest.new(pool) + defer = Rack::Utils::Context.new(pool, defer_session) + dreq = Rack::MockRequest.new(defer) + + res0 = req.get("/") + session = (cookie = res0["Set-Cookie"])[session_match] + res0.body.should.equal '{"counter"=>1}' + pool.pool.size.should.be 1 + + res1 = req.get("/", "HTTP_COOKIE" => cookie) + res1["Set-Cookie"][session_match].should.equal session + res1.body.should.equal '{"counter"=>2}' + pool.pool.size.should.be 1 + + res2 = dreq.get("/", "HTTP_COOKIE" => cookie) + res2["Set-Cookie"].should.equal nil + res2.body.should.equal '{"counter"=>3}' + pool.pool.size.should.be 1 + + res3 = req.get("/", "HTTP_COOKIE" => cookie) + res3["Set-Cookie"][session_match].should.equal session + res3.body.should.equal '{"counter"=>4}' + pool.pool.size.should.be 1 + end + + # anyone know how to do this better? + specify "multithread: should merge sessions" do + next unless $DEBUG + warn 'Running multithread tests for Session::Pool' + pool = Rack::Session::Pool.new(incrementor) + req = Rack::MockRequest.new(pool) + + res = req.get('/') + res.body.should.equal '{"counter"=>1}' + cookie = res["Set-Cookie"] + sess_id = cookie[/#{pool.key}=([^,;]+)/,1] + + delta_incrementor = lambda do |env| + # emulate disconjoinment of threading + env['rack.session'] = env['rack.session'].dup + Thread.stop + env['rack.session'][(Time.now.usec*rand).to_i] = true + incrementor.call(env) + end + tses = Rack::Utils::Context.new pool, delta_incrementor + treq = Rack::MockRequest.new(tses) + tnum = rand(7).to_i+5 + r = Array.new(tnum) do + Thread.new(treq) do |run| + run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) + end + end.reverse.map{|t| t.run.join.value } + r.each do |res| + res['Set-Cookie'].should.equal cookie + res.body.should.include '"counter"=>2' + end + + session = pool.pool[sess_id] + session.size.should.be tnum+1 # counter + session['counter'].should.be 2 # meeeh + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_showexceptions.rb b/vendor/gems/rack-1.1.0/test/spec_rack_showexceptions.rb new file mode 100644 index 00000000..bdbc1201 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_showexceptions.rb @@ -0,0 +1,21 @@ +require 'test/spec' + +require 'rack/showexceptions' +require 'rack/mock' + +context "Rack::ShowExceptions" do + specify "catches exceptions" do + res = nil + req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env| + raise RuntimeError + })) + lambda { + res = req.get("/") + }.should.not.raise + res.should.be.a.server_error + res.status.should.equal 500 + + res.should =~ /RuntimeError/ + res.should =~ /ShowExceptions/ + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_showstatus.rb b/vendor/gems/rack-1.1.0/test/spec_rack_showstatus.rb new file mode 100644 index 00000000..78700134 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_showstatus.rb @@ -0,0 +1,72 @@ +require 'test/spec' + +require 'rack/showstatus' +require 'rack/mock' + +context "Rack::ShowStatus" do + specify "should provide a default status message" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res.should =~ /404/ + res.should =~ /Not Found/ + end + + specify "should let the app provide additional information" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + env["rack.showstatus.detail"] = "gone too meta." + [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res.should =~ /404/ + res.should =~ /Not Found/ + res.should =~ /too meta/ + end + + specify "should not replace existing messages" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]] + })) + res = req.get("/", :lint => true) + res.should.be.not_found + + res.body.should == "foo!" + end + + specify "should pass on original headers" do + headers = {"WWW-Authenticate" => "Basic blah"} + + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| [401, headers, []] })) + res = req.get("/", :lint => true) + + res["WWW-Authenticate"].should.equal("Basic blah") + end + + specify "should replace existing messages if there is detail" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + env["rack.showstatus.detail"] = "gone too meta." + [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res["Content-Length"].should.not.equal("4") + res.should =~ /404/ + res.should =~ /too meta/ + res.body.should.not =~ /foo/ + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_static.rb b/vendor/gems/rack-1.1.0/test/spec_rack_static.rb new file mode 100644 index 00000000..19d2ecb7 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_static.rb @@ -0,0 +1,37 @@ +require 'test/spec' + +require 'rack/static' +require 'rack/mock' + +class DummyApp + def call(env) + [200, {}, ["Hello World"]] + end +end + +context "Rack::Static" do + root = File.expand_path(File.dirname(__FILE__)) + OPTIONS = {:urls => ["/cgi"], :root => root} + + setup do + @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS)) + end + + specify "serves files" do + res = @request.get("/cgi/test") + res.should.be.ok + res.body.should =~ /ruby/ + end + + specify "404s if url root is known but it can't find the file" do + res = @request.get("/cgi/foo") + res.should.be.not_found + end + + specify "calls down the chain if url root is not known" do + res = @request.get("/something/else") + res.should.be.ok + res.body.should == "Hello World" + end + +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_thin.rb b/vendor/gems/rack-1.1.0/test/spec_rack_thin.rb new file mode 100644 index 00000000..324f6498 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_thin.rb @@ -0,0 +1,91 @@ +require 'test/spec' + +begin +require 'rack/handler/thin' +require 'testrequest' +require 'timeout' + +context "Rack::Handler::Thin" do + include TestRequest::Helpers + + setup do + @app = Rack::Lint.new(TestRequest.new) + @server = nil + Thin::Logging.silent = true + @thread = Thread.new do + Rack::Handler::Thin.run(@app, :Host => @host='0.0.0.0', :Port => @port=9204) do |server| + @server = server + end + end + Thread.pass until @server && @server.running? + end + + specify "should respond" do + lambda { + GET("/") + }.should.not.raise + end + + specify "should be a Thin" do + GET("/") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /thin/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9204" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/") + response["rack.version"].should.equal [0,3] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/") + response["REQUEST_METHOD"].should.equal "GET" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.equal "/" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["REQUEST_PATH"].should.equal "/test/foo" + response["PATH_INFO"].should.equal "/test/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + teardown do + @server.stop! + @thread.kill + end +end + +rescue LoadError + $stderr.puts "Skipping Rack::Handler::Thin tests (Thin is required). `gem install thin` and try again." +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_urlmap.rb b/vendor/gems/rack-1.1.0/test/spec_rack_urlmap.rb new file mode 100644 index 00000000..3d8fe605 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_urlmap.rb @@ -0,0 +1,215 @@ +require 'test/spec' + +require 'rack/urlmap' +require 'rack/mock' + +context "Rack::URLMap" do + specify "dispatches paths correctly" do + app = lambda { |env| + [200, { + 'X-ScriptName' => env['SCRIPT_NAME'], + 'X-PathInfo' => env['PATH_INFO'], + 'Content-Type' => 'text/plain' + }, [""]] + } + map = Rack::URLMap.new({ + 'http://foo.org/bar' => app, + '/foo' => app, + '/foo/bar' => app + }) + + res = Rack::MockRequest.new(map).get("/") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/qux") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/foo") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo" + res["X-PathInfo"].should.equal "" + + res = Rack::MockRequest.new(map).get("/foo/") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo" + res["X-PathInfo"].should.equal "/" + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo/bar" + res["X-PathInfo"].should.equal "" + + res = Rack::MockRequest.new(map).get("/foo/bar/") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo/bar" + res["X-PathInfo"].should.equal "/" + + res = Rack::MockRequest.new(map).get("/foo///bar//quux") + res.status.should.equal 200 + res.should.be.ok + res["X-ScriptName"].should.equal "/foo/bar" + res["X-PathInfo"].should.equal "//quux" + + res = Rack::MockRequest.new(map).get("/foo/quux", "SCRIPT_NAME" => "/bleh") + res.should.be.ok + res["X-ScriptName"].should.equal "/bleh/foo" + res["X-PathInfo"].should.equal "/quux" + + res = Rack::MockRequest.new(map).get("/bar", 'HTTP_HOST' => 'foo.org') + res.should.be.ok + res["X-ScriptName"].should.equal "/bar" + res["X-PathInfo"].should.be.empty + + res = Rack::MockRequest.new(map).get("/bar/", 'HTTP_HOST' => 'foo.org') + res.should.be.ok + res["X-ScriptName"].should.equal "/bar" + res["X-PathInfo"].should.equal '/' + end + + + specify "dispatches hosts correctly" do + map = Rack::URLMap.new("http://foo.org/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "foo.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]}, + "http://subdomain.foo.org/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "subdomain.foo.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]}, + "http://bar.org/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "bar.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]}, + "/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "default.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]} + ) + + res = Rack::MockRequest.new(map).get("/") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "bar.org") + res.should.be.ok + res["X-Position"].should.equal "bar.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "foo.org") + res.should.be.ok + res["X-Position"].should.equal "foo.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "subdomain.foo.org", "SERVER_NAME" => "foo.org") + res.should.be.ok + res["X-Position"].should.equal "subdomain.foo.org" + + res = Rack::MockRequest.new(map).get("http://foo.org/") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "example.org") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", + "HTTP_HOST" => "example.org:9292", + "SERVER_PORT" => "9292") + res.should.be.ok + res["X-Position"].should.equal "default.org" + end + + specify "should be nestable" do + map = Rack::URLMap.new("/foo" => + Rack::URLMap.new("/bar" => + Rack::URLMap.new("/quux" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "/foo/bar/quux", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"], + }, [""]]} + ))) + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/foo/bar/quux") + res.should.be.ok + res["X-Position"].should.equal "/foo/bar/quux" + res["X-PathInfo"].should.equal "" + res["X-ScriptName"].should.equal "/foo/bar/quux" + end + + specify "should route root apps correctly" do + map = Rack::URLMap.new("/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "root", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]}, + "/foo" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "foo", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]} + ) + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.ok + res["X-Position"].should.equal "foo" + res["X-PathInfo"].should.equal "/bar" + res["X-ScriptName"].should.equal "/foo" + + res = Rack::MockRequest.new(map).get("/foo") + res.should.be.ok + res["X-Position"].should.equal "foo" + res["X-PathInfo"].should.equal "" + res["X-ScriptName"].should.equal "/foo" + + res = Rack::MockRequest.new(map).get("/bar") + res.should.be.ok + res["X-Position"].should.equal "root" + res["X-PathInfo"].should.equal "/bar" + res["X-ScriptName"].should.equal "" + + res = Rack::MockRequest.new(map).get("") + res.should.be.ok + res["X-Position"].should.equal "root" + res["X-PathInfo"].should.equal "/" + res["X-ScriptName"].should.equal "" + end + + specify "should not squeeze slashes" do + map = Rack::URLMap.new("/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "root", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]}, + "/foo" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "foo", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]} + ) + + res = Rack::MockRequest.new(map).get("/http://example.org/bar") + res.should.be.ok + res["X-Position"].should.equal "root" + res["X-PathInfo"].should.equal "/http://example.org/bar" + res["X-ScriptName"].should.equal "" + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_utils.rb b/vendor/gems/rack-1.1.0/test/spec_rack_utils.rb new file mode 100644 index 00000000..269a52bd --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_utils.rb @@ -0,0 +1,552 @@ +require 'test/spec' + +require 'rack/utils' +require 'rack/lint' +require 'rack/mock' + +context "Rack::Utils" do + specify "should escape correctly" do + Rack::Utils.escape("fobar").should.equal "fo%3Co%3Ebar" + Rack::Utils.escape("a space").should.equal "a+space" + Rack::Utils.escape("q1!2\"'w$5&7/z8)?\\"). + should.equal "q1%212%22%27w%245%267%2Fz8%29%3F%5C" + end + + specify "should escape correctly for multibyte characters" do + matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto + matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding + Rack::Utils.escape(matz_name).should.equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8' + matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto + matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding + Rack::Utils.escape(matz_name_sep).should.equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8' + end + + specify "should unescape correctly" do + Rack::Utils.unescape("fo%3Co%3Ebar").should.equal "fobar" + Rack::Utils.unescape("a+space").should.equal "a space" + Rack::Utils.unescape("a%20space").should.equal "a space" + Rack::Utils.unescape("q1%212%22%27w%245%267%2Fz8%29%3F%5C"). + should.equal "q1!2\"'w$5&7/z8)?\\" + end + + specify "should parse query strings correctly" do + Rack::Utils.parse_query("foo=bar"). + should.equal "foo" => "bar" + Rack::Utils.parse_query("foo=\"bar\""). + should.equal "foo" => "bar" + Rack::Utils.parse_query("foo=bar&foo=quux"). + should.equal "foo" => ["bar", "quux"] + Rack::Utils.parse_query("foo=1&bar=2"). + should.equal "foo" => "1", "bar" => "2" + Rack::Utils.parse_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"). + should.equal "my weird field" => "q1!2\"'w$5&7/z8)?" + Rack::Utils.parse_query("foo%3Dbaz=bar").should.equal "foo=baz" => "bar" + end + + specify "should parse nested query strings correctly" do + Rack::Utils.parse_nested_query("foo"). + should.equal "foo" => nil + Rack::Utils.parse_nested_query("foo="). + should.equal "foo" => "" + Rack::Utils.parse_nested_query("foo=bar"). + should.equal "foo" => "bar" + Rack::Utils.parse_nested_query("foo=\"bar\""). + should.equal "foo" => "bar" + + Rack::Utils.parse_nested_query("foo=bar&foo=quux"). + should.equal "foo" => "quux" + Rack::Utils.parse_nested_query("foo&foo="). + should.equal "foo" => "" + Rack::Utils.parse_nested_query("foo=1&bar=2"). + should.equal "foo" => "1", "bar" => "2" + Rack::Utils.parse_nested_query("&foo=1&&bar=2"). + should.equal "foo" => "1", "bar" => "2" + Rack::Utils.parse_nested_query("foo&bar="). + should.equal "foo" => nil, "bar" => "" + Rack::Utils.parse_nested_query("foo=bar&baz="). + should.equal "foo" => "bar", "baz" => "" + Rack::Utils.parse_nested_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"). + should.equal "my weird field" => "q1!2\"'w$5&7/z8)?" + + Rack::Utils.parse_nested_query("foo[]"). + should.equal "foo" => [nil] + Rack::Utils.parse_nested_query("foo[]="). + should.equal "foo" => [""] + Rack::Utils.parse_nested_query("foo[]=bar"). + should.equal "foo" => ["bar"] + + Rack::Utils.parse_nested_query("foo[]=1&foo[]=2"). + should.equal "foo" => ["1", "2"] + Rack::Utils.parse_nested_query("foo=bar&baz[]=1&baz[]=2&baz[]=3"). + should.equal "foo" => "bar", "baz" => ["1", "2", "3"] + Rack::Utils.parse_nested_query("foo[]=bar&baz[]=1&baz[]=2&baz[]=3"). + should.equal "foo" => ["bar"], "baz" => ["1", "2", "3"] + + Rack::Utils.parse_nested_query("x[y][z]=1"). + should.equal "x" => {"y" => {"z" => "1"}} + Rack::Utils.parse_nested_query("x[y][z][]=1"). + should.equal "x" => {"y" => {"z" => ["1"]}} + Rack::Utils.parse_nested_query("x[y][z]=1&x[y][z]=2"). + should.equal "x" => {"y" => {"z" => "2"}} + Rack::Utils.parse_nested_query("x[y][z][]=1&x[y][z][]=2"). + should.equal "x" => {"y" => {"z" => ["1", "2"]}} + + Rack::Utils.parse_nested_query("x[y][][z]=1"). + should.equal "x" => {"y" => [{"z" => "1"}]} + Rack::Utils.parse_nested_query("x[y][][z][]=1"). + should.equal "x" => {"y" => [{"z" => ["1"]}]} + Rack::Utils.parse_nested_query("x[y][][z]=1&x[y][][w]=2"). + should.equal "x" => {"y" => [{"z" => "1", "w" => "2"}]} + + Rack::Utils.parse_nested_query("x[y][][v][w]=1"). + should.equal "x" => {"y" => [{"v" => {"w" => "1"}}]} + Rack::Utils.parse_nested_query("x[y][][z]=1&x[y][][v][w]=2"). + should.equal "x" => {"y" => [{"z" => "1", "v" => {"w" => "2"}}]} + + Rack::Utils.parse_nested_query("x[y][][z]=1&x[y][][z]=2"). + should.equal "x" => {"y" => [{"z" => "1"}, {"z" => "2"}]} + Rack::Utils.parse_nested_query("x[y][][z]=1&x[y][][w]=a&x[y][][z]=2&x[y][][w]=3"). + should.equal "x" => {"y" => [{"z" => "1", "w" => "a"}, {"z" => "2", "w" => "3"}]} + + lambda { Rack::Utils.parse_nested_query("x[y]=1&x[y]z=2") }. + should.raise(TypeError). + message.should.equal "expected Hash (got String) for param `y'" + + lambda { Rack::Utils.parse_nested_query("x[y]=1&x[]=1") }. + should.raise(TypeError). + message.should.equal "expected Array (got Hash) for param `x'" + + lambda { Rack::Utils.parse_nested_query("x[y]=1&x[y][][w]=2") }. + should.raise(TypeError). + message.should.equal "expected Array (got String) for param `y'" + end + + specify "should build query strings correctly" do + Rack::Utils.build_query("foo" => "bar").should.equal "foo=bar" + Rack::Utils.build_query("foo" => ["bar", "quux"]). + should.equal "foo=bar&foo=quux" + Rack::Utils.build_query("foo" => "1", "bar" => "2"). + should.equal "foo=1&bar=2" + Rack::Utils.build_query("my weird field" => "q1!2\"'w$5&7/z8)?"). + should.equal "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F" + end + + specify "should build nested query strings correctly" do + Rack::Utils.build_nested_query("foo" => nil).should.equal "foo" + Rack::Utils.build_nested_query("foo" => "").should.equal "foo=" + Rack::Utils.build_nested_query("foo" => "bar").should.equal "foo=bar" + + Rack::Utils.build_nested_query("foo" => "1", "bar" => "2"). + should.equal "foo=1&bar=2" + Rack::Utils.build_nested_query("my weird field" => "q1!2\"'w$5&7/z8)?"). + should.equal "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F" + + Rack::Utils.build_nested_query("foo" => [nil]). + should.equal "foo[]" + Rack::Utils.build_nested_query("foo" => [""]). + should.equal "foo[]=" + Rack::Utils.build_nested_query("foo" => ["bar"]). + should.equal "foo[]=bar" + + # The ordering of the output query string is unpredictable with 1.8's + # unordered hash. Test that build_nested_query performs the inverse + # function of parse_nested_query. + [{"foo" => nil, "bar" => ""}, + {"foo" => "bar", "baz" => ""}, + {"foo" => ["1", "2"]}, + {"foo" => "bar", "baz" => ["1", "2", "3"]}, + {"foo" => ["bar"], "baz" => ["1", "2", "3"]}, + {"foo" => ["1", "2"]}, + {"foo" => "bar", "baz" => ["1", "2", "3"]}, + {"x" => {"y" => {"z" => "1"}}}, + {"x" => {"y" => {"z" => ["1"]}}}, + {"x" => {"y" => {"z" => ["1", "2"]}}}, + {"x" => {"y" => [{"z" => "1"}]}}, + {"x" => {"y" => [{"z" => ["1"]}]}}, + {"x" => {"y" => [{"z" => "1", "w" => "2"}]}}, + {"x" => {"y" => [{"v" => {"w" => "1"}}]}}, + {"x" => {"y" => [{"z" => "1", "v" => {"w" => "2"}}]}}, + {"x" => {"y" => [{"z" => "1"}, {"z" => "2"}]}}, + {"x" => {"y" => [{"z" => "1", "w" => "a"}, {"z" => "2", "w" => "3"}]}} + ].each { |params| + qs = Rack::Utils.build_nested_query(params) + Rack::Utils.parse_nested_query(qs).should.equal params + } + + lambda { Rack::Utils.build_nested_query("foo=bar") }. + should.raise(ArgumentError). + message.should.equal "value must be a Hash" + end + + specify "should figure out which encodings are acceptable" do + helper = lambda do |a, b| + request = Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => a)) + Rack::Utils.select_best_encoding(a, b) + end + + helper.call(%w(), [["x", 1]]).should.equal(nil) + helper.call(%w(identity), [["identity", 0.0]]).should.equal(nil) + helper.call(%w(identity), [["*", 0.0]]).should.equal(nil) + + helper.call(%w(identity), [["compress", 1.0], ["gzip", 1.0]]).should.equal("identity") + + helper.call(%w(compress gzip identity), [["compress", 1.0], ["gzip", 1.0]]).should.equal("compress") + helper.call(%w(compress gzip identity), [["compress", 0.5], ["gzip", 1.0]]).should.equal("gzip") + + helper.call(%w(foo bar identity), []).should.equal("identity") + helper.call(%w(foo bar identity), [["*", 1.0]]).should.equal("foo") + helper.call(%w(foo bar identity), [["*", 1.0], ["foo", 0.9]]).should.equal("bar") + + helper.call(%w(foo bar identity), [["foo", 0], ["bar", 0]]).should.equal("identity") + helper.call(%w(foo bar baz identity), [["*", 0], ["identity", 0.1]]).should.equal("identity") + end + + specify "should return the bytesize of String" do + Rack::Utils.bytesize("FOO\xE2\x82\xAC").should.equal 6 + end + + specify "should return status code for integer" do + Rack::Utils.status_code(200).should.equal 200 + end + + specify "should return status code for string" do + Rack::Utils.status_code("200").should.equal 200 + end + + specify "should return status code for symbol" do + Rack::Utils.status_code(:ok).should.equal 200 + end +end + +context "Rack::Utils::HeaderHash" do + specify "should retain header case" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + h['ETag'] = 'Boo!' + h.to_hash.should.equal "Content-MD5" => "d5ff4e2a0 ...", "ETag" => 'Boo!' + end + + specify "should check existence of keys case insensitively" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + h.should.include 'content-md5' + h.should.not.include 'ETag' + end + + specify "should merge case-insensitively" do + h = Rack::Utils::HeaderHash.new("ETag" => 'HELLO', "content-length" => '123') + merged = h.merge("Etag" => 'WORLD', 'Content-Length' => '321', "Foo" => 'BAR') + merged.should.equal "Etag"=>'WORLD', "Content-Length"=>'321', "Foo"=>'BAR' + end + + specify "should overwrite case insensitively and assume the new key's case" do + h = Rack::Utils::HeaderHash.new("Foo-Bar" => "baz") + h["foo-bar"] = "bizzle" + h["FOO-BAR"].should.equal "bizzle" + h.length.should.equal 1 + h.to_hash.should.equal "foo-bar" => "bizzle" + end + + specify "should be converted to real Hash" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.to_hash.should.be.instance_of Hash + end + + specify "should convert Array values to Strings when converting to Hash" do + h = Rack::Utils::HeaderHash.new("foo" => ["bar", "baz"]) + h.to_hash.should.equal({ "foo" => "bar\nbaz" }) + end + + specify "should replace hashes correctly" do + h = Rack::Utils::HeaderHash.new("Foo-Bar" => "baz") + j = {"foo" => "bar"} + h.replace(j) + h["foo"].should.equal "bar" + end + + specify "should be able to delete the given key case-sensitively" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.delete("foo") + h["foo"].should.be.nil + h["FOO"].should.be.nil + end + + specify "should be able to delete the given key case-insensitively" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.delete("FOO") + h["foo"].should.be.nil + h["FOO"].should.be.nil + end + + specify "should return the deleted value when #delete is called on an existing key" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.delete("Foo").should.equal("bar") + end + + specify "should return nil when #delete is called on a non-existant key" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.delete("Hello").should.be.nil + end + + specify "should avoid unnecessary object creation if possible" do + a = Rack::Utils::HeaderHash.new("foo" => "bar") + b = Rack::Utils::HeaderHash.new(a) + b.object_id.should.equal(a.object_id) + b.should.equal(a) + end + + specify "should convert Array values to Strings when responding to #each" do + h = Rack::Utils::HeaderHash.new("foo" => ["bar", "baz"]) + h.each do |k,v| + k.should.equal("foo") + v.should.equal("bar\nbaz") + end + end + +end + +context "Rack::Utils::Context" do + class ContextTest + attr_reader :app + def initialize app; @app=app; end + def call env; context env; end + def context env, app=@app; app.call(env); end + end + test_target1 = proc{|e| e.to_s+' world' } + test_target2 = proc{|e| e.to_i+2 } + test_target3 = proc{|e| nil } + test_target4 = proc{|e| [200,{'Content-Type'=>'text/plain', 'Content-Length'=>'0'},['']] } + test_app = ContextTest.new test_target4 + + specify "should set context correctly" do + test_app.app.should.equal test_target4 + c1 = Rack::Utils::Context.new(test_app, test_target1) + c1.for.should.equal test_app + c1.app.should.equal test_target1 + c2 = Rack::Utils::Context.new(test_app, test_target2) + c2.for.should.equal test_app + c2.app.should.equal test_target2 + end + + specify "should alter app on recontexting" do + c1 = Rack::Utils::Context.new(test_app, test_target1) + c2 = c1.recontext(test_target2) + c2.for.should.equal test_app + c2.app.should.equal test_target2 + c3 = c2.recontext(test_target3) + c3.for.should.equal test_app + c3.app.should.equal test_target3 + end + + specify "should run different apps" do + c1 = Rack::Utils::Context.new test_app, test_target1 + c2 = c1.recontext test_target2 + c3 = c2.recontext test_target3 + c4 = c3.recontext test_target4 + a4 = Rack::Lint.new c4 + a5 = Rack::Lint.new test_app + r1 = c1.call('hello') + r1.should.equal 'hello world' + r2 = c2.call(2) + r2.should.equal 4 + r3 = c3.call(:misc_symbol) + r3.should.be.nil + r4 = Rack::MockRequest.new(a4).get('/') + r4.status.should.be 200 + r5 = Rack::MockRequest.new(a5).get('/') + r5.status.should.be 200 + r4.body.should.equal r5.body + end +end + +context "Rack::Utils::Multipart" do + specify "should return nil if content type is not multipart" do + env = Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded') + Rack::Utils::Multipart.parse_multipart(env).should.equal nil + end + + specify "should parse multipart upload with text file" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:text)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"][:type].should.equal "text/plain" + params["files"][:filename].should.equal "file1.txt" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.should.equal "contents" + end + + specify "should parse multipart upload with nested parameters" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:nested)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["foo"]["submit-name"].should.equal "Larry" + params["foo"]["files"][:type].should.equal "text/plain" + params["foo"]["files"][:filename].should.equal "file1.txt" + params["foo"]["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"foo[files]\"; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + params["foo"]["files"][:name].should.equal "foo[files]" + params["foo"]["files"][:tempfile].read.should.equal "contents" + end + + specify "should parse multipart upload with binary file" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:binary)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"][:type].should.equal "image/png" + params["files"][:filename].should.equal "rack-logo.png" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; filename=\"rack-logo.png\"\r\n" + + "Content-Type: image/png\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.length.should.equal 26473 + end + + specify "should parse multipart upload with empty file" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:empty)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"][:type].should.equal "text/plain" + params["files"][:filename].should.equal "file1.txt" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.should.equal "" + end + + specify "should parse multipart upload with filename with semicolons" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:semicolon)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["files"][:type].should.equal "text/plain" + params["files"][:filename].should.equal "fi;le1.txt" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; filename=\"fi;le1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.should.equal "contents" + end + + specify "should not include file params if no file was selected" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:none)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"].should.equal nil + params.keys.should.not.include "files" + end + + specify "should parse IE multipart upload and clean up filename" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:ie)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["files"][:type].should.equal "text/plain" + params["files"][:filename].should.equal "file1.txt" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; " + + 'filename="C:\Documents and Settings\Administrator\Desktop\file1.txt"' + + "\r\nContent-Type: text/plain\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.should.equal "contents" + end + + specify "rewinds input after parsing upload" do + options = multipart_fixture(:text) + input = options[:input] + env = Rack::MockRequest.env_for("/", options) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"][:filename].should.equal "file1.txt" + input.read.length.should.equal 197 + end + + specify "builds multipart body" do + files = Rack::Utils::Multipart::UploadedFile.new(multipart_file("file1.txt")) + data = Rack::Utils::Multipart.build_multipart("submit-name" => "Larry", "files" => files) + + options = { + "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x", + "CONTENT_LENGTH" => data.length.to_s, + :input => StringIO.new(data) + } + env = Rack::MockRequest.env_for("/", options) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"][:filename].should.equal "file1.txt" + params["files"][:tempfile].read.should.equal "contents" + end + + specify "builds nested multipart body" do + files = Rack::Utils::Multipart::UploadedFile.new(multipart_file("file1.txt")) + data = Rack::Utils::Multipart.build_multipart("people" => [{"submit-name" => "Larry", "files" => files}]) + + options = { + "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x", + "CONTENT_LENGTH" => data.length.to_s, + :input => StringIO.new(data) + } + env = Rack::MockRequest.env_for("/", options) + params = Rack::Utils::Multipart.parse_multipart(env) + params["people"][0]["submit-name"].should.equal "Larry" + params["people"][0]["files"][:filename].should.equal "file1.txt" + params["people"][0]["files"][:tempfile].read.should.equal "contents" + end + + specify "can parse fields that end at the end of the buffer" do + input = File.read(multipart_file("bad_robots")) + + req = Rack::Request.new Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => "multipart/form-data, boundary=1yy3laWhgX31qpiHinh67wJXqKalukEUTvqTzmon", + "CONTENT_LENGTH" => input.size, + :input => input) + + req.POST['file.path'].should.equal "/var/tmp/uploads/4/0001728414" + req.POST['addresses'].should.not.equal nil + end + + specify "builds complete params with the chunk size of 16384 slicing exactly on boundary" do + data = File.open(multipart_file("fail_16384_nofile")) { |f| f.read }.gsub(/\n/, "\r\n") + options = { + "CONTENT_TYPE" => "multipart/form-data; boundary=----WebKitFormBoundaryWsY0GnpbI5U7ztzo", + "CONTENT_LENGTH" => data.length.to_s, + :input => StringIO.new(data) + } + env = Rack::MockRequest.env_for("/", options) + params = Rack::Utils::Multipart.parse_multipart(env) + + params.should.not.equal nil + params.keys.should.include "AAAAAAAAAAAAAAAAAAA" + params["AAAAAAAAAAAAAAAAAAA"].keys.should.include "PLAPLAPLA_MEMMEMMEMM_ATTRATTRER" + params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"].keys.should.include "new" + params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"].keys.should.include "-2" + params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"].keys.should.include "ba_unit_id" + params["AAAAAAAAAAAAAAAAAAA"]["PLAPLAPLA_MEMMEMMEMM_ATTRATTRER"]["new"]["-2"]["ba_unit_id"].should.equal "1017" + end + + specify "should return nil if no UploadedFiles were used" do + data = Rack::Utils::Multipart.build_multipart("people" => [{"submit-name" => "Larry", "files" => "contents"}]) + data.should.equal nil + end + + specify "should raise ArgumentError if params is not a Hash" do + lambda { Rack::Utils::Multipart.build_multipart("foo=bar") }. + should.raise(ArgumentError). + message.should.equal "value must be a Hash" + end + + private + def multipart_fixture(name) + file = multipart_file(name) + data = File.open(file, 'rb') { |io| io.read } + + type = "multipart/form-data; boundary=AaB03x" + length = data.respond_to?(:bytesize) ? data.bytesize : data.size + + { "CONTENT_TYPE" => type, + "CONTENT_LENGTH" => length.to_s, + :input => StringIO.new(data) } + end + + def multipart_file(name) + File.join(File.dirname(__FILE__), "multipart", name.to_s) + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rack_webrick.rb b/vendor/gems/rack-1.1.0/test/spec_rack_webrick.rb new file mode 100644 index 00000000..599425c4 --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rack_webrick.rb @@ -0,0 +1,130 @@ +require 'test/spec' + +require 'rack/handler/webrick' +require 'rack/lint' +require 'rack/response' +require 'testrequest' + +Thread.abort_on_exception = true + +context "Rack::Handler::WEBrick" do + include TestRequest::Helpers + + setup do + @server = WEBrick::HTTPServer.new(:Host => @host='0.0.0.0', + :Port => @port=9202, + :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), + :AccessLog => []) + @server.mount "/test", Rack::Handler::WEBrick, + Rack::Lint.new(TestRequest.new) + Thread.new { @server.start } + trap(:INT) { @server.shutdown } + end + + specify "should respond" do + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a WEBrick" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /WEBrick/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9202" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [1,1] + response["rack.multithread"].should.be true + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.equal "" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + + GET("/test/foo%25encoding?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo%25encoding" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + specify "should correctly set cookies" do + @server.mount "/cookie-test", Rack::Handler::WEBrick, + Rack::Lint.new(lambda { |req| + res = Rack::Response.new + res.set_cookie "one", "1" + res.set_cookie "two", "2" + res.finish + }) + + Net::HTTP.start(@host, @port) { |http| + res = http.get("/cookie-test") + res.code.to_i.should.equal 200 + res.get_fields("set-cookie").should.equal ["one=1", "two=2"] + } + end + + specify "should provide a .run" do + block_ran = false + catch(:done) { + Rack::Handler::WEBrick.run(lambda {}, + {:Port => 9210, + :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), + :AccessLog => []}) { |server| + block_ran = true + server.should.be.kind_of WEBrick::HTTPServer + @s = server + throw :done + } + } + block_ran.should.be true + @s.shutdown + end + + teardown do + @server.shutdown + end +end diff --git a/vendor/gems/rack-1.1.0/test/spec_rackup.rb b/vendor/gems/rack-1.1.0/test/spec_rackup.rb new file mode 100644 index 00000000..d9926fda --- /dev/null +++ b/vendor/gems/rack-1.1.0/test/spec_rackup.rb @@ -0,0 +1,154 @@ +require 'test/spec' +require 'testrequest' +require 'rack/server' +require 'open3' + +begin +require "mongrel" + +context "rackup" do + include TestRequest::Helpers + + def run_rackup(*args) + options = args.last.is_a?(Hash) ? args.pop : {} + flags = args.first + @host = options[:host] || "0.0.0.0" + @port = options[:port] || 9292 + + Dir.chdir("#{root}/test/rackup") do + @in, @rackup, @err = Open3.popen3("#{Gem.ruby} -S #{rackup} #{flags}") + end + + return if options[:port] == false + + # Wait until the server is available + begin + GET("/") + rescue + sleep 0.05 + retry + end + end + + def output + @rackup.read + end + + after do + # This doesn't actually return a response, so we rescue + GET "/die" rescue nil + + Dir["#{root}/**/*.pid"].each do |file| + File.delete(file) + end + + File.delete("#{root}/log_output") if File.exist?("#{root}/log_output") + end + + specify "rackup" do + run_rackup + response["PATH_INFO"].should.equal '/' + response["test.$DEBUG"].should.be false + response["test.$EVAL"].should.be nil + response["test.$VERBOSE"].should.be false + response["test.Ping"].should.be nil + response["SERVER_SOFTWARE"].should.not =~ /webrick/ + end + + specify "rackup --help" do + run_rackup "--help", :port => false + output.should.match /--port/ + end + + specify "rackup --port" do + run_rackup "--port 9000", :port => 9000 + response["SERVER_PORT"].should.equal "9000" + end + + specify "rackup --debug" do + run_rackup "--debug" + response["test.$DEBUG"].should.be true + end + + specify "rackup --eval" do + run_rackup %{--eval "BUKKIT = 'BUKKIT'"} + response["test.$EVAL"].should.equal "BUKKIT" + end + + specify "rackup --warn" do + run_rackup %{--warn} + response["test.$VERBOSE"].should.be true + end + + specify "rackup --include" do + run_rackup %{--include /foo/bar} + response["test.$LOAD_PATH"].should.include "/foo/bar" + end + + specify "rackup --require" do + run_rackup %{--require ping} + response["test.Ping"].should.equal "constant" + end + + specify "rackup --server" do + run_rackup %{--server webrick} + response["SERVER_SOFTWARE"].should =~ /webrick/i + end + + specify "rackup --host" do + run_rackup %{--host 127.0.0.1}, :host => "127.0.0.1" + response["REMOTE_ADDR"].should.equal "127.0.0.1" + end + + specify "rackup --daemonize --pid" do + run_rackup %{--daemonize --pid testing.pid} + status.should.be 200 + @rackup.should.be.eof? + Dir["#{root}/**/testing.pid"].should.not.be.empty? + end + + specify "rackup --pid" do + run_rackup %{--pid testing.pid} + status.should.be 200 + Dir["#{root}/**/testing.pid"].should.not.be.empty? + end + + specify "rackup --version" do + run_rackup %{--version}, :port => false + output.should =~ /1.0/ + end + + specify "rackup --env development includes lint" do + run_rackup + GET("/broken_lint") + status.should.be 500 + end + + specify "rackup --env deployment does not include lint" do + run_rackup %{--env deployment} + GET("/broken_lint") + status.should.be 200 + end + + specify "rackup --env none does not include lint" do + run_rackup %{--env none} + GET("/broken_lint") + status.should.be 200 + end + + specify "rackup --env deployment does log" do + run_rackup %{--env deployment} + log = File.read(response["test.stderr"]) + log.should.be.empty? + end + + specify "rackup --env none does not log" do + run_rackup %{--env none} + GET("/") + log = File.read(response["test.stderr"]) + log.should.be.empty? + end +end +rescue LoadError + $stderr.puts "Skipping rackup --server tests (mongrel is required). `gem install thin` and try again." +end \ No newline at end of file diff --git a/vendor/gems/sanitize-1.2.1/.specification b/vendor/gems/sanitize-1.2.1/.specification new file mode 100644 index 00000000..0dc79d6e --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/.specification @@ -0,0 +1,124 @@ +--- !ruby/object:Gem::Specification +name: sanitize +version: !ruby/object:Gem::Version + hash: 29 + prerelease: false + segments: + - 1 + - 2 + - 1 + version: 1.2.1 +platform: ruby +authors: +- Ryan Grove +autorequire: +bindir: bin +cert_chain: [] + +date: 2010-04-20 00:00:00 +02:00 +default_executable: +dependencies: +- !ruby/object:Gem::Dependency + name: nokogiri + prerelease: false + requirement: &id001 !ruby/object:Gem::Requirement + none: false + requirements: + - - ~> + - !ruby/object:Gem::Version + hash: 5 + segments: + - 1 + - 4 + - 1 + version: 1.4.1 + type: :runtime + version_requirements: *id001 +- !ruby/object:Gem::Dependency + name: bacon + prerelease: false + requirement: &id002 !ruby/object:Gem::Requirement + none: false + requirements: + - - ~> + - !ruby/object:Gem::Version + hash: 19 + segments: + - 1 + - 1 + - 0 + version: 1.1.0 + type: :development + version_requirements: *id002 +- !ruby/object:Gem::Dependency + name: rake + prerelease: false + requirement: &id003 !ruby/object:Gem::Requirement + none: false + requirements: + - - ~> + - !ruby/object:Gem::Version + hash: 63 + segments: + - 0 + - 8 + - 0 + version: 0.8.0 + type: :development + version_requirements: *id003 +description: +email: ryan@wonko.com +executables: [] + +extensions: [] + +extra_rdoc_files: [] + +files: +- HISTORY +- LICENSE +- README.rdoc +- lib/sanitize/config/basic.rb +- lib/sanitize/config/relaxed.rb +- lib/sanitize/config/restricted.rb +- lib/sanitize/config.rb +- lib/sanitize/version.rb +- lib/sanitize.rb +has_rdoc: true +homepage: http://github.com/rgrove/sanitize/ +licenses: [] + +post_install_message: +rdoc_options: [] + +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 59 + segments: + - 1 + - 8 + - 6 + version: 1.8.6 +required_rubygems_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +requirements: [] + +rubyforge_project: riposte +rubygems_version: 1.3.7 +signing_key: +specification_version: 3 +summary: Whitelist-based HTML sanitizer. +test_files: [] + diff --git a/vendor/gems/sanitize-1.2.1/HISTORY b/vendor/gems/sanitize-1.2.1/HISTORY new file mode 100644 index 00000000..23aaf28f --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/HISTORY @@ -0,0 +1,90 @@ +Sanitize History +================================================================================ + +Version 1.2.1 (2010-04-20) + * Added a :remove_contents config setting. If set to true, Sanitize will + remove the contents of all non-whitelisted elements in addition to the + elements themselves. If set to an Array of element names, Sanitize will + remove the contents of only those elements (when filtered), and leave the + contents of other filtered elements. [Thanks to Rafael Souza for the Array + option] + * Added an :output_encoding config setting to allow the character encoding for + HTML output to be specified. The default is 'utf-8'. + * The environment hash passed into transformers now includes a :node_name item + containing the lowercase name of the current HTML node (e.g. "div"). + * Returning anything other than a Hash or nil from a transformer will now + raise a meaningful Sanitize::Error exception rather than an unintended + NameError. + +Version 1.2.0 (2010-01-17) + * Requires Nokogiri ~> 1.4.1. + * Added support for transformers, which allow you to filter and alter nodes + using your own custom logic, on top of (or instead of) Sanitize's core + filter. See the README for details and examples. + * Added Sanitize.clean_node!, which sanitizes a Nokogiri::XML::Node and all + its children. + * Added elements

    through

    to the Relaxed whitelist. [Suggested by + David Reese] + +Version 1.1.0 (2009-10-11) + * Migrated from Hpricot to Nokogiri. Requires libxml2 >= 2.7.2 [Adam Hooper] + * Added an :output config setting to allow the output format to be specified. + Supported formats are :xhtml (the default) and :html (which outputs HTML4). + * Changed protocol regex to ensure Sanitize doesn't kill URLs with colons in + path segments. [Peter Cooper] + +Version 1.0.8 (2009-04-23) + * Added a workaround for an Hpricot bug that prevents attribute names from + being downcased in recent versions of Hpricot. This was exploitable to + prevent non-whitelisted protocols from being cleaned. [Reported by Ben + Wanicur] + +Version 1.0.7 (2009-04-11) + * Requires Hpricot 0.8.1+, which is finally compatible with Ruby 1.9.1. + * Fixed a bug that caused named character entities containing digits (like + ²) to be escaped when they shouldn't have been. [Reported by Sebastian + Steinmetz] + +Version 1.0.6 (2009-02-23) + * Removed htmlentities gem dependency. + * Existing well-formed character entity references in the input string are now + preserved rather than being decoded and re-encoded. + * The ' character is now encoded as ' instead of ' to prevent + problems in IE6. + * You can now specify the symbol :all in place of an element name in the + attributes config hash to allow certain attributes on all elements. [Thanks + to Mutwin Kraus] + +Version 1.0.5 (2009-02-05) + * Fixed a bug introduced in version 1.0.3 that prevented non-whitelisted + protocols from being cleaned when relative URLs were allowed. [Reported by + Dev Purkayastha] + * Fixed "undefined method `parent='" exceptions caused by parser changes in + edge Hpricot. + +Version 1.0.4 (2009-01-16) + * Fixed a bug that made it possible to sneak a non-whitelisted element through + by repeating it several times in a row. All versions of Sanitize prior to + 1.0.4 are vulnerable. [Reported by Cristobal] + +Version 1.0.3 (2009-01-15) + * Fixed a bug whereby incomplete Unicode or hex entities could be used to + prevent non-whitelisted protocols from being cleaned. Since IE6 and Opera + still decode the incomplete entities, users of those browsers may be + vulnerable to malicious script injection on websites using versions of + Sanitize prior to 1.0.3. + +Version 1.0.2 (2009-01-04) + * Fixed a bug that caused an exception to be thrown when parsing a valueless + attribute that's expected to contain a URL. + +Version 1.0.1 (2009-01-01) + * You can now specify :relative in a protocol config array to allow attributes + containing relative URLs with no protocol. The Basic and Relaxed configs + have been updated to allow relative URLs. + * Added a workaround for an Hpricot bug that causes HTML entities for + non-ASCII characters to be replaced by question marks, and all other + entities to be destructively decoded. + +Version 1.0.0 (2008-12-25) + * First release. diff --git a/vendor/gems/sanitize-1.2.1/LICENSE b/vendor/gems/sanitize-1.2.1/LICENSE new file mode 100644 index 00000000..bcdcc612 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/LICENSE @@ -0,0 +1,18 @@ +Copyright (c) 2010 Ryan Grove + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the 'Software'), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gems/sanitize-1.2.1/README.rdoc b/vendor/gems/sanitize-1.2.1/README.rdoc new file mode 100644 index 00000000..86d54da0 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/README.rdoc @@ -0,0 +1,333 @@ += Sanitize + +Sanitize is a whitelist-based HTML sanitizer. Given a list of acceptable +elements and attributes, Sanitize will remove all unacceptable HTML from a +string. + +Using a simple configuration syntax, you can tell Sanitize to allow certain +elements, certain attributes within those elements, and even certain URL +protocols within attributes that contain URLs. Any HTML elements or attributes +that you don't explicitly allow will be removed. + +Because it's based on Nokogiri, a full-fledged HTML parser, rather than a bunch +of fragile regular expressions, Sanitize has no trouble dealing with malformed +or maliciously-formed HTML, and will always output valid HTML or XHTML. + +*Author*:: Ryan Grove (mailto:ryan@wonko.com) +*Version*:: 1.2.1 (2010-04-20) +*Copyright*:: Copyright (c) 2010 Ryan Grove. All rights reserved. +*License*:: MIT License (http://opensource.org/licenses/mit-license.php) +*Website*:: http://github.com/rgrove/sanitize + +== Requires + +* Nokogiri ~> 1.4.1 +* libxml2 >= 2.7.2 + +== Installation + +Latest stable release: + + gem install sanitize + +Latest development version: + + gem install sanitize --pre + +== Usage + +If you don't specify any configuration options, Sanitize will use its strictest +settings by default, which means it will strip all HTML and leave only text +behind. + + require 'rubygems' + require 'sanitize' + + html = 'foo' + + Sanitize.clean(html) # => 'foo' + +== Configuration + +In addition to the ultra-safe default settings, Sanitize comes with three other +built-in modes. + +=== Sanitize::Config::RESTRICTED + +Allows only very simple inline formatting markup. No links, images, or block +elements. + + Sanitize.clean(html, Sanitize::Config::RESTRICTED) # => 'foo' + +=== Sanitize::Config::BASIC + +Allows a variety of markup including formatting tags, links, and lists. Images +and tables are not allowed, links are limited to FTP, HTTP, HTTPS, and mailto +protocols, and a rel="nofollow" attribute is added to all links to +mitigate SEO spam. + + Sanitize.clean(html, Sanitize::Config::BASIC) + # => 'foo' + +=== Sanitize::Config::RELAXED + +Allows an even wider variety of markup than BASIC, including images and tables. +Links are still limited to FTP, HTTP, HTTPS, and mailto protocols, while images +are limited to HTTP and HTTPS. In this mode, rel="nofollow" is not +added to links. + + Sanitize.clean(html, Sanitize::Config::RELAXED) + # => 'foo' + +=== Custom Configuration + +If the built-in modes don't meet your needs, you can easily specify a custom +configuration: + + Sanitize.clean(html, :elements => ['a', 'span'], + :attributes => {'a' => ['href', 'title'], 'span' => ['class']}, + :protocols => {'a' => {'href' => ['http', 'https', 'mailto']}}) + +==== :add_attributes (Hash) + +Attributes to add to specific elements. If the attribute already exists, it will +be replaced with the value specified here. Specify all element names and +attributes in lowercase. + + :add_attributes => { + 'a' => {'rel' => 'nofollow'} + } + +==== :attributes (Hash) + +Attributes to allow for specific elements. Specify all element names and +attributes in lowercase. + + :attributes => { + 'a' => ['href', 'title'], + 'blockquote' => ['cite'], + 'img' => ['alt', 'src', 'title'] + } + +If you'd like to allow certain attributes on all elements, use the symbol +:all instead of an element name. + + :attributes => { + :all => ['class'], + 'a' => ['href', 'title'] + } + +==== :allow_comments (boolean) + +Whether or not to allow HTML comments. Allowing comments is strongly +discouraged, since IE allows script execution within conditional comments. The +default value is false. + +==== :elements (Array) + +Array of element names to allow. Specify all names in lowercase. + + :elements => [ + 'a', 'b', 'blockquote', 'br', 'cite', 'code', 'dd', 'dl', 'dt', 'em', + 'i', 'li', 'ol', 'p', 'pre', 'q', 'small', 'strike', 'strong', 'sub', + 'sup', 'u', 'ul' + ] + +==== :output (Symbol) + +Output format. Supported formats are :html and :xhtml, +defaulting to :xhtml. + +==== :output_encoding (String) + +Character encoding to use for HTML output. Default is 'utf-8'. + +==== :protocols (Hash) + +URL protocols to allow in specific attributes. If an attribute is listed here +and contains a protocol other than those specified (or if it contains no +protocol at all), it will be removed. + + :protocols => { + 'a' => {'href' => ['ftp', 'http', 'https', 'mailto']}, + 'img' => {'src' => ['http', 'https']} + } + +If you'd like to allow the use of relative URLs which don't have a protocol, +include the symbol :relative in the protocol array: + + :protocols => { + 'a' => {'href' => ['http', 'https', :relative]} + } + +==== :remove_contents (boolean or Array) + +If set to +true+, Sanitize will remove the contents of any non-whitelisted +elements in addition to the elements themselves. By default, Sanitize leaves the +safe parts of an element's contents behind when the element is removed. + +If set to an Array of element names, then only the contents of the specified +elements (when filtered) will be removed, and the contents of all other filtered +elements will be left behind. + +The default value is false. + +==== :transformers + +See below. + +=== Transformers + +Transformers allow you to filter and alter nodes using your own custom logic, on +top of (or instead of) Sanitize's core filter. A transformer is any object that +responds to call() (such as a lambda or proc) and returns either +nil or a Hash containing certain optional response values. + +To use one or more transformers, pass them to the :transformers +config setting: + + Sanitize.clean(html, :transformers => [transformer_one, transformer_two]) + +==== Input + +Each registered transformer's call() method will be called once for +each element node in the HTML, and will receive as an argument an environment +Hash that contains the following items: + +[:config] + The current Sanitize configuration Hash. + +[:node] + A Nokogiri::XML::Node object representing an HTML element. + +[:node_name] + The name of the current HTML node, always lowercase (e.g. "div" or "span"). + +==== Processing + +Each transformer has full access to the Nokogiri::XML::Node that's passed into +it and to the rest of the document via the node's document() +method. Any changes will be reflected instantly in the document and passed on to +subsequently-called transformers and to Sanitize itself. A transformer may even +call Sanitize internally to perform custom sanitization if needed. + +Nodes are passed into transformers in the order in which they're traversed. It's +important to note that Nokogiri traverses markup from the deepest node upward, +not from the first node to the last node: + + html = '
    foo
    ' + transformer = lambda{|env| puts env[:node].name } + + # Prints "span", then "div". + Sanitize.clean(html, :transformers => transformer) + +Transformers have a tremendous amount of power, including the power to +completely bypass Sanitize's built-in filtering. Be careful! + +==== Output + +A transformer may return either +nil+ or a Hash. A return value of +nil+ +indicates that the transformer does not wish to act on the current node in any +way. A returned Hash may contain the following items, all of which are optional: + +[:attr_whitelist] + Array of attribute names to add to the whitelist for the current node, in + addition to any whitelisted attributes already defined in the current config. + +[:node] + A Nokogiri::XML::Node object that should replace the current node. All + subsequent transformers and Sanitize itself will receive this new node. + +[:whitelist] + If _true_, the current node (and only the current node) will be whitelisted, + regardless of the current Sanitize config. + +[:whitelist_nodes] + Array of specific Nokogiri::XML::Node objects to whitelist, anywhere in the + document, regardless of the current Sanitize config. + +==== Example: Transformer to whitelist YouTube video embeds + +The following example demonstrates how to create a Sanitize transformer that +will safely whitelist valid YouTube video embeds without having to blindly allow +other kinds of embedded content, which would be the case if you tried to do this +by just whitelisting all , , and + elements: + + lambda do |env| + node = env[:node] + node_name = env[:node_name] + parent = node.parent + + # Since the transformer receives the deepest nodes first, we look for a + # element or an element whose parent is an . + return nil unless (node_name == 'param' || node_name == 'embed') && + parent.name.to_s.downcase == 'object' + + if node_name == 'param' + # Quick XPath search to find the node that contains the video URL. + return nil unless movie_node = parent.search('param[@name="movie"]')[0] + url = movie_node['value'] + else + # Since this is an , the video URL is in the "src" attribute. No + # extra work needed. + url = node['src'] + end + + # Verify that the video URL is actually a valid YouTube video URL. + return nil unless url =~ /^http:\/\/(?:www\.)?youtube\.com\/v\// + + # We're now certain that this is a YouTube embed, but we still need to run + # it through a special Sanitize step to ensure that no unwanted elements or + # attributes that don't belong in a YouTube embed can sneak in. + Sanitize.clean_node!(parent, { + :elements => ['embed', 'object', 'param'], + :attributes => { + 'embed' => ['allowfullscreen', 'allowscriptaccess', 'height', 'src', 'type', 'width'], + 'object' => ['height', 'width'], + 'param' => ['name', 'value'] + } + }) + + # Now that we're sure that this is a valid YouTube embed and that there are + # no unwanted elements or attributes hidden inside it, we can tell Sanitize + # to whitelist the current node ( or ) and its parent + # (). + {:whitelist_nodes => [node, parent]} + end + +== Contributors + +The following lovely people have contributed to Sanitize in the form of patches +or ideas that later became code: + +* Peter Cooper +* Gabe da Silveira +* Ryan Grove +* Adam Hooper +* Mutwin Kraus +* Dev Purkayastha +* David Reese +* Rafael Souza +* Ben Wanicur + +== License + +Copyright (c) 2010 Ryan Grove + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the 'Software'), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize.rb new file mode 100644 index 00000000..398bafed --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize.rb @@ -0,0 +1,245 @@ +# encoding: utf-8 +#-- +# Copyright (c) 2010 Ryan Grove +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#++ + +require 'nokogiri' +require 'sanitize/version' +require 'sanitize/config' +require 'sanitize/config/restricted' +require 'sanitize/config/basic' +require 'sanitize/config/relaxed' + +class Sanitize + attr_reader :config + + # Matches an attribute value that could be treated by a browser as a URL + # with a protocol prefix, such as "http:" or "javascript:". Any string of zero + # or more characters followed by a colon is considered a match, even if the + # colon is encoded as an entity and even if it's an incomplete entity (which + # IE6 and Opera will still parse). + REGEX_PROTOCOL = /^([A-Za-z0-9\+\-\.\&\;\#\s]*?)(?:\:|�*58|�*3a)/i + + #-- + # Class Methods + #++ + + # Returns a sanitized copy of _html_, using the settings in _config_ if + # specified. + def self.clean(html, config = {}) + sanitize = Sanitize.new(config) + sanitize.clean(html) + end + + # Performs Sanitize#clean in place, returning _html_, or +nil+ if no changes + # were made. + def self.clean!(html, config = {}) + sanitize = Sanitize.new(config) + sanitize.clean!(html) + end + + # Sanitizes the specified Nokogiri::XML::Node and all its children. + def self.clean_node!(node, config = {}) + sanitize = Sanitize.new(config) + sanitize.clean_node!(node) + end + + #-- + # Instance Methods + #++ + + # Returns a new Sanitize object initialized with the settings in _config_. + def initialize(config = {}) + # Sanitize configuration. + @config = Config::DEFAULT.merge(config) + @config[:transformers] = Array(@config[:transformers].dup) + + # Convert the list of allowed elements to a Hash for faster lookup. + @allowed_elements = {} + @config[:elements].each {|el| @allowed_elements[el] = true } + + # Convert the list of :remove_contents elements to a Hash for faster lookup. + @remove_all_contents = false + @remove_element_contents = {} + + if @config[:remove_contents].is_a?(Array) + @config[:remove_contents].each {|el| @remove_element_contents[el] = true } + else + @remove_all_contents = !!@config[:remove_contents] + end + + # Specific nodes to whitelist (along with all their attributes). This array + # is generated at runtime by transformers, and is cleared before and after + # a fragment is cleaned (so it applies only to a specific fragment). + @whitelist_nodes = [] + end + + # Returns a sanitized copy of _html_. + def clean(html) + dupe = html.dup + clean!(dupe) || dupe + end + + # Performs clean in place, returning _html_, or +nil+ if no changes were + # made. + def clean!(html) + fragment = Nokogiri::HTML::DocumentFragment.parse(html) + clean_node!(fragment) + + output_method_params = {:encoding => @config[:output_encoding], :indent => 0} + + if @config[:output] == :xhtml + output_method = fragment.method(:to_xhtml) + output_method_params[:save_with] = Nokogiri::XML::Node::SaveOptions::AS_XHTML + elsif @config[:output] == :html + output_method = fragment.method(:to_html) + else + raise Error, "unsupported output format: #{@config[:output]}" + end + + result = output_method.call(output_method_params) + + return result == html ? nil : html[0, html.length] = result + end + + # Sanitizes the specified Nokogiri::XML::Node and all its children. + def clean_node!(node) + raise ArgumentError unless node.is_a?(Nokogiri::XML::Node) + + @whitelist_nodes = [] + + node.traverse do |child| + if child.element? + clean_element!(child) + elsif child.comment? + child.unlink unless @config[:allow_comments] + elsif child.cdata? + child.replace(Nokogiri::XML::Text.new(child.text, child.document)) + end + end + + @whitelist_nodes = [] + + node + end + + private + + def clean_element!(node) + # Run this node through all configured transformers. + transform = transform_element!(node) + + # If this node is in the dynamic whitelist array (built at runtime by + # transformers), let it live with all of its attributes intact. + return if @whitelist_nodes.include?(node) + + name = node.name.to_s.downcase + + # Delete any element that isn't in the whitelist. + unless transform[:whitelist] || @allowed_elements[name] + unless @remove_all_contents || @remove_element_contents[name] + node.children.each { |n| node.add_previous_sibling(n) } + end + + node.unlink + + return + end + + attr_whitelist = (transform[:attr_whitelist] + + (@config[:attributes][name] || []) + + (@config[:attributes][:all] || [])).uniq + + if attr_whitelist.empty? + # Delete all attributes from elements with no whitelisted attributes. + node.attribute_nodes.each {|attr| attr.remove } + else + # Delete any attribute that isn't in the whitelist for this element. + node.attribute_nodes.each do |attr| + attr.unlink unless attr_whitelist.include?(attr.name.downcase) + end + + # Delete remaining attributes that use unacceptable protocols. + if @config[:protocols].has_key?(name) + protocol = @config[:protocols][name] + + node.attribute_nodes.each do |attr| + attr_name = attr.name.downcase + next false unless protocol.has_key?(attr_name) + + del = if attr.value.to_s.downcase =~ REGEX_PROTOCOL + !protocol[attr_name].include?($1.downcase) + else + !protocol[attr_name].include?(:relative) + end + + attr.unlink if del + end + end + end + + # Add required attributes. + if @config[:add_attributes].has_key?(name) + @config[:add_attributes][name].each do |key, val| + node[key] = val + end + end + + transform + end + + def transform_element!(node) + output = { + :attr_whitelist => [], + :node => node, + :whitelist => false + } + + @config[:transformers].inject(node) do |transformer_node, transformer| + transform = transformer.call({ + :config => @config, + :node => transformer_node, + :node_name => transformer_node.name.downcase + }) + + if transform.nil? + transformer_node + elsif transform.is_a?(Hash) + if transform[:whitelist_nodes].is_a?(Array) + @whitelist_nodes += transform[:whitelist_nodes] + @whitelist_nodes.uniq! + end + + output[:attr_whitelist] += transform[:attr_whitelist] if transform[:attr_whitelist].is_a?(Array) + output[:whitelist] ||= true if transform[:whitelist] + output[:node] = transform[:node].is_a?(Nokogiri::XML::Node) ? transform[:node] : output[:node] + else + raise Error, "transformer output must be a Hash or nil" + end + end + + node.replace(output[:node]) if node != output[:node] + + return output + end + + class Error < StandardError; end +end diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize/config.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize/config.rb new file mode 100644 index 00000000..58071fc3 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize/config.rb @@ -0,0 +1,70 @@ +#-- +# Copyright (c) 2010 Ryan Grove +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#++ + +class Sanitize + module Config + DEFAULT = { + # Whether or not to allow HTML comments. Allowing comments is strongly + # discouraged, since IE allows script execution within conditional + # comments. + :allow_comments => false, + + # HTML attributes to add to specific elements. By default, no attributes + # are added. + :add_attributes => {}, + + # HTML attributes to allow in specific elements. By default, no attributes + # are allowed. + :attributes => {}, + + # HTML elements to allow. By default, no elements are allowed (which means + # that all HTML will be stripped). + :elements => [], + + # Output format. Supported formats are :html and :xhtml (which is the + # default). + :output => :xhtml, + + # Character encoding to use for HTML output. Default is 'utf-8'. + :output_encoding => 'utf-8', + + # URL handling protocols to allow in specific attributes. By default, no + # protocols are allowed. Use :relative in place of a protocol if you want + # to allow relative URLs sans protocol. + :protocols => {}, + + # If this is true, Sanitize will remove the contents of any filtered + # elements in addition to the elements themselves. By default, Sanitize + # leaves the safe parts of an element's contents behind when the element + # is removed. + # + # If this is an Array of element names, then only the contents of the + # specified elements (when filtered) will be removed, and the contents of + # all other filtered elements will be left behind. + :remove_contents => false, + + # Transformers allow you to filter or alter nodes using custom logic. See + # README.rdoc for details and examples. + :transformers => [] + } + end +end diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize/config/basic.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/basic.rb new file mode 100644 index 00000000..5bd563f4 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/basic.rb @@ -0,0 +1,49 @@ +#-- +# Copyright (c) 2010 Ryan Grove +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#++ + +class Sanitize + module Config + BASIC = { + :elements => [ + 'a', 'b', 'blockquote', 'br', 'cite', 'code', 'dd', 'dl', 'dt', 'em', + 'i', 'li', 'ol', 'p', 'pre', 'q', 'small', 'strike', 'strong', 'sub', + 'sup', 'u', 'ul'], + + :attributes => { + 'a' => ['href'], + 'blockquote' => ['cite'], + 'q' => ['cite'] + }, + + :add_attributes => { + 'a' => {'rel' => 'nofollow'} + }, + + :protocols => { + 'a' => {'href' => ['ftp', 'http', 'https', 'mailto', + :relative]}, + 'blockquote' => {'cite' => ['http', 'https', :relative]}, + 'q' => {'cite' => ['http', 'https', :relative]} + } + } + end +end diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize/config/relaxed.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/relaxed.rb new file mode 100644 index 00000000..07fed780 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/relaxed.rb @@ -0,0 +1,57 @@ +#-- +# Copyright (c) 2010 Ryan Grove +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#++ + +class Sanitize + module Config + RELAXED = { + :elements => [ + 'a', 'b', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', + 'colgroup', 'dd', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', + 'i', 'img', 'li', 'ol', 'p', 'pre', 'q', 'small', 'strike', 'strong', + 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'u', + 'ul'], + + :attributes => { + 'a' => ['href', 'title'], + 'blockquote' => ['cite'], + 'col' => ['span', 'width'], + 'colgroup' => ['span', 'width'], + 'img' => ['align', 'alt', 'height', 'src', 'title', 'width'], + 'ol' => ['start', 'type'], + 'q' => ['cite'], + 'table' => ['summary', 'width'], + 'td' => ['abbr', 'axis', 'colspan', 'rowspan', 'width'], + 'th' => ['abbr', 'axis', 'colspan', 'rowspan', 'scope', + 'width'], + 'ul' => ['type'] + }, + + :protocols => { + 'a' => {'href' => ['ftp', 'http', 'https', 'mailto', + :relative]}, + 'blockquote' => {'cite' => ['http', 'https', :relative]}, + 'img' => {'src' => ['http', 'https', :relative]}, + 'q' => {'cite' => ['http', 'https', :relative]} + } + } + end +end diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize/config/restricted.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/restricted.rb new file mode 100644 index 00000000..ff8bbc97 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize/config/restricted.rb @@ -0,0 +1,29 @@ +#-- +# Copyright (c) 2010 Ryan Grove +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#++ + +class Sanitize + module Config + RESTRICTED = { + :elements => ['b', 'em', 'i', 'strong', 'u'] + } + end +end diff --git a/vendor/gems/sanitize-1.2.1/lib/sanitize/version.rb b/vendor/gems/sanitize-1.2.1/lib/sanitize/version.rb new file mode 100644 index 00000000..7330cc15 --- /dev/null +++ b/vendor/gems/sanitize-1.2.1/lib/sanitize/version.rb @@ -0,0 +1,3 @@ +class Sanitize + VERSION = '1.2.1' +end diff --git a/vendor/gems/will_paginate-2.3.15/.specification b/vendor/gems/will_paginate-2.3.15/.specification new file mode 100644 index 00000000..93a17bf9 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/.specification @@ -0,0 +1,108 @@ +--- !ruby/object:Gem::Specification +name: will_paginate +version: !ruby/object:Gem::Version + hash: 29 + prerelease: false + segments: + - 2 + - 3 + - 15 + version: 2.3.15 +platform: ruby +authors: +- "Mislav Marohni\xC4\x87" +- PJ Hyett +autorequire: +bindir: bin +cert_chain: [] + +date: 2010-09-09 00:00:00 +02:00 +default_executable: +dependencies: [] + +description: The will_paginate library provides a simple, yet powerful and extensible API for ActiveRecord pagination and rendering of pagination links in ActionView templates. +email: mislav.marohnic@gmail.com +executables: [] + +extensions: [] + +extra_rdoc_files: +- README.rdoc +- LICENSE +- CHANGELOG.rdoc +files: +- Rakefile +- lib/will_paginate/array.rb +- lib/will_paginate/collection.rb +- lib/will_paginate/core_ext.rb +- lib/will_paginate/finder.rb +- lib/will_paginate/named_scope.rb +- lib/will_paginate/named_scope_patch.rb +- lib/will_paginate/version.rb +- lib/will_paginate/view_helpers.rb +- lib/will_paginate.rb +- test/boot.rb +- test/collection_test.rb +- test/console +- test/database.yml +- test/finder_test.rb +- test/fixtures/admin.rb +- test/fixtures/developer.rb +- test/fixtures/developers_projects.yml +- test/fixtures/project.rb +- test/fixtures/projects.yml +- test/fixtures/replies.yml +- test/fixtures/reply.rb +- test/fixtures/schema.rb +- test/fixtures/topic.rb +- test/fixtures/topics.yml +- test/fixtures/user.rb +- test/fixtures/users.yml +- test/helper.rb +- test/lib/activerecord_test_case.rb +- test/lib/activerecord_test_connector.rb +- test/lib/load_fixtures.rb +- test/lib/view_test_process.rb +- test/tasks.rake +- test/view_test.rb +- README.rdoc +- LICENSE +- CHANGELOG.rdoc +has_rdoc: true +homepage: http://github.com/mislav/will_paginate/wikis +licenses: [] + +post_install_message: +rdoc_options: +- --main +- README.rdoc +- --charset=UTF-8 +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +required_rubygems_version: !ruby/object:Gem::Requirement + none: false + requirements: + - - ">=" + - !ruby/object:Gem::Version + hash: 3 + segments: + - 0 + version: "0" +requirements: [] + +rubyforge_project: +rubygems_version: 1.3.7 +signing_key: +specification_version: 3 +summary: Pagination for Rails +test_files: [] + diff --git a/vendor/gems/will_paginate-2.3.15/CHANGELOG.rdoc b/vendor/gems/will_paginate-2.3.15/CHANGELOG.rdoc new file mode 100644 index 00000000..8c4d2c90 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/CHANGELOG.rdoc @@ -0,0 +1,139 @@ += 2.3.12, released 2009-12-01 + +* make view helpers "HTML safe" for Rails 2.3.5 with rails_xss plugin + += 2.3.11, released 2009-06-02 + +* fix `enable_actionpack` + += 2.3.10, released 2009-05-21 + +* count_by_sql: don't use table alias with any adapters starting with "oracle" +* Add back "AS count_table" alias to `paginate_by_sql` counter SQL + += 2.3.9, released 2009-05-29 + +* remove "AS count_table" alias from `paginate_by_sql` counter SQL +* Rails 2.3.2 compat: monkeypatch Rails issue #2189 (count breaks has_many :through) +* fix generation of page URLs that contain the "@" character +* check for method existance in a ruby 1.8- and 1.9-compatible way +* load will_paginate view helpers even if ActiveRecord is not loaded + +== 2.3.8, released 2009-03-09 + +* Rails 2.3 compat: query parameter parsing with Rack + +== 2.3.7, released 2009-02-09 + +* Removed all unnecessary &block variables since they cause serious memory damage and lots of subsequent gc runs. + +== 2.3.6, released 2008-10-26 + +* Rails 2.2 fix: stop using `extract_attribute_names_from_match` inernal AR method, it no longer exists + +== 2.3.5, released 2008-10-07 + +* update the backported named_scope implementation for Rails versions older than 2.1 +* break out of scope of paginated_each() yielded block when used on named scopes +* fix paginate(:from) + +== 2.3.4, released 2008-09-16 + +* Removed gem dependency to Active Support (causes trouble with vendored rails). +* Rails 2.1: fix a failing test and a deprecation warning. +* Cope with scoped :select when counting. + +== 2.3.3, released 2008-08-29 + +* Ensure that paginate_by_sql doesn't change the original SQL query. +* RDoc love (now live at http://gitrdoc.com/mislav/will_paginate/tree/master) +* Rename :prev_label to :previous_label for consistency. old name still functions but is deprecated +* ActiveRecord 2.1: Remove :include option from count_all query when it's possible. + +== 2.3.2, released 2008-05-16 + +* Fixed LinkRenderer#stringified_merge by removing "return" from iterator block +* Ensure that 'href' values in pagination links are escaped URLs + +== 2.3.1, released 2008-05-04 + +* Fixed page numbers not showing with custom routes and implicit first page +* Try to use Hanna for documentation (falls back to default RDoc template if not) + +== 2.3.0, released 2008-04-29 + +* Changed LinkRenderer to receive collection, options and reference to view template NOT in + constructor, but with the #prepare method. This is a step towards supporting passing of + LinkRenderer (or subclass) instances that may be preconfigured in some way +* LinkRenderer now has #page_link and #page_span methods for easier customization of output in + subclasses +* Changed page_entries_info() method to adjust its output according to humanized class name of + collection items. Override this with :entry_name parameter (singular). + + page_entries_info(@posts) + #-> "Displaying all 12 posts" + page_entries_info(@posts, :entry_name => 'item') + #-> "Displaying all 12 items" + +== 2.2.3, released 2008-04-26 + +* will_paginate gem is no longer published on RubyForge, but on + gems.github.com: + + gem sources -a http://gems.github.com/ (you only need to do this once) + gem install mislav-will_paginate + +* extract reusable pagination testing stuff into WillPaginate::View +* rethink the page URL construction mechanizm to be more bulletproof when + combined with custom routing for page parameter +* test that anchor parameter can be used in pagination links + +== 2.2.2, released 2008-04-21 + +* Add support for page parameter in custom routes like "/foo/page/2" +* Change output of "page_entries_info" on single-page collection and erraneous + output with empty collection as reported by Tim Chater + +== 2.2.1, released 2008-04-08 + +* take less risky path when monkeypatching named_scope; fix that it no longer + requires ActiveRecord::VERSION +* use strings in "respond_to?" calls to work around a bug in acts_as_ferret + stable (ugh) +* add rake release task + + +== 2.2.0, released 2008-04-07 + +=== API changes +* Rename WillPaginate::Collection#page_count to "total_pages" for consistency. + If you implemented this interface, change your implementation accordingly. +* Remove old, deprecated style of calling Array#paginate as "paginate(page, + per_page)". If you want to specify :page, :per_page or :total_entries, use a + parameter hash. +* Rename LinkRenderer#url_options to "url_for" and drastically optimize it + +=== View changes +* Added "prev_page" and "next_page" CSS classes on previous/next page buttons +* Add examples of pagination links styling in "examples/index.html" +* Change gap in pagination links from "..." to + "". +* Add "paginated_section", a block helper that renders pagination both above and + below content in the block +* Add rel="prev|next|start" to page links + +=== Other + +* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling + WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2) +* Support complex page parameters like "developers[page]" +* Move Array#paginate definition to will_paginate/array.rb. You can now easily + use pagination on arrays outside of Rails: + + gem 'will_paginate' + require 'will_paginate/array' + +* Add "paginated_each" method for iterating through every record by loading only + one page of records at the time +* Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by + default diff --git a/vendor/gems/will_paginate-2.3.15/LICENSE b/vendor/gems/will_paginate-2.3.15/LICENSE new file mode 100644 index 00000000..96a48cb3 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/LICENSE @@ -0,0 +1,18 @@ +Copyright (c) 2007 PJ Hyett and Mislav Marohnić + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gems/will_paginate-2.3.15/README.rdoc b/vendor/gems/will_paginate-2.3.15/README.rdoc new file mode 100644 index 00000000..2a52ed30 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/README.rdoc @@ -0,0 +1,107 @@ += WillPaginate + +Pagination is just limiting the number of records displayed. Why should you let +it get in your way while developing, then? This plugin makes magic happen. Did +you ever want to be able to do just this on a model: + + Post.paginate :page => 1, :order => 'created_at DESC' + +... and then render the page links with a single view helper? Well, now you +can. + +Some resources to get you started: + +* {Installation instructions}[http://github.com/mislav/will_paginate/wikis/installation] + on {the wiki}[http://github.com/mislav/will_paginate/wikis] +* Your mind reels with questions? Join our + {Google group}[http://groups.google.com/group/will_paginate]. +* {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs] + + +== Example usage + +Use a paginate finder in the controller: + + @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC' + +Yeah, +paginate+ works just like +find+ -- it just doesn't fetch all the +records. Don't forget to tell it which page you want, or it will complain! +Read more on WillPaginate::Finder::ClassMethods. + +Render the posts in your view like you would normally do. When you need to render +pagination, just stick this in: + + <%= will_paginate @posts %> + +You're done. (You can find the option list at WillPaginate::ViewHelpers.) + +How does it know how much items to fetch per page? It asks your model by calling +its per_page class method. You can define it like this: + + class Post < ActiveRecord::Base + cattr_reader :per_page + @@per_page = 50 + end + +... or like this: + + class Post < ActiveRecord::Base + def self.per_page + 50 + end + end + +... or don't worry about it at all. WillPaginate defines it to be 30 by default. +But you can always specify the count explicitly when calling +paginate+: + + @posts = Post.paginate :page => params[:page], :per_page => 50 + +The +paginate+ finder wraps the original finder and returns your resultset that now has +some new properties. You can use the collection as you would with any ActiveRecord +resultset. WillPaginate view helpers also need that object to be able to render pagination: + +
      + <% for post in @posts -%> +
    1. Render `post` in some nice way.
    2. + <% end -%> +
    + +

    Now let's render us some pagination!

    + <%= will_paginate @posts %> + +More detailed documentation: + +* WillPaginate::Finder::ClassMethods for pagination on your models; +* WillPaginate::ViewHelpers for your views. + + +== Authors and credits + +Authors:: Mislav Marohnić, PJ Hyett +Original announcement:: http://errtheblog.com/post/929 +Original PHP source:: http://www.strangerstudios.com/sandbox/pagination/diggstyle.php + +All these people helped making will_paginate what it is now with their code +contributions or just simply awesome ideas: + +Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence +Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs +van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel, +Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris Eppstein, +Denis Barushev, Ben Pickles. + + +== Usable pagination in the UI + +There are some CSS styles to get you started in the "examples/" directory. They +are {showcased online here}[http://mislav.uniqpath.com/will_paginate/]. + +More reading about pagination as design pattern: + +* {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101] +* {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/] +* {Pagination on Yahoo Design Pattern Library}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination] + +Want to discuss, request features, ask questions? Join the +{Google group}[http://groups.google.com/group/will_paginate]. + diff --git a/vendor/gems/will_paginate-2.3.15/Rakefile b/vendor/gems/will_paginate-2.3.15/Rakefile new file mode 100644 index 00000000..6226b1b7 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/Rakefile @@ -0,0 +1,53 @@ +require 'rubygems' +begin + hanna_dir = '/Users/mislav/Projects/Hanna/lib' + $:.unshift hanna_dir if File.exists? hanna_dir + require 'hanna/rdoctask' +rescue LoadError + require 'rake' + require 'rake/rdoctask' +end +load 'test/tasks.rake' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Generate RDoc documentation for the will_paginate plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc'). + include('lib/**/*.rb'). + exclude('lib/will_paginate/named_scope*'). + exclude('lib/will_paginate/array.rb'). + exclude('lib/will_paginate/version.rb') + + rdoc.main = "README.rdoc" # page to start on + rdoc.title = "will_paginate documentation" + + rdoc.rdoc_dir = 'doc' # rdoc output folder + rdoc.options << '--inline-source' << '--charset=UTF-8' + rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/' +end + +desc %{Update ".manifest" with the latest list of project filenames. Respect\ +.gitignore by excluding everything that git ignores. Update `files` and\ +`test_files` arrays in "*.gemspec" file if it's present.} +task :manifest do + list = `git ls-files --full-name --exclude=*.gemspec --exclude=.*`.chomp.split("\n") + + if spec_file = Dir['*.gemspec'].first + spec = File.read spec_file + spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do + assignment = $1 + bunch = $2 ? list.grep(/^test\//) : list + '%s%%w(%s)' % [assignment, bunch.join(' ')] + end + + File.open(spec_file, 'w') { |f| f << spec } + end + File.open('.manifest', 'w') { |f| f << list.join("\n") } +end + +task :examples do + %x(haml examples/index.haml examples/index.html) + %x(sass examples/pagination.sass examples/pagination.css) +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate.rb new file mode 100644 index 00000000..ac30b658 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate.rb @@ -0,0 +1,90 @@ +require 'active_support' +require 'will_paginate/core_ext' + +# = You *will* paginate! +# +# First read about WillPaginate::Finder::ClassMethods, then see +# WillPaginate::ViewHelpers. The magical array you're handling in-between is +# WillPaginate::Collection. +# +# Happy paginating! +module WillPaginate + class << self + # shortcut for enable_actionpack and enable_activerecord combined + def enable + enable_actionpack + enable_activerecord + end + + # hooks WillPaginate::ViewHelpers into ActionView::Base + def enable_actionpack + return if ActionView::Base.instance_methods.include_method? :will_paginate + require 'will_paginate/view_helpers' + ActionView::Base.send :include, ViewHelpers + + if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses + ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found + end + end + + # hooks WillPaginate::Finder into ActiveRecord::Base and classes that deal + # with associations + def enable_activerecord + return if ActiveRecord::Base.respond_to? :paginate + require 'will_paginate/finder' + ActiveRecord::Base.send :include, Finder + + # support pagination on associations + a = ActiveRecord::Associations + [ a::AssociationCollection ].tap { |classes| + # detect http://dev.rubyonrails.org/changeset/9230 + unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation + classes << a::HasManyThroughAssociation + end + }.each do |klass| + klass.send :include, Finder::ClassMethods + klass.class_eval { alias_method_chain :method_missing, :paginate } + end + + # monkeypatch Rails ticket #2189: "count breaks has_many :through" + ActiveRecord::Base.class_eval do + protected + def self.construct_count_options_from_args(*args) + result = super + result[0] = '*' if result[0].is_a?(String) and result[0] =~ /\.\*$/ + result + end + end + end + + # Enable named_scope, a feature of Rails 2.1, even if you have older Rails + # (tested on Rails 2.0.2 and 1.2.6). + # + # You can pass +false+ for +patch+ parameter to skip monkeypatching + # *associations*. Use this if you feel that named_scope broke + # has_many, has_many :through or has_and_belongs_to_many associations in + # your app. By passing +false+, you can still use named_scope in + # your models, but not through associations. + def enable_named_scope(patch = true) + return if defined? ActiveRecord::NamedScope + require 'will_paginate/named_scope' + require 'will_paginate/named_scope_patch' if patch + + ActiveRecord::Base.send :include, WillPaginate::NamedScope + end + end + + module Deprecation # :nodoc: + extend ActiveSupport::Deprecation + + def self.warn(message, callstack = caller) + message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ') + ActiveSupport::Deprecation.warn(message, callstack) + end + end +end + +if defined? Rails + WillPaginate.enable_activerecord if defined? ActiveRecord + WillPaginate.enable_actionpack if defined? ActionController +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/array.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/array.rb new file mode 100644 index 00000000..d061d2be --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/array.rb @@ -0,0 +1,16 @@ +require 'will_paginate/collection' + +# http://www.desimcadam.com/archives/8 +Array.class_eval do + def paginate(options = {}) + raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options + + WillPaginate::Collection.create( + options[:page] || 1, + options[:per_page] || 30, + options[:total_entries] || self.length + ) { |pager| + pager.replace self[pager.offset, pager.per_page].to_a + } + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/collection.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/collection.rb new file mode 100644 index 00000000..3ccb4a6a --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/collection.rb @@ -0,0 +1,144 @@ +module WillPaginate + # = Invalid page number error + # This is an ArgumentError raised in case a page was requested that is either + # zero or negative number. You should decide how do deal with such errors in + # the controller. + # + # If you're using Rails 2, then this error will automatically get handled like + # 404 Not Found. The hook is in "will_paginate.rb": + # + # ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found + # + # If you don't like this, use your preffered method of rescuing exceptions in + # public from your controllers to handle this differently. The +rescue_from+ + # method is a nice addition to Rails 2. + # + # This error is *not* raised when a page further than the last page is + # requested. Use WillPaginate::Collection#out_of_bounds? method to + # check for those cases and manually deal with them as you see fit. + class InvalidPage < ArgumentError + def initialize(page, page_num) + super "#{page.inspect} given as value, which translates to '#{page_num}' as page number" + end + end + + # = The key to pagination + # Arrays returned from paginating finds are, in fact, instances of this little + # class. You may think of WillPaginate::Collection as an ordinary array with + # some extra properties. Those properties are used by view helpers to generate + # correct page links. + # + # WillPaginate::Collection also assists in rolling out your own pagination + # solutions: see +create+. + # + # If you are writing a library that provides a collection which you would like + # to conform to this API, you don't have to copy these methods over; simply + # make your plugin/gem dependant on this library and do: + # + # require 'will_paginate/collection' + # # WillPaginate::Collection is now available for use + class Collection < Array + attr_reader :current_page, :per_page, :total_entries, :total_pages + + # Arguments to the constructor are the current page number, per-page limit + # and the total number of entries. The last argument is optional because it + # is best to do lazy counting; in other words, count *conditionally* after + # populating the collection using the +replace+ method. + def initialize(page, per_page, total = nil) + @current_page = page.to_i + raise InvalidPage.new(page, @current_page) if @current_page < 1 + @per_page = per_page.to_i + raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1 + + self.total_entries = total if total + end + + # Just like +new+, but yields the object after instantiation and returns it + # afterwards. This is very useful for manual pagination: + # + # @entries = WillPaginate::Collection.create(1, 10) do |pager| + # result = Post.find(:all, :limit => pager.per_page, :offset => pager.offset) + # # inject the result array into the paginated collection: + # pager.replace(result) + # + # unless pager.total_entries + # # the pager didn't manage to guess the total count, do it manually + # pager.total_entries = Post.count + # end + # end + # + # The possibilities with this are endless. For another example, here is how + # WillPaginate used to define pagination for Array instances: + # + # Array.class_eval do + # def paginate(page = 1, per_page = 15) + # WillPaginate::Collection.create(page, per_page, size) do |pager| + # pager.replace self[pager.offset, pager.per_page].to_a + # end + # end + # end + # + # The Array#paginate API has since then changed, but this still serves as a + # fine example of WillPaginate::Collection usage. + def self.create(page, per_page, total = nil) + pager = new(page, per_page, total) + yield pager + pager + end + + # Helper method that is true when someone tries to fetch a page with a + # larger number than the last page. Can be used in combination with flashes + # and redirecting. + def out_of_bounds? + current_page > total_pages + end + + # Current offset of the paginated collection. If we're on the first page, + # it is always 0. If we're on the 2nd page and there are 30 entries per page, + # the offset is 30. This property is useful if you want to render ordinals + # side by side with records in the view: simply start with offset + 1. + def offset + (current_page - 1) * per_page + end + + # current_page - 1 or nil if there is no previous page + def previous_page + current_page > 1 ? (current_page - 1) : nil + end + + # current_page + 1 or nil if there is no next page + def next_page + current_page < total_pages ? (current_page + 1) : nil + end + + # sets the total_entries property and calculates total_pages + def total_entries=(number) + @total_entries = number.to_i + @total_pages = (@total_entries / per_page.to_f).ceil + end + + # This is a magic wrapper for the original Array#replace method. It serves + # for populating the paginated collection after initialization. + # + # Why magic? Because it tries to guess the total number of entries judging + # by the size of given array. If it is shorter than +per_page+ limit, then we + # know we're on the last page. This trick is very useful for avoiding + # unnecessary hits to the database to do the counting after we fetched the + # data for the current page. + # + # However, after using +replace+ you should always test the value of + # +total_entries+ and set it to a proper value if it's +nil+. See the example + # in +create+. + def replace(array) + result = super + + # The collection is shorter then page limit? Rejoice, because + # then we know that we are on the last page! + if total_entries.nil? and length < per_page and (current_page == 1 or length > 0) + self.total_entries = offset + length + end + + result + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/core_ext.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/core_ext.rb new file mode 100644 index 00000000..3397736b --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/core_ext.rb @@ -0,0 +1,43 @@ +require 'set' +require 'will_paginate/array' + +# helper to check for method existance in ruby 1.8- and 1.9-compatible way +# because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9 +# +# ['foo', 'bar'].include_method?(:foo) # => true +class Array + def include_method?(name) + name = name.to_sym + !!(find { |item| item.to_sym == name }) + end +end + +unless Hash.instance_methods.include_method? :except + Hash.class_eval do + # Returns a new hash without the given keys. + def except(*keys) + rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) + reject { |key,| rejected.include?(key) } + end + + # Replaces the hash without only the given keys. + def except!(*keys) + replace(except(*keys)) + end + end +end + +unless Hash.instance_methods.include_method? :slice + Hash.class_eval do + # Returns a new hash with only the given keys. + def slice(*keys) + allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) + reject { |key,| !allowed.include?(key) } + end + + # Replaces the hash with only the given keys. + def slice!(*keys) + replace(slice(*keys)) + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb new file mode 100644 index 00000000..e121c5ff --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb @@ -0,0 +1,264 @@ +require 'will_paginate/core_ext' + +module WillPaginate + # A mixin for ActiveRecord::Base. Provides +per_page+ class method + # and hooks things up to provide paginating finders. + # + # Find out more in WillPaginate::Finder::ClassMethods + # + module Finder + def self.included(base) + base.extend ClassMethods + class << base + alias_method_chain :method_missing, :paginate + # alias_method_chain :find_every, :paginate + define_method(:per_page) { 30 } unless respond_to?(:per_page) + end + end + + # = Paginating finders for ActiveRecord models + # + # WillPaginate adds +paginate+, +per_page+ and other methods to + # ActiveRecord::Base class methods and associations. It also hooks into + # +method_missing+ to intercept pagination calls to dynamic finders such as + # +paginate_by_user_id+ and translate them to ordinary finders + # (+find_all_by_user_id+ in this case). + # + # In short, paginating finders are equivalent to ActiveRecord finders; the + # only difference is that we start with "paginate" instead of "find" and + # that :page is required parameter: + # + # @posts = Post.paginate :all, :page => params[:page], :order => 'created_at DESC' + # + # In paginating finders, "all" is implicit. There is no sense in paginating + # a single record, right? So, you can drop the :all argument: + # + # Post.paginate(...) => Post.find :all + # Post.paginate_all_by_something => Post.find_all_by_something + # Post.paginate_by_something => Post.find_all_by_something + # + # == The importance of the :order parameter + # + # In ActiveRecord finders, :order parameter specifies columns for + # the ORDER BY clause in SQL. It is important to have it, since + # pagination only makes sense with ordered sets. Without the ORDER + # BY clause, databases aren't required to do consistent ordering when + # performing SELECT queries; this is especially true for + # PostgreSQL. + # + # Therefore, make sure you are doing ordering on a column that makes the + # most sense in the current context. Make that obvious to the user, also. + # For perfomance reasons you will also want to add an index to that column. + module ClassMethods + # This is the main paginating finder. + # + # == Special parameters for paginating finders + # * :page -- REQUIRED, but defaults to 1 if false or nil + # * :per_page -- defaults to CurrentModel.per_page (which is 30 if not overridden) + # * :total_entries -- use only if you manually count total entries + # * :count -- additional options that are passed on to +count+ + # * :finder -- name of the ActiveRecord finder used (default: "find") + # + # All other options (+conditions+, +order+, ...) are forwarded to +find+ + # and +count+ calls. + def paginate(*args) + options = args.pop + page, per_page, total_entries = wp_parse_options(options) + finder = (options[:finder] || 'find').to_s + + if finder == 'find' + # an array of IDs may have been given: + total_entries ||= (Array === args.first and args.first.size) + # :all is implicit + args.unshift(:all) if args.empty? + end + + WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + count_options = options.except :page, :per_page, :total_entries, :finder + find_options = count_options.except(:count).update(:offset => pager.offset, :limit => pager.per_page) + + args << find_options + # @options_from_last_find = nil + pager.replace(send(finder, *args) { |*a| yield(*a) if block_given? }) + + # magic counting for user convenience: + pager.total_entries = wp_count(count_options, args, finder) unless pager.total_entries + end + end + + # Iterates through all records by loading one page at a time. This is useful + # for migrations or any other use case where you don't want to load all the + # records in memory at once. + # + # It uses +paginate+ internally; therefore it accepts all of its options. + # You can specify a starting page with :page (default is 1). Default + # :order is "id", override if necessary. + # + # See {Faking Cursors in ActiveRecord}[http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord] + # where Jamis Buck describes this and a more efficient way for MySQL. + def paginated_each(options = {}) + options = { :order => 'id', :page => 1 }.merge options + options[:page] = options[:page].to_i + options[:total_entries] = 0 # skip the individual count queries + total = 0 + + begin + collection = paginate(options) + with_exclusive_scope(:find => {}) do + # using exclusive scope so that the block is yielded in scope-free context + total += collection.each { |item| yield item }.size + end + options[:page] += 1 + end until collection.size < collection.per_page + + total + end + + # Wraps +find_by_sql+ by simply adding LIMIT and OFFSET to your SQL string + # based on the params otherwise used by paginating finds: +page+ and + # +per_page+. + # + # Example: + # + # @developers = Developer.paginate_by_sql ['select * from developers where salary > ?', 80000], + # :page => params[:page], :per_page => 3 + # + # A query for counting rows will automatically be generated if you don't + # supply :total_entries. If you experience problems with this + # generated SQL, you might want to perform the count manually in your + # application. + # + def paginate_by_sql(sql, options) + WillPaginate::Collection.create(*wp_parse_options(options)) do |pager| + query = sanitize_sql(sql.dup) + original_query = query.dup + # add limit, offset + add_limit! query, :offset => pager.offset, :limit => pager.per_page + # perfom the find + pager.replace find_by_sql(query) + + unless pager.total_entries + count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, '' + count_query = "SELECT COUNT(*) FROM (#{count_query})" + + unless self.connection.adapter_name =~ /^(oracle|oci$)/i + count_query << ' AS count_table' + end + # perform the count query + pager.total_entries = count_by_sql(count_query) + end + end + end + + def respond_to?(method, include_priv = false) #:nodoc: + case method.to_sym + when :paginate, :paginate_by_sql + true + else + super || super(method.to_s.sub(/^paginate/, 'find'), include_priv) + end + end + + protected + + def method_missing_with_paginate(method, *args) #:nodoc: + # did somebody tried to paginate? if not, let them be + unless method.to_s.index('paginate') == 0 + if block_given? + return method_missing_without_paginate(method, *args) { |*a| yield(*a) } + else + return method_missing_without_paginate(method, *args) + end + end + + # paginate finders are really just find_* with limit and offset + finder = method.to_s.sub('paginate', 'find') + finder.sub!('find', 'find_all') if finder.index('find_by_') == 0 + + options = args.pop + raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys + options = options.dup + options[:finder] = finder + args << options + + paginate(*args) { |*a| yield(*a) if block_given? } + end + + # Does the not-so-trivial job of finding out the total number of entries + # in the database. It relies on the ActiveRecord +count+ method. + def wp_count(options, args, finder) + excludees = [:count, :order, :limit, :offset, :readonly] + excludees << :from unless ActiveRecord::Calculations::CALCULATIONS_OPTIONS.include?(:from) + + # we may be in a model or an association proxy + klass = (@owner and @reflection) ? @reflection.klass : self + + # Use :select from scope if it isn't already present. + options[:select] = scope(:find, :select) unless options[:select] + + if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i + # Remove quoting and check for table_name.*-like statement. + if options[:select].gsub(/[`"]/, '') =~ /\w+\.\*/ + options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}" + end + else + excludees << :select # only exclude the select param if it doesn't begin with DISTINCT + end + + # count expects (almost) the same options as find + count_options = options.except *excludees + + # merge the hash found in :count + # this allows you to specify :select, :order, or anything else just for the count query + count_options.update options[:count] if options[:count] + + # forget about includes if they are irrelevant (Rails 2.1) + if count_options[:include] and + klass.private_methods.include_method?(:references_eager_loaded_tables?) and + !klass.send(:references_eager_loaded_tables?, count_options) + count_options.delete :include + end + + # we may have to scope ... + counter = Proc.new { count(count_options) } + + count = if finder.index('find_') == 0 and klass.respond_to?(scoper = finder.sub('find', 'with')) + # scope_out adds a 'with_finder' method which acts like with_scope, if it's present + # then execute the count with the scoping provided by the with_finder + send(scoper, &counter) + elsif finder =~ /^find_(all_by|by)_([_a-zA-Z]\w*)$/ + # extract conditions from calls like "paginate_by_foo_and_bar" + attribute_names = $2.split('_and_') + conditions = construct_attributes_from_arguments(attribute_names, args) + with_scope(:find => { :conditions => conditions }, &counter) + else + counter.call + end + + (!count.is_a?(Integer) && count.respond_to?(:length)) ? count.length : count + end + + def wp_parse_options(options) #:nodoc: + raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys + options = options.symbolize_keys + raise ArgumentError, ':page parameter required' unless options.key? :page + + if options[:count] and options[:total_entries] + raise ArgumentError, ':count and :total_entries are mutually exclusive' + end + + page = options[:page] || 1 + per_page = options[:per_page] || self.per_page + total = options[:total_entries] + [page, per_page, total] + end + + private + + # def find_every_with_paginate(options) + # @options_from_last_find = options + # find_every_without_paginate(options) + # end + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope.rb new file mode 100644 index 00000000..5a743d7f --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope.rb @@ -0,0 +1,170 @@ +module WillPaginate + # This is a feature backported from Rails 2.1 because of its usefullness not only with will_paginate, + # but in other aspects when managing complex conditions that you want to be reusable. + module NamedScope + # All subclasses of ActiveRecord::Base have two named_scopes: + # * all, which is similar to a find(:all) query, and + # * scoped, which allows for the creation of anonymous scopes, on the fly: Shirt.scoped(:conditions => {:color => 'red'}).scoped(:include => :washing_instructions) + # + # These anonymous scopes tend to be useful when procedurally generating complex queries, where passing + # intermediate values (scopes) around as first-class objects is convenient. + def self.included(base) + base.class_eval do + extend ClassMethods + named_scope :scoped, lambda { |scope| scope } + end + end + + module ClassMethods + def scopes + read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}) + end + + # Adds a class method for retrieving and querying objects. A scope represents a narrowing of a database query, + # such as :conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions. + # + # class Shirt < ActiveRecord::Base + # named_scope :red, :conditions => {:color => 'red'} + # named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] + # end + # + # The above calls to named_scope define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, + # in effect, represents the query Shirt.find(:all, :conditions => {:color => 'red'}). + # + # Unlike Shirt.find(...), however, the object returned by Shirt.red is not an Array; it resembles the association object + # constructed by a has_many declaration. For instance, you can invoke Shirt.red.find(:first), Shirt.red.count, + # Shirt.red.find(:all, :conditions => {:size => 'small'}). Also, just + # as with the association objects, name scopes acts like an Array, implementing Enumerable; Shirt.red.each(&block), + # Shirt.red.first, and Shirt.red.inject(memo, &block) all behave as if Shirt.red really were an Array. + # + # These named scopes are composable. For instance, Shirt.red.dry_clean_only will produce all shirts that are both red and dry clean only. + # Nested finds and calculations also work with these compositions: Shirt.red.dry_clean_only.count returns the number of garments + # for which these criteria obtain. Similarly with Shirt.red.dry_clean_only.average(:thread_count). + # + # All scopes are available as class methods on the ActiveRecord::Base descendent upon which the scopes were defined. But they are also available to + # has_many associations. If, + # + # class Person < ActiveRecord::Base + # has_many :shirts + # end + # + # then elton.shirts.red.dry_clean_only will return all of Elton's red, dry clean + # only shirts. + # + # Named scopes can also be procedural. + # + # class Shirt < ActiveRecord::Base + # named_scope :colored, lambda { |color| + # { :conditions => { :color => color } } + # } + # end + # + # In this example, Shirt.colored('puce') finds all puce shirts. + # + # Named scopes can also have extensions, just as with has_many declarations: + # + # class Shirt < ActiveRecord::Base + # named_scope :red, :conditions => {:color => 'red'} do + # def dom_id + # 'red_shirts' + # end + # end + # end + # + # + # For testing complex named scopes, you can examine the scoping options using the + # proxy_options method on the proxy itself. + # + # class Shirt < ActiveRecord::Base + # named_scope :colored, lambda { |color| + # { :conditions => { :color => color } } + # } + # end + # + # expected_options = { :conditions => { :colored => 'red' } } + # assert_equal expected_options, Shirt.colored('red').proxy_options + def named_scope(name, options = {}) + name = name.to_sym + scopes[name] = lambda do |parent_scope, *args| + Scope.new(parent_scope, case options + when Hash + options + when Proc + options.call(*args) + end) { |*a| yield(*a) if block_given? } + end + (class << self; self end).instance_eval do + define_method name do |*args| + scopes[name].call(self, *args) + end + end + end + end + + class Scope + attr_reader :proxy_scope, :proxy_options + + [].methods.each do |m| + unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|^find$|count|sum|average|maximum|minimum|paginate|first|last|empty\?|respond_to\?)/ + delegate m, :to => :proxy_found + end + end + + delegate :scopes, :with_scope, :to => :proxy_scope + + def initialize(proxy_scope, options) + [options[:extend]].flatten.each { |extension| extend extension } if options[:extend] + extend Module.new { |*args| yield(*args) } if block_given? + @proxy_scope, @proxy_options = proxy_scope, options.except(:extend) + end + + def reload + load_found; self + end + + def first(*args) + if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash)) + proxy_found.first(*args) + else + find(:first, *args) + end + end + + def last(*args) + if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash)) + proxy_found.last(*args) + else + find(:last, *args) + end + end + + def empty? + @found ? @found.empty? : count.zero? + end + + def respond_to?(method, include_private = false) + super || @proxy_scope.respond_to?(method, include_private) + end + + protected + def proxy_found + @found || load_found + end + + private + def method_missing(method, *args) + if scopes.include?(method) + scopes[method].call(self, *args) + else + with_scope :find => proxy_options do + proxy_scope.send(method, *args) { |*a| yield(*a) if block_given? } + end + end + end + + def load_found + @found = find(:all) + end + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope_patch.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope_patch.rb new file mode 100644 index 00000000..7daff592 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/named_scope_patch.rb @@ -0,0 +1,37 @@ +ActiveRecord::Associations::AssociationProxy.class_eval do + protected + def with_scope(*args) + @reflection.klass.send(:with_scope, *args) { |*a| yield(*a) if block_given? } + end +end + +[ ActiveRecord::Associations::AssociationCollection, + ActiveRecord::Associations::HasManyThroughAssociation ].each do |klass| + klass.class_eval do + protected + alias :method_missing_without_scopes :method_missing_without_paginate + def method_missing_without_paginate(method, *args) + if @reflection.klass.scopes.include?(method) + @reflection.klass.scopes[method].call(self, *args) { |*a| yield(*a) if block_given? } + else + method_missing_without_scopes(method, *args) { |*a| yield(*a) if block_given? } + end + end + end +end + +# Rails 1.2.6 +ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do + protected + def method_missing(method, *args) + if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) + super + elsif @reflection.klass.scopes.include?(method) + @reflection.klass.scopes[method].call(self, *args) + else + @reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do + @reflection.klass.send(method, *args) { |*a| yield(*a) if block_given? } + end + end + end +end if ActiveRecord::Base.respond_to? :find_first diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/version.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/version.rb new file mode 100644 index 00000000..b7de1ad3 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/version.rb @@ -0,0 +1,9 @@ +module WillPaginate + module VERSION + MAJOR = 2 + MINOR = 3 + TINY = 15 + + STRING = [MAJOR, MINOR, TINY].join('.') + end +end diff --git a/vendor/gems/will_paginate-2.3.15/lib/will_paginate/view_helpers.rb b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/view_helpers.rb new file mode 100644 index 00000000..48972b6e --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/lib/will_paginate/view_helpers.rb @@ -0,0 +1,410 @@ +require 'will_paginate/core_ext' + +module WillPaginate + # = Will Paginate view helpers + # + # The main view helper, #will_paginate, renders + # pagination links for the given collection. The helper itself is lightweight + # and serves only as a wrapper around LinkRenderer instantiation; the + # renderer then does all the hard work of generating the HTML. + # + # == Global options for helpers + # + # Options for pagination helpers are optional and get their default values from the + # WillPaginate::ViewHelpers.pagination_options hash. You can write to this hash to + # override default options on the global level: + # + # WillPaginate::ViewHelpers.pagination_options[:previous_label] = 'Previous page' + # + # By putting this into "config/initializers/will_paginate.rb" (or simply environment.rb in + # older versions of Rails) you can easily translate link texts to previous + # and next pages, as well as override some other defaults to your liking. + module ViewHelpers + # default options that can be overridden on the global level + @@pagination_options = { + :class => 'pagination', + :previous_label => '« Previous', + :next_label => 'Next »', + :inner_window => 4, # links around the current page + :outer_window => 1, # links around beginning and end + :separator => ' ', # single space is friendly to spiders and non-graphic browsers + :param_name => :page, + :params => nil, + :renderer => 'WillPaginate::LinkRenderer', + :page_links => true, + :container => true + } + mattr_reader :pagination_options + + # Renders Digg/Flickr-style pagination for a WillPaginate::Collection + # object. Nil is returned if there is only one page in total; no point in + # rendering the pagination in that case... + # + # ==== Options + # Display options: + # * :previous_label -- default: "« Previous" (this parameter is called :prev_label in versions 2.3.2 and older!) + # * :next_label -- default: "Next »" + # * :page_links -- when false, only previous/next links are rendered (default: true) + # * :inner_window -- how many links are shown around the current page (default: 4) + # * :outer_window -- how many links are around the first and the last page (default: 1) + # * :separator -- string separator for page HTML elements (default: single space) + # + # HTML options: + # * :class -- CSS class name for the generated DIV (default: "pagination") + # * :container -- toggles rendering of the DIV container for pagination links, set to + # false only when you are rendering your own pagination markup (default: true) + # * :id -- HTML ID for the container (default: nil). Pass +true+ to have the ID + # automatically generated from the class name of objects in collection: for example, paginating + # ArticleComment models would yield an ID of "article_comments_pagination". + # + # Advanced options: + # * :param_name -- parameter name for page number in URLs (default: :page) + # * :params -- additional parameters when generating pagination links + # (eg. :controller => "foo", :action => nil) + # * :renderer -- class name, class or instance of a link renderer (default: + # WillPaginate::LinkRenderer) + # + # All options not recognized by will_paginate will become HTML attributes on the container + # element for pagination links (the DIV). For example: + # + # <%= will_paginate @posts, :style => 'font-size: small' %> + # + # ... will result in: + # + # + # + # ==== Using the helper without arguments + # If the helper is called without passing in the collection object, it will + # try to read from the instance variable inferred by the controller name. + # For example, calling +will_paginate+ while the current controller is + # PostsController will result in trying to read from the @posts + # variable. Example: + # + # <%= will_paginate :id => true %> + # + # ... will result in @post collection getting paginated: + # + # + # + def will_paginate(collection = nil, options = {}) + options, collection = collection, nil if collection.is_a? Hash + unless collection or !controller + collection_name = "@#{controller.controller_name}" + collection = instance_variable_get(collection_name) + raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " + + "forget to pass the collection object for will_paginate?" unless collection + end + # early exit if there is nothing to render + return nil unless WillPaginate::ViewHelpers.total_pages_for_collection(collection) > 1 + + options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options + if options[:prev_label] + WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated", caller) + options[:previous_label] = options.delete(:prev_label) + end + + # get the renderer instance + renderer = case options[:renderer] + when String + options[:renderer].to_s.constantize.new + when Class + options[:renderer].new + else + options[:renderer] + end + # render HTML for pagination + renderer.prepare collection, options, self + renderer.to_html + end + + # Wrapper for rendering pagination links at both top and bottom of a block + # of content. + # + # <% paginated_section @posts do %> + #
      + # <% for post in @posts %> + #
    1. ...
    2. + # <% end %> + #
    + # <% end %> + # + # will result in: + # + # + #
      + # ... + #
    + # + # + # Arguments are passed to a will_paginate call, so the same options + # apply. Don't use the :id option; otherwise you'll finish with two + # blocks of pagination links sharing the same ID (which is invalid HTML). + def paginated_section(*args, &block) + pagination = will_paginate(*args).to_s + + unless ActionView::Base.respond_to? :erb_variable + concat pagination + yield + concat pagination + else + content = pagination + capture(&block) + pagination + concat(content, block.binding) + end + end + + # Renders a helpful message with numbers of displayed vs. total entries. + # You can use this as a blueprint for your own, similar helpers. + # + # <%= page_entries_info @posts %> + # #-> Displaying posts 6 - 10 of 26 in total + # + # By default, the message will use the humanized class name of objects + # in collection: for instance, "project types" for ProjectType models. + # Override this with the :entry_name parameter: + # + # <%= page_entries_info @posts, :entry_name => 'item' %> + # #-> Displaying items 6 - 10 of 26 in total + def page_entries_info(collection, options = {}) + entry_name = options[:entry_name] || + (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' ')) + + if collection.total_pages < 2 + case collection.size + when 0; "No #{entry_name.pluralize} found" + when 1; "Displaying 1 #{entry_name}" + else; "Displaying all #{collection.size} #{entry_name.pluralize}" + end + else + %{Displaying #{entry_name.pluralize} %d - %d of %d in total} % [ + collection.offset + 1, + collection.offset + collection.length, + collection.total_entries + ] + end + end + + if respond_to? :safe_helper + safe_helper :will_paginate, :paginated_section, :page_entries_info + end + + def self.total_pages_for_collection(collection) #:nodoc: + if collection.respond_to?('page_count') and !collection.respond_to?('total_pages') + WillPaginate::Deprecation.warn %{ + You are using a paginated collection of class #{collection.class.name} + which conforms to the old API of WillPaginate::Collection by using + `page_count`, while the current method name is `total_pages`. Please + upgrade yours or 3rd-party code that provides the paginated collection}, caller + class << collection + def total_pages; page_count; end + end + end + collection.total_pages + end + end + + # This class does the heavy lifting of actually building the pagination + # links. It is used by the will_paginate helper internally. + class LinkRenderer + + # The gap in page links is represented by: + # + # + attr_accessor :gap_marker + + def initialize + @gap_marker = '' + end + + # * +collection+ is a WillPaginate::Collection instance or any other object + # that conforms to that API + # * +options+ are forwarded from +will_paginate+ view helper + # * +template+ is the reference to the template being rendered + def prepare(collection, options, template) + @collection = collection + @options = options + @template = template + + # reset values in case we're re-using this instance + @total_pages = @param_name = @url_string = nil + end + + # Process it! This method returns the complete HTML string which contains + # pagination links. Feel free to subclass LinkRenderer and change this + # method as you see fit. + def to_html + links = @options[:page_links] ? windowed_links : [] + # previous/next buttons + links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label]) + links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label]) + + html = links.join(@options[:separator]) + html = html.html_safe if html.respond_to? :html_safe + @options[:container] ? @template.content_tag(:div, html, html_attributes) : html + end + + # Returns the subset of +options+ this instance was initialized with that + # represent HTML attributes for the container element of pagination links. + def html_attributes + return @html_attributes if @html_attributes + @html_attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class]) + # pagination of Post models will have the ID of "posts_pagination" + if @options[:container] and @options[:id] === true + @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination' + end + @html_attributes + end + + protected + + # Collects link items for visible page numbers. + def windowed_links + prev = nil + + visible_page_numbers.inject [] do |links, n| + # detect gaps: + links << gap_marker if prev and n > prev + 1 + links << page_link_or_span(n, 'current') + prev = n + links + end + end + + # Calculates visible page numbers using the :inner_window and + # :outer_window options. + def visible_page_numbers + inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i + window_from = current_page - inner_window + window_to = current_page + inner_window + + # adjust lower or upper limit if other is out of bounds + if window_to > total_pages + window_from -= window_to - total_pages + window_to = total_pages + end + if window_from < 1 + window_to += 1 - window_from + window_from = 1 + window_to = total_pages if window_to > total_pages + end + + visible = (1..total_pages).to_a + left_gap = (2 + outer_window)...window_from + right_gap = (window_to + 1)...(total_pages - outer_window) + visible -= left_gap.to_a if left_gap.last - left_gap.first > 1 + visible -= right_gap.to_a if right_gap.last - right_gap.first > 1 + + visible + end + + def page_link_or_span(page, span_class, text = nil) + text ||= page.to_s + text = text.html_safe if text.respond_to? :html_safe + + if page and page != current_page + classnames = span_class && span_class.index(' ') && span_class.split(' ', 2).last + page_link page, text, :rel => rel_value(page), :class => classnames + else + page_span page, text, :class => span_class + end + end + + def page_link(page, text, attributes = {}) + @template.link_to text, url_for(page), attributes + end + + def page_span(page, text, attributes = {}) + @template.content_tag :span, text, attributes + end + + # Returns URL params for +page_link_or_span+, taking the current GET params + # and :params option into account. + def url_for(page) + page_one = page == 1 + unless @url_string and !page_one + @url_params = {} + # page links should preserve GET parameters + stringified_merge @url_params, @template.params if @template.request.get? + stringified_merge @url_params, @options[:params] if @options[:params] + + if complex = param_name.index(/[^\w-]/) + page_param = parse_query_parameters("#{param_name}=#{page}") + + stringified_merge @url_params, page_param + else + @url_params[param_name] = page_one ? 1 : 2 + end + + url = @template.url_for(@url_params) + return url if page_one + + if complex + @url_string = url.sub(%r!((?:\?|&)#{CGI.escape param_name}=)#{page}!, "\\1\0") + return url + else + @url_string = url + @url_params[param_name] = 3 + @template.url_for(@url_params).split(//).each_with_index do |char, i| + if char == '3' and url[i, 1] == '2' + @url_string[i] = "\0" + break + end + end + end + end + # finally! + @url_string.sub "\0", page.to_s + end + + private + + def rel_value(page) + case page + when @collection.previous_page; 'prev' + (page == 1 ? ' start' : '') + when @collection.next_page; 'next' + when 1; 'start' + end + end + + def current_page + @collection.current_page + end + + def total_pages + @total_pages ||= WillPaginate::ViewHelpers.total_pages_for_collection(@collection) + end + + def param_name + @param_name ||= @options[:param_name].to_s + end + + # Recursively merge into target hash by using stringified keys from the other one + def stringified_merge(target, other) + other.each do |key, value| + key = key.to_s # this line is what it's all about! + existing = target[key] + + if value.is_a?(Hash) and (existing.is_a?(Hash) or existing.nil?) + stringified_merge(existing || (target[key] = {}), value) + else + target[key] = value + end + end + end + + def parse_query_parameters(params) + if defined? Rack::Utils + # For Rails > 2.3 + Rack::Utils.parse_nested_query(params) + elsif defined?(ActionController::AbstractRequest) + ActionController::AbstractRequest.parse_query_parameters(params) + elsif defined?(ActionController::UrlEncodedPairParser) + # For Rails > 2.2 + ActionController::UrlEncodedPairParser.parse_query_parameters(params) + elsif defined?(CGIMethods) + CGIMethods.parse_query_parameters(params) + else + raise "unsupported ActionPack version" + end + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/boot.rb b/vendor/gems/will_paginate-2.3.15/test/boot.rb new file mode 100644 index 00000000..5344b079 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/boot.rb @@ -0,0 +1,21 @@ +plugin_root = File.join(File.dirname(__FILE__), '..') +version = ENV['RAILS_VERSION'] +version = nil if version and version == "" + +# first look for a symlink to a copy of the framework +if !version and framework_root = ["#{plugin_root}/rails", "#{plugin_root}/../../rails"].find { |p| File.directory? p } + puts "found framework root: #{framework_root}" + # this allows for a plugin to be tested outside of an app and without Rails gems + $:.unshift "#{framework_root}/activesupport/lib", "#{framework_root}/activerecord/lib", "#{framework_root}/actionpack/lib" +else + # simply use installed gems if available + puts "using Rails#{version ? ' ' + version : nil} gems" + require 'rubygems' + + if version + gem 'rails', version + else + gem 'actionpack', '< 3.0.0.a' + gem 'activerecord', '< 3.0.0.a' + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/collection_test.rb b/vendor/gems/will_paginate-2.3.15/test/collection_test.rb new file mode 100644 index 00000000..a9336bbe --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/collection_test.rb @@ -0,0 +1,143 @@ +require 'helper' +require 'will_paginate/array' + +class ArrayPaginationTest < Test::Unit::TestCase + + def setup ; end + + def test_simple + collection = ('a'..'e').to_a + + [{ :page => 1, :per_page => 3, :expected => %w( a b c ) }, + { :page => 2, :per_page => 3, :expected => %w( d e ) }, + { :page => 1, :per_page => 5, :expected => %w( a b c d e ) }, + { :page => 3, :per_page => 5, :expected => [] }, + ]. + each do |conditions| + expected = conditions.delete :expected + assert_equal expected, collection.paginate(conditions) + end + end + + def test_defaults + result = (1..50).to_a.paginate + assert_equal 1, result.current_page + assert_equal 30, result.size + end + + def test_deprecated_api + assert_raise(ArgumentError) { [].paginate(2) } + assert_raise(ArgumentError) { [].paginate(2, 10) } + end + + def test_total_entries_has_precedence + result = %w(a b c).paginate :total_entries => 5 + assert_equal 5, result.total_entries + end + + def test_argument_error_with_params_and_another_argument + assert_raise ArgumentError do + [].paginate({}, 5) + end + end + + def test_paginated_collection + entries = %w(a b c) + collection = create(2, 3, 10) do |pager| + assert_equal entries, pager.replace(entries) + end + + assert_equal entries, collection + assert_respond_to_all collection, %w(total_pages each offset size current_page per_page total_entries) + assert_kind_of Array, collection + assert_instance_of Array, collection.entries + assert_equal 3, collection.offset + assert_equal 4, collection.total_pages + assert !collection.out_of_bounds? + end + + def test_previous_next_pages + collection = create(1, 1, 3) + assert_nil collection.previous_page + assert_equal 2, collection.next_page + + collection = create(2, 1, 3) + assert_equal 1, collection.previous_page + assert_equal 3, collection.next_page + + collection = create(3, 1, 3) + assert_equal 2, collection.previous_page + assert_nil collection.next_page + end + + def test_out_of_bounds + entries = create(2, 3, 2){} + assert entries.out_of_bounds? + + entries = create(1, 3, 2){} + assert !entries.out_of_bounds? + end + + def test_guessing_total_count + entries = create do |pager| + # collection is shorter than limit + pager.replace array + end + assert_equal 8, entries.total_entries + + entries = create(2, 5, 10) do |pager| + # collection is shorter than limit, but we have an explicit count + pager.replace array + end + assert_equal 10, entries.total_entries + + entries = create do |pager| + # collection is the same as limit; we can't guess + pager.replace array(5) + end + assert_equal nil, entries.total_entries + + entries = create do |pager| + # collection is empty; we can't guess + pager.replace array(0) + end + assert_equal nil, entries.total_entries + + entries = create(1) do |pager| + # collection is empty and we're on page 1, + # so the whole thing must be empty, too + pager.replace array(0) + end + assert_equal 0, entries.total_entries + end + + def test_invalid_page + bad_inputs = [0, -1, nil, '', 'Schnitzel'] + + bad_inputs.each do |bad| + assert_raise(WillPaginate::InvalidPage) { create bad } + end + end + + def test_invalid_per_page_setting + assert_raise(ArgumentError) { create(1, -1) } + end + + def test_page_count_was_removed + assert_raise(NoMethodError) { create.page_count } + # It's `total_pages` now. + end + + private + def create(page = 2, limit = 5, total = nil, &block) + if block_given? + WillPaginate::Collection.create(page, limit, total, &block) + else + WillPaginate::Collection.new(page, limit, total) + end + end + + def array(size = 3) + Array.new(size) + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/console b/vendor/gems/will_paginate-2.3.15/test/console new file mode 100755 index 00000000..3f282f11 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/console @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' +libs = [] + +libs << 'irb/completion' +libs << File.join('lib', 'load_fixtures') + +exec "#{irb} -Ilib:test#{libs.map{ |l| " -r #{l}" }.join} --simple-prompt" diff --git a/vendor/gems/will_paginate-2.3.15/test/database.yml b/vendor/gems/will_paginate-2.3.15/test/database.yml new file mode 100644 index 00000000..b2794c3e --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/database.yml @@ -0,0 +1,22 @@ +sqlite3: + database: ":memory:" + adapter: sqlite3 + timeout: 500 + +sqlite2: + database: ":memory:" + adapter: sqlite2 + +mysql: + adapter: mysql + username: root + password: + encoding: utf8 + database: will_paginate_unittest + +postgres: + adapter: postgresql + username: mislav + password: + database: will_paginate_unittest + min_messages: warning diff --git a/vendor/gems/will_paginate-2.3.15/test/finder_test.rb b/vendor/gems/will_paginate-2.3.15/test/finder_test.rb new file mode 100644 index 00000000..9e1381a3 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/finder_test.rb @@ -0,0 +1,496 @@ +require 'helper' +require 'lib/activerecord_test_case' + +require 'will_paginate' +WillPaginate.enable_activerecord +WillPaginate.enable_named_scope + +class FinderTest < ActiveRecordTestCase + fixtures :topics, :replies, :users, :projects, :developers_projects + + def test_new_methods_presence + assert_respond_to_all Topic, %w(per_page paginate paginate_by_sql paginate_by_definition_in_class) + end + + def test_simple_paginate + assert_queries(1) do + entries = Topic.paginate :page => nil + assert_equal 1, entries.current_page + assert_equal 1, entries.total_pages + assert_equal 4, entries.size + end + + assert_queries(2) do + entries = Topic.paginate :page => 2 + assert_equal 1, entries.total_pages + assert entries.empty? + end + end + + def test_parameter_api + # :page parameter in options is required! + assert_raise(ArgumentError){ Topic.paginate } + assert_raise(ArgumentError){ Topic.paginate({}) } + + # explicit :all should not break anything + assert_equal Topic.paginate(:page => nil), Topic.paginate(:all, :page => 1) + + # :count could be nil and we should still not cry + assert_nothing_raised { Topic.paginate :page => 1, :count => nil } + end + + def test_counting_when_integer_has_length_method + Integer.module_eval { def length; to_s.length; end } + begin + assert_equal 2, 11.length + entries = Developer.paginate :page => 1, :per_page => 5 + assert_equal 11, entries.total_entries + assert_equal 5, entries.size + assert_equal 3, entries.total_pages + ensure + begin + Integer.module_eval { remove_method :length } + rescue + end + end + end + + def test_paginate_with_per_page + entries = Topic.paginate :page => 1, :per_page => 1 + assert_equal 1, entries.size + assert_equal 4, entries.total_pages + + # Developer class has explicit per_page at 10 + entries = Developer.paginate :page => 1 + assert_equal 10, entries.size + assert_equal 2, entries.total_pages + + entries = Developer.paginate :page => 1, :per_page => 5 + assert_equal 11, entries.total_entries + assert_equal 5, entries.size + assert_equal 3, entries.total_pages + end + + def test_paginate_with_order + entries = Topic.paginate :page => 1, :order => 'created_at desc' + expected = [topics(:futurama), topics(:harvey_birdman), topics(:rails), topics(:ar)].reverse + assert_equal expected, entries.to_a + assert_equal 1, entries.total_pages + end + + def test_paginate_with_conditions + entries = Topic.paginate :page => 1, :conditions => ["created_at > ?", 30.minutes.ago] + expected = [topics(:rails), topics(:ar)] + assert_equal expected, entries.to_a + assert_equal 1, entries.total_pages + end + + def test_paginate_with_include_and_conditions + entries = Topic.paginate \ + :page => 1, + :include => :replies, + :conditions => "replies.content LIKE 'Bird%' ", + :per_page => 10 + + expected = Topic.find :all, + :include => 'replies', + :conditions => "replies.content LIKE 'Bird%' ", + :limit => 10 + + assert_equal expected, entries.to_a + assert_equal 1, entries.total_entries + end + + def test_paginate_with_include_and_order + entries = nil + assert_queries(2) do + entries = Topic.paginate \ + :page => 1, + :include => :replies, + :order => 'replies.created_at asc, topics.created_at asc', + :per_page => 10 + end + + expected = Topic.find :all, + :include => 'replies', + :order => 'replies.created_at asc, topics.created_at asc', + :limit => 10 + + assert_equal expected, entries.to_a + assert_equal 4, entries.total_entries + end + + def test_paginate_associations_with_include + entries, project = nil, projects(:active_record) + + assert_nothing_raised "THIS IS A BUG in Rails 1.2.3 that was fixed in [7326]. " + + "Please upgrade to a newer version of Rails." do + entries = project.topics.paginate \ + :page => 1, + :include => :replies, + :conditions => "replies.content LIKE 'Nice%' ", + :per_page => 10 + end + + expected = Topic.find :all, + :include => 'replies', + :conditions => "project_id = #{project.id} AND replies.content LIKE 'Nice%' ", + :limit => 10 + + assert_equal expected, entries.to_a + end + + def test_paginate_associations + dhh = users :david + expected_name_ordered = [projects(:action_controller), projects(:active_record)] + expected_id_ordered = [projects(:active_record), projects(:action_controller)] + + assert_queries(2) do + # with association-specified order + entries = dhh.projects.paginate(:page => 1) + assert_equal expected_name_ordered, entries + assert_equal 2, entries.total_entries + end + + # with explicit order + entries = dhh.projects.paginate(:page => 1, :order => 'projects.id') + assert_equal expected_id_ordered, entries + assert_equal 2, entries.total_entries + + assert_nothing_raised { dhh.projects.find(:all, :order => 'projects.id', :limit => 4) } + entries = dhh.projects.paginate(:page => 1, :order => 'projects.id', :per_page => 4) + assert_equal expected_id_ordered, entries + + # has_many with implicit order + topic = Topic.find(1) + expected = [replies(:spam), replies(:witty_retort)] + assert_equal expected.map(&:id).sort, topic.replies.paginate(:page => 1).map(&:id).sort + assert_equal expected.reverse, topic.replies.paginate(:page => 1, :order => 'replies.id ASC') + end + + def test_paginate_association_extension + project = Project.find(:first) + + assert_queries(2) do + entries = project.replies.paginate_recent :page => 1 + assert_equal [replies(:brave)], entries + end + end + + def test_paginate_with_joins + entries = nil + + assert_queries(1) do + entries = Developer.paginate :page => 1, + :joins => 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id', + :conditions => 'project_id = 1' + assert_equal 2, entries.size + developer_names = entries.map &:name + assert developer_names.include?('David') + assert developer_names.include?('Jamis') + end + + assert_queries(1) do + expected = entries.to_a + entries = Developer.paginate :page => 1, + :joins => 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id', + :conditions => 'project_id = 1', :count => { :select => "users.id" } + assert_equal expected, entries.to_a + assert_equal 2, entries.total_entries + end + end + + def test_paginate_with_group + entries = nil + assert_queries(1) do + entries = Developer.paginate :page => 1, :per_page => 10, + :group => 'salary', :select => 'salary', :order => 'salary' + end + + expected = [ users(:david), users(:jamis), users(:dev_10), users(:poor_jamis) ].map(&:salary).sort + assert_equal expected, entries.map(&:salary) + end + + def test_paginate_with_dynamic_finder + expected = [replies(:witty_retort), replies(:spam)] + assert_equal expected, Reply.paginate_by_topic_id(1, :page => 1, :order => :created_at) + + entries = Developer.paginate :conditions => { :salary => 100000 }, :page => 1, :per_page => 5 + assert_equal 8, entries.total_entries + assert_equal entries, Developer.paginate_by_salary(100000, :page => 1, :per_page => 5) + + # dynamic finder + conditions + entries = Developer.paginate_by_salary(100000, :page => 1, + :conditions => ['id > ?', 6]) + assert_equal 4, entries.total_entries + assert_equal (7..10).to_a, entries.map(&:id) + + assert_raises NoMethodError do + Developer.paginate_by_inexistent_attribute 100000, :page => 1 + end + end + + def test_scoped_paginate + entries = Developer.with_poor_ones { Developer.paginate :page => 1 } + + assert_equal 2, entries.size + assert_equal 2, entries.total_entries + end + + ## named_scope ## + + def test_paginate_in_named_scope + entries = Developer.poor.paginate :page => 1, :per_page => 1 + + assert_equal 1, entries.size + assert_equal 2, entries.total_entries + end + + def test_paginate_in_named_scope_on_habtm_association + project = projects(:active_record) + assert_queries(2) do + entries = project.developers.poor.paginate :page => 1, :per_page => 1 + + assert_equal 1, entries.size, 'one developer should be found' + assert_equal 1, entries.total_entries, 'only one developer should be found' + end + end + + def test_paginate_in_named_scope_on_hmt_association + project = projects(:active_record) + expected = [replies(:brave)] + + assert_queries(2) do + entries = project.replies.recent.paginate :page => 1, :per_page => 1 + assert_equal expected, entries + assert_equal 1, entries.total_entries, 'only one reply should be found' + end + end + + def test_paginate_in_named_scope_on_has_many_association + project = projects(:active_record) + expected = [topics(:ar)] + + assert_queries(2) do + entries = project.topics.mentions_activerecord.paginate :page => 1, :per_page => 1 + assert_equal expected, entries + assert_equal 1, entries.total_entries, 'only one topic should be found' + end + end + + def test_named_scope_with_include + project = projects(:active_record) + entries = project.topics.with_replies_starting_with('AR ').paginate(:page => 1, :per_page => 1) + assert_equal 1, entries.size + end + + ## misc ## + + def test_count_and_total_entries_options_are_mutually_exclusive + e = assert_raise ArgumentError do + Developer.paginate :page => 1, :count => {}, :total_entries => 1 + end + assert_match /exclusive/, e.to_s + end + + def test_readonly + assert_nothing_raised { Developer.paginate :readonly => true, :page => 1 } + end + + # this functionality is temporarily removed + def xtest_pagination_defines_method + pager = "paginate_by_created_at" + assert !User.methods.include_method?(pager), "User methods should not include `#{pager}` method" + # paginate! + assert 0, User.send(pager, nil, :page => 1).total_entries + # the paging finder should now be defined + assert User.methods.include_method?(pager), "`#{pager}` method should be defined on User" + end + + # Is this Rails 2.0? Find out by testing find_all which was removed in [6998] + unless ActiveRecord::Base.respond_to? :find_all + def test_paginate_array_of_ids + # AR finders also accept arrays of IDs + # (this was broken in Rails before [6912]) + assert_queries(1) do + entries = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2, :order => 'id') + assert_equal (4..6).to_a, entries.map(&:id) + assert_equal 8, entries.total_entries + end + end + end + + uses_mocha 'internals' do + def test_implicit_all_with_dynamic_finders + Topic.expects(:find_all_by_foo).returns([]) + Topic.expects(:count).returns(0) + Topic.paginate_by_foo :page => 2 + end + + def test_guessing_the_total_count + Topic.expects(:find).returns(Array.new(2)) + Topic.expects(:count).never + + entries = Topic.paginate :page => 2, :per_page => 4 + assert_equal 6, entries.total_entries + end + + def test_guessing_that_there_are_no_records + Topic.expects(:find).returns([]) + Topic.expects(:count).never + + entries = Topic.paginate :page => 1, :per_page => 4 + assert_equal 0, entries.total_entries + end + + def test_extra_parameters_stay_untouched + Topic.expects(:find).with(:all, {:foo => 'bar', :limit => 4, :offset => 0 }).returns(Array.new(5)) + Topic.expects(:count).with({:foo => 'bar'}).returns(1) + + Topic.paginate :foo => 'bar', :page => 1, :per_page => 4 + end + + def test_count_skips_select + Developer.stubs(:find).returns([]) + Developer.expects(:count).with({}).returns(0) + Developer.paginate :select => 'salary', :page => 2 + end + + def test_count_select_when_distinct + Developer.stubs(:find).returns([]) + Developer.expects(:count).with(:select => 'DISTINCT salary').returns(0) + Developer.paginate :select => 'DISTINCT salary', :page => 2 + end + + def test_count_with_scoped_select_when_distinct + Developer.stubs(:find).returns([]) + Developer.expects(:count).with(:select => 'DISTINCT users.id').returns(0) + Developer.distinct.paginate :page => 2 + end + + def test_should_use_scoped_finders_if_present + # scope-out compatibility + Topic.expects(:find_best).returns(Array.new(5)) + Topic.expects(:with_best).returns(1) + + Topic.paginate_best :page => 1, :per_page => 4 + end + + def test_paginate_by_sql + sql = "SELECT * FROM users WHERE type = 'Developer' ORDER BY id" + entries = Developer.paginate_by_sql(sql, :page => 2, :per_page => 3) + assert_equal 11, entries.total_entries + assert_equal [users(:dev_4), users(:dev_5), users(:dev_6)], entries + end + + def test_paginate_by_sql_respects_total_entries_setting + sql = "SELECT * FROM users" + entries = Developer.paginate_by_sql(sql, :page => 1, :total_entries => 999) + assert_equal 999, entries.total_entries + end + + def test_paginate_by_sql_strips_order_by_when_counting + Developer.expects(:find_by_sql).returns([]) + Developer.expects(:count_by_sql).with("SELECT COUNT(*) FROM (sql\n ) AS count_table").returns(0) + + Developer.paginate_by_sql "sql\n ORDER\nby foo, bar, `baz` ASC", :page => 2 + end + + # TODO: counts are still wrong + def test_ability_to_use_with_custom_finders + # acts_as_taggable defines find_tagged_with(tag, options) + Topic.expects(:find_tagged_with).with('will_paginate', :offset => 5, :limit => 5).returns([]) + Topic.expects(:count).with({}).returns(0) + + Topic.paginate_tagged_with 'will_paginate', :page => 2, :per_page => 5 + end + + def test_array_argument_doesnt_eliminate_count + ids = (1..8).to_a + Developer.expects(:find_all_by_id).returns([]) + Developer.expects(:count).returns(0) + + Developer.paginate_by_id(ids, :per_page => 3, :page => 2, :order => 'id') + end + + def test_paginating_finder_doesnt_mangle_options + Developer.expects(:find).returns([]) + options = { :page => 1, :per_page => 2, :foo => 'bar' } + options_before = options.dup + + Developer.paginate(options) + assert_equal options_before, options + end + + def test_paginate_by_sql_doesnt_change_original_query + query = 'SQL QUERY' + original_query = query.dup + Developer.expects(:find_by_sql).returns([]) + + Developer.paginate_by_sql query, :page => 1 + assert_equal original_query, query + end + + def test_paginated_each + collection = stub('collection', :size => 5, :empty? => false, :per_page => 5) + collection.expects(:each).times(2).returns(collection) + last_collection = stub('collection', :size => 4, :empty? => false, :per_page => 5) + last_collection.expects(:each).returns(last_collection) + + params = { :order => 'id', :total_entries => 0 } + + Developer.expects(:paginate).with(params.merge(:page => 2)).returns(collection) + Developer.expects(:paginate).with(params.merge(:page => 3)).returns(collection) + Developer.expects(:paginate).with(params.merge(:page => 4)).returns(last_collection) + + assert_equal 14, Developer.paginated_each(:page => '2') { } + end + + def test_paginated_each_with_named_scope + assert_equal 2, Developer.poor.paginated_each(:per_page => 1) { + assert_equal 11, Developer.count + } + end + + # detect ActiveRecord 2.1 + if ActiveRecord::Base.private_methods.include_method?(:references_eager_loaded_tables?) + def test_removes_irrelevant_includes_in_count + Developer.expects(:find).returns([1]) + Developer.expects(:count).with({}).returns(0) + + Developer.paginate :page => 1, :per_page => 1, :include => :projects + end + + def test_doesnt_remove_referenced_includes_in_count + Developer.expects(:find).returns([1]) + Developer.expects(:count).with({ :include => :projects, :conditions => 'projects.id > 2' }).returns(0) + + Developer.paginate :page => 1, :per_page => 1, + :include => :projects, :conditions => 'projects.id > 2' + end + end + + def test_paginate_from + result = Developer.paginate(:from => 'users', :page => 1, :per_page => 1) + assert_equal 1, result.size + end + + def test_hmt_with_include + # ticket #220 + reply = projects(:active_record).replies.find(:first, :order => 'replies.id') + assert_equal replies(:decisive), reply + + # ticket #223 + Project.find(1, :include => :replies) + + # I cannot reproduce any of the failures from those reports :( + end + + def test_hmt_with_uniq + project = Project.find(1) + result = project.unique_replies.paginate :page => 1, :per_page => 1, + :order => 'replies.id' + assert_equal replies(:decisive), result.first + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/admin.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/admin.rb new file mode 100644 index 00000000..1d5e7f36 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/admin.rb @@ -0,0 +1,3 @@ +class Admin < User + has_many :companies, :finder_sql => 'SELECT * FROM companies' +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/developer.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/developer.rb new file mode 100644 index 00000000..0224f4bf --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/developer.rb @@ -0,0 +1,14 @@ +class Developer < User + has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name' + + def self.with_poor_ones(&block) + with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do + yield + end + end + + named_scope :distinct, :select => 'DISTINCT `users`.*' + named_scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary' + + def self.per_page() 10 end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/developers_projects.yml b/vendor/gems/will_paginate-2.3.15/test/fixtures/developers_projects.yml new file mode 100644 index 00000000..cee359c7 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/developers_projects.yml @@ -0,0 +1,13 @@ +david_action_controller: + developer_id: 1 + project_id: 2 + joined_on: 2004-10-10 + +david_active_record: + developer_id: 1 + project_id: 1 + joined_on: 2004-10-10 + +jamis_active_record: + developer_id: 2 + project_id: 1 \ No newline at end of file diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/project.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/project.rb new file mode 100644 index 00000000..7f6d72cd --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/project.rb @@ -0,0 +1,17 @@ +class Project < ActiveRecord::Base + has_and_belongs_to_many :developers, :uniq => true + + has_many :topics + # :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})', + # :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = #{id})' + + has_many :replies, :through => :topics do + def find_recent(params = {}) + with_scope :find => { :conditions => ['replies.created_at > ?', 15.minutes.ago] } do + find :all, params + end + end + end + + has_many :unique_replies, :through => :topics, :source => :replies, :uniq => true +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/projects.yml b/vendor/gems/will_paginate-2.3.15/test/fixtures/projects.yml new file mode 100644 index 00000000..74f3c32f --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/projects.yml @@ -0,0 +1,6 @@ +active_record: + id: 1 + name: Active Record +action_controller: + id: 2 + name: Active Controller diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/replies.yml b/vendor/gems/will_paginate-2.3.15/test/fixtures/replies.yml new file mode 100644 index 00000000..9a83c004 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/replies.yml @@ -0,0 +1,29 @@ +witty_retort: + id: 1 + topic_id: 1 + content: Birdman is better! + created_at: <%= 6.hours.ago.to_s(:db) %> + +another: + id: 2 + topic_id: 2 + content: Nuh uh! + created_at: <%= 1.hour.ago.to_s(:db) %> + +spam: + id: 3 + topic_id: 1 + content: Nice site! + created_at: <%= 1.hour.ago.to_s(:db) %> + +decisive: + id: 4 + topic_id: 4 + content: "I'm getting to the bottom of this" + created_at: <%= 30.minutes.ago.to_s(:db) %> + +brave: + id: 5 + topic_id: 4 + content: "AR doesn't scare me a bit" + created_at: <%= 10.minutes.ago.to_s(:db) %> diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/reply.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/reply.rb new file mode 100644 index 00000000..ecaf3c1f --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/reply.rb @@ -0,0 +1,7 @@ +class Reply < ActiveRecord::Base + belongs_to :topic, :include => [:replies] + + named_scope :recent, :conditions => ['replies.created_at > ?', 15.minutes.ago] + + validates_presence_of :content +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/schema.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/schema.rb new file mode 100644 index 00000000..8831aad2 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/schema.rb @@ -0,0 +1,38 @@ +ActiveRecord::Schema.define do + + create_table "users", :force => true do |t| + t.column "name", :text + t.column "salary", :integer, :default => 70000 + t.column "created_at", :datetime + t.column "updated_at", :datetime + t.column "type", :text + end + + create_table "projects", :force => true do |t| + t.column "name", :text + end + + create_table "developers_projects", :id => false, :force => true do |t| + t.column "developer_id", :integer, :null => false + t.column "project_id", :integer, :null => false + t.column "joined_on", :date + t.column "access_level", :integer, :default => 1 + end + + create_table "topics", :force => true do |t| + t.column "project_id", :integer + t.column "title", :string + t.column "subtitle", :string + t.column "content", :text + t.column "created_at", :datetime + t.column "updated_at", :datetime + end + + create_table "replies", :force => true do |t| + t.column "content", :text + t.column "created_at", :datetime + t.column "updated_at", :datetime + t.column "topic_id", :integer + end + +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/topic.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/topic.rb new file mode 100644 index 00000000..2dd94955 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/topic.rb @@ -0,0 +1,12 @@ +class Topic < ActiveRecord::Base + has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC' + belongs_to :project + + named_scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%'] + + named_scope :with_replies_starting_with, lambda { |text| + { :conditions => "replies.content LIKE '#{text}%' ", :include => :replies } + } + + def self.paginate_by_definition_in_class; end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/topics.yml b/vendor/gems/will_paginate-2.3.15/test/fixtures/topics.yml new file mode 100644 index 00000000..0a269047 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/topics.yml @@ -0,0 +1,30 @@ +futurama: + id: 1 + title: Isnt futurama awesome? + subtitle: It really is, isnt it. + content: I like futurama + created_at: <%= 1.day.ago.to_s(:db) %> + updated_at: + +harvey_birdman: + id: 2 + title: Harvey Birdman is the king of all men + subtitle: yup + content: He really is + created_at: <%= 2.hours.ago.to_s(:db) %> + updated_at: + +rails: + id: 3 + project_id: 1 + title: Rails is nice + subtitle: It makes me happy + content: except when I have to hack internals to fix pagination. even then really. + created_at: <%= 20.minutes.ago.to_s(:db) %> + +ar: + id: 4 + project_id: 1 + title: ActiveRecord sometimes freaks me out + content: "I mean, what's the deal with eager loading?" + created_at: <%= 15.minutes.ago.to_s(:db) %> diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/user.rb b/vendor/gems/will_paginate-2.3.15/test/fixtures/user.rb new file mode 100644 index 00000000..4a57cf07 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/user.rb @@ -0,0 +1,2 @@ +class User < ActiveRecord::Base +end diff --git a/vendor/gems/will_paginate-2.3.15/test/fixtures/users.yml b/vendor/gems/will_paginate-2.3.15/test/fixtures/users.yml new file mode 100644 index 00000000..ed2c03ae --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/fixtures/users.yml @@ -0,0 +1,35 @@ +david: + id: 1 + name: David + salary: 80000 + type: Developer + +jamis: + id: 2 + name: Jamis + salary: 150000 + type: Developer + +<% for digit in 3..10 %> +dev_<%= digit %>: + id: <%= digit %> + name: fixture_<%= digit %> + salary: 100000 + type: Developer +<% end %> + +poor_jamis: + id: 11 + name: Jamis + salary: 9000 + type: Developer + +admin: + id: 12 + name: admin + type: Admin + +goofy: + id: 13 + name: Goofy + type: Admin diff --git a/vendor/gems/will_paginate-2.3.15/test/helper.rb b/vendor/gems/will_paginate-2.3.15/test/helper.rb new file mode 100644 index 00000000..7b55af59 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/helper.rb @@ -0,0 +1,37 @@ +require 'test/unit' +require 'rubygems' + +# gem install redgreen for colored test output +begin require 'redgreen'; rescue LoadError; end + +require 'boot' unless defined?(ActiveRecord) + +class Test::Unit::TestCase + protected + def assert_respond_to_all object, methods + methods.each do |method| + [method.to_s, method.to_sym].each { |m| assert_respond_to object, m } + end + end + + def collect_deprecations + old_behavior = WillPaginate::Deprecation.behavior + deprecations = [] + WillPaginate::Deprecation.behavior = Proc.new do |message, callstack| + deprecations << message + end + result = yield + [result, deprecations] + ensure + WillPaginate::Deprecation.behavior = old_behavior + end +end + +# Wrap tests that use Mocha and skip if unavailable. +def uses_mocha(test_name) + require 'mocha' +rescue LoadError + $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." +else + yield +end diff --git a/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_case.rb b/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_case.rb new file mode 100644 index 00000000..72a6b16e --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_case.rb @@ -0,0 +1,43 @@ +require 'lib/activerecord_test_connector' + +class ActiveRecordTestCase < Test::Unit::TestCase + if defined?(ActiveSupport::Testing::SetupAndTeardown) + include ActiveSupport::Testing::SetupAndTeardown + end + + if defined?(ActiveRecord::TestFixtures) + include ActiveRecord::TestFixtures + end + # Set our fixture path + if ActiveRecordTestConnector.able_to_connect + self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures') + self.use_transactional_fixtures = true + end + + def self.fixtures(*args) + super if ActiveRecordTestConnector.connected + end + + def run(*args) + super if ActiveRecordTestConnector.connected + end + + # Default so Test::Unit::TestCase doesn't complain + def test_truth + end + + protected + + def assert_queries(num = 1) + $query_count = 0 + yield + ensure + assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed." + end + + def assert_no_queries(&block) + assert_queries(0, &block) + end +end + +ActiveRecordTestConnector.setup diff --git a/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_connector.rb b/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_connector.rb new file mode 100644 index 00000000..d3e80e6e --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/lib/activerecord_test_connector.rb @@ -0,0 +1,76 @@ +require 'active_record' +require 'active_record/version' +require 'active_record/fixtures' + +class ActiveRecordTestConnector + cattr_accessor :able_to_connect + cattr_accessor :connected + + FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures') + + # Set our defaults + self.connected = false + self.able_to_connect = true + + def self.setup + unless self.connected || !self.able_to_connect + setup_connection + load_schema + add_load_path FIXTURES_PATH + self.connected = true + end + rescue Exception => e # errors from ActiveRecord setup + $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n" + self.able_to_connect = false + end + + private + + def self.add_load_path(path) + dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies + autoload_paths = dep.respond_to?(:autoload_paths) ? dep.autoload_paths : dep.load_paths + autoload_paths.unshift path + end + + def self.setup_connection + db = ENV['DB'].blank?? 'sqlite3' : ENV['DB'] + + configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml')) + raise "no configuration for '#{db}'" unless configurations.key? db + configuration = configurations[db] + + ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb' + puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank? + + gem 'sqlite3-ruby' if 'sqlite3' == db + + ActiveRecord::Base.establish_connection(configuration) + ActiveRecord::Base.configurations = { db => configuration } + prepare ActiveRecord::Base.connection + + unless Object.const_defined?(:QUOTED_TYPE) + Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type') + end + end + + def self.load_schema + ActiveRecord::Base.silence do + ActiveRecord::Migration.verbose = false + load File.join(FIXTURES_PATH, 'schema.rb') + end + end + + def self.prepare(conn) + class << conn + IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /] + + def execute_with_counting(sql, name = nil, &block) + $query_count ||= 0 + $query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r } + execute_without_counting(sql, name, &block) + end + + alias_method_chain :execute, :counting + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/lib/load_fixtures.rb b/vendor/gems/will_paginate-2.3.15/test/lib/load_fixtures.rb new file mode 100644 index 00000000..10d6f420 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/lib/load_fixtures.rb @@ -0,0 +1,11 @@ +require 'boot' +require 'lib/activerecord_test_connector' + +# setup the connection +ActiveRecordTestConnector.setup + +# load all fixtures +Fixtures.create_fixtures(ActiveRecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables) + +require 'will_paginate' +WillPaginate.enable_activerecord diff --git a/vendor/gems/will_paginate-2.3.15/test/lib/view_test_process.rb b/vendor/gems/will_paginate-2.3.15/test/lib/view_test_process.rb new file mode 100644 index 00000000..8da1b71c --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/lib/view_test_process.rb @@ -0,0 +1,179 @@ +require 'will_paginate/core_ext' +require 'action_controller' +require 'action_controller/test_process' + +require 'will_paginate' +WillPaginate.enable_actionpack + +ActionController::Routing::Routes.draw do |map| + map.connect 'dummy/page/:page', :controller => 'dummy' + map.connect 'dummy/dots/page.:page', :controller => 'dummy', :action => 'dots' + map.connect 'ibocorp/:page', :controller => 'ibocorp', + :requirements => { :page => /\d+/ }, + :defaults => { :page => 1 } + + map.connect ':controller/:action/:id' +end + +ActionController::Base.perform_caching = false + +class WillPaginate::ViewTestCase < Test::Unit::TestCase + if defined?(ActionController::TestCase::Assertions) + include ActionController::TestCase::Assertions + end + if defined?(ActiveSupport::Testing::Deprecation) + include ActiveSupport::Testing::Deprecation + end + + def setup + super + @controller = DummyController.new + @request = @controller.request + @html_result = nil + @template = '<%= will_paginate collection, options %>' + + @view = ActionView::Base.new + @view.assigns['controller'] = @controller + @view.assigns['_request'] = @request + @view.assigns['_params'] = @request.params + end + + def test_no_complain; end + + protected + + def paginate(collection = {}, options = {}, &block) + if collection.instance_of? Hash + page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection) + collection = [1].paginate(page_options) + end + + locals = { :collection => collection, :options => options } + + unless @view.respond_to? :render_template + # Rails 2.2 + @html_result = ActionView::InlineTemplate.new(@template).render(@view, locals) + else + if defined? ActionView::InlineTemplate + # Rails 2.1 + args = [ ActionView::InlineTemplate.new(@view, @template, locals) ] + else + # older Rails versions + args = [nil, @template, nil, locals] + end + + @html_result = @view.render_template(*args) + end + + @html_document = HTML::Document.new(@html_result, true, false) + + if block_given? + classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class] + assert_select("div.#{classname}", 1, 'no main DIV', &block) + end + end + + def response_from_page_or_rjs + @html_document.root + end + + def validate_page_numbers expected, links, param_name = :page + param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/ + + assert_equal(expected, links.map { |e| + e['href'] =~ param_pattern + $1 ? $1.to_i : $1 + }) + end + + def assert_links_match pattern, links = nil, numbers = nil + links ||= assert_select 'div.pagination a[href]' do |elements| + elements + end + + pages = [] if numbers + + links.each do |el| + assert_match pattern, el['href'] + if numbers + el['href'] =~ pattern + pages << ($1.nil?? nil : $1.to_i) + end + end + + assert_equal numbers, pages, "page numbers don't match" if numbers + end + + def assert_no_links_match pattern + assert_select 'div.pagination a[href]' do |elements| + elements.each do |el| + assert_no_match pattern, el['href'] + end + end + end +end + +class DummyRequest + attr_accessor :symbolized_path_parameters + + def initialize + @get = true + @params = {} + @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' } + end + + def get? + @get + end + + def post + @get = false + end + + def relative_url_root + '' + end + + def params(more = nil) + @params.update(more) if more + @params + end +end + +class DummyController + attr_reader :request + attr_accessor :controller_name + + def initialize + @request = DummyRequest.new + @url = ActionController::UrlRewriter.new(@request, @request.params) + end + + def params + @request.params + end + + def url_for(params) + @url.rewrite(params) + end +end + +module HTML + Node.class_eval do + def inner_text + children.map(&:inner_text).join('') + end + end + + Text.class_eval do + def inner_text + self.to_s + end + end + + Tag.class_eval do + def inner_text + childless?? '' : super + end + end +end diff --git a/vendor/gems/will_paginate-2.3.15/test/tasks.rake b/vendor/gems/will_paginate-2.3.15/test/tasks.rake new file mode 100644 index 00000000..a0453e60 --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/tasks.rake @@ -0,0 +1,59 @@ +require 'rake/testtask' + +desc 'Test the will_paginate plugin.' +Rake::TestTask.new(:test) do |t| + t.pattern = 'test/**/*_test.rb' + t.verbose = true + t.libs << 'test' +end + +# I want to specify environment variables at call time +class EnvTestTask < Rake::TestTask + attr_accessor :env + + def ruby(*args) + env.each { |key, value| ENV[key] = value } if env + super + env.keys.each { |key| ENV.delete key } if env + end +end + +for configuration in %w( sqlite3 mysql postgres ) + EnvTestTask.new("test_#{configuration}") do |t| + t.pattern = 'test/finder_test.rb' + t.verbose = true + t.env = { 'DB' => configuration } + t.libs << 'test' + end +end + +task :test_databases => %w(test_mysql test_sqlite3 test_postgres) + +desc %{Test everything on SQLite3, MySQL and PostgreSQL} +task :test_full => %w(test test_mysql test_postgres) + +desc %{Test everything with Rails 2.1.x, 2.0.x & 1.2.x gems} +task :test_all do + all = Rake::Task['test_full'] + versions = %w(2.3.2 2.2.2 2.1.0 2.0.4 1.2.6) + versions.each do |version| + ENV['RAILS_VERSION'] = "~> #{version}" + all.invoke + reset_invoked unless version == versions.last + end +end + +def reset_invoked + %w( test_full test test_mysql test_postgres ).each do |name| + Rake::Task[name].instance_variable_set '@already_invoked', false + end +end + +task :rcov do + excludes = %w( lib/will_paginate/named_scope* + lib/will_paginate/core_ext.rb + lib/will_paginate.rb + rails* ) + + system %[rcov -Itest:lib test/*.rb -x #{excludes.join(',')}] +end diff --git a/vendor/gems/will_paginate-2.3.15/test/view_test.rb b/vendor/gems/will_paginate-2.3.15/test/view_test.rb new file mode 100644 index 00000000..3777cced --- /dev/null +++ b/vendor/gems/will_paginate-2.3.15/test/view_test.rb @@ -0,0 +1,373 @@ +require 'helper' +require 'lib/view_test_process' + +class AdditionalLinkAttributesRenderer < WillPaginate::LinkRenderer + def initialize(link_attributes = nil) + super() + @additional_link_attributes = link_attributes || { :default => 'true' } + end + + def page_link(page, text, attributes = {}) + @template.link_to text, url_for(page), attributes.merge(@additional_link_attributes) + end +end + +class ViewTest < WillPaginate::ViewTestCase + + ## basic pagination ## + + def test_will_paginate + paginate do |pagination| + assert_select 'a[href]', 3 do |elements| + validate_page_numbers [2,3,2], elements + assert_select elements.last, ':last-child', "Next »" + end + assert_select 'span', 2 + assert_select 'span.disabled:first-child', '« Previous' + assert_select 'span.current', '1' + assert_equal '« Previous 1 2 3 Next »', pagination.first.inner_text + end + end + + def test_no_pagination_when_page_count_is_one + paginate :per_page => 30 + assert_equal '', @html_result + end + + def test_will_paginate_with_options + paginate({ :page => 2 }, + :class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do + assert_select 'a[href]', 4 do |elements| + validate_page_numbers [1,1,3,3], elements + # test rel attribute values: + assert_select elements[1], 'a', '1' do |link| + assert_equal 'prev start', link.first['rel'] + end + assert_select elements.first, 'a', "Prev" do |link| + assert_equal 'prev start', link.first['rel'] + end + assert_select elements.last, 'a', "Next" do |link| + assert_equal 'next', link.first['rel'] + end + end + assert_select 'span.current', '2' + end + end + + def test_will_paginate_using_renderer_class + paginate({}, :renderer => AdditionalLinkAttributesRenderer) do + assert_select 'a[default=true]', 3 + end + end + + def test_will_paginate_using_renderer_instance + renderer = WillPaginate::LinkRenderer.new + renderer.gap_marker = '~~' + + paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :renderer => renderer) do + assert_select 'span.my-gap', '~~' + end + + renderer = AdditionalLinkAttributesRenderer.new(:title => 'rendered') + paginate({}, :renderer => renderer) do + assert_select 'a[title=rendered]', 3 + end + end + + def test_prev_next_links_have_classnames + paginate do |pagination| + assert_select 'span.disabled.prev_page:first-child' + assert_select 'a.next_page[href]:last-child' + end + end + + def test_prev_label_deprecated + assert_deprecated ':previous_label' do + paginate({ :page => 2 }, :prev_label => 'Deprecated') do + assert_select 'a[href]:first-child', 'Deprecated' + end + end + end + + def test_full_output + paginate + expected = <<-HTML + + HTML + expected.strip!.gsub!(/\s{2,}/, ' ') + + assert_dom_equal expected, @html_result + end + + def test_escaping_of_urls + paginate({:page => 1, :per_page => 1, :total_entries => 2}, + :page_links => false, :params => { :tag => '
    ' }) + + assert_select 'a[href]', 1 do |links| + query = links.first['href'].split('?', 2)[1] + assert_equal %w(page=2 tag=%3Cbr%3E), query.split('&').sort + end + end + + ## advanced options for pagination ## + + def test_will_paginate_without_container + paginate({}, :container => false) + assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t' + assert_select 'a[href]', 3 + end + + def test_will_paginate_without_page_links + paginate({ :page => 2 }, :page_links => false) do + assert_select 'a[href]', 2 do |elements| + validate_page_numbers [1,3], elements + end + end + end + + def test_will_paginate_windows + paginate({ :page => 6, :per_page => 1 }, :inner_window => 1) do |pagination| + assert_select 'a[href]', 8 do |elements| + validate_page_numbers [5,1,2,5,7,10,11,7], elements + assert_select elements.first, 'a', '« Previous' + assert_select elements.last, 'a', 'Next »' + end + assert_select 'span.current', '6' + assert_equal '« Previous 1 2 … 5 6 7 … 10 11 Next »', pagination.first.inner_text + end + end + + def test_will_paginate_eliminates_small_gaps + paginate({ :page => 6, :per_page => 1 }, :inner_window => 2) do + assert_select 'a[href]', 12 do |elements| + validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements + end + end + end + + def test_container_id + paginate do |div| + assert_nil div.first['id'] + end + + # magic ID + paginate({}, :id => true) do |div| + assert_equal 'fixnums_pagination', div.first['id'] + end + + # explicit ID + paginate({}, :id => 'custom_id') do |div| + assert_equal 'custom_id', div.first['id'] + end + end + + ## other helpers ## + + def test_paginated_section + @template = <<-ERB + <% paginated_section collection, options do %> + <%= content_tag :div, '', :id => "developers" %> + <% end %> + ERB + + paginate + assert_select 'div.pagination', 2 + assert_select 'div.pagination + div#developers', 1 + end + + def test_page_entries_info + @template = '<%= page_entries_info collection %>' + array = ('a'..'z').to_a + + paginate array.paginate(:page => 2, :per_page => 5) + assert_equal %{Displaying strings 6 - 10 of 26 in total}, + @html_result + + paginate array.paginate(:page => 7, :per_page => 4) + assert_equal %{Displaying strings 25 - 26 of 26 in total}, + @html_result + end + + uses_mocha 'class name' do + def test_page_entries_info_with_longer_class_name + @template = '<%= page_entries_info collection %>' + collection = ('a'..'z').to_a.paginate + collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType')) + + paginate collection + assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'" + end + end + + def test_page_entries_info_with_single_page_collection + @template = '<%= page_entries_info collection %>' + + paginate(('a'..'d').to_a.paginate(:page => 1, :per_page => 5)) + assert_equal %{Displaying all 4 strings}, @html_result + + paginate(['a'].paginate(:page => 1, :per_page => 5)) + assert_equal %{Displaying 1 string}, @html_result + + paginate([].paginate(:page => 1, :per_page => 5)) + assert_equal %{No entries found}, @html_result + end + + def test_page_entries_info_with_custom_entry_name + @template = '<%= page_entries_info collection, :entry_name => "author" %>' + + entries = (1..20).to_a + + paginate(entries.paginate(:page => 1, :per_page => 5)) + assert_equal %{Displaying authors 1 - 5 of 20 in total}, @html_result + + paginate(entries.paginate(:page => 1, :per_page => 20)) + assert_equal %{Displaying all 20 authors}, @html_result + + paginate(['a'].paginate(:page => 1, :per_page => 5)) + assert_equal %{Displaying 1 author}, @html_result + + paginate([].paginate(:page => 1, :per_page => 5)) + assert_equal %{No authors found}, @html_result + end + + ## parameter handling in page links ## + + def test_will_paginate_preserves_parameters_on_get + @request.params :foo => { :bar => 'baz' } + paginate + assert_links_match /foo%5Bbar%5D=baz/ + end + + def test_will_paginate_doesnt_preserve_parameters_on_post + @request.post + @request.params :foo => 'bar' + paginate + assert_no_links_match /foo=bar/ + end + + def test_adding_additional_parameters + paginate({}, :params => { :foo => 'bar' }) + assert_links_match /foo=bar/ + end + + def test_adding_anchor_parameter + paginate({}, :params => { :anchor => 'anchor' }) + assert_links_match /#anchor$/ + end + + def test_removing_arbitrary_parameters + @request.params :foo => 'bar' + paginate({}, :params => { :foo => nil }) + assert_no_links_match /foo=bar/ + end + + def test_adding_additional_route_parameters + paginate({}, :params => { :controller => 'baz', :action => 'list' }) + assert_links_match %r{\Wbaz/list\W} + end + + def test_will_paginate_with_custom_page_param + paginate({ :page => 2 }, :param_name => :developers_page) do + assert_select 'a[href]', 4 do |elements| + validate_page_numbers [1,1,3,3], elements, :developers_page + end + end + end + + def test_will_paginate_with_atmark_url + @request.symbolized_path_parameters[:action] = "@tag" + renderer = WillPaginate::LinkRenderer.new + + paginate({ :page => 1 }, :renderer=>renderer) + assert_links_match %r[/foo/@tag\?page=\d] + end + + def test_complex_custom_page_param + @request.params :developers => { :page => 2 } + + paginate({ :page => 2 }, :param_name => 'developers[page]') do + assert_select 'a[href]', 4 do |links| + assert_links_match /\?developers%5Bpage%5D=\d+$/, links + validate_page_numbers [1,1,3,3], links, 'developers[page]' + end + end + end + + def test_custom_routing_page_param + @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil + paginate :per_page => 2 do + assert_select 'a[href]', 6 do |links| + assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2] + end + end + end + + def test_custom_routing_page_param_with_dot_separator + @request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots' + paginate :per_page => 2 do + assert_select 'a[href]', 6 do |links| + assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2] + end + end + end + + def test_custom_routing_with_first_page_hidden + @request.symbolized_path_parameters.update :controller => 'ibocorp', :action => nil + paginate :page => 2, :per_page => 2 do + assert_select 'a[href]', 7 do |links| + assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3] + end + end + end + + ## internal hardcore stuff ## + + class LegacyCollection < WillPaginate::Collection + alias :page_count :total_pages + undef :total_pages + end + + def test_deprecation_notices_with_page_count + collection = LegacyCollection.new(1, 1, 2) + + assert_deprecated collection.class.name do + paginate collection + end + end + + uses_mocha 'view internals' do + def test_collection_name_can_be_guessed + collection = mock + collection.expects(:total_pages).returns(1) + + @template = '<%= will_paginate options %>' + @controller.controller_name = 'developers' + @view.assigns['developers'] = collection + + paginate(nil) + end + end + + def test_inferred_collection_name_raises_error_when_nil + @template = '<%= will_paginate options %>' + @controller.controller_name = 'developers' + + e = assert_raise ArgumentError do + paginate(nil) + end + assert e.message.include?('@developers') + end + + if ActionController::Base.respond_to? :rescue_responses + # only on Rails 2 + def test_rescue_response_hook_presence + assert_equal :not_found, + ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] + end + end + +end