cookpad/garage — pull request #4 by taiki45 (2014-10-09 02:27:03+00:00)
Title: Don't require 'ac/responder' explicitly

It seems [requiring 'action_controller/responser'](https://github.com/cookpad/garage/pull/2) breaks Rails 4.2- apps. The below app is using Rails4.1 and with HEAD version of garage it is broken. https://github.com/taiki45/garage-example-test/tree/master

```
~/tmp/garage_example master
❯ bundle update garage
[...]

~/tmp/garage_example master*
❯ bundle exec rspec
/Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/bundler/gems/garage-78157933f728/lib/garage/app_responder.rb:2:in `require': cannot load such file -- action_controller/responder (LoadError)
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/bundler/gems/garage-78157933f728/lib/garage/app_responder.rb:2:in `'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/bundler/gems/garage-78157933f728/lib/garage.rb:7:in `require'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/bundler/gems/garage-78157933f728/lib/garage.rb:7:in `'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:76:in `require'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:72:in `each'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:72:in `block in require'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:61:in `each'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:61:in `require'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler.rb:133:in `require'
from /Users/taiki-ono/tmp/garage_example/config/application.rb:14:in `'
from /Users/taiki-ono/tmp/garage_example/config/environment.rb:2:in `require'
from /Users/taiki-ono/tmp/garage_example/config/environment.rb:2:in `'
from /Users/taiki-ono/tmp/garage_example/spec/rails_helper.rb:4:in `require'
from /Users/taiki-ono/tmp/garage_example/spec/rails_helper.rb:4:in `'
from /Users/taiki-ono/tmp/garage_example/spec/models/user_spec.rb:1:in `require'
from /Users/taiki-ono/tmp/garage_example/spec/models/user_spec.rb:1:in `'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:96:in `setup'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:84:in `run'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:69:in `run'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/taiki-ono/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.4/exe/rspec:4:in `'
from /Users/taiki-ono/.rbenv/versions/2.1.3/bin/rspec:23:in `load'
from /Users/taiki-ono/.rbenv/versions/2.1.3/bin/rspec:23:in `

'
```

In Rails4.2-, [`:Responder` is set autoloading under 'metal'](https://github.com/rails/rails/blob/v4.1.6/actionpack/lib/action_controller.rb#L36), so we can access `:Responder` via `ActionController::Responder` and it causes requiring 'action_controller/metal/responder' and actionpack locates responder.rb in `ib/action_controller/metal/responder.rb`.

```
~/.ghq/github.com/rails/rails/actionpack v4.1.6
❯ ls -l lib/action_controller/metal/responder.rb
-rw-r--r-- 1 taiki-ono staff 9313 10 9 09:56 lib/action_controller/metal/responder.rb

~/.ghq/github.com/rails/rails/actionpack v4.1.6
❯ ls -l lib/action_controller/responder.rb
ls: lib/action_controller/responder.rb: No such file or directory
```

In Rails4.2+ with responders gem, [`:Responder` is just set autoloading in ActionController module with path 'action_controller/responder'](https://github.com/plataformatec/responders/blob/master/lib/responders.rb#L4). responders gem locates responder.rb in `lib/action_controller/responder.rb` in v2.0.0.

```
~/.ghq/github.com/plataformatec/responders master
❯ ls -l lib/action_controller/responder.rb
-rw-r--r-- 1 taiki-ono staff 9272 10 9 10:06 lib/action_controller/responder.rb
```

Considering above conditions and in my opinion, we remove requiring `'action_controller/responder'` with any version of Rails, and add responders gem to dependency if user uses Rails 4.2+. Then we can just refer `ActionController::Responder` and autoloading will work fine for the constant.

Does this have any rack of points or am I misunderstanding? [I tried that in my example project](https://github.com/taiki45/garage-example-test/tree/rails42) and it seems it works fine.

cc @amatsuda