From bed38c6591443065045e76ef9c0f87a6196a99f3 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 1 Oct 2024 18:50:52 -0400 Subject: [PATCH 1/2] test: add coverage for generator templates and matrix across Rails 7.2, 8.0, and main --- .github/workflows/upstream.yml | 9 ++++----- test/integration/user_journey_test.sh | 13 ++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 0b0f35eb..0ba5507a 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -10,8 +10,6 @@ on: types: [opened, synchronize] branches: - '*' - paths: - - .github/workflows/upstream.yml # this file jobs: tests: @@ -37,14 +35,15 @@ jobs: run: bin/test user-journey: - name: "user-journey (rails main)" + name: "user-journey (rails ${{ matrix.ref }})" runs-on: ${{matrix.plat}}-latest strategy: fail-fast: false matrix: - plat: ["ubuntu", "windows", "macos"] + plat: ["ubuntu"] + ref: ["7-2-stable", "v8.0.0.beta1", "main"] env: - RAILSOPTS: --git=https://github.com/rails/rails --branch main + RAILSOPTS: --git=https://github.com/rails/rails --ref=${{ matrix.ref }} steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/test/integration/user_journey_test.sh b/test/integration/user_journey_test.sh index 4016ec20..1877e871 100755 --- a/test/integration/user_journey_test.sh +++ b/test/integration/user_journey_test.sh @@ -32,12 +32,13 @@ bundle add rails --skip-install ${RAILSOPTS:-} bundle add tailwindcss-rails --path="../.." bundle install bundle show --paths +bundle binstubs --all # install tailwindcss bin/rails tailwindcss:install # TEST: tailwind was installed correctly -grep tailwind app/views/layouts/application.html.erb +grep -q tailwind app/views/layouts/application.html.erb # TEST: rake tasks don't exec (#188) cat <> Rakefile @@ -47,3 +48,13 @@ end EOF bin/rails tailwindcss:build still_here | grep "Rake process did not exit early" + +if [[ $(rails -v) > "Rails 8.0.0.beta" ]] ; then + # TEST: presence of the generated file + bin/rails generate authentication + grep -q PasswordsController app/controllers/passwords_controller.rb +fi + +# TEST: presence of the generated file +bin/rails generate scaffold post title:string body:text published:boolean +grep -q "Show this post" app/views/posts/index.html.erb From 9dee33a64db4323414bab5910f379b38fb8b0d47 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 1 Oct 2024 18:20:05 -0400 Subject: [PATCH 2/2] Make copies of the auth templates for Rails 8 beta1 We can revert this once beta2 is out. --- .../templates/views/passwords/edit.html.erb | 21 +++++++++++++ .../templates/views/passwords/new.html.erb | 17 ++++++++++ .../templates/views/sessions/new.html.erb | 31 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb create mode 100644 lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb create mode 100644 lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb new file mode 100644 index 00000000..939b0b8d --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb @@ -0,0 +1,21 @@ +
+ <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + +

Update your password

+ + <%%= form_with url: password_path(params[:token]), method: :put, class: "contents" do |form| %> +
+ <%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.submit "Save", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ <%% end %> +
diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb new file mode 100644 index 00000000..e5d88197 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb @@ -0,0 +1,17 @@ +
+ <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + +

Forgot your password?

+ + <%%= form_with url: passwords_path, class: "contents" do |form| %> +
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.submit "Email reset instructions", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ <%% end %> +
diff --git a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb new file mode 100644 index 00000000..a4751541 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb @@ -0,0 +1,31 @@ +
+ <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + + <%% if notice = flash[:notice] %> +

<%%= notice %>

+ <%% end %> + +

Sign in

+ + <%%= form_with url: session_url, class: "contents" do |form| %> +
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+
+ <%%= form.submit "Sign in", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ +
+ <%%= link_to "Forgot password?", new_password_path, class: "text-gray-700 underline" %> +
+
+ <%% end %> +