diff --git a/CHANGELOG.md b/CHANGELOG.md index e84092f..0bb6d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile b/Gemfile index 7e476d8..ace341b 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index c8c0b96..ed3abf1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -25,21 +29,6 @@ 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) @@ -47,12 +36,12 @@ GEM 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) @@ -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) @@ -74,7 +68,6 @@ PLATFORMS ruby DEPENDENCIES - activemodel (~> 4.2.0)! + activemodel (= 4.2.0) mocha - railties (~> 4.2.0)! responders! diff --git a/README.md b/README.md index 1d502a5..0663fe3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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/) diff --git a/lib/generators/responders/install_generator.rb b/lib/generators/responders/install_generator.rb index bb6466e..4877e59 100644 --- a/lib/generators/responders/install_generator.rb +++ b/lib/generators/responders/install_generator.rb @@ -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 diff --git a/lib/responders.rb b/lib/responders.rb index 113e422..9dd26fe 100644 --- a/lib/responders.rb +++ b/lib/responders.rb @@ -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__) diff --git a/test/action_controller/respond_with_test.rb b/test/action_controller/respond_with_test.rb index 9596380..94ae293 100644 --- a/test/action_controller/respond_with_test.rb +++ b/test/action_controller/respond_with_test.rb @@ -410,7 +410,7 @@ 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 @@ -418,7 +418,7 @@ def test_using_resource_for_put_with_json_yields_no_content_on_success 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 @@ -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 @@ -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 diff --git a/test/responders/http_cache_responder_test.rb b/test/responders/http_cache_responder_test.rb index b06dc56..53c83bd 100644 --- a/test/responders/http_cache_responder_test.rb +++ b/test/responders/http_cache_responder_test.rb @@ -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