blob: 033477fe391884e0f3917ce6114879c26bbd9fc3 (
plain) (
blame)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 | require File.dirname(__FILE__) + '/../abstract_unit'
class FlashTest < Test::Unit::TestCase
  class TestController < ActionController::Base
    def set_flash
      flash["that"] = "hello"
      render_text "hello"
    end
    def use_flash
      @flashy = flash["that"]
      render_text "hello"
    end
    def use_flash_and_keep_it
      @flashy = flash["that"]
      keep_flash
      render_text "hello"
    end
    def rescue_action(e)
      raise unless ActionController::MissingTemplate === e
    end
  end
  def setup
    initialize_request_and_response
  end
  def test_flash
    @request.action = "set_flash"
    response = process_request
    @request.action = "use_flash"
    first_response = process_request
    assert_equal "hello", first_response.template.assigns["flash"]["that"]
    assert_equal "hello", first_response.template.assigns["flashy"]
    second_response = process_request
    assert_nil second_response.template.assigns["flash"]["that"], "On second flash"
  end
  def test_keep_flash
    @request.action = "set_flash"
    response = process_request
    
    @request.action = "use_flash_and_keep_it"
    first_response = process_request
    assert_equal "hello", first_response.template.assigns["flash"]["that"]
    assert_equal "hello", first_response.template.assigns["flashy"]
    @request.action = "use_flash"
    second_response = process_request
    assert_equal "hello", second_response.template.assigns["flash"]["that"], "On second flash"
    third_response = process_request
    assert_nil third_response.template.assigns["flash"]["that"], "On third flash"
  end
  
  private
    def initialize_request_and_response
      @request  = ActionController::TestRequest.new
      @response = ActionController::TestResponse.new
    end
  
    def process_request
      TestController.process(@request, @response)
    end
end
 |