Skip to content

Commit

Permalink
Add Rails 5 support
Browse files Browse the repository at this point in the history
Closes [#376].

Required changes
----------------

Run test suite against the latest `5.0.0.betaX` and `master` branches of
[`rails/rails`][rails].

Since `EmberController` extends `ApplicationController`, which can now
extend from either `ActionController::Base` (which implements
`helper_method`) and `ActionController::API` (which doesn't implement
`helper_method`), we can't depend on that API existing.

Remove call to `helper_method` from `EmberController`, as it is no
longer supported.

**Allow JRuby failures in CI**

**Improve `setup_ember` script**

* Don't overwrite `gemfiles/` changes with `appraisal install`
* Localize Ember setup to `bin/setup_ember`
* Always invoke, let `bin/setup_ember` decide whether or not to no-op

**Fix `EmberCli::EmberController` inheritance**

The `EmberCli::EmberController` used to inherit from
`ApplicationController` in order to reap the benefits of
application-wide configurations and behavior (such as
authentication-based `before_action` calls and other macros).

Unfortunately, with the introduction of Rails 5's `rails new --api`,
applications' `ApplicationController` can now inherit from
[`ActionController::API`][api], which doesn't serve HTML by default.

To support Rails 5's default `--api` behavior,
`EmberCli::EmberController` must inherit from `ActionController::Base`,
forcing the controller to forfeit all the benefits of sharing behavior
with `ApplicationController`.

[api]: http://edgeapi.rubyonrails.org/classes/ActionController/API.html

**Depend on `test-unit`**

```
Ruby 2.2+ has removed test/unit from the core library. Rails requires
this as a dependency. Please add test-unit gem to your Gemfile:
`gem 'test-unit', '~> 3.0'` (cannot load such file -- test/unit)"
```

Support changes
---------------

Rails 5 depends on `rack@2.0.x`, which **requires** Ruby `2.2.2` or
greater.

In order to support Rails 5, we will no longer support versions of Ruby
prior to `2.2.2`.

[#376]: #376
[rails]: https://github.com/rails/rails
  • Loading branch information
seanpdoyle committed Aug 10, 2016
1 parent 8746bf3 commit 876720b
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 60 deletions.
16 changes: 10 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ cache: bundler
notifications:
email: false
rvm:
- 2.3.0
- 2.2
- 2.1
- jruby-9.0.3.0
- 2.3.0
- 2.2.2
- jruby-9.0.3.0
before_install:
- echo '--colour' > ~/.rspec
- 'echo ''gem: --no-document'' > ~/.gemrc'
- echo '--colour' > ~/.rspec
- 'echo ''gem: --no-document'' > ~/.gemrc'
before_script: bin/setup
script: bin/rake
env:
Expand All @@ -19,3 +18,8 @@ env:
gemfile:
- gemfiles/4.1.gemfile
- gemfiles/4.2.gemfile
- gemfiles/5.0.0.gemfile
- gemfiles/master.gemfile
matrix:
allow_failures:
- rvm: jruby-9.0.3.0
12 changes: 8 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
appraise "3.2" do
gem "rails", git: "https://github.com/rails/rails.git", branch: "3-2-stable"
end

appraise "4.1" do
gem "rails", "~> 4.1.1"
end

appraise "4.2" do
gem "rails", "~> 4.2.1"
end

appraise "5.0.0" do
gem "rails", "5.0.0"
end

appraise "master" do
gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
end
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
master
------

* `EmberCli::EmberController` now inherits from `ActionController::Base` instead
of `ApplicationController`. [#400]
* Remove support for Ruby 2.1.x. [#400]
* Don't route requests to `/rails/info` through the mounted Ember application.

0.7.4
Expand Down Expand Up @@ -33,6 +36,7 @@ master
* `EmberCli::Deploy::File` serves assets with Rails' `static_cache_control`
value. [#403]

[#400]: https://github.com/thoughtbot/ember-cli-rails/pull/400
[#396]: https://github.com/thoughtbot/ember-cli-rails/pull/396
[#403]: https://github.com/thoughtbot/ember-cli-rails/pull/403

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ gem "rails", "4.2.4"
gem "pry"

group :development, :test do
gem "high_voltage", "~> 2.4.0"
gem "rspec-rails", "~> 3.3.0"
gem "high_voltage", "~> 3.0.0"
gem "rspec-rails", "~> 3.5.0"
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ This project supports:

This project supports:

* Ruby versions `>= 2.1.0`
* Ruby versions `>= 2.2.0`
* Rails versions `>=4.1.x`.

To learn more about supported versions and upgrades, read the [upgrading guide].
Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Additionally, this codebase makes use of [(required) keyword arguments][kwargs].
From `ember-cli-rails@0.4.0` and on, we will no longer support versions of Ruby
prior to `2.1.0`.

`ember-cli-rails@0.8.0` adds support for Rails 5, which depends on `rack@2.0.x`,
which **requires** Ruby `2.2.2` or greater.

From `ember-cli-rails@0.8.0` and on, we will no longer support versions of Ruby
prior to `2.2.2`.

To use `ember-cli-rails` with older versions of Ruby, try the `0.3.x` series.

[kwargs]: https://robots.thoughtbot.com/ruby-2-keyword-arguments
Expand Down
5 changes: 0 additions & 5 deletions app/controller/ember_cli/ember_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ class EmberController < ::ApplicationController
def index
render layout: false
end

def ember_app
params[:ember_app]
end
helper_method :ember_app
end
end
2 changes: 1 addition & 1 deletion app/helpers/ember_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def render_ember_app(name, &block)

head, body = markup_capturer.capture

render html: EmberCli[name].index_html(head: head, body: body).html_safe
render text: EmberCli[name].index_html(head: head, body: body).html_safe
end
end
2 changes: 1 addition & 1 deletion app/views/ember_cli/ember/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render_ember_app ember_app do |head| %>
<%= render_ember_app params[:ember_app] do |head| %>
<% head.append do %>
<%= csrf_meta_tags %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion bin/clean
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

rm -rf spec/dummy/my-app
rm -rf spec/dummy/{my-app,tmp}
19 changes: 2 additions & 17 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ if ! command -v bower > /dev/null; then
npm install -g bower
fi

if ! [ -d spec/dummy/my-app ]; then
git clone https://github.com/ember-cli/ember-new-output.git spec/dummy/my-app
bin/setup_ember spec/dummy/my-app

bin/setup_ember
fi

# Only if this isn't CI
if [ -z "$CI" ]; then
bin/appraisal install
fi

root="$(pwd)"

cd ${root}/spec/dummy/my-app &&
npm install --save-dev ember-cli-rails-addon@rondale-sc/ember-cli-rails-addon
bower install

cd ${root}/spec/dummy && bundle exec rake ember:install
cd spec/dummy && bundle exec rake ember:install
28 changes: 20 additions & 8 deletions bin/setup_ember
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

set -e

# make router catchall routes
sed -i -e 's/auto/hash/' spec/dummy/my-app/config/environment.js
setup_ember() {
local target="${1-spec/dummy/my-app}"

# add text to a template
echo 'Welcome to Ember' >> spec/dummy/my-app/app/templates/application.hbs
if ! [ -d $target ]; then
git clone -b stable https://github.com/ember-cli/ember-new-output.git $target

# add an image to a template
echo '<img src="assets/logo.png">' >> spec/dummy/my-app/app/templates/application.hbs
mkdir -p spec/dummy/my-app/public/assets
cp spec/fixtures/logo.png spec/dummy/my-app/public/assets
# make router catchall routes
sed -i -e 's/auto/hash/' $target/config/environment.js

# add an image to a template
echo '<p>Welcome to Ember</p>' >> $target/app/templates/application.hbs
echo '<img src="assets/logo.png">' >> $target/app/templates/application.hbs
mkdir -p $target/public/assets
cp spec/fixtures/logo.png $target/public/assets

cd $target &&
npm install --save-dev ember-cli-rails-addon@rondale-sc/ember-cli-rails-addon
bower install
fi
}

setup_ember
4 changes: 2 additions & 2 deletions ember-cli-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Gem::Specification.new do |spec|
spec.license = "MIT"
spec.files = Dir["README.md", "CHANGELOG.md", "LICENSE.txt", "{lib,app,config}/**/*"]

spec.required_ruby_version = ">= 2.1.0"
spec.required_ruby_version = ">= 2.2.0"

spec.add_dependency "ember-cli-rails-assets", "~> 0.6.2"
spec.add_dependency "railties", ">= 3.2", "< 5"
spec.add_dependency "railties", ">= 3.2"
spec.add_dependency "cocaine", "~> 0.5.8"
spec.add_dependency "html_page", "~> 0.1.0"
end
4 changes: 2 additions & 2 deletions gemfiles/4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ gem "rails", "~> 4.1.1"
gem "pry"

group :development, :test do
gem "high_voltage", "~> 2.4.0"
gem "rspec-rails", "~> 3.3.0"
gem "high_voltage", "~> 3.0.0"
gem "rspec-rails", "~> 3.5.0"
end

group :test do
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ gem "rails", "~> 4.2.1"
gem "pry"

group :development, :test do
gem "high_voltage", "~> 2.4.0"
gem "rspec-rails", "~> 3.3.0"
gem "high_voltage", "~> 3.0.0"
gem "rspec-rails", "~> 3.5.0"
end

group :test do
Expand Down
19 changes: 19 additions & 0 deletions gemfiles/5.0.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "rails", "5.0.0"
gem "pry"

group :development, :test do
gem "high_voltage", "~> 3.0.0"
gem "rspec-rails", "~> 3.5.0"
end

group :test do
gem "poltergeist", "~> 1.8.0"
gem "codeclimate-test-reporter", :require => nil
end

gemspec :path => "../"
19 changes: 19 additions & 0 deletions gemfiles/master.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "rails", :git => "https://github.com/rails/rails.git", :branch => "master"
gem "pry"

group :development, :test do
gem "high_voltage", "~> 3.0.0"
gem "rspec-rails", "~> 3.5.0"
end

group :test do
gem "poltergeist", "~> 1.8.0"
gem "codeclimate-test-reporter", :require => nil
end

gemspec :path => "../"
10 changes: 2 additions & 8 deletions spec/lib/ember_cli/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

describe "#compile" do
it "exits with exit status of 0" do
passed = silence_stdout { EmberCli["my-app"].compile }
passed = EmberCli["my-app"].compile

expect(passed).to be true
end
end

describe "#test" do
it "exits with exit status of 0" do
passed = silence_stdout { EmberCli["my-app"].test }
passed = EmberCli["my-app"].test

expect(passed).to be true
end
Expand Down Expand Up @@ -65,12 +65,6 @@
end
end

def silence_stdout
silence_stream($stdout) do
yield
end
end

def stub_paths(method_to_value)
allow_any_instance_of(EmberCli::PathSet).
to receive(method_to_value.keys.first).
Expand Down

0 comments on commit 876720b

Please sign in to comment.