responders 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 729b9991a4c4c71e5def865e458f1941283aa074
4
- data.tar.gz: 2f866da6f3f9f07fbc21f87405e66fd8245e12c6
3
+ metadata.gz: afe9de77cd0ac2f430924b58d84e0cf582e3011c
4
+ data.tar.gz: e8771d1fb3bd0b9e0036a70b5aaf667528451e2a
5
5
  SHA512:
6
- metadata.gz: 550177b2c6824672e37d78391dd9e96b8e36c12ffe5a570aa116737b33301287cb53dac1b304d84f022c3c5d30aa42de1d0cfa3fde93caf991e069908ad79682
7
- data.tar.gz: 01b5e546b4c55e00d29865e0479e1ce2ced384a31f4108ed79617596473e357d1ca1b8752e015cb4ac242d9385b7998f02433b7d26cbc51ad9909b7c4db7f7b5
6
+ metadata.gz: cd38360684067e7b60ab94a362f438676b69ab4bb956ffdea5197f1831a4bdfadbc1bfd373395ca235124af57c863094935390362e333995a8614a3ad3fff98b
7
+ data.tar.gz: ddf8300eb26872a38e79fe55ca308120d9b3c0f0ec3e80aaf44a8337f2ea54d4b515151adccda351b59fb519db182e49e202793be6634c21f831bc0e891009ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1.0
2
+
3
+ * Support Rails 4.1.
4
+ * Allow callable objects as the location.
5
+
1
6
  ## 1.0.0
2
7
 
3
8
  * Improve controller generator to work closer to the Rails 4 one, and make it
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2009-2013 Plataforma Tecnologia. http://blog.plataformatec.com.br
1
+ Copyright 2009-2014 Plataforma Tecnologia. http://blog.plataformatec.com.br
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -60,6 +60,24 @@ 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
64
+
65
+ This responder allows you to use callable objects as the redirect location.
66
+ Useful when you want to use the `respond_with` method with
67
+ a custom route that requires persisted objects, but the validation may fail.
68
+
69
+ ```ruby
70
+ class ThingsController < ApplicationController
71
+ responders :location, :flash
72
+ respond_to :html
73
+
74
+ def create
75
+ @thing = Things.create(params[:thing])
76
+ respond_with @thing, location: -> { thing_path(@thing) }
77
+ end
78
+ end
79
+ ```
80
+
63
81
  ### HttpCacheResponder
64
82
 
65
83
  Automatically adds Last-Modified headers to API requests. This
@@ -168,4 +186,4 @@ If you discover any bugs or want to drop a line, feel free to create an issue on
168
186
 
169
187
  http://github.com/plataformatec/responders/issues
170
188
 
171
- MIT License. Copyright 2009-2013 Plataforma Tecnologia. http://blog.plataformatec.com.br
189
+ MIT License. Copyright 2009-2014 Plataforma Tecnologia. http://blog.plataformatec.com.br
@@ -89,7 +89,10 @@ module Responders
89
89
 
90
90
  self.flash_keys = [ :notice, :alert ]
91
91
  self.namespace_lookup = false
92
- self.helper = Object.new.extend(ActionView::Helpers::TranslationHelper)
92
+ self.helper = Object.new.extend(
93
+ ActionView::Helpers::TranslationHelper,
94
+ ActionView::Helpers::TagHelper
95
+ )
93
96
 
94
97
  def initialize(controller, resources, options={})
95
98
  super
@@ -0,0 +1,26 @@
1
+ module Responders
2
+ # Responder to accept callable objects as the redirect location.
3
+ # Useful when you want to use the <tt>respond_with</tt> method with
4
+ # a route that requires persisted objects, but the validation may fail.
5
+ #
6
+ # class ThingsController < ApplicationController
7
+ # responders :location, :flash
8
+ # respond_to :html
9
+ #
10
+ # def create
11
+ # @thing = Things.create(params[:thing])
12
+ # respond_with @thing, location: -> { thing_path(@thing) }
13
+ # end
14
+ # end
15
+ #
16
+ module LocationResponder
17
+ def initialize(controller, resources, options = {})
18
+ super
19
+
20
+ if options[:location].respond_to?(:call)
21
+ location = options.delete(:location)
22
+ options[:location] = location.call unless has_errors?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
data/lib/responders.rb CHANGED
@@ -4,6 +4,7 @@ module Responders
4
4
  autoload :FlashResponder, 'responders/flash_responder'
5
5
  autoload :HttpCacheResponder, 'responders/http_cache_responder'
6
6
  autoload :CollectionResponder, 'responders/collection_responder'
7
+ autoload :LocationResponder, 'responders/location_responder'
7
8
 
8
9
  require 'responders/controller_method'
9
10
 
@@ -51,6 +51,12 @@ class AddressesController < ApplicationController
51
51
  end
52
52
  end
53
53
 
54
+ class PolymorphicAddesssController < AddressesController
55
+ def create
56
+ respond_with(User.new, Address.new)
57
+ end
58
+ end
59
+
54
60
  module Admin
55
61
  class AddressesController < ::AddressesController
56
62
  end
@@ -185,9 +191,10 @@ class FlashResponderTest < ActionController::TestCase
185
191
  assert_not_flash_now :failure
186
192
  end
187
193
 
188
- # If we have flash.now, it's always marked as used.
194
+ # If we have flash.now, it's always marked as used. Rails 4.1 has string keys,
195
+ # whereas 3.2 and 4.0 has symbols, so we need to test both.
189
196
  def assert_flash_now(k)
190
- assert flash.used_keys.include?(k.to_sym),
197
+ assert flash.used_keys.include?(k.to_sym) || flash.used_keys.include?(k.to_s),
191
198
  "Expected #{k} to be in flash.now, but it's not."
192
199
  end
193
200
 
@@ -237,3 +244,17 @@ class NamespacedFlashResponderTest < ActionController::TestCase
237
244
  assert_equal nil, flash[:notice]
238
245
  end
239
246
  end
247
+
248
+ class PolymorhicFlashResponderTest < ActionController::TestCase
249
+ tests PolymorphicAddesssController
250
+
251
+ def setup
252
+ Responders::FlashResponder.flash_keys = [ :notice, :alert ]
253
+ @controller.stubs(:polymorphic_url).returns("/")
254
+ end
255
+
256
+ def test_polymorhic_respond_with
257
+ post :create
258
+ assert_equal "Address was successfully created.", flash[:notice]
259
+ end
260
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class LocationResponder < ActionController::Responder
4
+ include Responders::LocationResponder
5
+ end
6
+
7
+ class LocationsController < ApplicationController
8
+ self.responder = LocationResponder
9
+
10
+ respond_to :html
11
+ before_filter :set_resource
12
+
13
+ def create
14
+ respond_with @resource, location: -> { 'given_location' }
15
+ end
16
+
17
+ def update
18
+ respond_with @resource, location: 'given_location'
19
+ end
20
+
21
+ def set_resource
22
+ @resource = Address.new
23
+ @resource.errors[:fail] << "FAIL" if params[:fail]
24
+ end
25
+ end
26
+
27
+ class LocationResponderTest < ActionController::TestCase
28
+ tests LocationsController
29
+
30
+ def test_redirects_to_block_location_on_success
31
+ post :create
32
+ assert_redirected_to 'given_location'
33
+ end
34
+
35
+ def test_renders_page_on_fail
36
+ post :create, fail: true
37
+ assert @response.body.include?('new.html.erb')
38
+ end
39
+
40
+ def test_redirects_to_plain_string
41
+ post :update
42
+ assert_redirected_to 'given_location'
43
+ end
44
+ end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,5 @@
1
- require 'bundler'
2
-
3
- Bundler.setup
4
- require 'test/unit'
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
5
3
  require 'mocha/setup'
6
4
 
7
5
  # Configure Rails
@@ -16,6 +14,7 @@ require 'rails/railtie'
16
14
  $:.unshift File.expand_path('../../lib', __FILE__)
17
15
  require 'responders'
18
16
 
17
+ I18n.enforce_available_locales = true
19
18
  I18n.load_path << File.expand_path('../locales/en.yml', __FILE__)
20
19
  I18n.reload!
21
20
 
@@ -0,0 +1 @@
1
+ new.html.erb
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responders
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-21 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'
33
33
  description: A set of Rails responders to dry up your application
@@ -39,26 +39,29 @@ files:
39
39
  - CHANGELOG.md
40
40
  - MIT-LICENSE
41
41
  - README.md
42
+ - lib/generators/rails/USAGE
42
43
  - lib/generators/rails/responders_controller_generator.rb
43
44
  - lib/generators/rails/templates/controller.rb
44
- - lib/generators/rails/USAGE
45
45
  - lib/generators/responders/install_generator.rb
46
+ - lib/responders.rb
46
47
  - lib/responders/collection_responder.rb
47
48
  - lib/responders/controller_method.rb
48
49
  - lib/responders/flash_responder.rb
49
50
  - lib/responders/http_cache_responder.rb
50
51
  - lib/responders/locales/en.yml
52
+ - lib/responders/location_responder.rb
51
53
  - lib/responders/version.rb
52
- - lib/responders.rb
53
54
  - test/collection_responder_test.rb
54
55
  - test/controller_method_test.rb
55
56
  - test/flash_responder_test.rb
56
57
  - test/http_cache_responder_test.rb
57
58
  - test/locales/en.yml
59
+ - test/location_responder_test.rb
58
60
  - test/test_helper.rb
59
61
  - test/views/addresses/create.js.erb
60
62
  - test/views/addresses/edit.html.erb
61
63
  - test/views/addresses/new.html.erb
64
+ - test/views/locations/new.html.erb
62
65
  homepage: http://github.com/plataformatec/responders
63
66
  licenses:
64
67
  - MIT
@@ -69,17 +72,17 @@ require_paths:
69
72
  - lib
70
73
  required_ruby_version: !ruby/object:Gem::Requirement
71
74
  requirements:
72
- - - '>='
75
+ - - ">="
73
76
  - !ruby/object:Gem::Version
74
77
  version: '0'
75
78
  required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
- - - '>='
80
+ - - ">="
78
81
  - !ruby/object:Gem::Version
79
82
  version: '0'
80
83
  requirements: []
81
84
  rubyforge_project: responders
82
- rubygems_version: 2.0.6
85
+ rubygems_version: 2.2.2
83
86
  signing_key:
84
87
  specification_version: 4
85
88
  summary: A set of Rails responders to dry up your application
@@ -89,7 +92,9 @@ test_files:
89
92
  - test/flash_responder_test.rb
90
93
  - test/http_cache_responder_test.rb
91
94
  - test/locales/en.yml
95
+ - test/location_responder_test.rb
92
96
  - test/test_helper.rb
93
97
  - test/views/addresses/create.js.erb
94
98
  - test/views/addresses/edit.html.erb
95
99
  - test/views/addresses/new.html.erb
100
+ - test/views/locations/new.html.erb