-
Notifications
You must be signed in to change notification settings - Fork 5
/
rails-streaming.rb
executable file
·91 lines (73 loc) · 2.02 KB
/
rails-streaming.rb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', "~> #{ARGV.first || "6.0"}"
end
require 'rack/test'
require 'action_controller/railtie'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.hosts.clear if config.respond_to? :hosts # needed to allow request in Rails 6
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get '/' => 'test#index'
get '/set_flash' => 'test#set_flash'
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
prepend_view_path Rails.root
def index
render template: 'template', stream: params[:stream]
end
def set_flash
flash.notice = 'notice'
render plain: 'ok'
end
end
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class BugTest < Minitest::Test
include Rack::Test::Methods
def setup
IO.write('template.html.erb', '<%= csrf_meta_tag %><%= flash.notice %>')
end
def teardown
File.unlink('template.html.erb')
end
def test_works_without_stream
get '/set_flash'
assert last_response.ok?
get '/'
assert last_response.ok?
assert_match /notice/, last_response.body
get '/'
assert last_response.ok?
refute_match /notice/, last_response.body
end
def test_works_with_stream
get '/set_flash'
assert last_response.ok?
get '/', stream: true
assert last_response.ok?
assert_match /notice/, last_response.body
get '/', stream: true
assert last_response.ok?
refute_match /notice/, last_response.body
end
private
def app
Rails.application
end
end