combustion-0.5.4/0000755000004100000410000000000012655536360013745 5ustar www-datawww-datacombustion-0.5.4/Rakefile0000644000004100000410000000003412655536357015415 0ustar www-datawww-datarequire 'bundler/gem_tasks' combustion-0.5.4/bin/0000755000004100000410000000000012655536357014523 5ustar www-datawww-datacombustion-0.5.4/bin/combust0000755000004100000410000000017312655536357016126 0ustar www-datawww-data#!/usr/bin/env ruby # -*- mode: ruby -*- require 'combustion' require 'combustion/generator' Combustion::Generator.start combustion-0.5.4/Gemfile0000644000004100000410000000004612655536357015246 0ustar www-datawww-datasource "http://rubygems.org" gemspec combustion-0.5.4/templates/0000755000004100000410000000000012655536360015743 5ustar www-datawww-datacombustion-0.5.4/templates/schema.rb0000644000004100000410000000004712655536360017531 0ustar www-datawww-dataActiveRecord::Schema.define do # end combustion-0.5.4/templates/database.yml0000644000004100000410000000014712655536360020234 0ustar www-datawww-datatest: adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3 database: db/combustion_test.sqlite combustion-0.5.4/templates/routes.rb0000644000004100000410000000005112655536360017605 0ustar www-datawww-dataRails.application.routes.draw do # end combustion-0.5.4/templates/config.ru0000644000004100000410000000020612655536360017556 0ustar www-datawww-datarequire 'rubygems' require 'bundler' Bundler.require :default, :development Combustion.initialize! :all run Combustion::Application combustion-0.5.4/spec/0000755000004100000410000000000012655536360014677 5ustar www-datawww-datacombustion-0.5.4/spec/spec_helper.rb0000644000004100000410000000007512655536360017517 0ustar www-datawww-data# coding: utf-8 require 'bundler/setup' require 'combustion' combustion-0.5.4/spec/dummy/0000755000004100000410000000000012655536360016032 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/db/0000755000004100000410000000000012655536360016417 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/db/migrate/0000755000004100000410000000000012655536360020047 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/db/migrate/20150717075542_create_dummy_test_table.rb0000644000004100000410000000015312655536360026734 0ustar www-datawww-dataclass CreateDummyTestTable < ActiveRecord::Migration def change create_table 'dummy_table' end end combustion-0.5.4/spec/dummy/spec/0000755000004100000410000000000012655536360016764 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/spec/internal/0000755000004100000410000000000012655536360020600 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/spec/internal/log/0000755000004100000410000000000012655536360021361 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/spec/internal/log/.gitignore0000644000004100000410000000000512655536360023344 0ustar www-datawww-data*.logcombustion-0.5.4/spec/dummy/spec/internal/db/0000755000004100000410000000000012655536360021165 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/spec/internal/db/schema.rb0000644000004100000410000000004712655536360022753 0ustar www-datawww-dataActiveRecord::Schema.define do # end combustion-0.5.4/spec/dummy/spec/internal/config/0000755000004100000410000000000012655536360022045 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/spec/internal/config/database.yml0000644000004100000410000000010012655536360024323 0ustar www-datawww-datatest: adapter: sqlite3 database: db/combustion_test.sqlite combustion-0.5.4/spec/dummy/spec/internal/config/routes.rb0000644000004100000410000000005112655536360023707 0ustar www-datawww-dataRails.application.routes.draw do # end combustion-0.5.4/spec/dummy/lib/0000755000004100000410000000000012655536360016600 5ustar www-datawww-datacombustion-0.5.4/spec/dummy/lib/engine.rb0000644000004100000410000000031112655536360020365 0ustar www-datawww-datamodule Dummy class Engine < ::Rails::Engine initializer :dummy, before: :load_init_rb do |app| app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded) end end end combustion-0.5.4/spec/database_spec.rb0000644000004100000410000000063212655536357020011 0ustar www-datawww-datarequire 'spec_helper' require File.expand_path("../dummy/lib/engine.rb", __FILE__) module Combustion describe Database do before do Dir.chdir(File.expand_path('../dummy', __FILE__)) do Combustion.initialize! :active_record end end it 'run migration from dummy engine' do expect(ActiveRecord::Base.connection.table_exists?('dummy_table')).to eq true end end end combustion-0.5.4/lib/0000755000004100000410000000000012655536357014521 5ustar www-datawww-datacombustion-0.5.4/lib/combustion.rb0000644000004100000410000000321512655536357017231 0ustar www-datawww-datarequire 'rails' require 'active_support/dependencies' module Combustion mattr_accessor :path, :schema_format mattr_reader :setup_environment self.path = '/spec/internal' self.schema_format = :ruby if Rails.version.to_s > '3.1' Modules = %w( active_record action_controller action_view action_mailer sprockets ) else Modules = %w( active_record action_controller action_view action_mailer ) end def self.initialize!(*modules, &block) @@setup_environment = block if block_given? modules = Modules if modules == [:all] modules.each { |mod| require "#{mod}/railtie" } Bundler.require :default, Rails.env Combustion::Application.configure_for_combustion if modules.map(&:to_s).include? 'active_record' Combustion::Application.config.to_prepare do Combustion::Database.setup end end Combustion::Application.initialize! RSpec.configure do |config| include_capybara_into config config.include Combustion::Application.routes.url_helpers if Combustion::Application.routes.respond_to?(:mounted_helpers) config.include Combustion::Application.routes.mounted_helpers end end if defined?(RSpec) && RSpec.respond_to?(:configure) end def self.include_capybara_into(config) return unless defined?(Capybara) config.include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers) config.include Capybara::DSL if defined?(Capybara::DSL) unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL) config.include Capybara end end end require 'combustion/application' require 'combustion/database' combustion-0.5.4/lib/combustion/0000755000004100000410000000000012655536357016703 5ustar www-datawww-datacombustion-0.5.4/lib/combustion/application.rb0000644000004100000410000000400112655536357021526 0ustar www-datawww-datarequire 'securerandom' Rails.env = ENV['RAILS_ENV'] || 'test' module Combustion class Application < Rails::Application # Core Settings config.cache_classes = true config.whiny_nils = true if Rails.version.to_s < '4.0.0' config.consider_all_requests_local = true config.secret_token = Digest::SHA1.hexdigest Time.now.to_s config.eager_load = Rails.env.production? config.secret_key_base = SecureRandom.hex if Rails.version.to_s >= '4.0.0' # ActiveSupport Settings config.active_support.deprecation = :stderr # Some settings we're not sure if we want, so let's not load them by # default. Instead, wait for this method to be invoked (to get around # load-order complications). def self.configure_for_combustion config.root = File.expand_path File.join(Dir.pwd, Combustion.path) if defined?(ActiveRecord::Railtie) && ::ActiveRecord.constants.include?(:MassAssignmentSecurity) # Turn on ActiveRecord attribute whitelisting # This way the dummy app matches new rails apps re: this setting config.active_record.whitelist_attributes = true config.active_record.mass_assignment_sanitizer = :strict end if defined?(ActionController::Railtie) config.action_dispatch.show_exceptions = false config.action_controller.perform_caching = false config.action_controller.allow_forgery_protection = false end if defined?(ActionMailer::Railtie) config.action_mailer.delivery_method = :test config.action_mailer.default_url_options = {:host => 'www.example.com'} end if defined?(Sprockets) config.assets.enabled = true end end initializer :load_customized_environment_for_combustion, :before => :load_environment_config, :group => :all do Combustion::Application.class_eval(&Combustion.setup_environment) if Combustion.setup_environment end end end combustion-0.5.4/lib/combustion/database.rb0000644000004100000410000001575212655536357021006 0ustar www-datawww-datamodule Combustion class Database def self.setup reset_database load_schema migrate end def self.reset_database ActiveRecord::Base.configurations = YAML.load(ERB.new(File.read("#{Rails.root}/config/database.yml")).result) abcs = ActiveRecord::Base.configurations case abcs['test']['adapter'] when /mysql/ drop_database(abcs['test']['database']) create_database(abcs['test']) ActiveRecord::Base.establish_connection(:test) when /postgresql/ ActiveRecord::Base.clear_active_connections! drop_database(abcs['test']) create_database(abcs['test']) when /sqlite/ drop_database(abcs['test']) create_database(abcs['test']) when 'sqlserver' test = abcs.deep_dup['test'] test_database = test['database'] test['database'] = 'master' ActiveRecord::Base.establish_connection(test) ActiveRecord::Base.connection.recreate_database!(test_database) when "oci", "oracle" ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| ActiveRecord::Base.connection.execute(ddl) end when 'firebird' ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.recreate_database! else raise "Cannot reset databases for '#{abcs['test']['adapter']}'" end end def self.load_schema case Combustion.schema_format when :ruby load Rails.root.join('db', 'schema.rb') when :sql ActiveRecord::Base.connection.execute( File.read(Rails.root.join('db', 'structure.sql')) ) else raise "Unknown schema format: #{Combustion.schema_format}" end end def self.migrate migrator = ActiveRecord::Migrator engine_path = Rails.application.root.sub(::Combustion.path, '') engine_migration_paths = Rails.application.paths['db/migrate'].to_a if engine_migration_paths.include?(engine_path.join('db/migrate').to_s) paths = [] else paths = base_migration_paths end paths += engine_migration_paths paths.uniq! # Append the migrations inside the internal app's db/migrate directory paths << File.join(Rails.root, 'db/migrate') if ActiveRecord::VERSION::STRING >= '3.1.0' migrator.migrate paths, nil else paths.each { |path| migrator.migrate path, nil } end end private def self.base_migration_paths if ActiveRecord::Migrator.respond_to?(:migrations_paths) ActiveRecord::Migrator.migrations_paths else Array('db/migrate/') end end def self.create_database(config) begin if config['adapter'] =~ /sqlite/ if File.exist?(config['database']) $stderr.puts "#{config['database']} already exists" else begin # Create the SQLite database ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection rescue Exception => e $stderr.puts e, *(e.backtrace) $stderr.puts "Couldn't create database for #{config.inspect}" end end return # Skip the else clause of begin/rescue else ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection end rescue case config['adapter'] when /^(jdbc)?mysql/ if config['adapter'] =~ /jdbc/ #FIXME After Jdbcmysql gives this class require 'active_record/railties/jdbcmysql_error' error_class = ArJdbcMySQL::Error else error_class = config['adapter'] =~ /mysql2/ && defined?(Mysql2) ? Mysql2::Error : Mysql::Error end access_denied_error = 1045 begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config)) ActiveRecord::Base.establish_connection(config) rescue error_class => sqlerr if sqlerr.errno == access_denied_error print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>" root_password = $stdin.gets.strip grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \ "TO '#{config['username']}'@'localhost' " \ "IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;" ActiveRecord::Base.establish_connection(config.merge( 'database' => nil, 'username' => 'root', 'password' => root_password)) ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config)) ActiveRecord::Base.connection.execute grant_statement ActiveRecord::Base.establish_connection(config) else $stderr.puts sqlerr.error $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}" $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset'] end end when /^(jdbc)?postgresql$/ @encoding = config['encoding'] || ENV['CHARSET'] || 'utf8' begin ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding)) ActiveRecord::Base.establish_connection(config) rescue Exception => e $stderr.puts e, *(e.backtrace) $stderr.puts "Couldn't create database for #{config.inspect}" end end else $stderr.puts "#{config['database']} already exists" end end def self.drop_database(config) case config['adapter'] when /^(jdbc)?mysql/ ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database config['database'] when /^(jdbc)?sqlite/ require 'pathname' path = Pathname.new(config['database']) file = path.absolute? ? path.to_s : File.join(Rails.root, path) FileUtils.rm_f(file) if File.exist?(file) when /^(jdbc)?postgresql$/ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.connection.drop_database config['database'] end end def self.mysql_creation_options(config) @charset = ENV['CHARSET'] || 'utf8' @collation = ENV['COLLATION'] || 'utf8_unicode_ci' { :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation) } end end end combustion-0.5.4/lib/combustion/generator.rb0000644000004100000410000000165312655536357021223 0ustar www-datawww-datarequire 'thor/group' module Combustion class Generator < Thor::Group include Thor::Actions def self.source_root File.expand_path File.join(File.dirname(__FILE__), '..', '..') end def create_directories empty_directory 'spec/internal' empty_directory 'spec/internal/config' empty_directory 'spec/internal/db' empty_directory 'spec/internal/log' empty_directory 'spec/internal/public' end def create_files template 'templates/routes.rb', 'spec/internal/config/routes.rb' template 'templates/database.yml', 'spec/internal/config/database.yml' template 'templates/schema.rb', 'spec/internal/db/schema.rb' template 'templates/config.ru', 'config.ru' create_file 'spec/internal/public/favicon.ico' create_file 'spec/internal/log/.gitignore' do '*.log' end end end end combustion-0.5.4/metadata.yml0000644000004100000410000000772112655536360016257 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: combustion version: !ruby/object:Gem::Version version: 0.5.4 platform: ruby authors: - Pat Allan autorequire: bindir: bin cert_chain: [] date: 2016-01-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activesupport requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.0.0 - !ruby/object:Gem::Dependency name: railties requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.0.0 - !ruby/object:Gem::Dependency name: thor requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.14.6 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.14.6 - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: sqlite3 requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: Test your Rails Engines without needing a full Rails app email: - pat@freelancing-gods.com executables: - combust extensions: [] extra_rdoc_files: [] files: - ".gitignore" - Gemfile - HISTORY - LICENCE - README.md - Rakefile - bin/combust - combustion.gemspec - lib/combustion.rb - lib/combustion/application.rb - lib/combustion/database.rb - lib/combustion/generator.rb - spec/database_spec.rb - spec/dummy/db/migrate/20150717075542_create_dummy_test_table.rb - spec/dummy/lib/engine.rb - spec/dummy/spec/internal/config/database.yml - spec/dummy/spec/internal/config/routes.rb - spec/dummy/spec/internal/db/schema.rb - spec/dummy/spec/internal/log/.gitignore - spec/spec_helper.rb - templates/config.ru - templates/database.yml - templates/routes.rb - templates/schema.rb homepage: https://github.com/pat/combustion licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: combustion rubygems_version: 2.4.8 signing_key: specification_version: 4 summary: Elegant Rails Engine Testing test_files: - spec/database_spec.rb - spec/dummy/db/migrate/20150717075542_create_dummy_test_table.rb - spec/dummy/lib/engine.rb - spec/dummy/spec/internal/config/database.yml - spec/dummy/spec/internal/config/routes.rb - spec/dummy/spec/internal/db/schema.rb - spec/dummy/spec/internal/log/.gitignore - spec/spec_helper.rb combustion-0.5.4/.gitignore0000644000004100000410000000015112655536357015740 0ustar www-datawww-data*.gem .bundle Gemfile.lock pkg/* .rvmrc .ruby-version spec/dummy/spec/internal/db/combustion_test.sqlite combustion-0.5.4/HISTORY0000644000004100000410000000651712655536357015050 0ustar www-datawww-data0.5.4 - January 12th 2016 * Remove silent_stream call for Rails 5.0 compatability (Bryan Ricker). * Fix duplicate migrations error (Semyon Pupkov). 0.5.3 - March 1st 2015 * Use migrations from dependent gems (Korotaev Danil, Меркушин Михаил). 0.5.2 - July 18th 2014 * Note MIT licence in gemspec (@ktdreyer). * Use local create/drop methods when resetting database (Bryan Ricker). * ERB is now supported in config/database.yml, matching Rails (@patorash). * The database now is configured before the application is loaded (@patorash). * Documentation and generated config.ru now specify explicly loading all Rails libraries by default (Pat Allan). 0.5.1 - July 25th 2013 * Mass assignment errors raise exceptions instead of just being logged (Pat Allan). * whilelist_attributes is only set for Rails 3.2 apps (Philip Arndt). * Support ActiveRecord 3.0.x (Philip Arndt). * Allow custom application configuration (Pablo Herrero). 0.5.0 - May 1st 2013 * whitelist_attributes is now set within configure_for_combustion, as it depends on which Railties are loaded. * Make sure Rails gems are loaded before the engine's gem (Pablo Herrero). * Fixed Rails version comparison (Josh Adam). 0.4.0 - March 16th 2013 * Don't delete the SQLite test database if it doesn't exist (Michael Gee, Alexander Rozumiy). * Support for secret_key_base for Rails 4 apps (Philip Arndt). * eager_load is set to true when using the production environment (Philip Arndt). * whiny_nils is not set if using Rails 4 (Philip Arndt). * Mysql2 can raise Mysql::Error with JRuby (Philip Arndt). * Whitelist attributes typo is fixed (Geoff Hodgson). * Mass assignment checks are now turned on, so errors are raised. This matches Rails' defaults for test environments (Josh Adams). * Combustion no longer loads all of the Rails stack by default, just Railties and ActiveSupport. A combustion-rails gem will be created that uses all of Rails by default (Philip Arndt). * Combustion classes now all define the outer module, so each can be required by themselves, should you desire (Philip Arndt). 0.3.3 - December 23rd 2012 * Removing version file - version number can just live in the gemspec. * Load ActionController and ActionMailer via their Railties, not non-existent Engines (Chris Beer). * SQL Schema support (Geoff Hodgson). * Documentation fixes (Philip Arndt, Inge Jørgensen, Erkan Yilmaz). * Include migrations from the internal app when migrating the database (Warren Seen). * Correctly drop the test database when using SQLite (Warren Seen). * Don't attempt to load sprockets for Rails 3.0.x (Alex Rozumey). 0.3.2 - March 3rd 2012 * Tentative Rails 3.0 and migrations support. * Allow for different internal app directory. 0.3.1 - September 12th 2011 * Allow for different versions of Capybara (Leo Liang). * Including Capybara::DSL instead of Capybara. * Require 3.1.0 or better. * Allow for JRuby in the database.yml template (Philip Arndt). 0.3.0 - September 2nd 2011 * Simple generator to create a pretty minimal internal Rails app. 0.2.0 - August 30th 2011 * Documentation. * Allow developers to choose which Rails modules they wish to be loaded. * Load Rails routes and Capybara helpers into RSpec examples when appropriate. 0.1.1 - August 24th 2011 * Support assets properly by loading ActionView and Sprockets railties. 0.1.0 - August 19th 2011 * First release, extracted from Dobro for HyperTiny. combustion-0.5.4/combustion.gemspec0000644000004100000410000000166112655536357017506 0ustar www-datawww-data# -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'combustion' s.version = '0.5.4' s.authors = ['Pat Allan'] s.email = ['pat@freelancing-gods.com'] s.homepage = 'https://github.com/pat/combustion' s.summary = 'Elegant Rails Engine Testing' s.description = 'Test your Rails Engines without needing a full Rails app' s.license = 'MIT' s.rubyforge_project = 'combustion' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ['lib'] s.add_runtime_dependency 'activesupport', '>= 3.0.0' s.add_runtime_dependency 'railties', '>= 3.0.0' s.add_runtime_dependency 'thor', '>= 0.14.6' s.add_development_dependency 'rails' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec' end combustion-0.5.4/LICENCE0000644000004100000410000000203512655536357014740 0ustar www-datawww-dataCopyright (c) 2011 Pat Allan 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. combustion-0.5.4/README.md0000644000004100000410000002005312655536357015232 0ustar www-datawww-data# Combustion Combustion is a library to help you test your Rails Engines in a simple and effective manner, instead of creating a full Rails application in your spec or test folder. It allows you to write your specs within the context of your engine, using only the parts of a Rails app you need. ## Usage Get the gem into either your gemspec or your Gemfile, depending on how you manage your engine's dependencies: ```ruby # gemspec gem.add_development_dependency 'combustion', '~> 0.5.4' # Gemfile gem 'combustion', '~> 0.5.4', :group => :test ``` In your `spec_helper.rb`, get Combustion to set itself up - which has to happen before you introduce `rspec/rails` and - if being used - `capybara/rails`. Here's an example within context: ```ruby require 'rubygems' require 'bundler/setup' require 'combustion' require 'capybara/rspec' Combustion.initialize! :all require 'rspec/rails' require 'capybara/rails' RSpec.configure do |config| config.use_transactional_fixtures = true end ``` You'll also want to run the generator that creates a minimal set of files expected by Rails - run this in the directory of your engine: ```shell combust # or, if bundling with the git repo: bundle exec combust ``` What Combustion is doing is setting up a Rails application at `spec/internal` - but you only need to add the files within that directory that you're going to use. Read on for some detail about what that involves. If you want to use Cucumber, I recommend starting with [these notes in issue #16](https://github.com/pat/combustion/issues/16) from Niklas Cathor. ### Configuring a different test app directory If you want your app to be located somewhere other than `spec/internal`, then make sure you configure it before you call `Combustion.initialize!`: ```ruby Combustion.path = 'spec/dummy' Combustion.initialize! :all ``` ### Configuring which Rails modules should be loaded. By default, Combustion doesn't come with any of the Rails stack. You can customise this though - just pass in what you'd like loaded to the `Combustion.initialize!` call: ```ruby Combustion.initialize! :active_record, :action_controller, :action_view, :sprockets ``` And then in your engine's Gemfile: ```ruby group :test do gem 'activerecord' gem 'actionpack' # action_controller, action_view gem 'sprockets' end ``` Make sure to specify the appropriate version that you want to use. ActiveSupport and Railties are always loaded, as they're an integral part of Rails. ### Using Models and ActiveRecord If you're using ActiveRecord, then there are two critical files within your internal Rails app at `spec/internal` that you'll need to modify: * config/database.yml * db/schema.rb Both follow the same structure as in any normal Rails application - and the schema file lets you avoid migrations, as it gets run whenever the test suite starts. Here's a quick sample (note that tables are overwritten if they already exist - this is necessary): ```ruby ActiveRecord::Schema.define do create_table(:pages, :force => true) do |t| t.string :name t.text :content t.timestamps end end ``` ### Configuring Combustion to initialise the test db from a .sql file instead of schema.rb Name the file structure.sql and configure Combustion to use it before initialising: ```ruby Combustion.schema_format = :sql Combustion.initialize! :all ``` Any models that aren't provided by your engine should be located at `spec/internal/app/models`. ### Using ActionController and ActionView You'll only need to add controllers and views to your internal Rails app for whatever you're testing that your engine doesn't provide - this may be nothing at all, so perhaps you don't even need `spec/internal/app/views` or `spec/internal/app/controllers` directories. However, if you're doing any testing of your engine's controllers or views, then you're going to need routes set up for them - so modify `spec/internal/config/routes.rb` accordingly: ```ruby Rails.application.routes.draw do resources :pages end ``` Just like in a standard Rails app, if you have a mounted engine, then its routes are accessible through whatever it has been loaded as. ### Customizing Rails application settings If you would like to specify any Rails configuration parameter, you can do it without creating any environment file, simply passing a block to Combustion.initialize! like this: ```ruby Combustion.initialize! :all do config.active_record.whitelist_attributes = false end ``` Values given through the initialize! block will be set during Rails initialization proccess, exactly before the corresponding environment file inside `spec/internals/config/enviroments` is loaded (when that file exists), overriding Combustion's defaults. Parameters defined in, for instance, `spec/internals/config/environments/test.rb`, would override Combustion's defaults and also config settings passed to initialize!. ### Using other Rails-focused libraries Be aware that other gems may require parts of Rails when they're loaded, and this could cause some issues with Combustion's own setup. You may need to manage the loading yourself by setting `:require` to false in your Gemfile for the gem in question, and then requiring it manually in your spec_helper. View [issue #33](https://github.com/pat/combustion/issues/33) for an example with FactoryGirl. ### Environment and Logging Your tests will execute within the test environment for the internal Rails app - and so logs are available at `spec/internal/log/test.log`. You should probably create that log directory so Rails doesn't complain. ### Rack it up Once you've got this set up, you can fire up your test environment quite easily with Rack - a `config.ru` file is provided by the generator. Just run `rackup` and visit [http://localhost:9292](http://localhost:9292). ### Get your test on! Now you're good to go - you can write specs within your engine's spec directory just like you were testing a full Rails application - models in `spec/models`, controllers in `spec/controllers`. If you bring Capybara into the mix, then the standard helpers from that will be loaded as well. ```ruby require 'spec_helper' describe Page do describe '#valid' do it 'requires a name' do # This is just an example. Go write your own tests! end end end ``` ## Compatibility Developed for Rails 3.1 or better (including Rails 4) and Ruby 1.9 or better. It should work on any other Ruby, and possibly Rails 3.0, but will not work neatly with earlier versions of Rails. You can also use Combustion with multiple versions of Rails to test compatibility across them. [Appraisal](https://github.com/thoughtbot/appraisal) is a gem that can help with this, and a good starting reference is the [Thinking Sphinx](https://github.com/pat/thinking-sphinx) test suite, which runs against [multiple versions](https://github.com/pat/thinking-sphinx/blob/master/Appraisals) of Rails. ## Limitations and Known Issues Combustion is currently written with the expectation it'll be used with RSpec. I'd love to make this more flexible - if you want to give it a shot before I get around to it, patches are very much welcome. I've not tried using this with Cucumber, but it should work in theory without too much hassle. Let me know if I'm wrong! ## Contributing Please note that this project now has a [Contributor Code of Conduct](http://contributor-covenant.org/version/1/0/0/). By participating in this project you agree to abide by its terms. Contributions are very much welcome - but keep in mind the following: * Keep patches in a separate branch * Don't mess with the version or history file. I'll take care of that when the patch is merged in. There are no tests - partly because Combustion was extracted out from the tests of HyperTiny's Dobro, and partly because there's not much code. Still, if you can find a clean way of testing this, that'd be fantastic. ## Credits Copyright (c) 2011, Combustion is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to HyperTiny for encouraging its development, and [all who have contributed patches](https://github.com/pat/combustion/contributors).