responders 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,6 +64,8 @@ module Responders
64
64
  #
65
65
  # respond_with(@user, :notice => "Hooray! Welcome!", :alert => "Woot! You failed.")
66
66
  #
67
+ # * :flash_now - Sets the flash message using flash.now. Accepts true, :on_failure or :on_sucess.
68
+ #
67
69
  # == Configure status keys
68
70
  #
69
71
  # As said previously, FlashResponder by default use :notice and :alert
@@ -87,8 +89,8 @@ module Responders
87
89
  end
88
90
 
89
91
  def to_html
90
- super
91
92
  set_flash_message! if set_flash_message?
93
+ super
92
94
  end
93
95
 
94
96
  protected
@@ -112,10 +114,14 @@ module Responders
112
114
  def set_flash(key, value)
113
115
  return if value.blank?
114
116
  flash = controller.flash
115
- flash = flash.now if @flash_now
117
+ flash = flash.now if set_flash_now?
116
118
  flash[key] ||= value
117
119
  end
118
120
 
121
+ def set_flash_now?
122
+ (@flash_now == true) || (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success)
123
+ end
124
+
119
125
  def set_flash_message? #:nodoc:
120
126
  !get? && @flash != false
121
127
  end
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.5.4".freeze
2
+ VERSION = "0.5.5".freeze
3
3
  end
@@ -114,6 +114,18 @@ class FlashResponderTest < ActionController::TestCase
114
114
  assert_equal "Resource created with success", @now[:success]
115
115
  end
116
116
 
117
+ def test_sets_flash_message_can_be_set_to_now_only_on_success
118
+ @now = {}
119
+ @controller.flash.expects(:now).returns(@now)
120
+ post :create, :flash_now => :on_success
121
+ assert_equal "Resource created with success", @now[:success]
122
+ end
123
+
124
+ def test_sets_flash_message_can_be_set_to_now_only_on_failure
125
+ @controller.flash.expects(:now).never
126
+ post :create, :flash_now => :on_failure
127
+ end
128
+
117
129
  def test_sets_message_based_on_notice_key
118
130
  Responders::FlashResponder.flash_keys = [ :notice, :alert ]
119
131
  post :another
data/test/test_helper.rb CHANGED
@@ -16,7 +16,6 @@ require 'mocha'
16
16
 
17
17
  # Configure Rails
18
18
  ENV["RAILS_ENV"] = "test"
19
- RAILS_ROOT = "anywhere"
20
19
 
21
20
  require 'active_support'
22
21
  require 'action_controller'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 4
9
- version: 0.5.4
8
+ - 5
9
+ version: 0.5.5
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-13 00:00:00 +01:00
17
+ date: 2010-03-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20