|
1 | 1 | require 'test_helper'
|
2 |
| -require 'fileutils' |
3 |
| - |
4 | 2 | class ReactTest < ActionDispatch::IntegrationTest
|
5 | 3 | setup do
|
6 |
| - Rails.application.assets.send(:expire_index!) |
| 4 | + FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist? |
| 5 | + |
| 6 | + end |
| 7 | + |
| 8 | + teardown do |
7 | 9 | FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist?
|
8 | 10 | end
|
9 | 11 |
|
10 | 12 | test 'asset pipeline should deliver drop-in react file replacement' do
|
11 | 13 | app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__)
|
12 |
| - |
13 |
| - react_file_token = "'test_confirmation_token_react_content_non_production';\n"; |
| 14 | + react_file_token = "'test_confirmation_token_react_content_non_production';\n" |
14 | 15 | File.write(app_react_file_path, react_file_token)
|
15 | 16 |
|
16 |
| - asset_pipeline_length = Rails.application.assets.find_asset('react').to_s.length |
| 17 | + react_asset = Rails.application.assets['react.js'] |
| 18 | + |
| 19 | + # Sprockets 2 doesn't expire this asset correctly, |
| 20 | + # so override `fresh?` to mark it as expired. |
| 21 | + def react_asset.fresh?(env); false; end |
| 22 | + |
| 23 | + react_asset = Rails.application.assets['react.js'] |
| 24 | + |
17 | 25 | get '/assets/react.js'
|
18 | 26 |
|
19 | 27 | File.unlink(app_react_file_path)
|
20 |
| - FileUtils.rm_r CACHE_PATH if CACHE_PATH.exist? |
| 28 | + FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist? |
21 | 29 |
|
22 | 30 | assert_response :success
|
23 |
| - assert_equal react_file_token.length, asset_pipeline_length, "The asset pipeline serves the drop-in file" |
| 31 | + assert_equal react_file_token.length, react_asset.to_s.length, "The asset pipeline serves the drop-in file" |
24 | 32 | assert_equal react_file_token.length, @response.body.length, "The asset route serves the drop-in file"
|
25 | 33 | end
|
26 | 34 |
|
|
0 commit comments