From 664546c208c406bba08b8eda2e6a600154d7232e Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Tue, 5 Aug 2014 09:05:14 +0300 Subject: Integration testing --- test/dummy/Rakefile | 3 + test/dummy/app/assets/images/.keep | 0 .../app/controllers/application_controller.rb | 3 + test/dummy/app/controllers/concerns/.keep | 0 test/dummy/app/helpers/application_helper.rb | 2 + test/dummy/app/jobs/test_job.rb | 9 +++ test/dummy/app/mailers/.keep | 0 test/dummy/app/models/.keep | 0 test/dummy/app/models/concerns/.keep | 0 test/dummy/config.ru | 4 ++ test/dummy/config/application.rb | 9 +++ test/dummy/config/boot.rb | 5 ++ test/dummy/config/database.yml | 3 + test/dummy/config/environment.rb | 2 + test/dummy/config/environments/test.rb | 13 +++++ test/dummy/config/initializers/activejob.rb | 65 +++++++++++++++++++++ test/dummy/config/initializers/session_store.rb | 1 + test/dummy/config/routes.rb | 2 + test/dummy/config/secrets.yml | 2 + .../migrate/20140804200445_create_delayed_jobs.rb | 22 +++++++ test/dummy/db/schema.rb | 32 ++++++++++ test/dummy/db/test.sqlite3 | Bin 0 -> 24576 bytes test/dummy/lib/assets/.keep | 0 test/dummy/log/.keep | 0 test/dummy/tmp/.keep | 0 25 files changed, 177 insertions(+) create mode 100644 test/dummy/Rakefile create mode 100644 test/dummy/app/assets/images/.keep create mode 100644 test/dummy/app/controllers/application_controller.rb create mode 100644 test/dummy/app/controllers/concerns/.keep create mode 100644 test/dummy/app/helpers/application_helper.rb create mode 100644 test/dummy/app/jobs/test_job.rb create mode 100644 test/dummy/app/mailers/.keep create mode 100644 test/dummy/app/models/.keep create mode 100644 test/dummy/app/models/concerns/.keep create mode 100644 test/dummy/config.ru create mode 100644 test/dummy/config/application.rb create mode 100644 test/dummy/config/boot.rb create mode 100644 test/dummy/config/database.yml create mode 100644 test/dummy/config/environment.rb create mode 100644 test/dummy/config/environments/test.rb create mode 100644 test/dummy/config/initializers/activejob.rb create mode 100644 test/dummy/config/initializers/session_store.rb create mode 100644 test/dummy/config/routes.rb create mode 100644 test/dummy/config/secrets.yml create mode 100644 test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb create mode 100644 test/dummy/db/schema.rb create mode 100644 test/dummy/db/test.sqlite3 create mode 100644 test/dummy/lib/assets/.keep create mode 100644 test/dummy/log/.keep create mode 100644 test/dummy/tmp/.keep (limited to 'test/dummy') diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile new file mode 100644 index 0000000000..9866295e6a --- /dev/null +++ b/test/dummy/Rakefile @@ -0,0 +1,3 @@ +require 'sneakers/tasks' +require File.expand_path('../config/application', __FILE__) +Rails.application.load_tasks diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000000..1c07694e9d --- /dev/null +++ b/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception +end diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/test/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/dummy/app/jobs/test_job.rb b/test/dummy/app/jobs/test_job.rb new file mode 100644 index 0000000000..281771a851 --- /dev/null +++ b/test/dummy/app/jobs/test_job.rb @@ -0,0 +1,9 @@ +class TestJob < ActiveJob::Base + queue_as :default + + def perform(x) + File.open(Rails.root.join("tmp/#{x}"), "w+") do |f| + f.write x + end + end +end diff --git a/test/dummy/app/mailers/.keep b/test/dummy/app/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/app/models/.keep b/test/dummy/app/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/config.ru b/test/dummy/config.ru new file mode 100644 index 0000000000..5bc2a619e8 --- /dev/null +++ b/test/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb new file mode 100644 index 0000000000..8b06039a68 --- /dev/null +++ b/test/dummy/config/application.rb @@ -0,0 +1,9 @@ +require File.expand_path('../boot', __FILE__) +require 'rails/all' +Bundler.require(*Rails.groups) + +module Dummy + class Application < Rails::Application + end +end + diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb new file mode 100644 index 0000000000..6266cfc509 --- /dev/null +++ b/test/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml new file mode 100644 index 0000000000..f5f3aaf1fa --- /dev/null +++ b/test/dummy/config/database.yml @@ -0,0 +1,3 @@ +test: + adapter: sqlite3 + database: "db/test.sqlite3" diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb new file mode 100644 index 0000000000..7fd2f91b8f --- /dev/null +++ b/test/dummy/config/environment.rb @@ -0,0 +1,2 @@ +require File.expand_path('../application', __FILE__) +Rails.application.initialize! diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb new file mode 100644 index 0000000000..ff0318412f --- /dev/null +++ b/test/dummy/config/environments/test.rb @@ -0,0 +1,13 @@ +Rails.application.configure do + config.cache_classes = true + config.eager_load = false + config.serve_static_assets = true + config.static_cache_control = 'public, max-age=3600' + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.action_dispatch.show_exceptions = false + config.action_controller.allow_forgery_protection = false + config.action_mailer.delivery_method = :test + config.active_support.deprecation = :stderr + config.log_level = :debug +end diff --git a/test/dummy/config/initializers/activejob.rb b/test/dummy/config/initializers/activejob.rb new file mode 100644 index 0000000000..5fcde86c96 --- /dev/null +++ b/test/dummy/config/initializers/activejob.rb @@ -0,0 +1,65 @@ +case ENV['AJADAPTER'] +when "delayed_job" + ActiveJob::Base.queue_adapter = :delayed_job +when "sidekiq" + ActiveJob::Base.queue_adapter = :sidekiq +when "resque" + ActiveJob::Base.queue_adapter = :resque + Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "tcp://127.0.0.1:6379/12", :thread_safe => true) + Resque.logger = Rails.logger +when 'qu' + ActiveJob::Base.queue_adapter = :qu + ENV['REDISTOGO_URL'] = "tcp://127.0.0.1:6379/12" + backend = Qu::Backend::Redis.new + backend.namespace = "active_jobs_int_test" + Qu.backend = backend + Qu.logger = Rails.logger + Qu.interval = 0.5 +when 'que' + ActiveJob::Base.queue_adapter = :que + QUE_URL = ENV['QUE_DATABASE_URL'] || 'postgres://localhost/active_jobs_que_int_test' + uri = URI.parse(QUE_URL) + user = uri.user||ENV['USER'] + pass = uri.password + db = uri.path[1..-1] + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + Que.connection = Sequel.connect(QUE_URL) + Que.migrate! + Que.mode = :off + Que.worker_count = 1 +when 'queue_classic' + ENV['QC_DATABASE_URL'] ||= 'postgres://localhost/active_jobs_qc_int_test' + ENV['QC_LISTEN_TIME'] = "0.5" + ActiveJob::Base.queue_adapter = :queue_classic + uri = URI.parse(ENV['QC_DATABASE_URL']) + user = uri.user||ENV['USER'] + pass = uri.password + db = uri.path[1..-1] + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + QC::Setup.create +when 'sidekiq' + ActiveJob::Base.queue_adapter = :sidekiq +when 'sneakers' + ActiveJob::Base.queue_adapter = :sneakers + Sneakers.configure :heartbeat => 2, + :amqp => 'amqp://guest:guest@localhost:5672', + :vhost => '/', + :exchange => 'active_jobs_sneakers_int_test', + :exchange_type => :direct, + :daemonize => true, + :threads => 1, + :workers => 1, + :pid_path => Rails.root.join("tmp/sneakers.pid").to_s, + :log => Rails.root.join("log/sneakers.log").to_s +when 'sucker_punch' + ActiveJob::Base.queue_adapter = :sucker_punch +when 'backburner' + ActiveJob::Base.queue_adapter = :backburner + Backburner.configure do |config| + config.logger = Rails.logger + end +else + ActiveJob::Base.queue_adapter = nil +end diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000000..70a5a506a9 --- /dev/null +++ b/test/dummy/config/initializers/session_store.rb @@ -0,0 +1 @@ +Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb new file mode 100644 index 0000000000..1daf9a4121 --- /dev/null +++ b/test/dummy/config/routes.rb @@ -0,0 +1,2 @@ +Rails.application.routes.draw do +end diff --git a/test/dummy/config/secrets.yml b/test/dummy/config/secrets.yml new file mode 100644 index 0000000000..7dfacb38ea --- /dev/null +++ b/test/dummy/config/secrets.yml @@ -0,0 +1,2 @@ +test: + secret_key_base: b83ee5aeada663bc4270a1817d0ca43b2784017cc77dc8afcd60967cc968d4ce30caff9eb682766129e18a4048c4d5ebf14eabf463fc37ad67c18934f4345545 diff --git a/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb b/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb new file mode 100644 index 0000000000..ec0dd93ce1 --- /dev/null +++ b/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb @@ -0,0 +1,22 @@ +class CreateDelayedJobs < ActiveRecord::Migration + def self.up + create_table :delayed_jobs, :force => true do |table| + table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue + table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually. + table.text :handler, :null => false # 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.zone.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.string :queue # The name of the queue this job is in + table.timestamps + end + + add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' + end + + def self.down + drop_table :delayed_jobs + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb new file mode 100644 index 0000000000..012a099f9c --- /dev/null +++ b/test/dummy/db/schema.rb @@ -0,0 +1,32 @@ +# encoding: UTF-8 +# 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 +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140804200445) do + + create_table "delayed_jobs", force: true do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by" + t.string "queue" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority" + +end diff --git a/test/dummy/db/test.sqlite3 b/test/dummy/db/test.sqlite3 new file mode 100644 index 0000000000..671e20102e Binary files /dev/null and b/test/dummy/db/test.sqlite3 differ diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/log/.keep b/test/dummy/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/dummy/tmp/.keep b/test/dummy/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3