responders 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +1 -0
- data/lib/responders/flash_responder.rb +14 -6
- data/lib/responders/version.rb +1 -1
- data/test/flash_responder_test.rb +8 -1
- data/test/test_helper.rb +8 -3
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -80,9 +80,10 @@ module Responders
|
|
80
80
|
|
81
81
|
def initialize(controller, resources, options={})
|
82
82
|
super
|
83
|
-
@flash
|
84
|
-
@notice
|
85
|
-
@alert
|
83
|
+
@flash = options.delete(:flash)
|
84
|
+
@notice = options.delete(:notice)
|
85
|
+
@alert = options.delete(:alert)
|
86
|
+
@flash_now = options.delete(:flash_now)
|
86
87
|
end
|
87
88
|
|
88
89
|
def to_html
|
@@ -94,10 +95,10 @@ module Responders
|
|
94
95
|
|
95
96
|
def set_flash_message!
|
96
97
|
if has_errors?
|
97
|
-
|
98
|
+
set_flash(:alert, @alert)
|
98
99
|
status = Responders::FlashResponder.flash_keys.last
|
99
100
|
else
|
100
|
-
|
101
|
+
set_flash(:notice, @notice)
|
101
102
|
status = Responders::FlashResponder.flash_keys.first
|
102
103
|
end
|
103
104
|
|
@@ -105,7 +106,14 @@ module Responders
|
|
105
106
|
|
106
107
|
options = mount_i18n_options(status)
|
107
108
|
message = ::I18n.t options[:default].shift, options
|
108
|
-
|
109
|
+
set_flash(status, message)
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_flash(key, value)
|
113
|
+
return if value.blank?
|
114
|
+
flash = controller.flash
|
115
|
+
flash = flash.now if @flash_now
|
116
|
+
flash[key] ||= value
|
109
117
|
end
|
110
118
|
|
111
119
|
def set_flash_message? #:nodoc:
|
data/lib/responders/version.rb
CHANGED
@@ -18,7 +18,7 @@ class AddressesController < ApplicationController
|
|
18
18
|
self.responder = FlashResponder
|
19
19
|
|
20
20
|
def action
|
21
|
-
options = params.slice(:flash)
|
21
|
+
options = params.slice(:flash, :flash_now)
|
22
22
|
flash[:success] = "Flash is set" if params[:set_flash]
|
23
23
|
respond_with(@resource, options)
|
24
24
|
end
|
@@ -107,6 +107,13 @@ class FlashResponderTest < ActionController::TestCase
|
|
107
107
|
assert_equal "Resource with block created with success", flash[:success]
|
108
108
|
end
|
109
109
|
|
110
|
+
def test_sets_flash_message_can_be_set_to_now
|
111
|
+
@now = {}
|
112
|
+
@controller.flash.expects(:now).returns(@now)
|
113
|
+
post :create, :flash_now => true
|
114
|
+
assert_equal "Resource created with success", @now[:success]
|
115
|
+
end
|
116
|
+
|
110
117
|
def test_sets_message_based_on_notice_key
|
111
118
|
Responders::FlashResponder.flash_keys = [ :notice, :alert ]
|
112
119
|
post :another
|
data/test/test_helper.rb
CHANGED
@@ -20,8 +20,6 @@ RAILS_ROOT = "anywhere"
|
|
20
20
|
|
21
21
|
require 'active_support'
|
22
22
|
require 'action_controller'
|
23
|
-
require 'action_dispatch/middleware/flash'
|
24
|
-
|
25
23
|
require 'rails/railtie'
|
26
24
|
|
27
25
|
class ApplicationController < ActionController::Base
|
@@ -36,12 +34,19 @@ I18n.reload!
|
|
36
34
|
|
37
35
|
ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
|
38
36
|
|
39
|
-
|
37
|
+
Responders::Router = ActionDispatch::Routing::RouteSet.new
|
38
|
+
Responders::Router.draw do |map|
|
40
39
|
map.connect 'admin/:action', :controller => "admin/addresses"
|
41
40
|
map.connect ':controller/:action/:id'
|
42
41
|
map.connect ':controller/:action'
|
43
42
|
end
|
44
43
|
|
44
|
+
class ActiveSupport::TestCase
|
45
|
+
setup do
|
46
|
+
@router = Responders::Router
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
45
50
|
class Model < Struct.new(:updated_at)
|
46
51
|
attr_writer :new_record
|
47
52
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 4
|
9
|
+
version: 0.5.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jos\xC3\xA9 Valim"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-13 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|