responders 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dc27831fc7b12f53a28dba5186e256cceab2d17
4
- data.tar.gz: 277b5266e4495e11b903ca12b36aecd192d494b3
3
+ metadata.gz: 8b652ad426b4ce87cb002a4b5562f79c2335c412
4
+ data.tar.gz: ee67a5d29f4cd5920a228ccc6229c52bfdddfea8
5
5
  SHA512:
6
- metadata.gz: 6cb93c417ef6b0dd0844684cecc12e29822e422f88bdaf3fee3188d83c581042e6fc302b25e2717168821fc248dd2530f104d2819501aeec4887cdfdaaf3b575
7
- data.tar.gz: b289b2e512aa9fcbb8ffdeaaa04857bbcf0caeef8a0026a257891856e4e0f13f8d90858bb276d44d4a1fe38919fd832c831b09e26fa79da15ed1855d237465cf
6
+ metadata.gz: 102cd8209ca03e4275003de1c82814eec7da60f92f118d7dd38bbaca8ce56a1e1fef7b0278a99cecaf9a3016fc85e4381e1fee440a1ecc376c024924b3b9d2dd
7
+ data.tar.gz: 6733104f4c7ce9f7250f1ce410562661f16b8d11ce0193c0054264682d4757f4b44d47ce2931df6986d0864b6bc74411388caf7a09c2e5707bf00470f29784bd
@@ -1,3 +1,9 @@
1
+ ## 2.0.1
2
+
3
+ * Require "rails/railtie" explicitly before using it
4
+ * Require "action_controller" explicitly before using it
5
+ * Remove unecessary and limitting `resourceful?` check that required models to implement `to_#{format}` (such checks are responsibility of the rendering layer)
6
+
1
7
  ## 2.0.0
2
8
 
3
9
  * Import `respond_with` and class-level `respond_to` from Rails
data/README.md CHANGED
@@ -60,7 +60,7 @@ You can also have embedded HTML. Just create a `_html` scope.
60
60
 
61
61
  See also the `namespace_lookup` option to search the full hierarchy of possible keys.
62
62
 
63
- ### Location Responder
63
+ ### LocationResponder
64
64
 
65
65
  This responder allows you to use callable objects as the redirect location.
66
66
  Useful when you want to use the `respond_with` method with
@@ -72,7 +72,7 @@ class ThingsController < ApplicationController
72
72
  respond_to :html
73
73
 
74
74
  def create
75
- @thing = Things.create(params[:thing])
75
+ @thing = Thing.create(params[:thing])
76
76
  respond_with @thing, location: -> { thing_path(@thing) }
77
77
  end
78
78
  end
@@ -187,8 +187,8 @@ module ActionController #:nodoc:
187
187
  else
188
188
  display_errors
189
189
  end
190
- rescue ActionView::MissingTemplate => e
191
- api_behavior(e)
190
+ rescue ActionView::MissingTemplate
191
+ api_behavior
192
192
  end
193
193
 
194
194
  protected
@@ -205,8 +205,7 @@ module ActionController #:nodoc:
205
205
  end
206
206
 
207
207
  # This is the common behavior for formats associated with APIs, such as :xml and :json.
208
- def api_behavior(error)
209
- raise error unless resourceful?
208
+ def api_behavior
210
209
  raise MissingRenderer.new(format) unless has_renderer?
211
210
 
212
211
  if get?
@@ -218,12 +217,6 @@ module ActionController #:nodoc:
218
217
  end
219
218
  end
220
219
 
221
- # Checks whether the resource responds to the current format or not.
222
- #
223
- def resourceful?
224
- resource.respond_to?("to_#{format}")
225
- end
226
-
227
220
  # Returns the resource location by retrieving it from the options or
228
221
  # returning the resources array.
229
222
  #
@@ -1,4 +1,5 @@
1
- require 'action_controller/base'
1
+ require 'action_controller'
2
+ require 'rails/railtie'
2
3
 
3
4
  module ActionController
4
5
  autoload :Responder, 'action_controller/responder'
@@ -34,11 +34,11 @@ module Responders
34
34
 
35
35
  def do_http_cache?
36
36
  get? && @http_cache != false && ActionController::Base.perform_caching &&
37
- persisted? && resourceful? && resource.respond_to?(:updated_at)
37
+ persisted? && resource.respond_to?(:updated_at)
38
38
  end
39
39
 
40
40
  def persisted?
41
41
  resource.respond_to?(:persisted?) ? resource.persisted? : true
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.0.1".freeze
3
3
  end
@@ -4,8 +4,6 @@ class Customer < Struct.new(:name, :id)
4
4
  extend ActiveModel::Naming
5
5
  include ActiveModel::Conversion
6
6
 
7
- undef_method :to_json
8
-
9
7
  def to_xml(options={})
10
8
  if options[:builder]
11
9
  options[:builder].name name
@@ -201,9 +199,9 @@ class RespondWithControllerTest < ActionController::TestCase
201
199
  assert_equal "<name>david</name>", @response.body
202
200
 
203
201
  @request.accept = "application/json"
204
- assert_raise ActionView::MissingTemplate do
205
- get :using_resource
206
- end
202
+ get :using_resource
203
+ assert_equal "application/json", @response.content_type
204
+ assert_equal "{\"name\":\"david\",\"id\":13}", @response.body
207
205
  end
208
206
 
209
207
  def test_using_resource_with_js_simply_tries_to_render_the_template
@@ -6,7 +6,6 @@ require 'mocha/setup'
6
6
  ENV["RAILS_ENV"] = "test"
7
7
 
8
8
  require 'active_support'
9
- require 'action_controller'
10
9
  require 'active_model'
11
10
  require 'rails/engine'
12
11
  require 'rails/railtie'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responders
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties