|
3 | 3 |
|
4 | 4 | class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
|
5 | 5 | tests Tailwindcss::Generators::ScaffoldGenerator
|
6 |
| - destination Dir.mktmpdir |
| 6 | + destination TAILWINDCSS_TEST_APP_ROOT |
7 | 7 |
|
8 | 8 | arguments %w(message title:string content:text)
|
9 | 9 |
|
10 |
| - test "generates correct view templates" do |
| 10 | + test "generates view templates" do |
11 | 11 | run_generator
|
12 | 12 |
|
13 |
| - %w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" } |
| 13 | + %w(index edit new show _form _message).each do |view| |
| 14 | + assert_file "app/views/messages/#{view}.html.erb" |
| 15 | + end |
14 | 16 | end
|
15 | 17 |
|
16 |
| - test "with namespace invoked" do |
| 18 | + test "generates view templates with namespace" do |
17 | 19 | run_generator [ "admin/role", "name:string", "description:string" ]
|
18 | 20 |
|
19 |
| - %w(index edit new show _form _role).each { |view| assert_file "app/views/admin/roles/#{view}.html.erb" } |
| 21 | + %w(index edit new show _form _role).each do |view| |
| 22 | + assert_file "app/views/admin/roles/#{view}.html.erb" |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + [ |
| 27 | + "lib/templates/tailwindcss/scaffold", |
| 28 | + "lib/templates/erb/scaffold", |
| 29 | + ].each do |templates_path| |
| 30 | + test "overriding generator templates in #{templates_path}" do |
| 31 | + override_dir = File.join(destination_root, templates_path) |
| 32 | + FileUtils.mkdir_p override_dir |
| 33 | + File.open(File.join(override_dir, "index.html.erb"), "w") { |f| f.puts "This is a custom template" } |
| 34 | + |
| 35 | + # change directory because the generator adds a relative path to source_paths |
| 36 | + Dir.chdir(destination_root) do |
| 37 | + run_generator |
| 38 | + end |
| 39 | + |
| 40 | + %w(edit new show _form _message).each do |view| |
| 41 | + assert_file "app/views/messages/#{view}.html.erb" |
| 42 | + end |
| 43 | + |
| 44 | + assert_file "app/views/messages/index.html.erb" do |body| |
| 45 | + assert_match("This is a custom template", body, "index custom template should be used") |
| 46 | + end |
| 47 | + end |
20 | 48 | end
|
21 | 49 | end
|
0 commit comments