Skip to content

Commit 0401abb

Browse files
committed
Setup tests
1 parent f189ba5 commit 0401abb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+209
-54
lines changed

.github/workflows/generators.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test Generators
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'lib/generators/**'
9+
- '.github/workflows/generators.yml'
10+
- 'lib/inertia_rails/generators/**'
11+
pull_request:
12+
paths:
13+
- 'lib/generators/**'
14+
- '.github/workflows/generators.yml'
15+
- 'lib/inertia_rails/generators/**'
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
framework: [react, vue, svelte4, svelte]
23+
typescript: [true, false]
24+
tailwind: [true, false]
25+
ruby: ['3.3']
26+
node: ['22']
27+
28+
name: ${{ matrix.framework }} (TS:${{ matrix.typescript }}, TW:${{ matrix.tailwind }})
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Set up Ruby
34+
uses: ruby/setup-ruby@v1
35+
with:
36+
ruby-version: ${{ matrix.ruby }}
37+
bundler-cache: true
38+
39+
- name: Set up Node
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: ${{ matrix.node }}
43+
44+
- name: Cache dependencies
45+
uses: actions/cache@v3
46+
with:
47+
path: |
48+
tmp/bundle_cache
49+
tmp/npm_cache
50+
~/.npm
51+
key: ${{ runner.os }}-deps-${{ matrix.framework }}-${{ hashFiles('**/Gemfile.lock') }}-${{ github.sha }}
52+
restore-keys: |
53+
${{ runner.os }}-deps-${{ matrix.framework }}-
54+
${{ runner.os }}-deps-
55+
56+
- name: Install Rails
57+
run: gem install rails
58+
59+
- name: Run test script
60+
run: |
61+
ts_flag=${{ matrix.typescript && '--typescript' || '--no-typescript' }}
62+
tw_flag=${{ matrix.tailwind && '--tailwind' || '--no-tailwind' }}
63+
bin/generate_scaffold_example --framework=${{ matrix.framework }} $ts_flag $tw_flag
64+
65+
- name: Upload test artifacts
66+
if: failure()
67+
uses: actions/upload-artifact@v3
68+
with:
69+
name: test-output-${{ matrix.framework }}-ts${{ matrix.typescript }}-tw${{ matrix.tailwind }}
70+
path: |
71+
tmp/scaffold_example/log
72+
tmp/scaffold_example/tmp/screenshots
73+
if-no-files-found: ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/pkg/
77
/spec/reports/
88
/tmp/
9+
/.cache/
910
/Gemfile.lock
1011

1112
/spec/dummy/db/*.sqlite3

bin/generate_scaffold_example

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'fileutils'
5+
require 'optparse'
6+
7+
# Parse command line options
8+
options = {
9+
framework: 'react',
10+
typescript: true,
11+
tailwind: true,
12+
}
13+
14+
OptionParser.new do |opts|
15+
opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
16+
17+
opts.on('--framework FRAMEWORK', %w[react vue svelte svelte4],
18+
'Choose framework (react/vue/svelte4/svelte)') do |f|
19+
options[:framework] = f
20+
end
21+
22+
opts.on('--[no-]typescript', 'Enable/disable TypeScript') do |t|
23+
options[:typescript] = t
24+
end
25+
26+
opts.on('--[no-]tailwind', 'Enable/disable Tailwind') do |t|
27+
options[:tailwind] = t
28+
end
29+
end.parse!
30+
31+
# Build generator args string
32+
generator_args = "--framework=#{options[:framework]}"
33+
generator_args += ' --typescript' if options[:typescript]
34+
generator_args += ' --install-vite'
35+
generator_args += ' --install-tailwind' if options[:tailwind]
36+
37+
# Setup paths relative to project root
38+
project_root = File.expand_path('..', __dir__)
39+
working_dir = File.join(project_root, 'tmp')
40+
gem_cache = File.join(working_dir, 'bundle_cache')
41+
npm_cache = File.join(working_dir, 'npm_cache')
42+
43+
# Create cache directories if they don't exist
44+
[gem_cache, npm_cache, working_dir].each do |dir|
45+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
46+
end
47+
48+
# Clean working directory
49+
FileUtils.rm_r(working_dir) if File.directory?(working_dir)
50+
FileUtils.mkdir_p(working_dir)
51+
52+
# Generate a new Rails app
53+
app_name = 'scaffold_example'
54+
app_dir = File.join(working_dir, app_name)
55+
system("rails new #{app_dir} -J")
56+
57+
# Install and configure with caching
58+
Dir.chdir(app_dir) do
59+
# Configure bundler to use cache in project root
60+
system("bundle config set --local path '#{gem_cache}'")
61+
62+
# Configure npm to use cache in project root
63+
system("npm config set cache '#{npm_cache}'")
64+
65+
# Install dependencies
66+
system('bundle add inertia_rails --path ../../')
67+
system('bundle add bcrypt')
68+
system('bin/rails active_storage:install')
69+
70+
# Run install generator with configured options
71+
system("bin/rails g inertia:install --no-interactive --force #{generator_args}")
72+
73+
# Generate a scaffold
74+
system('bin/rails g inertia:scaffold user name email admin:boolean password:digest avatar:attachment')
75+
system('bin/rails g inertia:scaffold post content:text published_at:date gallery:attachments')
76+
system('bin/rails db:migrate')
77+
78+
# Run tests
79+
system('bin/rails test')
80+
system('bin/rails test:system')
81+
end

docs/cookbook/integrating-shadcn-ui.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you're starting fresh, create a new Rails application with Inertia (or skip t
1414
rails new -JA shadcn-inertia-rails
1515
cd shadcn-inertia-rails
1616

17-
rails generate inertia:install --framework=react --typescript --install-vite --install-tailwind --no-interactive
17+
rails generate inertia:install `--framework=react --typescript --install-vite --install-tailwind --no-interactive`
1818
Installing Inertia's Rails adapter
1919
...
2020
```

docs/guide/server-side-setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ First, setup the root template that will be loaded on the first page visit. This
122122
<meta name="viewport" content="width=device-width,initial-scale=1">
123123
<%= csp_meta_tag %>
124124
125-
<%= inertia_headers %>
125+
<%= inertia_ssr_head %>
126126
127127
<%# If you want to use React add `vite_react_refresh_tag` %>
128128
<%= vite_client_tag %>
@@ -144,7 +144,7 @@ First, setup the root template that will be loaded on the first page visit. This
144144
<meta name="viewport" content="width=device-width,initial-scale=1">
145145
<%= csp_meta_tag %>
146146
147-
<%= inertia_headers %>
147+
<%= inertia_ssr_head %>
148148
149149
<%= stylesheet_pack_tag 'application' %>
150150
<%= javascript_pack_tag 'application', defer: true %>
@@ -157,7 +157,7 @@ First, setup the root template that will be loaded on the first page visit. This
157157
158158
:::
159159
160-
This template should include your assets, as well as the `yield` method to render the Inertia page. The `inertia_headers` method is used to include the Inertia headers in the response, it's required when [SSR](/guide/server-side-rendering.md) is enabled.
160+
This template should include your assets, as well as the `yield` method to render the Inertia page. The `inertia_ssr_head` method is used to include the Inertia headers in the response, it's required when [SSR](/guide/server-side-rendering.md) is enabled.
161161

162162
Inertia's adapter will use standard Rails layout inheritance, with `view/layouts/application.html.erb` as a default layout. If you would like to use a different default layout, you can change it using the `InertiaRails.configure`.
163163

lib/generators/inertia/install/install_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def install_inertia
9494
say "Adding #{inertia_entrypoint} script tag to the application layout"
9595
headers = <<-ERB
9696
<%= #{vite_tag} "inertia" %>
97-
<%= inertia_headers %>
97+
<%= inertia_ssr_head %>
9898
ERB
9999
insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"
100100

@@ -109,7 +109,7 @@ def install_inertia
109109
say_error 'Could not find the application layout file. Please add the following tags manually:', :red
110110
say_error '- <title>...</title>'
111111
say_error '+ <title inertia>...</title>'
112-
say_error '+ <%= inertia_headers %>'
112+
say_error '+ <%= inertia_ssr_head %>'
113113
say_error '+ <%= vite_react_refresh_tag %>' if framework == 'react'
114114
say_error "+ <%= #{vite_tag} \"inertia\" %>"
115115
end

lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function Edit({ <%= singular_table_name %> }) {
2020
form.patch(`<%= js_resource_path %>`)
2121
<% end -%>
2222
}}
23-
submitText="Update <%= human_name.downcase %>"
23+
submitText="Update <%= human_name %>"
2424
/>
2525

2626
<br />

lib/generators/inertia_templates/scaffold/templates/react/Edit.tsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function Edit({ <%= singular_table_name %> }: EditProps) {
2525
form.patch(`<%= js_resource_path %>`)
2626
<% end -%>
2727
}}
28-
submitText="Update <%= human_name.downcase %>"
28+
submitText="Update <%= human_name %>"
2929
/>
3030

3131
<br />

lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function Form({ <%= singular_table_name %>, onSubmit, submitText
3939

4040
<div>
4141
<label style={{ display: 'block' }} htmlFor="password_confirmation">
42-
Password Confirmation
42+
Password confirmation
4343
</label>
4444
<input
4545
type="password"

lib/generators/inertia_templates/scaffold/templates/react/Form.tsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function Form({ <%= singular_table_name %>, onSubmit, submitText
4747

4848
<div>
4949
<label style={{ display: 'block' }} htmlFor="password_confirmation">
50-
Password Confirmation
50+
Password confirmation
5151
</label>
5252
<input
5353
type="password"

lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function New({ <%= singular_table_name %> }) {
1414
form.transform((data) => ({ <%= singular_table_name %>: data }))
1515
form.post('<%= js_resources_path %>')
1616
}}
17-
submitText="Create <%= human_name.downcase %>"
17+
submitText="Create <%= human_name %>"
1818
/>
1919

2020
<br />

lib/generators/inertia_templates/scaffold/templates/react/New.tsx.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function New({ <%= singular_table_name %> }: NewProps) {
1919
form.transform((data) => ({ <%= singular_table_name %>: data }))
2020
form.post('<%= js_resources_path %>')
2121
}}
22-
submitText="Create <%= human_name.downcase %>"
22+
submitText="Create <%= human_name %>"
2323
/>
2424

2525
<br />

lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<Form
2626
{<%= singular_table_name %>}
27-
submitText="Update <%= human_name.downcase %>"
27+
submitText="Update <%= human_name %>"
2828
onSubmit={handleSubmit}
2929
/>
3030

lib/generators/inertia_templates/scaffold/templates/svelte/Edit.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<Form
2727
{<%= singular_table_name %>}
28-
submitText="Update <%= human_name.downcase %>"
28+
submitText="Update <%= human_name %>"
2929
onSubmit={handleSubmit}
3030
/>
3131

lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</div>
3838

3939
<div>
40-
<label for="password_confirmation">Password Confirmation</label>
40+
<label for="password_confirmation">Password confirmation</label>
4141
<input
4242
type="password"
4343
name="password_confirmation"

lib/generators/inertia_templates/scaffold/templates/svelte/Form.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343

4444
<div>
45-
<label for="password_confirmation">Password Confirmation</label>
45+
<label for="password_confirmation">Password confirmation</label>
4646
<input
4747
type="password"
4848
name="password_confirmation"

lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<Form
2020
{<%= singular_table_name %>}
21-
submitText="Create <%= human_name.downcase %>"
21+
submitText="Create <%= human_name %>"
2222
onSubmit={handleSubmit}
2323
/>
2424

lib/generators/inertia_templates/scaffold/templates/svelte/New.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Form
2121
{<%= singular_table_name %>}
22-
submitText="Create <%= human_name.downcase %>"
22+
submitText="Create <%= human_name %>"
2323
onSubmit={handleSubmit}
2424
/>
2525

lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<Form
2727
{<%= singular_table_name %>}
28-
submitText="Update <%= human_name.downcase %>"
28+
submitText="Update <%= human_name %>"
2929
on:submit={handleSubmit}
3030
/>
3131

lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<Form
2828
{<%= singular_table_name %>}
29-
submitText="Update <%= human_name.downcase %>"
29+
submitText="Update <%= human_name %>"
3030
on:submit={handleSubmit}
3131
/>
3232

lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</div>
3737

3838
<div>
39-
<label for="password_confirmation">Password Confirmation</label>
39+
<label for="password_confirmation">Password confirmation</label>
4040
<input
4141
type="password"
4242
name="password_confirmation"

lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</div>
4747

4848
<div>
49-
<label for="password_confirmation">Password Confirmation</label>
49+
<label for="password_confirmation">Password confirmation</label>
5050
<input
5151
type="password"
5252
name="password_confirmation"

lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Form
2121
{<%= singular_table_name %>}
22-
submitText="Create <%= human_name.downcase %>"
22+
submitText="Create <%= human_name %>"
2323
on:submit={handleSubmit}
2424
/>
2525

lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<Form
2222
{<%= singular_table_name %>}
23-
submitText="Create <%= human_name.downcase %>"
23+
submitText="Create <%= human_name %>"
2424
on:submit={handleSubmit}
2525
/>
2626

lib/generators/inertia_templates/scaffold/templates/vue/Edit.ts.vue.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<Form
77
:<%= singular_table_name %>="<%= singular_table_name %>"
8-
submitText="Update <%= human_name.downcase %>"
8+
submitText="Update <%= human_name %>"
99
@onSubmit="handleSubmit"
1010
/>
1111

lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<Form
77
:<%= singular_table_name %>="<%= singular_table_name %>"
8-
submitText="Update <%= human_name.downcase %>"
8+
submitText="Update <%= human_name %>"
99
@onSubmit="handleSubmit"
1010
/>
1111

0 commit comments

Comments
 (0)