Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaning out some unused plugins

  • Loading branch information...
commit 11529a4e7622e8c0ca9af8ec00d48908129082cc 1 parent f6fd20d
@ryanb authored
Showing with 7 additions and 3,254 deletions.
  1. +7 −6 db/schema.rb
  2. +0 −182 lib/tasks/rspec.rake
  3. +0 −20 vendor/plugins/delayed_job/MIT-LICENSE
  4. +0 −107 vendor/plugins/delayed_job/README.textile
  5. +0 −22 vendor/plugins/delayed_job/Rakefile
  6. +0 −1  vendor/plugins/delayed_job/VERSION
  7. +0 −61 vendor/plugins/delayed_job/delayed_job.gemspec
  8. +0 −11 vendor/plugins/delayed_job/generators/delayed_job/delayed_job_generator.rb
  9. +0 −20 vendor/plugins/delayed_job/generators/delayed_job/templates/migration.rb
  10. +0 −7 vendor/plugins/delayed_job/generators/delayed_job/templates/script
  11. +0 −1  vendor/plugins/delayed_job/init.rb
  12. +0 −65 vendor/plugins/delayed_job/lib/delayed/command.rb
  13. +0 −271 vendor/plugins/delayed_job/lib/delayed/job.rb
  14. +0 −17 vendor/plugins/delayed_job/lib/delayed/message_sending.rb
  15. +0 −55 vendor/plugins/delayed_job/lib/delayed/performable_method.rb
  16. +0 −54 vendor/plugins/delayed_job/lib/delayed/worker.rb
  17. +0 −13 vendor/plugins/delayed_job/lib/delayed_job.rb
  18. +0 −26 vendor/plugins/delayed_job/recipes/delayed_job.rb
  19. +0 −42 vendor/plugins/delayed_job/spec/database.rb
  20. +0 −128 vendor/plugins/delayed_job/spec/delayed_method_spec.rb
  21. +0 −389 vendor/plugins/delayed_job/spec/job_spec.rb
  22. +0 −17 vendor/plugins/delayed_job/spec/story_spec.rb
  23. +0 −1  vendor/plugins/delayed_job/tasks/jobs.rake
  24. +0 −15 vendor/plugins/delayed_job/tasks/tasks.rb
  25. +0 −20 vendor/plugins/rails_upgrade/MIT-LICENSE
  26. +0 −20 vendor/plugins/rails_upgrade/README
  27. +0 −22 vendor/plugins/rails_upgrade/Rakefile
  28. +0 −2  vendor/plugins/rails_upgrade/init.rb
  29. +0 −38 vendor/plugins/rails_upgrade/install.rb
  30. +0 −472 vendor/plugins/rails_upgrade/lib/application_checker.rb
  31. +0 −95 vendor/plugins/rails_upgrade/lib/gemfile_generator.rb
  32. +0 −51 vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb
  33. 0  vendor/plugins/rails_upgrade/lib/rails_upgrade.rb
  34. +0 −349 vendor/plugins/rails_upgrade/lib/routes_upgrader.rb
  35. +0 −78 vendor/plugins/rails_upgrade/lib/tasks/rails_upgrade_tasks.rake
  36. +0 −293 vendor/plugins/rails_upgrade/test/application_checker_test.rb
  37. +0 −72 vendor/plugins/rails_upgrade/test/gemfile_generator_test.rb
  38. +0 −63 vendor/plugins/rails_upgrade/test/new_configuration_generator_test.rb
  39. +0 −142 vendor/plugins/rails_upgrade/test/routes_upgrader_test.rb
  40. +0 −5 vendor/plugins/rails_upgrade/test/test_helper.rb
  41. +0 −1  vendor/plugins/rails_upgrade/uninstall.rb
View
13 db/schema.rb
@@ -1,10 +1,11 @@
-# This file is auto-generated from the current state of the database. Instead of editing this file,
-# please use the migrations feature of Active Record to incrementally modify your database, and
-# then regenerate this schema definition.
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
#
-# Note that this schema.rb definition is the authoritative source for your database schema. If you need
-# to create the application database on another system, you should be using db:schema:load, not running
-# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
View
182 lib/tasks/rspec.rake
@@ -1,182 +0,0 @@
-gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
-rspec_gem_dir = nil
-Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
- rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
-end
-rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
-
-if rspec_gem_dir && (test ?d, rspec_plugin_dir)
- raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
-end
-
-if rspec_gem_dir
- $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
-elsif File.exist?(rspec_plugin_dir)
- $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
-end
-
-# Don't load rspec if running "rake gems:*"
-unless ARGV.any? {|a| a =~ /^gems/}
-
-begin
- require 'spec/rake/spectask'
-rescue MissingSourceFile
- module Spec
- module Rake
- class SpecTask
- def initialize(name)
- task name do
- # if rspec-rails is a configured gem, this will output helpful material and exit ...
- require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
-
- # ... otherwise, do this:
- raise <<-MSG
-
-#{"*" * 80}
-* You are trying to run an rspec rake task defined in
-* #{__FILE__},
-* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
-#{"*" * 80}
-MSG
- end
- end
- end
- end
- end
-end
-
-Rake.application.instance_variable_get('@tasks').delete('default')
-
-spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
-task :noop do
-end
-
-task :default => :spec
-task :stats => "spec:statsetup"
-
-desc "Run all specs in spec directory (excluding plugin specs)"
-Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-namespace :spec do
- desc "Run all specs in spec directory with RCov (excluding plugin specs)"
- Spec::Rake::SpecTask.new(:rcov) do |t|
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.rcov = true
- t.rcov_opts = lambda do
- IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
- end
- end
-
- desc "Print Specdoc for all specs (excluding plugin specs)"
- Spec::Rake::SpecTask.new(:doc) do |t|
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
- t.spec_files = FileList['spec/**/*_spec.rb']
- end
-
- desc "Print Specdoc for all plugin examples"
- Spec::Rake::SpecTask.new(:plugin_doc) do |t|
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
- t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
- end
-
- [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
- desc "Run the code examples in spec/#{sub}"
- Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
- end
- end
-
- desc "Run the code examples in vendor/plugins (except RSpec's own)"
- Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
- end
-
- namespace :plugins do
- desc "Runs the examples for rspec_on_rails"
- Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
- end
- end
-
- # Setup specs for stats
- task :statsetup do
- require 'code_statistics'
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
- ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
- ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
- ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
- ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
- ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
- ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
- ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
- ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
- ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
- ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
- ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
- end
-
- namespace :db do
- namespace :fixtures do
- desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
- task :load => :environment do
- ActiveRecord::Base.establish_connection(Rails.env)
- base_dir = File.join(Rails.root, 'spec', 'fixtures')
- fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
-
- require 'active_record/fixtures'
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
- Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
- end
- end
- end
- end
-
- namespace :server do
- daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
-
- desc "start spec_server."
- task :start do
- if File.exist?(daemonized_server_pid)
- $stderr.puts "spec_server is already running."
- else
- $stderr.puts %Q{Starting up spec_server ...}
- FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
- system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
- end
- end
-
- desc "stop spec_server."
- task :stop do
- unless File.exist?(daemonized_server_pid)
- $stderr.puts "No server running."
- else
- $stderr.puts "Shutting down spec_server ..."
- system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
- File.delete(daemonized_server_pid)
- end
- end
-
- desc "restart spec_server."
- task :restart => [:stop, :start]
-
- desc "check if spec server is running"
- task :status do
- if File.exist?(daemonized_server_pid)
- $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
- else
- $stderr.puts "No server running."
- end
- end
- end
-end
-
-end
View
20 vendor/plugins/delayed_job/MIT-LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2005 Tobias Luetke
-
-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 PURPOa AND
-NONINFRINGEMENT. IN NO EVENT SaALL 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.
View
107 vendor/plugins/delayed_job/README.textile
@@ -1,107 +0,0 @@
-h1. Delayed::Job
-
-Delated_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background.
-
-It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks. Amongst those tasks are:
-
-* sending massive newsletters
-* image resizing
-* http downloads
-* updating smart collections
-* updating solr, our search server, after product changes
-* batch imports
-* spam checks
-
-h2. Setup
-
-The library evolves around a delayed_jobs table which looks as follows:
-
- create_table :delayed_jobs, :force => true do |table|
- table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
- table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
- table.text :handler # YAML-encoded string of the object that will do work
- table.string :last_error # reason for last failure (See Note below)
- table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future.
- table.datetime :locked_at # Set when a client is working on this object
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
- table.string :locked_by # Who is working on this object (if locked)
- table.timestamps
- end
-
-On failure, the job is scheduled again in 5 seconds + N ** 4, where N is the number of retries.
-
-The default MAX_ATTEMPTS is 25. After this, the job either deleted (default), or left in the database with "failed_at" set.
-With the default of 25 attempts, the last retry will be 20 days later, with the last interval being almost 100 hours.
-
-The default MAX_RUN_TIME is 4.hours. If your job takes longer than that, another computer could pick it up. It's up to you to
-make sure your job doesn't exceed this time. You should set this to the longest time you think the job could take.
-
-By default, it will delete failed jobs (and it always deletes successful jobs). If you want to keep failed jobs, set
-Delayed::Job.destroy_failed_jobs = false. The failed jobs will be marked with non-null failed_at.
-
-Here is an example of changing job parameters in Rails:
-
- # config/initializers/delayed_job_config.rb
- Delayed::Job.destroy_failed_jobs = false
- silence_warnings do
- Delayed::Job.const_set("MAX_ATTEMPTS", 3)
- Delayed::Job.const_set("MAX_RUN_TIME", 5.minutes)
- end
-
-Note: If your error messages are long, consider changing last_error field to a :text instead of a :string (255 character limit).
-
-
-h2. Usage
-
-Jobs are simple ruby objects with a method called perform. Any object which responds to perform can be stuffed into the jobs table.
-Job objects are serialized to yaml so that they can later be resurrected by the job runner.
-
- class NewsletterJob < Struct.new(:text, :emails)
- def perform
- emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
- end
- end
-
- Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email))
-
-There is also a second way to get jobs in the queue: send_later.
-
-
- BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv)
-
-
-This will simply create a Delayed::PerformableMethod job in the jobs table which serializes all the parameters you pass to it. There are some special smarts for active record objects
-which are stored as their text representation and loaded from the database fresh when the job is actually run later.
-
-
-h2. Running the jobs
-
-Run @script/generate delayed_job@ to add @script/delayed_job@. This script can then be used to manage a process which will start working off jobs.
-
- # Runs two workers in separate processes.
- $ ruby script/delayed_job -e production -n 2 start
- $ ruby script/delayed_job -e production stop
-
-You can invoke @rake jobs:work@ which will start working off jobs. You can cancel the rake task with @CTRL-C@.
-
-Workers can be running on any computer, as long as they have access to the database and their clock is in sync. You can even
-run multiple workers on per computer, but you must give each one a unique name. (TODO: put in an example)
-Keep in mind that each worker will check the database at least every 5 seconds.
-
-Note: The rake task will exit if the database has any network connectivity problems.
-
-h3. Cleaning up
-
-You can invoke @rake jobs:clear@ to delete all jobs in the queue.
-
-h3. Changes
-
-* 1.7.0: Added failed_at column which can optionally be set after a certain amount of failed job attempts. By default failed job attempts are destroyed after about a month.
-
-* 1.6.0: Renamed locked_until to locked_at. We now store when we start a given job instead of how long it will be locked by the worker. This allows us to get a reading on how long a job took to execute.
-
-* 1.5.0: Job runners can now be run in parallel. Two new database columns are needed: locked_until and locked_by. This allows us to use pessimistic locking instead of relying on row level locks. This enables us to run as many worker processes as we need to speed up queue processing.
-
-* 1.2.0: Added #send_later to Object for simpler job creation
-
-* 1.0.0: Initial release
View
22 vendor/plugins/delayed_job/Rakefile
@@ -1,22 +0,0 @@
-# -*- encoding: utf-8 -*-
-begin
- require 'jeweler'
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
- exit 1
-end
-
-Jeweler::Tasks.new do |s|
- s.name = "delayed_job"
- s.summary = "Database-backed asynchronous priority queue system -- Extracted from Shopify"
- s.email = "tobi@leetsoft.com"
- s.homepage = "http://github.com/tobi/delayed_job/tree/master"
- s.description = "Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks."
- s.authors = ["Tobias Lütke"]
-
- s.has_rdoc = true
- s.rdoc_options = ["--main", "README.textile", "--inline-source", "--line-numbers"]
- s.extra_rdoc_files = ["README.textile"]
-
- s.test_files = Dir['spec/**/*']
-end
View
1  vendor/plugins/delayed_job/VERSION
@@ -1 +0,0 @@
-1.8.0
View
61 vendor/plugins/delayed_job/delayed_job.gemspec
@@ -1,61 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-Gem::Specification.new do |s|
- s.name = %q{delayed_job}
- s.version = "1.8.0"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Tobias L\303\274tke"]
- s.date = %q{2009-07-19}
- s.description = %q{Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.}
- s.email = %q{tobi@leetsoft.com}
- s.extra_rdoc_files = [
- "README.textile"
- ]
- s.files = [
- ".gitignore",
- "MIT-LICENSE",
- "README.textile",
- "Rakefile",
- "VERSION",
- "delayed_job.gemspec",
- "generators/delayed_job/delayed_job_generator.rb",
- "generators/delayed_job/templates/migration.rb",
- "generators/delayed_job/templates/script",
- "init.rb",
- "lib/delayed/command.rb",
- "lib/delayed/job.rb",
- "lib/delayed/message_sending.rb",
- "lib/delayed/performable_method.rb",
- "lib/delayed/worker.rb",
- "lib/delayed_job.rb",
- "recipes/delayed_job.rb",
- "spec/database.rb",
- "spec/delayed_method_spec.rb",
- "spec/job_spec.rb",
- "spec/story_spec.rb",
- "tasks/jobs.rake",
- "tasks/tasks.rb"
- ]
- s.homepage = %q{http://github.com/tobi/delayed_job/tree/master}
- s.rdoc_options = ["--main", "README.textile", "--inline-source", "--line-numbers"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.3}
- s.summary = %q{Database-backed asynchronous priority queue system -- Extracted from Shopify}
- s.test_files = [
- "spec/database.rb",
- "spec/delayed_method_spec.rb",
- "spec/job_spec.rb",
- "spec/story_spec.rb"
- ]
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
-end
View
11 vendor/plugins/delayed_job/generators/delayed_job/delayed_job_generator.rb
@@ -1,11 +0,0 @@
-class DelayedJobGenerator < Rails::Generator::Base
-
- def manifest
- record do |m|
- m.template 'script', 'script/delayed_job', :chmod => 0755
- m.migration_template "migration.rb", 'db/migrate',
- :migration_file_name => "create_delayed_jobs"
- end
- end
-
-end
View
20 vendor/plugins/delayed_job/generators/delayed_job/templates/migration.rb
@@ -1,20 +0,0 @@
-class CreateDelayedJobs < ActiveRecord::Migration
- def self.up
- create_table :delayed_jobs, :force => true do |table|
- table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
- table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
- table.text :handler # YAML-encoded string of the object that will do work
- table.text :last_error # reason for last failure (See Note below)
- table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future.
- table.datetime :locked_at # Set when a client is working on this object
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
- table.string :locked_by # Who is working on this object (if locked)
- table.timestamps
- end
-
- end
-
- def self.down
- drop_table :delayed_jobs
- end
-end
View
7 vendor/plugins/delayed_job/generators/delayed_job/templates/script
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
-RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
-
-require File.join(File.dirname(__FILE__), *%w(.. vendor plugins delayed_job lib delayed command))
-Delayed::Command.new(ARGV).daemonize
View
1  vendor/plugins/delayed_job/init.rb
@@ -1 +0,0 @@
-require File.dirname(__FILE__) + '/lib/delayed_job'
View
65 vendor/plugins/delayed_job/lib/delayed/command.rb
@@ -1,65 +0,0 @@
-require 'rubygems'
-require 'daemons'
-require 'optparse'
-
-module Delayed
- class Command
- attr_accessor :worker_count
-
- def initialize(args)
- @options = {:quiet => true}
- @worker_count = 1
-
- opts = OptionParser.new do |opts|
- opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run"
-
- opts.on('-h', '--help', 'Show this message') do
- puts opts
- exit 1
- end
- opts.on('-e', '--environment=NAME', 'Specifies the environment to run this delayed jobs under (test/development/production).') do |e|
- ENV['RAILS_ENV'] = e
- end
- opts.on('--min-priority N', 'Minimum priority of jobs to run.') do |n|
- @options[:min_priority] = n
- end
- opts.on('--max-priority N', 'Maximum priority of jobs to run.') do |n|
- @options[:max_priority] = n
- end
- opts.on('-n', '--number_of_workers=workers', "Number of unique workers to spawn") do |worker_count|
- @worker_count = worker_count.to_i rescue 1
- end
- end
- @args = opts.parse!(args)
- end
-
- def daemonize
- worker_count.times do |worker_index|
- process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
- Daemons.run_proc(process_name, :dir => "#{RAILS_ROOT}/tmp/pids", :dir_mode => :normal, :ARGV => @args) do |*args|
- run process_name
- end
- end
- end
-
- def run(worker_name = nil)
- Dir.chdir(RAILS_ROOT)
- require File.join(RAILS_ROOT, 'config', 'environment')
-
- # Replace the default logger
- logger = Logger.new(File.join(RAILS_ROOT, 'log', 'delayed_job.log'))
- logger.level = ActiveRecord::Base.logger.level
- ActiveRecord::Base.logger = logger
- ActiveRecord::Base.clear_active_connections!
- Delayed::Worker.logger = logger
- Delayed::Job.worker_name = "#{worker_name} #{Delayed::Job.worker_name}"
-
- Delayed::Worker.new(@options).start
- rescue => e
- logger.fatal e
- STDERR.puts e.message
- exit 1
- end
-
- end
-end
View
271 vendor/plugins/delayed_job/lib/delayed/job.rb
@@ -1,271 +0,0 @@
-require 'timeout'
-
-module Delayed
-
- class DeserializationError < StandardError
- end
-
- # A job object that is persisted to the database.
- # Contains the work object as a YAML field.
- class Job < ActiveRecord::Base
- MAX_ATTEMPTS = 25
- MAX_RUN_TIME = 4.hours
- set_table_name :delayed_jobs
-
- # By default failed jobs are destroyed after too many attempts.
- # If you want to keep them around (perhaps to inspect the reason
- # for the failure), set this to false.
- cattr_accessor :destroy_failed_jobs
- self.destroy_failed_jobs = true
-
- # Every worker has a unique name which by default is the pid of the process.
- # There are some advantages to overriding this with something which survives worker retarts:
- # Workers can safely resume working on tasks which are locked by themselves. The worker will assume that it crashed before.
- cattr_accessor :worker_name
- self.worker_name = "host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
-
- NextTaskSQL = '(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR (locked_by = ?)) AND failed_at IS NULL'
- NextTaskOrder = 'priority DESC, run_at ASC'
-
- ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
-
- cattr_accessor :min_priority, :max_priority
- self.min_priority = nil
- self.max_priority = nil
-
- # When a worker is exiting, make sure we don't have any locked jobs.
- def self.clear_locks!
- update_all("locked_by = null, locked_at = null", ["locked_by = ?", worker_name])
- end
-
- def failed?
- failed_at
- end
- alias_method :failed, :failed?
-
- def payload_object
- @payload_object ||= deserialize(self['handler'])
- end
-
- def name
- @name ||= begin
- payload = payload_object
- if payload.respond_to?(:display_name)
- payload.display_name
- else
- payload.class.name
- end
- end
- end
-
- def payload_object=(object)
- self['handler'] = object.to_yaml
- end
-
- # Reschedule the job in the future (when a job fails).
- # Uses an exponential scale depending on the number of failed attempts.
- def reschedule(message, backtrace = [], time = nil)
- if self.attempts < MAX_ATTEMPTS
- time ||= Job.db_time_now + (attempts ** 4) + 5
-
- self.attempts += 1
- self.run_at = time
- self.last_error = message + "\n" + backtrace.join("\n")
- self.unlock
- save!
- else
- logger.info "* [JOB] PERMANENTLY removing #{self.name} because of #{attempts} consequetive failures."
- destroy_failed_jobs ? destroy : update_attribute(:failed_at, Time.now)
- end
- end
-
-
- # Try to run one job. Returns true/false (work done/work failed) or nil if job can't be locked.
- def run_with_lock(max_run_time, worker_name)
- logger.info "* [JOB] acquiring lock on #{name}"
- unless lock_exclusively!(max_run_time, worker_name)
- # We did not get the lock, some other worker process must have
- logger.warn "* [JOB] failed to acquire exclusive lock for #{name}"
- return nil # no work done
- end
-
- begin
- runtime = Benchmark.realtime do
- Timeout.timeout(max_run_time.to_i) { invoke_job }
- destroy
- end
- # TODO: warn if runtime > max_run_time ?
- logger.info "* [JOB] #{name} completed after %.4f" % runtime
- return true # did work
- rescue Exception => e
- reschedule e.message, e.backtrace
- log_exception(e)
- return false # work failed
- end
- end
-
- # Add a job to the queue
- def self.enqueue(*args, &block)
- object = block_given? ? EvaledJob.new(&block) : args.shift
-
- unless object.respond_to?(:perform) || block_given?
- raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
- end
-
- priority = args.first || 0
- run_at = args[1]
-
- Job.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at)
- end
-
- # Find a few candidate jobs to run (in case some immediately get locked by others).
- def self.find_available(limit = 5, max_run_time = MAX_RUN_TIME)
-
- time_now = db_time_now
-
- sql = NextTaskSQL.dup
-
- conditions = [time_now, time_now - max_run_time, worker_name]
-
- if self.min_priority
- sql << ' AND (priority >= ?)'
- conditions << min_priority
- end
-
- if self.max_priority
- sql << ' AND (priority <= ?)'
- conditions << max_priority
- end
-
- conditions.unshift(sql)
-
- ActiveRecord::Base.silence do
- find(:all, :conditions => conditions, :order => NextTaskOrder, :limit => limit)
- end
- end
-
- # Run the next job we can get an exclusive lock on.
- # If no jobs are left we return nil
- def self.reserve_and_run_one_job(max_run_time = MAX_RUN_TIME)
-
- # We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next.
- # this leads to a more even distribution of jobs across the worker processes
- find_available(5, max_run_time).each do |job|
- t = job.run_with_lock(max_run_time, worker_name)
- return t unless t == nil # return if we did work (good or bad)
- end
-
- nil # we didn't do any work, all 5 were not lockable
- end
-
- # Lock this job for this worker.
- # Returns true if we have the lock, false otherwise.
- def lock_exclusively!(max_run_time, worker = worker_name)
- now = self.class.db_time_now
- affected_rows = if locked_by != worker
- # We don't own this job so we will update the locked_by name and the locked_at
- self.class.update_all(["locked_at = ?, locked_by = ?", now, worker], ["id = ? and (locked_at is null or locked_at < ?) and (run_at <= ?)", id, (now - max_run_time.to_i), now])
- else
- # We already own this job, this may happen if the job queue crashes.
- # Simply resume and update the locked_at
- self.class.update_all(["locked_at = ?", now], ["id = ? and locked_by = ?", id, worker])
- end
- if affected_rows == 1
- self.locked_at = now
- self.locked_by = worker
- return true
- else
- return false
- end
- end
-
- # Unlock this job (note: not saved to DB)
- def unlock
- self.locked_at = nil
- self.locked_by = nil
- end
-
- # This is a good hook if you need to report job processing errors in additional or different ways
- def log_exception(error)
- logger.error "* [JOB] #{name} failed with #{error.class.name}: #{error.message} - #{attempts} failed attempts"
- logger.error(error)
- end
-
- # Do num jobs and return stats on success/failure.
- # Exit early if interrupted.
- def self.work_off(num = 100)
- success, failure = 0, 0
-
- num.times do
- case self.reserve_and_run_one_job
- when true
- success += 1
- when false
- failure += 1
- else
- break # leave if no work could be done
- end
- break if $exit # leave if we're exiting
- end
-
- return [success, failure]
- end
-
- # Moved into its own method so that new_relic can trace it.
- def invoke_job
- payload_object.perform
- end
-
- private
-
- def deserialize(source)
- handler = YAML.load(source) rescue nil
-
- unless handler.respond_to?(:perform)
- if handler.nil? && source =~ ParseObjectFromYaml
- handler_class = $1
- end
- attempt_to_load(handler_class || handler.class)
- handler = YAML.load(source)
- end
-
- return handler if handler.respond_to?(:perform)
-
- raise DeserializationError,
- 'Job failed to load: Unknown handler. Try to manually require the appropriate file.'
- rescue TypeError, LoadError, NameError => e
- raise DeserializationError,
- "Job failed to load: #{e.message}. Try to manually require the required file."
- end
-
- # Constantize the object so that ActiveSupport can attempt
- # its auto loading magic. Will raise LoadError if not successful.
- def attempt_to_load(klass)
- klass.constantize
- end
-
- # Get the current time (GMT or local depending on DB)
- # Note: This does not ping the DB to get the time, so all your clients
- # must have syncronized clocks.
- def self.db_time_now
- (ActiveRecord::Base.default_timezone == :utc) ? Time.now.utc : Time.now
- end
-
- protected
-
- def before_save
- self.run_at ||= self.class.db_time_now
- end
-
- end
-
- class EvaledJob
- def initialize
- @job = yield
- end
-
- def perform
- eval(@job)
- end
- end
-end
View
17 vendor/plugins/delayed_job/lib/delayed/message_sending.rb
@@ -1,17 +0,0 @@
-module Delayed
- module MessageSending
- def send_later(method, *args)
- Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args)
- end
-
- module ClassMethods
- def handle_asynchronously(method)
- without_name = "#{method}_without_send_later"
- define_method("#{method}_with_send_later") do |*args|
- send_later(without_name, *args)
- end
- alias_method_chain method, :send_later
- end
- end
- end
-end
View
55 vendor/plugins/delayed_job/lib/delayed/performable_method.rb
@@ -1,55 +0,0 @@
-module Delayed
- class PerformableMethod < Struct.new(:object, :method, :args)
- CLASS_STRING_FORMAT = /^CLASS\:([A-Z][\w\:]+)$/
- AR_STRING_FORMAT = /^AR\:([A-Z][\w\:]+)\:(\d+)$/
-
- def initialize(object, method, args)
- raise NoMethodError, "undefined method `#{method}' for #{self.inspect}" unless object.respond_to?(method)
-
- self.object = dump(object)
- self.args = args.map { |a| dump(a) }
- self.method = method.to_sym
- end
-
- def display_name
- case self.object
- when CLASS_STRING_FORMAT then "#{$1}.#{method}"
- when AR_STRING_FORMAT then "#{$1}##{method}"
- else "Unknown##{method}"
- end
- end
-
- def perform
- load(object).send(method, *args.map{|a| load(a)})
- rescue ActiveRecord::RecordNotFound
- # We cannot do anything about objects which were deleted in the meantime
- true
- end
-
- private
-
- def load(arg)
- case arg
- when CLASS_STRING_FORMAT then $1.constantize
- when AR_STRING_FORMAT then $1.constantize.find($2)
- else arg
- end
- end
-
- def dump(arg)
- case arg
- when Class then class_to_string(arg)
- when ActiveRecord::Base then ar_to_string(arg)
- else arg
- end
- end
-
- def ar_to_string(obj)
- "AR:#{obj.class}:#{obj.id}"
- end
-
- def class_to_string(obj)
- "CLASS:#{obj.name}"
- end
- end
-end
View
54 vendor/plugins/delayed_job/lib/delayed/worker.rb
@@ -1,54 +0,0 @@
-module Delayed
- class Worker
- SLEEP = 5
-
- cattr_accessor :logger
- self.logger = if defined?(Merb::Logger)
- Merb.logger
- elsif defined?(RAILS_DEFAULT_LOGGER)
- RAILS_DEFAULT_LOGGER
- end
-
- def initialize(options={})
- @quiet = options[:quiet]
- Delayed::Job.min_priority = options[:min_priority] if options.has_key?(:min_priority)
- Delayed::Job.max_priority = options[:max_priority] if options.has_key?(:max_priority)
- end
-
- def start
- say "*** Starting job worker #{Delayed::Job.worker_name}"
-
- trap('TERM') { say 'Exiting...'; $exit = true }
- trap('INT') { say 'Exiting...'; $exit = true }
-
- loop do
- result = nil
-
- realtime = Benchmark.realtime do
- result = Delayed::Job.work_off
- end
-
- count = result.sum
-
- break if $exit
-
- if count.zero?
- sleep(SLEEP)
- else
- say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
- end
-
- break if $exit
- end
-
- ensure
- Delayed::Job.clear_locks!
- end
-
- def say(text)
- puts text unless @quiet
- logger.info text if logger
- end
-
- end
-end
View
13 vendor/plugins/delayed_job/lib/delayed_job.rb
@@ -1,13 +0,0 @@
-autoload :ActiveRecord, 'activerecord'
-
-require File.dirname(__FILE__) + '/delayed/message_sending'
-require File.dirname(__FILE__) + '/delayed/performable_method'
-require File.dirname(__FILE__) + '/delayed/job'
-require File.dirname(__FILE__) + '/delayed/worker'
-
-Object.send(:include, Delayed::MessageSending)
-Module.send(:include, Delayed::MessageSending::ClassMethods)
-
-if defined?(Merb::Plugins)
- Merb::Plugins.add_rakefiles File.dirname(__FILE__) / '..' / 'tasks' / 'tasks'
-end
View
26 vendor/plugins/delayed_job/recipes/delayed_job.rb
@@ -1,26 +0,0 @@
-# Capistrano Recipes for managing delayed_job
-#
-# Add these callbacks to have the delayed_job process restart when the server
-# is restarted:
-#
-# after "deploy:stop", "delayed_job:stop"
-# after "deploy:start", "delayed_job:start"
-# after "deploy:restart", "delayed_job:restart"
-
-
-namespace :delayed_job do
- desc "Stop the delayed_job process"
- task :stop, :roles => :app do
- run "cd #{current_path}; script/delayed_job -e #{rails_env} stop"
- end
-
- desc "Start the delayed_job process"
- task :start, :roles => :app do
- run "cd #{current_path}; script/delayed_job -e #{rails_env} start"
- end
-
- desc "Restart the delayed_job process"
- task :restart, :roles => :app do
- run "cd #{current_path}; script/delayed_job -e #{rails_env} restart"
- end
-end
View
42 vendor/plugins/delayed_job/spec/database.rb
@@ -1,42 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../rspec/lib')
-
-require 'rubygems'
-require 'active_record'
-gem 'sqlite3-ruby'
-
-require File.dirname(__FILE__) + '/../init'
-require 'spec'
-
-ActiveRecord::Base.logger = Logger.new('/tmp/dj.log')
-ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => '/tmp/jobs.sqlite')
-ActiveRecord::Migration.verbose = false
-
-ActiveRecord::Schema.define do
-
- create_table :delayed_jobs, :force => true do |table|
- table.integer :priority, :default => 0
- table.integer :attempts, :default => 0
- table.text :handler
- table.string :last_error
- table.datetime :run_at
- table.datetime :locked_at
- table.string :locked_by
- table.datetime :failed_at
- table.timestamps
- end
-
- create_table :stories, :force => true do |table|
- table.string :text
- end
-
-end
-
-
-# Purely useful for test cases...
-class Story < ActiveRecord::Base
- def tell; text; end
- def whatever(n, _); tell*n; end
-
- handle_asynchronously :whatever
-end
View
128 vendor/plugins/delayed_job/spec/delayed_method_spec.rb
@@ -1,128 +0,0 @@
-require File.dirname(__FILE__) + '/database'
-
-class SimpleJob
- cattr_accessor :runs; self.runs = 0
- def perform; @@runs += 1; end
-end
-
-class RandomRubyObject
- def say_hello
- 'hello'
- end
-end
-
-class ErrorObject
-
- def throw
- raise ActiveRecord::RecordNotFound, '...'
- false
- end
-
-end
-
-class StoryReader
-
- def read(story)
- "Epilog: #{story.tell}"
- end
-
-end
-
-class StoryReader
-
- def read(story)
- "Epilog: #{story.tell}"
- end
-
-end
-
-describe 'random ruby objects' do
- before { Delayed::Job.delete_all }
-
- it "should respond_to :send_later method" do
-
- RandomRubyObject.new.respond_to?(:send_later)
-
- end
-
- it "should raise a ArgumentError if send_later is called but the target method doesn't exist" do
- lambda { RandomRubyObject.new.send_later(:method_that_deos_not_exist) }.should raise_error(NoMethodError)
- end
-
- it "should add a new entry to the job table when send_later is called on it" do
- Delayed::Job.count.should == 0
-
- RandomRubyObject.new.send_later(:to_s)
-
- Delayed::Job.count.should == 1
- end
-
- it "should add a new entry to the job table when send_later is called on the class" do
- Delayed::Job.count.should == 0
-
- RandomRubyObject.send_later(:to_s)
-
- Delayed::Job.count.should == 1
- end
-
- it "should run get the original method executed when the job is performed" do
-
- RandomRubyObject.new.send_later(:say_hello)
-
- Delayed::Job.count.should == 1
- end
-
- it "should ignore ActiveRecord::RecordNotFound errors because they are permanent" do
-
- ErrorObject.new.send_later(:throw)
-
- Delayed::Job.count.should == 1
-
- Delayed::Job.reserve_and_run_one_job
-
- Delayed::Job.count.should == 0
-
- end
-
- it "should store the object as string if its an active record" do
- story = Story.create :text => 'Once upon...'
- story.send_later(:tell)
-
- job = Delayed::Job.find(:first)
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.object.should == "AR:Story:#{story.id}"
- job.payload_object.method.should == :tell
- job.payload_object.args.should == []
- job.payload_object.perform.should == 'Once upon...'
- end
-
- it "should store arguments as string if they an active record" do
-
- story = Story.create :text => 'Once upon...'
-
- reader = StoryReader.new
- reader.send_later(:read, story)
-
- job = Delayed::Job.find(:first)
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.method.should == :read
- job.payload_object.args.should == ["AR:Story:#{story.id}"]
- job.payload_object.perform.should == 'Epilog: Once upon...'
- end
-
- it "should call send later on methods which are wrapped with handle_asynchronously" do
- story = Story.create :text => 'Once upon...'
-
- Delayed::Job.count.should == 0
-
- story.whatever(1, 5)
-
- Delayed::Job.count.should == 1
- job = Delayed::Job.find(:first)
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.method.should == :whatever_without_send_later
- job.payload_object.args.should == [1, 5]
- job.payload_object.perform.should == 'Once upon...'
- end
-
-end
View
389 vendor/plugins/delayed_job/spec/job_spec.rb
@@ -1,389 +0,0 @@
-require File.dirname(__FILE__) + '/database'
-
-class SimpleJob
- cattr_accessor :runs; self.runs = 0
- def perform; @@runs += 1; end
-end
-
-class ErrorJob
- cattr_accessor :runs; self.runs = 0
- def perform; raise 'did not work'; end
-end
-
-class LongRunningJob
- def perform; sleep 250; end
-end
-
-module M
- class ModuleJob
- cattr_accessor :runs; self.runs = 0
- def perform; @@runs += 1; end
- end
-
-end
-
-describe Delayed::Job do
- before do
- Delayed::Job.max_priority = nil
- Delayed::Job.min_priority = nil
-
- Delayed::Job.delete_all
- end
-
- before(:each) do
- SimpleJob.runs = 0
- end
-
- it "should set run_at automatically if not set" do
- Delayed::Job.create(:payload_object => ErrorJob.new ).run_at.should_not == nil
- end
-
- it "should not set run_at automatically if already set" do
- later = 5.minutes.from_now
- Delayed::Job.create(:payload_object => ErrorJob.new, :run_at => later).run_at.should == later
- end
-
- it "should raise ArgumentError when handler doesn't respond_to :perform" do
- lambda { Delayed::Job.enqueue(Object.new) }.should raise_error(ArgumentError)
- end
-
- it "should increase count after enqueuing items" do
- Delayed::Job.enqueue SimpleJob.new
- Delayed::Job.count.should == 1
- end
-
- it "should be able to set priority when enqueuing items" do
- Delayed::Job.enqueue SimpleJob.new, 5
- Delayed::Job.first.priority.should == 5
- end
-
- it "should be able to set run_at when enqueuing items" do
- later = 5.minutes.from_now
- Delayed::Job.enqueue SimpleJob.new, 5, later
-
- # use be close rather than equal to because millisecond values cn be lost in DB round trip
- Delayed::Job.first.run_at.should be_close(later, 1)
- end
-
- it "should call perform on jobs when running work_off" do
- SimpleJob.runs.should == 0
-
- Delayed::Job.enqueue SimpleJob.new
- Delayed::Job.work_off
-
- SimpleJob.runs.should == 1
- end
-
-
- it "should work with eval jobs" do
- $eval_job_ran = false
-
- Delayed::Job.enqueue do <<-JOB
- $eval_job_ran = true
- JOB
- end
-
- Delayed::Job.work_off
-
- $eval_job_ran.should == true
- end
-
- it "should work with jobs in modules" do
- M::ModuleJob.runs.should == 0
-
- Delayed::Job.enqueue M::ModuleJob.new
- Delayed::Job.work_off
-
- M::ModuleJob.runs.should == 1
- end
-
- it "should re-schedule by about 1 second at first and increment this more and more minutes when it fails to execute properly" do
- Delayed::Job.enqueue ErrorJob.new
- Delayed::Job.work_off(1)
-
- job = Delayed::Job.find(:first)
-
- job.last_error.should =~ /did not work/
- job.last_error.should =~ /job_spec.rb:10:in `perform'/
- job.attempts.should == 1
-
- job.run_at.should > Delayed::Job.db_time_now - 10.minutes
- job.run_at.should < Delayed::Job.db_time_now + 10.minutes
- end
-
- it "should raise an DeserializationError when the job class is totally unknown" do
-
- job = Delayed::Job.new
- job['handler'] = "--- !ruby/object:JobThatDoesNotExist {}"
-
- lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
- end
-
- it "should try to load the class when it is unknown at the time of the deserialization" do
- job = Delayed::Job.new
- job['handler'] = "--- !ruby/object:JobThatDoesNotExist {}"
-
- job.should_receive(:attempt_to_load).with('JobThatDoesNotExist').and_return(true)
-
- lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
- end
-
- it "should try include the namespace when loading unknown objects" do
- job = Delayed::Job.new
- job['handler'] = "--- !ruby/object:Delayed::JobThatDoesNotExist {}"
- job.should_receive(:attempt_to_load).with('Delayed::JobThatDoesNotExist').and_return(true)
- lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
- end
-
- it "should also try to load structs when they are unknown (raises TypeError)" do
- job = Delayed::Job.new
- job['handler'] = "--- !ruby/struct:JobThatDoesNotExist {}"
-
- job.should_receive(:attempt_to_load).with('JobThatDoesNotExist').and_return(true)
-
- lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
- end
-
- it "should try include the namespace when loading unknown structs" do
- job = Delayed::Job.new
- job['handler'] = "--- !ruby/struct:Delayed::JobThatDoesNotExist {}"
-
- job.should_receive(:attempt_to_load).with('Delayed::JobThatDoesNotExist').and_return(true)
- lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError)
- end
-
- it "should be failed if it failed more than MAX_ATTEMPTS times and we don't want to destroy jobs" do
- default = Delayed::Job.destroy_failed_jobs
- Delayed::Job.destroy_failed_jobs = false
-
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :attempts => 50
- @job.reload.failed_at.should == nil
- @job.reschedule 'FAIL'
- @job.reload.failed_at.should_not == nil
-
- Delayed::Job.destroy_failed_jobs = default
- end
-
- it "should be destroyed if it failed more than MAX_ATTEMPTS times and we want to destroy jobs" do
- default = Delayed::Job.destroy_failed_jobs
- Delayed::Job.destroy_failed_jobs = true
-
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :attempts => 50
- @job.should_receive(:destroy)
- @job.reschedule 'FAIL'
-
- Delayed::Job.destroy_failed_jobs = default
- end
-
- it "should fail after MAX_RUN_TIME" do
- @job = Delayed::Job.create :payload_object => LongRunningJob.new
- Delayed::Job.reserve_and_run_one_job(1.second)
- @job.reload.last_error.should =~ /expired/
- @job.attempts.should == 1
- end
-
- it "should never find failed jobs" do
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :attempts => 50, :failed_at => Time.now
- Delayed::Job.find_available(1).length.should == 0
- end
-
- context "when another worker is already performing an task, it" do
-
- before :each do
- Delayed::Job.worker_name = 'worker1'
- @job = Delayed::Job.create :payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => Delayed::Job.db_time_now - 5.minutes
- end
-
- it "should not allow a second worker to get exclusive access" do
- @job.lock_exclusively!(4.hours, 'worker2').should == false
- end
-
- it "should allow a second worker to get exclusive access if the timeout has passed" do
- @job.lock_exclusively!(1.minute, 'worker2').should == true
- end
-
- it "should be able to get access to the task if it was started more then max_age ago" do
- @job.locked_at = 5.hours.ago
- @job.save
-
- @job.lock_exclusively! 4.hours, 'worker2'
- @job.reload
- @job.locked_by.should == 'worker2'
- @job.locked_at.should > 1.minute.ago
- end
-
- it "should not be found by another worker" do
- Delayed::Job.worker_name = 'worker2'
-
- Delayed::Job.find_available(1, 6.minutes).length.should == 0
- end
-
- it "should be found by another worker if the time has expired" do
- Delayed::Job.worker_name = 'worker2'
-
- Delayed::Job.find_available(1, 4.minutes).length.should == 1
- end
-
- it "should be able to get exclusive access again when the worker name is the same" do
- @job.lock_exclusively! 5.minutes, 'worker1'
- @job.lock_exclusively! 5.minutes, 'worker1'
- @job.lock_exclusively! 5.minutes, 'worker1'
- end
- end
-
- context "when another worker has worked on a task since the job was found to be available, it" do
-
- before :each do
- Delayed::Job.worker_name = 'worker1'
- @job = Delayed::Job.create :payload_object => SimpleJob.new
- @job_copy_for_worker_2 = Delayed::Job.find(@job.id)
- end
-
- it "should not allow a second worker to get exclusive access if already successfully processed by worker1" do
- @job.delete
- @job_copy_for_worker_2.lock_exclusively!(4.hours, 'worker2').should == false
- end
-
- it "should not allow a second worker to get exclusive access if failed to be processed by worker1 and run_at time is now in future (due to backing off behaviour)" do
- @job.update_attributes(:attempts => 1, :run_at => Time.now + 1.day)
- @job_copy_for_worker_2.lock_exclusively!(4.hours, 'worker2').should == false
- end
- end
-
- context "#name" do
- it "should be the class name of the job that was enqueued" do
- Delayed::Job.create(:payload_object => ErrorJob.new ).name.should == 'ErrorJob'
- end
-
- it "should be the method that will be called if its a performable method object" do
- Delayed::Job.send_later(:clear_locks!)
- Delayed::Job.last.name.should == 'Delayed::Job.clear_locks!'
-
- end
- it "should be the instance method that will be called if its a performable method object" do
- story = Story.create :text => "..."
-
- story.send_later(:save)
-
- Delayed::Job.last.name.should == 'Story#save'
- end
- end
-
- context "worker prioritization" do
-
- before(:each) do
- Delayed::Job.max_priority = nil
- Delayed::Job.min_priority = nil
- end
-
- it "should only work_off jobs that are >= min_priority" do
- Delayed::Job.min_priority = -5
- Delayed::Job.max_priority = 5
- SimpleJob.runs.should == 0
-
- Delayed::Job.enqueue SimpleJob.new, -10
- Delayed::Job.enqueue SimpleJob.new, 0
- Delayed::Job.work_off
-
- SimpleJob.runs.should == 1
- end
-
- it "should only work_off jobs that are <= max_priority" do
- Delayed::Job.min_priority = -5
- Delayed::Job.max_priority = 5
- SimpleJob.runs.should == 0
-
- Delayed::Job.enqueue SimpleJob.new, 10
- Delayed::Job.enqueue SimpleJob.new, 0
-
- Delayed::Job.work_off
-
- SimpleJob.runs.should == 1
- end
-
- it "should fetch jobs ordered by priority" do
- number_of_jobs = 10
- number_of_jobs.times { Delayed::Job.enqueue SimpleJob.new, rand(10) }
- jobs = Delayed::Job.find_available(10)
- ordered = true
- jobs[1..-1].each_index{ |i|
- if (jobs[i].priority < jobs[i+1].priority)
- ordered = false
- break
- end
- }
- ordered.should == true
- end
-
- end
-
- context "when pulling jobs off the queue for processing, it" do
- before(:each) do
- @job = Delayed::Job.create(
- :payload_object => SimpleJob.new,
- :locked_by => 'worker1',
- :locked_at => Delayed::Job.db_time_now - 5.minutes)
- end
-
- it "should leave the queue in a consistent state and not run the job if locking fails" do
- SimpleJob.runs.should == 0
- @job.stub!(:lock_exclusively!).with(any_args).once.and_return(false)
- Delayed::Job.should_receive(:find_available).once.and_return([@job])
- Delayed::Job.work_off(1)
- SimpleJob.runs.should == 0
- end
-
- end
-
- context "while running alongside other workers that locked jobs, it" do
- before(:each) do
- Delayed::Job.worker_name = 'worker1'
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => (Delayed::Job.db_time_now - 1.minutes))
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker2', :locked_at => (Delayed::Job.db_time_now - 1.minutes))
- Delayed::Job.create(:payload_object => SimpleJob.new)
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => (Delayed::Job.db_time_now - 1.minutes))
- end
-
- it "should ingore locked jobs from other workers" do
- Delayed::Job.worker_name = 'worker3'
- SimpleJob.runs.should == 0
- Delayed::Job.work_off
- SimpleJob.runs.should == 1 # runs the one open job
- end
-
- it "should find our own jobs regardless of locks" do
- Delayed::Job.worker_name = 'worker1'
- SimpleJob.runs.should == 0
- Delayed::Job.work_off
- SimpleJob.runs.should == 3 # runs open job plus worker1 jobs that were already locked
- end
- end
-
- context "while running with locked and expired jobs, it" do
- before(:each) do
- Delayed::Job.worker_name = 'worker1'
- exp_time = Delayed::Job.db_time_now - (1.minutes + Delayed::Job::MAX_RUN_TIME)
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => exp_time)
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker2', :locked_at => (Delayed::Job.db_time_now - 1.minutes))
- Delayed::Job.create(:payload_object => SimpleJob.new)
- Delayed::Job.create(:payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => (Delayed::Job.db_time_now - 1.minutes))
- end
-
- it "should only find unlocked and expired jobs" do
- Delayed::Job.worker_name = 'worker3'
- SimpleJob.runs.should == 0
- Delayed::Job.work_off
- SimpleJob.runs.should == 2 # runs the one open job and one expired job
- end
-
- it "should ignore locks when finding our own jobs" do
- Delayed::Job.worker_name = 'worker1'
- SimpleJob.runs.should == 0
- Delayed::Job.work_off
- SimpleJob.runs.should == 3 # runs open job plus worker1 jobs
- # This is useful in the case of a crash/restart on worker1, but make sure multiple workers on the same host have unique names!
- end
-
- end
-
-end
View
17 vendor/plugins/delayed_job/spec/story_spec.rb
@@ -1,17 +0,0 @@
-require File.dirname(__FILE__) + '/database'
-
-describe "A story" do
-
- before(:all) do
- @story = Story.create :text => "Once upon a time..."
- end
-
- it "should be shared" do
- @story.tell.should == 'Once upon a time...'
- end
-
- it "should not return its result if it storytelling is delayed" do
- @story.send_later(:tell).should_not == 'Once upon a time...'
- end
-
-end
View
1  vendor/plugins/delayed_job/tasks/jobs.rake
@@ -1 +0,0 @@
-require File.join(File.dirname(__FILE__), 'tasks')
View
15 vendor/plugins/delayed_job/tasks/tasks.rb
@@ -1,15 +0,0 @@
-# Re-definitions are appended to existing tasks
-task :environment
-task :merb_env
-
-namespace :jobs do
- desc "Clear the delayed_job queue."
- task :clear => [:merb_env, :environment] do
- Delayed::Job.delete_all
- end
-
- desc "Start a delayed_job worker."
- task :work => [:merb_env, :environment] do
- Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY']).start
- end
-end
View
20 vendor/plugins/rails_upgrade/MIT-LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2010 Jeremy McAnally
-
-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.
View
20 vendor/plugins/rails_upgrade/README
@@ -1,20 +0,0 @@
-= rails-upgrade
-
-A simple battery of scripts for upgrading Rails app/checking them for required updates. This application should work on Rails 2.x and 3.0, with a focus on upgrading to 3.0.
-
-== Usage
-
- # Check your app for required upgrades
- rake rails:upgrade:check
-
- # Backup your likely modified files that might be overwritten by the generator
- rake rails:upgrade:backup
-
- # Generate a new route file
- rake rails:upgrade:routes
-
- # Generate a Gemfile from your config.gem directives
- rake rails:upgrade:gems
-
- # Generate code for a new config/application.rb from your environment.rb
- rake rails:upgrade:configuration
View
22 vendor/plugins/rails_upgrade/Rakefile
@@ -1,22 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-Rake::TestTask.new do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.test_files = FileList['test/*_test.rb']
- t.verbose = true
-end
-
-desc 'Generate documentation for the rails_upgrade plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'Rails-upgrade'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
View
2  vendor/plugins/rails_upgrade/init.rb
@@ -1,2 +0,0 @@
-# Get long stack traces for easier debugging; you'll thank me later.
-Rails.backtrace_cleaner.remove_silencers!
View
38 vendor/plugins/rails_upgrade/install.rb
@@ -1,38 +0,0 @@
-puts "Thanks for installing the Rails upgrade plugin. This is a set of generators and analysis tools to help you upgrade your application to Rails 3. It consists of three tasks...
-
-To get a feel for what you'll need to change to get your app running, run the application analysis:
-
- rake rails:upgrade:check
-
-This should give you an idea of the manual changes that need to be done, but you'll probably want to upgrade some of those automatically. The fastest way to do this is to run 'rails .', which will simply generate a new app on top of your existing code. But this generation also has the effect of replacing some existing files, some of which you might not want to replace. To back those up, first run:
-
- rake rails:upgrade:backup
-
-That will backup files you've probably edited that will be replaced in the upgrade; if you finish the upgrade and find that you don't need the old copies, just delete them. Otherwise, copy their contents back into the new files or run one of the following upgraders...
-
-Routes upgrader
-===============
-
-To generate a new routes file from your existing routes file, simply run the following Rake task:
-
- rake rails:upgrade:routes
-
-This will output a new routes file that you can copy and paste or pipe into a new, Rails 3 compatible config/routes.rb.
-
-Gemfile generator
-=================
-
-Creating a new Gemfile is as simple as running:
-
- rake rails:upgrade:gems
-
-This task will extract your config.gem calls and generate code you can put into a bundler compatible Gemfile.
-
-Configuration generator
-=======================
-
-Much of the configuration information that lived in environment.rb now belongs in a new file named config/application.rb; use the following task to generate code you can put into config/application.rb from your existing config/environment.rb:
-
- rake rails:upgrade:configuration
-
-"
View
472 vendor/plugins/rails_upgrade/lib/application_checker.rb
@@ -1,472 +0,0 @@
-require 'open3'
-
-module Rails
- module Upgrading
- class ApplicationChecker
- def initialize
- @issues = []
-
- raise NotInRailsAppError unless in_rails_app?
- end
-
- def in_rails_app?
- File.exist?("config/environment.rb")
- end
-
- # Run all the check methods
- def run
- # Ruby 1.8 returns method names as strings whereas 1.9 uses symbols
- the_methods = (self.public_methods - Object.methods) - [:run, :initialize, "run", "initialize"]
-
- the_methods.each {|m| send m }
- end
-
- # Check for deprecated ActiveRecord calls
- def check_ar_methods
- files = []
- ["find(:all", "find(:first", "find.*:conditions =>", ":joins =>"].each do |v|
- lines = grep_for(v, "app/")
- files += extract_filenames(lines) || []
- end
-
- unless files.empty?
- alert(
- "Soon-to-be-deprecated ActiveRecord calls",
- "Methods such as find(:all), find(:first), finds with conditions, and the :joins option will soon be deprecated.",
- "http://m.onkey.org/2010/1/22/active-record-query-interface",
- files
- )
- end
-
- lines = grep_for("named_scope", "app/models/")
- files = extract_filenames(lines)
-
- if files
- alert(
- "named_scope is now just scope",
- "The named_scope method has been renamed to just scope.",
- "http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914",
- files
- )
- end
- end
-
- def check_validation_on_methods
- files = []
-
- ["validate_on_create", "validate_on_update"].each do |v|
- lines = grep_for(v, "app/models/")
- files += extract_filenames(lines) || []
- end
-
- unless files.empty?
- alert(
- "Updated syntax for validate_on_* methods",
- "Validate-on-callback methods (validate_on_create/validate_on_destroy) have been changed to validate :x, :on => :create",
- "https://rails.lighthouseapp.com/projects/8994/tickets/3880-validate_on_create-and-validate_on_update-no-longer-seem-to-exist",
- files
- )
- end
- end
-
- def check_before_validation_on_methods
- files = []
-
- %w(before_validation_on_create before_validation_on_update).each do |v|
- lines = grep_for(v, "app/models/")
- files += extract_filenames(lines) || []
- end
-
- unless files.empty?
- alert(
- "Updated syntax for before_validation_on_* methods",
- "before_validation_on_* methods have been changed to before_validation(:on => :create/:update) { ... }",
- "https://rails.lighthouseapp.com/projects/8994/tickets/4699-before_validation_on_create-and-before_validation_on_update-doesnt-exist",
- files
- )
- end
- end
-
- # Check for deprecated router syntax
- def check_routes
- lines = ["map\\.", "ActionController::Routing::Routes", "\\.resources"].map do |v|
- grep_for(v, "config/routes.rb").empty? ? nil : true
- end.compact
-
- unless lines.empty?
- alert(
- "Old router API",
- "The router API has totally changed.",
- "http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/",
- "config/routes.rb"
- )
- end
- end
-
- # Check for deprecated test_help require
- def check_test_help
- files = []
-
- # Hate to duplicate code, but we have to double quote this one...
- lines = grep_for("\'test_help\'", "test/", true)
- files += extract_filenames(lines) || []
-
- lines = grep_for("\"test_help\"", "test/")
- files += extract_filenames(lines) || []
-
- files.uniq!
-
- unless files.empty?
- alert(
- "Deprecated test_help path",
- "You now must require 'rails/test_help' not just 'test_help'.",
- "http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices",
- files
- )
- end
- end
-
- # Check for old (pre-application.rb) environment.rb file
- def check_environment
- unless File.exist?("config/application.rb")
- alert(
- "New file needed: config/application.rb",
- "You need to add a config/application.rb.",
- "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
- "config/application.rb"
- )
- end
-
- lines = grep_for("config.", "config/environment.rb")
-
- unless lines.empty?
- alert(
- "Old environment.rb",
- "environment.rb doesn't do what it used to; you'll need to move some of that into application.rb.",
- "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
- "config/environment.rb"
- )
- end
- end
-
- # Check for deprecated constants
- def check_deprecated_constants
- files = []
- ["RAILS_ENV", "RAILS_ROOT", "RAILS_DEFAULT_LOGGER"].each do |v|
- lines = grep_for(v, "app/")
- files += extract_filenames(lines) || []
-
- lines = grep_for(v, "lib/")
- files += extract_filenames(lines) || []
- end
-
- unless files.empty?
- alert(
- "Deprecated constant(s)",
- "Constants like RAILS_ENV, RAILS_ROOT, and RAILS_DEFAULT_LOGGER are now deprecated.",
- "http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/",
- files.uniq
- )
- end
- end
-
- # Check for old-style config.gem calls
- def check_gems
- lines = grep_for("config.gem ", "config/*.rb")
- files = extract_filenames(lines)
-
- if files
- alert(
- "Old gem bundling (config.gems)",
- "The old way of bundling is gone now. You need a Gemfile for bundler.",
- "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
- files
- )
- end
- end
-
- # Checks for old mailer syntax in both mailer classes and those
- # classes utilizing the mailers
- def check_mailers
- lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/")
- files = extract_filenames(lines)
-
- if files
- alert(
- "Deprecated ActionMailer API",
- "You're using the old ActionMailer API to send e-mails in a controller, model, or observer.",
- "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
- files
- )
- end
-
- files = []
- ["recipients ", "attachment(?!s) ", "(?<!:)subject ", "(?<!:)from "].each do |v|
- lines = grep_for_with_perl_regex(v, "app/models/")
- files += extract_filenames(lines) || []
- end
-
- unless files.empty?
- alert(
- "Old ActionMailer class API",
- "You're using the old API in a mailer class.",
- "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
- files
- )
- end
- end
-
- # Checks for old-style generators
- def check_generators
- generators = Dir.glob(base_path + "vendor/plugins/**/generators/**/")
-
- unless generators.empty?
- files = generators.reject do |g|
- grep_for("def manifest", g).empty?
- end.compact
-
- if !files.empty?
- alert(
- "Old Rails generator API",
- "A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).",
- "http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/",
- files
- )
- end
- end
- end
-
- # Checks a list of known broken plugins and gems
- def check_plugins
- # This list is off the wiki; will need to be updated often, esp. since RSpec is working on it
- bad_plugins = ["rspec", "rspec-rails", "hoptoad", "authlogic", "nifty-generators",
- "restful_authentication", "searchlogic", "cucumber", "cucumber-rails", "devise",
- "inherited_resources"]
-
- bad_plugins = bad_plugins.map do |p|
- p if File.exist?("#{base_path}vendor/plugins/#{p}") || !Dir.glob("#{base_path}vendor/gems/#{p}-*").empty?
- end.compact
-
- unless bad_plugins.empty?
- alert(
- "Known broken plugins",
- "At least one plugin in your app is broken (according to the wiki). Most of project maintainers are rapidly working towards compatability, but do be aware you may encounter issues.",
- "http://wiki.rubyonrails.org/rails/version3/plugins_and_gems",
- bad_plugins
- )
- end
- end
-
- # Checks for old-style ERb helpers
- def check_old_helpers
-
- lines = grep_for("<% .*content_tag.* do.*%>", "app/views/**/*")
- lines += grep_for("<% .*javascript_tag.* do.*%>", "app/views/**/*")
- lines += grep_for("<% .*form_for.* do.*%>", "app/views/**/*")
- lines += grep_for("<% .*form_tag.* do.*%>", "app/views/**/*")
- lines += grep_for("<% .*fields_for.* do.*%>", "app/views/**/*")
- lines += grep_for("<% .*field_set_tag.* do.*%>", "app/views/**/*")
-
- files = extract_filenames(lines)
-
- if files
- alert(
- "Deprecated ERb helper calls",
- "Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.",
- "http://weblog.rubyonrails.org/",
- files
- )
- end
- end
-
- # Checks for old-style AJAX helpers
- def check_old_ajax_helpers
- files = []
- ['link_to_remote','form_remote_tag','remote_form_for'].each do |type|
- lines = grep_for(type, "app/views/**/*")
- inner_files = extract_filenames(lines)
- files += inner_files unless inner_files.nil?
- end
-
- unless files.empty?
- alert(
- "Deprecated AJAX helper calls",
- "AJAX javascript helpers have been switched to be unobtrusive and use :remote => true instead of having a seperate function to handle remote requests.",
- "http://www.themodestrubyist.com/2010/02/24/rails-3-ujs-and-csrf-meta-tags/",
- files
- )
- end
- end
-
- # Checks for old cookie secret settings
- def check_old_cookie_secret
- lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*")
- files = extract_filenames(lines)
-
- if files
- alert(
- "Deprecated cookie secret setting",
- "Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.",
- "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
- files
- )
- end
- end
-
- def check_old_session_secret
- lines = grep_for("ActionController::Base.session = {", "config/**/*")
- files = extract_filenames(lines)
-
- if files
- alert(
- "Deprecated session secret setting",
- "Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.",
- "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
- files
- )
- end
- end
-
- # Checks for old session settings
- def check_old_session_setting
- lines = grep_for("ActionController::Base.session_store", "config/**/*")
- files = extract_filenames(lines)
-
- if files
- alert(
- "Old session store setting",
- "Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.",
- "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
- files
- )
- end
- end
-
- private
- def grep_for_with_perl_regex(text, where = "./", double_quote = false)
- grep_for(text, where, double_quote, true)
- end
-
- # Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
- # depending on platform.
- #
- # TODO: Figure out if this works on Windows.
- def grep_for(text, where = "./", double_quote = false, perl_regex = false)
- # If they're on Windows, they probably don't have grep.
- @probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
-
- # protect against double root paths in Rails 3
- where.gsub!(Regexp.new(base_path),'')
-
- lines = if @probably_has_grep
- find_with_grep(text, base_path + where, double_quote, perl_regex)
- else
- find_with_rak(text, base_path + where, double_quote)
- end
-
- # ignore comments
- lines.gsub /^(\/[^:]+:)?\s*#.+$/m, ""
- end
-
- # Sets a base path for finding files; mostly for testing
- def base_path
- Dir.pwd + "/"
- end
-
- # Use the grep utility to find a string in a set of files
- def find_with_grep(text, where, double_quote, perl_regex = false)
- value = ""
- # Specifically double quote for finding 'test_help'
- command = if double_quote
- "grep -r #{"-P" if perl_regex} --exclude=\*.svn\* \"#{text}\" #{where}"
- else
- "grep -r #{"-P" if perl_regex} --exclude=\*.svn\* '#{text}' #{where}"
- end
-
- Open3.popen3(command) do |stdin, stdout, stderr|
- value = stdout.read
- end
- value
- end
-
- # Use the rak gem to grep the files (not yet implemented)
- def find_with_rak(text, where, double_quote)
- value = ""
- Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
- value = stdout.read
- end
- value
- end
-
- # Extract the filenames from the grep output
- def extract_filenames(output)
- if @probably_has_grep
- extract_filenames_from_grep(output)
- else
- extract_filenames_from_rak(output)
- end
- end
-
- def extract_filenames_from_grep(output)
- return nil if output.empty?
-
- output.split("\n").map do |fn|
- if m = fn.match(/^(.+?):/)
- m[1]
- end
- end.compact.uniq
- end
-
- def extract_filenames_from_rak(output)
- return nil if output.empty?
-
- output.split("\n").uniq
- end
-
- # Terminal colors, borrowed from Thor
- CLEAR = "\e[0m"
- BOLD = "\e[1m"
- RED = "\e[31m"
- YELLOW = "\e[33m"
- CYAN = "\e[36m"
- WHITE = "\e[37m"
-
- # Show an upgrade alert to the user
- def alert(title, text, more_info_url, culprits)
- if Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/
- basic_alert(title, text, more_info_url, culprits)
- else
- color_alert(title, text, more_info_url, culprits)
- end
- end
-
- # Show an upgrade alert to the user. If we're on Windows, we can't
- # use terminal colors, hence this method.
- def basic_alert(title, text, more_info_url, culprits)
- puts "** " + title
- puts text
- puts "More information: #{more_info_url}"
- puts
- puts "The culprits: "
- Array(culprits).each do |c|
- puts "\t- #{c}"
- end
- puts
- end
-
- # Show a colorful alert to the user
- def color_alert(title, text, more_info_url, culprits)
- puts "#{RED}#{BOLD}#{title}#{CLEAR}"
- puts "#{WHITE}#{text}"
- puts "#{BOLD}More information:#{CLEAR} #{CYAN}#{more_info_url}"
- puts
- puts "#{WHITE}The culprits: "
- Array(culprits).each do |c|
- puts "#{YELLOW}\t- #{c}"
- end
- ensure
- puts "#{CLEAR}"
- end
- end
- end
-end
View
95 vendor/plugins/rails_upgrade/lib/gemfile_generator.rb
@@ -1,95 +0,0 @@
-module Rails
- module Upgrading
- class GemfileGenerator
- def generate_new_gemfile
- if has_environment?
- generate_gemfile
- else
- raise FileNotFoundError, "Can't find environment.rb [config/environment.rb]!"
- end
- end
-
- def has_environment?
- File.exists?("config/environment.rb")
- end
-
- def environment_code
- File.open("config/environment.rb").read
- end
-
- def generate_gemfile
- environment_file = environment_code
-
- # Get each line that starts with config.gem
- gem_lines = environment_file.split("\n").select {|l| l =~ /^\s*config\.gem/}
-
- # Toss those lines to a generator class; the lines are evaluated in the
- # context of that instance.
- config = GemfileGenerator.new
- config.instance_eval(gem_lines.join("\n"))
-
- config.output
- end
- end
-
- class GemfileGenerator
- # Creates a target for the config.gem calls
- def config
- self
- end
-
- def initialize
- @gems = []
- end
-
- # Receive a call to add a gem to the list
- def gem(name, options={})
- data = {}
-
- # Add new keys from old keys
- data[:require] = options[:lib] if options[:lib]
- data[:source] = options[:source] if options[:source]
-
- version = options[:version]
- @gems << [name, version, data]
- end
-
- # Generate the Gemfile output
- def output
- # Generic preamble, taken from Yehuda Katz's blog
- preamble = <<STR
-# Edit this Gemfile to bundle your application's dependencies.
-# This preamble is the current preamble for Rails 3 apps; edit as needed.
-source 'http://rubygems.org'
-
-gem 'rails', '3.0.0.beta3'
-
-STR
- preamble + generate_upgraded_code
- end
-
- # Get Gemfile call for all the gems
- def generate_upgraded_code
- code = @gems.map do |name, version, data|
- version_string = (version ? "'#{version}'" : nil)
- source = data.delete(:source)
-
- data_string = nil
- unless data.empty?
- data_string = data.to_a.map {|k, v| ":#{k} => '#{v}'"}.join(", ")
- end
-
- # If we have a source, generate a call to +source+ then output the
- # gem call. Otherwise, just generate the gem requirement.
- if source
- str = ["'#{name}'", version_string, data_string].compact.join(", ")
- "source '#{source}'\ngem #{str}"
- else
- str = ["'#{name}'", version_string, data_string].compact.join(", ")
- "gem #{str}"
- end
- end.join("\n")
- end
- end
- end
-end
View
51 vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb
@@ -1,51 +0,0 @@
-module Rails
- module Upgrading
- class NewConfigurationGenerator
- def generate_new_configurations
- if has_environment?
- generate_new_application_rb
- else
- raise FileNotFoundError, "Can't find environment.rb [config/environment.rb]!"
- end
- end
-
- def has_environment?
- File.exists?("config/environment.rb")
- end
-
- def environment_code
- File.open("config/environment.rb").read
- end
-
- def generate_new_application_rb
- environment_file = environment_code
-
- initializer_code = ""
- if matches = environment_file.match(/Rails\:\:Initializer\.run do \|config\|\n(.*)\nend/m)
- initializer_code = matches[1]
- else
- raise "There doesn't seem to be a real environment.rb in your app. Are you sure config/environment.rb has the right contents?"
- end
-
- frame = "# Put this in config/application.rb
-require File.expand_path('../boot', __FILE__)
-
-module #{app_name.classify}
- class Application < Rails::Application
-%s
- end
-end"
-
- frame % [indent(initializer_code)]
- end
-
- def indent(text)
- text.split("\n").map {|l| " #{l}"}.join("\n")
- end
-
- def app_name
- File.basename(Dir.pwd)
- end
- end
- end
-end
View
0  vendor/plugins/rails_upgrade/lib/rails_upgrade.rb
No changes.
View
349 vendor/plugins/rails_upgrade/lib/routes_upgrader.rb
@@ -1,349 +0,0 @@
-# TODO: Fix formatting on member/collection methods
-
-module Rails
- module Upgrading
- module FakeRouter
- module ActionController
- module Routing
- class Routes
- def self.setup
- @redrawer = Rails::Upgrading::RouteRedrawer.new
- end
-
- def self.redrawer
- @redrawer
- end
-
- def self.draw
- yield @redrawer
- end
- end
- end
- end
- end
-
- class RoutesUpgrader
- def generate_new_routes
- if has_routes_file?
- upgrade_routes
- else
- raise FileNotFoundError, "Can't find your routes file [config/routes.rb]!"
- end
- end
-
- def has_routes_file?
- File.exists?("config/routes.rb")
- end
-
- def routes_code
- File.read("config/routes.rb")
- end
-
- def upgrade_routes
- FakeRouter::ActionController::Routing::Routes.setup
-
- # Read and eval the file; our fake route mapper will capture
- # the calls to draw routes and generate new route code
- FakeRouter.module_eval(routes_code)
-
- # Give the route set to the code generator and get its output
- generator = RouteGenerator.new(FakeRouter::ActionController::Routing::Routes.redrawer.routes)
- generator.generate
- end
- end
-
- class RouteRedrawer
- attr_accessor :routes
-
- def self.stack