Skip to content

Commit

Permalink
Update to Rails 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jan 27, 2015
1 parent c3e2d04 commit 4e70f8e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

* Import `respond_with` and class-level `respond_to` from Rails
* Support only Rails ~> 4.2
* `Responders::LocationResponder` is now included by in the default responder (and therefore deprecated)
* `Responders::LocationResponder` is now included by the default responder (and therefore deprecated)

## 1.1.0

Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ source 'https://rubygems.org'

gemspec

gem 'railties', '~> 4.2.0', github: 'rails/rails', branch: '4-2-stable'
gem 'activemodel', '~> 4.2.0', github: 'rails/rails', branch: '4-2-stable'
gem 'activemodel', '4.2.0'
gem 'mocha'
45 changes: 19 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
GIT
remote: git://github.com/rails/rails.git
revision: 2910956fc9006d3c26f56992dab630fa97b7f7bc
branch: 4-2-stable
PATH
remote: .
specs:
responders (2.0.2)
railties (>= 4.2.0, < 5)

GEM
remote: https://rubygems.org/
specs:
actionpack (4.2.0)
actionview (= 4.2.0)
Expand All @@ -25,34 +29,19 @@ GIT
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)

PATH
remote: .
specs:
responders (2.0.2)
railties (>= 4.2.0, < 5)

GEM
remote: https://rubygems.org/
specs:
builder (3.2.2)
erubis (2.7.0)
i18n (0.7.0)
json (1.8.1)
loofah (2.0.1)
nokogiri (>= 1.5.9)
metaclass (0.0.4)
mini_portile (0.6.2)
minitest (5.5.0)
mini_portile (0.6.0)
minitest (5.4.2)
mocha (1.1.0)
metaclass (~> 0.0.1)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
rack (1.6.0)
rack-test (0.6.2)
rack (>= 1.0)
Expand All @@ -64,7 +53,12 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
rake (10.4.2)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
thor (0.19.1)
thread_safe (0.3.4)
tzinfo (1.2.2)
Expand All @@ -74,7 +68,6 @@ PLATFORMS
ruby

DEPENDENCIES
activemodel (~> 4.2.0)!
activemodel (= 4.2.0)
mocha
railties (~> 4.2.0)!
responders!
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
[![Build Status](https://api.travis-ci.org/plataformatec/responders.png?branch=master)](http://travis-ci.org/plataformatec/responders)
[![Code Climate](https://codeclimate.com/github/plataformatec/responders.png)](https://codeclimate.com/github/plataformatec/responders)

A set of responders modules to dry up your Rails 3.2+ app.
A set of responders modules to dry up your Rails 4.2+ app.

## Installation

Add the responders gem to your Gemfile:

gem "responders"

Update your bundle and run the install generator:

$ bundle install
$ rails g responders:install

## Responders Types

Expand Down Expand Up @@ -92,20 +103,9 @@ end

## Configuring your own responder

The first step is to install the responders gem and configure it in your application:

```console
gem install responders
```

In your Gemfile, add this line:

```ruby
gem 'responders'
```

Responders only provides a set of modules, to use them, you have to create your own
responder. This can be done inside the lib folder for example:
Responders only provides a set of modules and to use them you have to create your own
responder. After you run the install command, the following responder will be
generated in your application:

```ruby
# lib/application_responder.rb
Expand All @@ -115,7 +115,7 @@ class AppResponder < ActionController::Responder
end
```

And then you need to configure your application to use it:
Your application also needs to be configured to use it:

```ruby
# app/controllers/application_controller.rb
Expand All @@ -127,12 +127,6 @@ class ApplicationController < ActionController::Base
end
```

Or, for your convenience, just do:

```console
rails generate responders:install
```

## Controller method

This gem also includes the controller method `responders`, which allows you to cherry-pick which
Expand Down Expand Up @@ -170,17 +164,14 @@ Now you would see the message "bob@bob.com was successfully created" instead of
## Generator

This gem also includes a responders controller generator, so your scaffold can be customized
to use `respond_with` instead of default `respond_to` blocks. Installing this gem automatically
sets the generator.
to use `respond_with` instead of default `respond_to` blocks. From 2.1, you need to explicitly opt-in to use this generator by adding the following to your `config/application.rb`:

To use default rails scaffold_controller add `config.app_generators.scaffold_controller :scaffold_controller`
to `config/application.rb`.
config.app_generators.scaffold_controller :responders_controller

## Examples

Want more examples ? Check out this blog posts:

* [One in Three: Inherited Resources, Has Scope and Responders](http://blog.plataformatec.com.br/2009/12/one-in-three-inherited-resources-has-scope-and-responders/)
* [Embracing REST with mind, body and soul](http://blog.plataformatec.com.br/2009/08/embracing-rest-with-mind-body-and-soul/)
* [Three reasons to love ActionController::Responder](http://weblog.rubyonrails.org/2009/8/31/three-reasons-love-responder/)
* [My five favorite things about Rails 3](http://www.engineyard.com/blog/2009/my-five-favorite-things-about-rails-3/)
Expand Down
8 changes: 8 additions & 0 deletions lib/generators/responders/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class ApplicationResponder < ActionController::Responder
RUBY
end

def update_application
inject_into_class "config/application.rb", "Application", <<-RUBY
# Use the responders controller from the responders gem
config.app_generators.scaffold_controller :responders_controller
RUBY
end

def update_application_controller
prepend_file "app/controllers/application_controller.rb", %{require "application_responder"\n\n}
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", <<-RUBY
Expand Down
6 changes: 0 additions & 6 deletions lib/responders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class Railtie < ::Rails::Railtie
config.responders.flash_keys = [:notice, :alert]
config.responders.namespace_lookup = false

if config.respond_to?(:app_generators)
config.app_generators.scaffold_controller = :responders_controller
else
config.generators.scaffold_controller = :responders_controller
end

# Add load paths straight to I18n, so engines and application can overwrite it.
require 'active_support/i18n'
I18n.load_path << File.expand_path('../responders/locales/en.yml', __FILE__)
Expand Down
8 changes: 4 additions & 4 deletions test/action_controller/respond_with_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ def test_using_resource_for_put_with_xml_yields_no_content_on_success
put :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
assert_equal " ", @response.body
end

def test_using_resource_for_put_with_json_yields_no_content_on_success
@request.accept = "application/json"
put :using_resource_with_json
assert_equal "application/json", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
assert_equal " ", @response.body
end

def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
Expand Down Expand Up @@ -460,7 +460,7 @@ def test_using_resource_for_delete_with_xml_yields_no_content_on_success
delete :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
assert_equal " ", @response.body
end

def test_using_resource_for_delete_with_json_yields_no_content_on_success
Expand All @@ -469,7 +469,7 @@ def test_using_resource_for_delete_with_json_yields_no_content_on_success
delete :using_resource_with_json
assert_equal "application/json", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
assert_equal " ", @response.body
end

def test_using_resource_for_delete_with_html_redirects_on_failure
Expand Down
2 changes: 1 addition & 1 deletion test/responders/http_cache_responder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_returns_not_modified_if_return_is_cache_is_still_valid
@request.env["HTTP_IF_MODIFIED_SINCE"] = Time.utc(2009, 6).httpdate
get :single
assert_equal 304, @response.status
assert_includes "", @response.body
assert_includes " ", @response.body
end

def test_refreshes_last_modified_if_cache_is_expired
Expand Down

0 comments on commit 4e70f8e

Please sign in to comment.