Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Specify supported rails versions #82

Merged
merged 7 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/InstalledFiles
/pkg/
/spec/reports/
/spec/test_app/db/*.sqlite3
/spec/test_app/log/*
/spec/test_app/tmp/*
/spec/test_apps/*/db/*.sqlite3
/spec/test_apps/*/log/*
/spec/test_apps/*/tmp/*
/tmp/

## Documentation cache and generated files:
Expand All @@ -25,3 +25,5 @@

node_modules
npm-debug.log

gemfiles/*.gemfile.lock
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%w[
4.2.10
].each do |rails_version|
ENV['APPRAISAL_RAILS_VERSION'] = rails_version
appraise("rails-#{rails_version}") { gem 'rails', rails_version }
end
36 changes: 14 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

require 'rdoc/task'
RSpec::Core::RakeTask.new(:spec)

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Guide'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
task :setup_test_app, [:rails_version] do |_task, args|
require_relative './spec/test_apps/setup'
TestApps::Setup.call args.fetch(:rails_version) {
abort "Example usage: rake #{ARGV[0]}[5.1.4]"
}
end

APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'


load 'rails/tasks/statistics.rake'



Bundler::GemHelper.install_tasks

if ENV['APPRAISAL_INITIALIZED'] || ENV['TRAVIS']
task default: :spec
else
require 'appraisal'
task default: :appraisal
end
7 changes: 7 additions & 0 deletions gemfiles/rails_4.2.10.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "4.2.10"

gemspec path: "../"
1 change: 1 addition & 0 deletions guide.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |s|
s.add_dependency "rails", ">= 3.1", "< 5"
s.add_dependency "sass-rails", ">= 3.2"

s.add_development_dependency "appraisal"
s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"
s.add_development_dependency "pry"
Expand Down
3 changes: 2 additions & 1 deletion scripts/buildkite_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
set -ex

bundle install --path vendor/bundle --retry 3
bundle exec rspec spec
bundle exec appraisal install
bundle exec appraisal rspec spec
5 changes: 4 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path("../../spec/test_app/config/environment", __FILE__)

rails_version = ENV.fetch('APPRAISAL_RAILS_VERSION', '4.2.10')
require File.expand_path("../../spec/test_apps/rails-#{rails_version}/config/environment", __FILE__)

# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
Expand Down
1 change: 1 addition & 0 deletions spec/test_apps/rails-4.2.10/app
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.load_path += Dir[Rails.root.join('../../config', 'locales', '**', '*.{rb,yml}')]

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
Expand Down
1 change: 1 addition & 0 deletions spec/test_apps/rails-4.2.10/config/database.yml
1 change: 1 addition & 0 deletions spec/test_apps/rails-4.2.10/config/initializers/i18n.rb
100 changes: 100 additions & 0 deletions spec/test_apps/setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module TestApps
class Setup
def self.call(*args)
new(*args).call
end

def initialize(rails_version)
@rails_version = rails_version
end

def call
return if completed?
abort(generate_app_instructions) unless app_exists?
add_symlinks
puts "Done!"
end

private

attr_reader :rails_version

def completed?
app_exists? && symlinks_exist?
end

def app_exists?
Dir.exists?(root)
end

def root
File.join(test_apps_root, "rails-#{rails_version}")
end

def test_apps_root
File.expand_path('..', __FILE__)
end

def symlinks_exist?
symlink_sources.all? do |source|
File.exist?(symlink_dest(source))
end
end

def symlink_sources
Dir[File.join(shared_root, '**/*')].select(&File.method(:file?))
end

def symlink_dest(source)
source.sub(shared_root, root)
end

def shared_root
File.join(test_apps_root, 'shared')
end

def generate_app_instructions
<<~EOS

A test app running rails v#{rails_version} needs to be added.

This can be achieved by running:

cd /tmp \\
&& gem install rails -v#{rails_version} \\
&& rails _#{rails_version}_ new test_app \\
--database=sqlite3 \\
--skip-yarn \\
--skip-gemfile \\
--skip-git \\
--skip-keeps \\
--skip-action-mailer \\
--skip-puma \\
--skip-action-cable \\
--skip-spring \\
--skip-listen \\
--skip-coffee \\
--skip-turbolinks \\
--skip-test \\
--skip-system-test \\
--skip-bundle \\
&& mv test_app #{root} \\
&& cd #{gem_root} \\
&& bundle exec rake setup_test_app[#{rails_version}]

EOS
end

def gem_root
File.expand_path('../../..', __FILE__)
end

def add_symlinks
symlink_sources.all? do |source|
dest = symlink_dest(source)
FileUtils.mkdir_p File.dirname(dest)
FileUtils.ln_sf source, dest
end
end
end
end
1 change: 1 addition & 0 deletions spec/test_apps/shared/config/initializers/i18n.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.i18n.load_path += Dir[Rails.root.join('../../../config', 'locales', '**', '*.{rb,yml}')]