From cf16188afdc8d78164a422d30187a3e43e0fbecc Mon Sep 17 00:00:00 2001 From: Greg Lazarev Date: Wed, 10 Jul 2013 11:39:05 -0700 Subject: [PATCH] Add support for Rails 4 * add rails4 default gems as development dependencies * drop support for Rails 3.0.x * move gems used for developoment and testing to Gemfile * (to allow using git url, and to try a new strategy of specifying development gems) --- .gitignore | 1 - Appraisals | 6 ++-- Gemfile | 15 ++++++++++ Gemfile.lock | 29 ++++++++++++------- README.md | 2 +- clearance.gemspec | 16 +--------- .../step_definitions/configuration_steps.rb | 28 ++++++++++-------- lib/clearance/testing/application.rb | 26 ++++++++--------- 8 files changed, 68 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index ca070f6ed..52f3212b4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ *.swp *~ .bundle -bin/ db/*.sqlite3 gemfiles/ log/*.log diff --git a/Appraisals b/Appraisals index f84423a87..505ac3966 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,7 @@ -if RUBY_VERSION >= '2.0' - rails_versions = ['~> 3.2.13'] +if RUBY_VERSION >= '1.9.3' + rails_versions = ['~> 3.2.13', '~> 4.0.0'] else - rails_versions = ['~> 3.0.20', '~> 3.1.12', '~> 3.2.13'] + rails_versions = ['~> 3.1.12'] end rails_versions.each do |rails_version| diff --git a/Gemfile b/Gemfile index fa75df156..8da5f872e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,18 @@ source 'https://rubygems.org' gemspec + +gem 'appraisal', '~> 0.5' +gem 'aruba', '~> 0.5' +gem 'bourne', '~> 1.4' +gem 'bundler', '~> 1.3' +gem 'capybara', '~> 2.0.3' +gem 'cucumber-rails', '~> 1.3' +gem 'database_cleaner', '~> 1.0' +gem 'factory_girl_rails', '~> 4.2' +gem 'jbuilder', '~> 1.2' +gem 'rspec-rails', '~> 2.13' +gem 'sdoc' +gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers' , branch: 'dp-rails-four' +gem 'sqlite3', '~> 1.3' +gem 'timecop', '~> 0.6' diff --git a/Gemfile.lock b/Gemfile.lock index 9bff33b23..36d9b30ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,18 @@ +GIT + remote: git://github.com/thoughtbot/shoulda-matchers.git + revision: 96e734d8946151ebf0e0d4488d05f2da30fdb59a + branch: dp-rails-four + specs: + shoulda-matchers (2.1.0) + activesupport (>= 3.0.0) + PATH remote: . specs: clearance (1.0.0.rc7) bcrypt-ruby email_validator (~> 1.4) - rails (>= 3.0) + rails (>= 3.1) GEM remote: https://rubygems.org/ @@ -44,7 +52,7 @@ GEM childprocess (>= 0.3.6) cucumber (>= 1.1.1) rspec-expectations (>= 2.7.0) - bcrypt-ruby (3.0.1) + bcrypt-ruby (3.1.1) bourne (1.4.0) mocha (~> 0.13.2) builder (3.0.4) @@ -82,6 +90,9 @@ GEM multi_json (~> 1.3) hike (1.2.3) i18n (0.6.4) + jbuilder (1.4.2) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) journey (1.0.4) json (1.8.0) mail (2.4.4) @@ -122,10 +133,6 @@ GEM rake (10.1.0) rdoc (3.12.2) json (~> 1.4) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) rspec-core (2.13.1) rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) @@ -138,13 +145,14 @@ GEM rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) rubyzip (0.9.9) + sdoc (0.3.20) + json (>= 1.1.3) + rdoc (~> 3.10) selenium-webdriver (2.33.0) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip websocket (~> 1.0.4) - shoulda-matchers (2.2.0) - activesupport (>= 3.0.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -175,8 +183,9 @@ DEPENDENCIES cucumber-rails (~> 1.3) database_cleaner (~> 1.0) factory_girl_rails (~> 4.2) - rspec (~> 2.13) + jbuilder (~> 1.2) rspec-rails (~> 2.13) - shoulda-matchers (~> 2.2) + sdoc + shoulda-matchers! sqlite3 (~> 1.3) timecop (~> 0.6) diff --git a/README.md b/README.md index fcc49a16f..8fc8c7671 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Read [CONTRIBUTING.md](/CONTRIBUTING.md) to contribute. Install ------- -Clearance is a Rails engine tested against Rails 3.x on Ruby 1.9.x and +Clearance is a Rails engine tested against Rails `>= 3.1` on Ruby 1.9.x, and Rails `>= 3.2.13` on Ruby 2.0 Include the gem in your Gemfile: diff --git a/clearance.gemspec b/clearance.gemspec index aa0c4dfa5..4bc15112c 100644 --- a/clearance.gemspec +++ b/clearance.gemspec @@ -24,19 +24,5 @@ Gem::Specification.new do |s| s.add_dependency 'bcrypt-ruby' s.add_dependency 'email_validator', '~> 1.4' - s.add_dependency 'rails', '>= 3.0' - - s.add_development_dependency 'appraisal', '~> 0.5' - s.add_development_dependency 'aruba', '~> 0.5' - s.add_development_dependency 'bourne', '~> 1.4' - s.add_development_dependency 'bundler', '~> 1.3' - s.add_development_dependency 'capybara', '~> 2.0.3' - s.add_development_dependency 'cucumber-rails', '~> 1.3' - s.add_development_dependency 'database_cleaner', '~> 1.0' - s.add_development_dependency 'factory_girl_rails', '~> 4.2' - s.add_development_dependency 'rspec', '~> 2.13' - s.add_development_dependency 'rspec-rails', '~> 2.13' - s.add_development_dependency 'shoulda-matchers', '~> 2.2' - s.add_development_dependency 'sqlite3', '~> 1.3' - s.add_development_dependency 'timecop', '~> 0.6' + s.add_dependency 'rails', '>= 3.1' end diff --git a/features/step_definitions/configuration_steps.rb b/features/step_definitions/configuration_steps.rb index 162f4214c..4883503ec 100644 --- a/features/step_definitions/configuration_steps.rb +++ b/features/step_definitions/configuration_steps.rb @@ -15,9 +15,13 @@ step "I successfully run `bundle exec rails new testapp --skip-bundle --skip-javascript --skip-sprockets`" end + step 'I cd to "testapp"' + + unless Clearance::Testing.rails4? + step 'I remove the file "public/index.html"' + end + steps %Q{ - When I cd to "testapp" - And I remove the file "public/index.html" And I remove the file "app/views/layouts/application.html.erb" And I configure ActionMailer to use "localhost" as a host And I configure a root route @@ -62,19 +66,11 @@ def show 'clearance.rb' ) steps %Q{ - And I write to "test/test_helper.rb" with: + When I append to "test/test_helper.rb" with: """ - ENV['RAILS_ENV'] = 'test' - require File.expand_path('../../config/environment', __FILE__) - require 'rails/test_help' - - class ActiveSupport::TestCase - fixtures :all - end - require 'clearance/testing' """ - And I write to "test/functional/posts_controller_test.rb" with: + And I overwrite "test/#{controller_test_dir}/posts_controller_test.rb" with: """ require 'test_helper' @@ -136,3 +132,11 @@ def self.down """ } end + +def controller_test_dir + if Clearance::Testing.rails4? + 'controllers' + else + 'functional' + end +end diff --git a/lib/clearance/testing/application.rb b/lib/clearance/testing/application.rb index 4c5be490a..936d29c54 100644 --- a/lib/clearance/testing/application.rb +++ b/lib/clearance/testing/application.rb @@ -4,6 +4,10 @@ module Clearance module Testing APP_ROOT = File.expand_path('..', __FILE__).freeze + def self.rails4? + Rails::VERSION::MAJOR == 4 + end + class Application < Rails::Application config.action_controller.allow_forgery_protection = false config.action_controller.perform_caching = false @@ -11,25 +15,21 @@ class Application < Rails::Application config.action_mailer.default_url_options = { :host => 'localhost' } config.action_mailer.delivery_method = :test config.active_support.deprecation = :stderr + config.assets.enabled = true config.cache_classes = true config.consider_all_requests_local = true + config.eager_load = false config.encoding = 'utf-8' + config.paths['app/controllers'] << "#{APP_ROOT}/app/controllers" + config.paths['app/views'] << "#{APP_ROOT}/app/views" + config.paths['config/database'] = "#{APP_ROOT}/config/database.yml" + config.paths['log'] = 'tmp/log/development.log' config.secret_token = 'SECRET_TOKEN_IS_MIN_30_CHARS_LONG' - config.whiny_nils = true - if Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR >= 1 - config.assets.enabled = true - config.paths['app/controllers'] << "#{APP_ROOT}/app/controllers" - config.paths['app/views'] << "#{APP_ROOT}/app/views" - config.paths['config/database'] = "#{APP_ROOT}/config/database.yml" - config.paths['config/routes'] << "#{APP_ROOT}/config/routes.rb" - config.paths['log'] = 'tmp/log/development.log' + if Clearance::Testing.rails4? + config.paths.add 'config/routes.rb', with: "#{APP_ROOT}/config/routes.rb" else - config.paths.app.controllers << "#{APP_ROOT}/app/controllers" - config.paths.app.views << "#{APP_ROOT}/app/views" - config.paths.config.database = "#{APP_ROOT}/config/database.yml" - config.paths.config.routes << "#{APP_ROOT}/config/routes.rb" - config.paths.log = 'tmp/log' + config.paths.add 'config/routes', with: "#{APP_ROOT}/config/routes.rb" end def require_environment!