responders 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -5
- data/lib/generators/rails/templates/controller.rb +0 -13
- data/lib/responders/controller_method.rb +4 -4
- data/lib/responders/flash_responder.rb +2 -2
- data/lib/responders/version.rb +1 -1
- data/test/controller_method_test.rb +8 -8
- data/test/flash_responder_test.rb +12 -2
- data/test/http_cache_responder_test.rb +5 -5
- metadata +6 -5
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# Responders
|
2
2
|
|
3
|
-
A set of responders modules to dry up your Rails 3 app.
|
4
|
-
to be used with Rails 2.3 together with Inherited Resources, please check this branch instead:
|
5
|
-
|
6
|
-
http://github.com/plataformatec/responders/tree/v0.4
|
3
|
+
A set of responders modules to dry up your Rails 3+ app.
|
7
4
|
|
8
5
|
## Responders Types
|
9
6
|
|
@@ -56,6 +53,8 @@ You can also have embedded HTML. Just create a `_html` scope.
|
|
56
53
|
notice_html: "<strong>Yay!</strong> You did it!"
|
57
54
|
```
|
58
55
|
|
56
|
+
See also the `namespace_lookup` option to search the full hierarchy of possible keys.
|
57
|
+
|
59
58
|
### HttpCacheResponder
|
60
59
|
|
61
60
|
Automatically adds Last-Modified headers to API requests. This
|
@@ -68,7 +67,7 @@ Makes your create and update action redirect to the collection on success.
|
|
68
67
|
|
69
68
|
## Configuring your own responder
|
70
69
|
|
71
|
-
The first step is
|
70
|
+
The first step is to install the responders gem and configure it in your application:
|
72
71
|
|
73
72
|
```console
|
74
73
|
gem install responders
|
@@ -1,51 +1,38 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= controller_class_name %>Controller < ApplicationController
|
3
3
|
<% unless options[:singleton] -%>
|
4
|
-
# GET /<%= table_name %>
|
5
|
-
# GET /<%= table_name %>.xml
|
6
4
|
def index
|
7
5
|
@<%= table_name %> = <%= orm_class.all(class_name) %>
|
8
6
|
respond_with(@<%= table_name %>)
|
9
7
|
end
|
10
8
|
<% end -%>
|
11
9
|
|
12
|
-
# GET /<%= table_name %>/1
|
13
|
-
# GET /<%= table_name %>/1.xml
|
14
10
|
def show
|
15
11
|
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
16
12
|
respond_with(@<%= file_name %>)
|
17
13
|
end
|
18
14
|
|
19
|
-
# GET /<%= table_name %>/new
|
20
|
-
# GET /<%= table_name %>/new.xml
|
21
15
|
def new
|
22
16
|
@<%= file_name %> = <%= orm_class.build(class_name) %>
|
23
17
|
respond_with(@<%= file_name %>)
|
24
18
|
end
|
25
19
|
|
26
|
-
# GET /<%= table_name %>/1/edit
|
27
20
|
def edit
|
28
21
|
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
29
22
|
end
|
30
23
|
|
31
|
-
# POST /<%= table_name %>
|
32
|
-
# POST /<%= table_name %>.xml
|
33
24
|
def create
|
34
25
|
@<%= file_name %> = <%= orm_class.build(class_name, "params[:#{file_name}]") %>
|
35
26
|
<%= "flash[:notice] = '#{class_name} was successfully created.' if " if flash? %>@<%= orm_instance.save %>
|
36
27
|
respond_with(@<%= file_name %>)
|
37
28
|
end
|
38
29
|
|
39
|
-
# PUT /<%= table_name %>/1
|
40
|
-
# PUT /<%= table_name %>/1.xml
|
41
30
|
def update
|
42
31
|
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
43
32
|
<%= "flash[:notice] = '#{class_name} was successfully updated.' if " if flash? %>@<%= orm_instance.update_attributes("params[:#{file_name}]") %>
|
44
33
|
respond_with(@<%= file_name %>)
|
45
34
|
end
|
46
35
|
|
47
|
-
# DELETE /<%= table_name %>/1
|
48
|
-
# DELETE /<%= table_name %>/1.xml
|
49
36
|
def destroy
|
50
37
|
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
51
38
|
@<%= orm_instance.destroy %>
|
@@ -2,7 +2,7 @@ module Responders
|
|
2
2
|
module ControllerMethod
|
3
3
|
# Adds the given responders to the current controller's responder, allowing you to cherry-pick
|
4
4
|
# which responders you want per controller.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# class InvitationsController < ApplicationController
|
7
7
|
# responders :flash, :http_cache
|
8
8
|
# end
|
@@ -22,11 +22,11 @@ module Responders
|
|
22
22
|
when Module
|
23
23
|
responder
|
24
24
|
when String, Symbol
|
25
|
-
Responders.const_get("#{responder.to_s.
|
25
|
+
Responders.const_get("#{responder.to_s.camelize}Responder")
|
26
26
|
else
|
27
27
|
raise "responder has to be a string, a symbol or a module"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
klass.send(:include, responder)
|
31
31
|
klass
|
32
32
|
end
|
@@ -34,4 +34,4 @@ module Responders
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
ActionController::Base.extend Responders::ControllerMethod
|
37
|
+
ActionController::Base.extend Responders::ControllerMethod
|
@@ -113,11 +113,11 @@ module Responders
|
|
113
113
|
|
114
114
|
def set_flash_message!
|
115
115
|
if has_errors?
|
116
|
-
set_flash(:alert, @alert)
|
117
116
|
status = Responders::FlashResponder.flash_keys.last
|
117
|
+
set_flash(status, @alert)
|
118
118
|
else
|
119
|
-
set_flash(:notice, @notice)
|
120
119
|
status = Responders::FlashResponder.flash_keys.first
|
120
|
+
set_flash(status, @notice)
|
121
121
|
end
|
122
122
|
|
123
123
|
return if controller.flash[status].present?
|
data/lib/responders/version.rb
CHANGED
@@ -16,7 +16,7 @@ module BarResponder
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
module
|
19
|
+
module PeopleResponder
|
20
20
|
def to_html
|
21
21
|
@resource << "baz"
|
22
22
|
super
|
@@ -25,7 +25,7 @@ end
|
|
25
25
|
|
26
26
|
class PeopleController < ApplicationController
|
27
27
|
responders :foo, BarResponder
|
28
|
-
|
28
|
+
|
29
29
|
def index
|
30
30
|
@array = []
|
31
31
|
respond_with(@array) do |format|
|
@@ -35,7 +35,7 @@ class PeopleController < ApplicationController
|
|
35
35
|
end
|
36
36
|
|
37
37
|
class SpecialPeopleController < PeopleController
|
38
|
-
responders :
|
38
|
+
responders :people
|
39
39
|
end
|
40
40
|
|
41
41
|
class ControllerMethodTest < ActionController::TestCase
|
@@ -49,7 +49,7 @@ class ControllerMethodTest < ActionController::TestCase
|
|
49
49
|
get :index
|
50
50
|
assert assigns(:array).include? "foo"
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def test_bar_responder_gets_added
|
54
54
|
get :index
|
55
55
|
assert assigns(:array).include? "bar"
|
@@ -58,15 +58,15 @@ end
|
|
58
58
|
|
59
59
|
class ControllerMethodInheritanceTest < ActionController::TestCase
|
60
60
|
tests SpecialPeopleController
|
61
|
-
|
61
|
+
|
62
62
|
def setup
|
63
|
-
@controller.stubs(:polymorphic_url).returns("/")
|
63
|
+
@controller.stubs(:polymorphic_url).returns("/")
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def test_responder_is_inherited
|
67
67
|
get :index
|
68
68
|
assert assigns(:array).include? "foo"
|
69
69
|
assert assigns(:array).include? "bar"
|
70
70
|
assert assigns(:array).include? "baz"
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
@@ -131,6 +131,16 @@ class FlashResponderTest < ActionController::TestCase
|
|
131
131
|
assert_not_flash_now :success
|
132
132
|
end
|
133
133
|
|
134
|
+
def test_sets_message_based_on_notice_key_with_custom_keys
|
135
|
+
post :another
|
136
|
+
assert_equal "Yes, notice this!", flash[:success]
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_sets_message_based_on_alert_key_with_custom_keys
|
140
|
+
post :another, :fail => true
|
141
|
+
assert_equal "Warning, warning!", flash[:failure]
|
142
|
+
end
|
143
|
+
|
134
144
|
def test_sets_message_based_on_notice_key
|
135
145
|
Responders::FlashResponder.flash_keys = [ :notice, :alert ]
|
136
146
|
post :another
|
@@ -161,12 +171,12 @@ class FlashResponderTest < ActionController::TestCase
|
|
161
171
|
|
162
172
|
def test_sets_flash_now_on_failure_by_default
|
163
173
|
post :another, :fail => true
|
164
|
-
assert_flash_now :
|
174
|
+
assert_flash_now :failure
|
165
175
|
end
|
166
176
|
|
167
177
|
def test_never_set_flash_now
|
168
178
|
post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
|
169
|
-
assert_not_flash_now :
|
179
|
+
assert_not_flash_now :failure
|
170
180
|
end
|
171
181
|
|
172
182
|
# If we have flash.now, it's always marked as used.
|
@@ -63,15 +63,15 @@ class HttpCacheResponderTest < ActionController::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_does_not_set_cache_unless_get_requests
|
66
|
-
|
66
|
+
post :single
|
67
67
|
assert_nil @response.headers["Last-Modified"]
|
68
|
-
assert_equal
|
68
|
+
assert_equal 201, @response.status
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_does_not_use_cache_unless_get_requests
|
72
72
|
@request.env["HTTP_IF_MODIFIED_SINCE"] = Time.utc(2009, 6).httpdate
|
73
|
-
|
74
|
-
assert_equal
|
73
|
+
post :single
|
74
|
+
assert_equal 201, @response.status
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_does_not_set_cache_if_http_cache_is_false
|
@@ -117,4 +117,4 @@ class HttpCacheResponderTest < ActionController::TestCase
|
|
117
117
|
assert_equal "<xml />", @response.body
|
118
118
|
assert_equal 200, @response.status
|
119
119
|
end
|
120
|
-
end
|
120
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &2166146420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2166146420
|
25
25
|
description: A set of Rails 3 responders to dry up your application
|
26
26
|
email: contact@plataformatec.com.br
|
27
27
|
executables: []
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project: responders
|
80
|
-
rubygems_version: 1.8.
|
80
|
+
rubygems_version: 1.8.15
|
81
81
|
signing_key:
|
82
82
|
specification_version: 3
|
83
83
|
summary: A set of Rails 3 responders to dry up your application
|
@@ -91,3 +91,4 @@ test_files:
|
|
91
91
|
- test/views/addresses/create.js.erb
|
92
92
|
- test/views/addresses/edit.html.erb
|
93
93
|
- test/views/addresses/new.html.erb
|
94
|
+
has_rdoc:
|