Skip to content

Commit ff093e8

Browse files
committed
Extract thank yous controller
1 parent dcae80b commit ff093e8

File tree

8 files changed

+28
-16
lines changed

8 files changed

+28
-16
lines changed

app/controllers/concerns/erroring.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Erroring
22
def not_found!
3-
raise ActionController::RoutingError, "Not Found"
3+
raise ActionController::RoutingError, "Route not found #{request.path}"
44
end
55
end

app/controllers/users/registrations_controller.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create
1919
NewUserNotifier.deliver_to(AdminUser.all, user: user)
2020
EmailConfirmationNotifier.deliver_to(user)
2121

22-
redirect_to thanks_users_registration_path, notice: "Welcome to Joy of Rails! Please check your email for confirmation instructions"
22+
redirect_to users_thank_you_path, notice: "Welcome to Joy of Rails! Please check your email for confirmation instructions"
2323
else
2424
render Users::Registrations::NewView.new(user: user), status: :unprocessable_entity
2525
end
@@ -60,10 +60,6 @@ def destroy
6060
redirect_to root_path, notice: "Your account has been deleted"
6161
end
6262

63-
def thanks
64-
render Users::Dashboard::IndexView.new
65-
end
66-
6763
private
6864

6965
def feature_enabled!
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class Users::ThankYousController < ApplicationController
4+
def show
5+
render Users::ThankYous::ShowView.new
6+
end
7+
end

app/views/users/newsletter_subscriptions/show_view.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
class Users::NewsletterSubscriptions::ShowView < ApplicationView
4+
include Phlex::Rails::Helpers::LinkTo
45
include Phlex::Rails::Helpers::TurboFrameTag
56

67
def initialize(newsletter_subscription:, show_unsubscribe: false)
@@ -31,7 +32,9 @@ def view_template
3132
end
3233

3334
def subscribed_message
34-
plain "You are subscribed to the Joy of Rails newsletter!"
35+
link_to("Thank you", users_thank_you_path, class: "font-bold", data: {turbo_frame: "_top"})
36+
whitespace
37+
plain "for subscribing to the Joy of Rails newsletter!"
3538
if @newsletter_subscription.subscriber.needs_confirmation?
3639
whitespace
3740
plain "Please check your email for a confirmation link."

app/views/users/registrations/thanks_view.rb renamed to app/views/users/thank_yous/show_view.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class Users::Registration::ThanksView < ApplicationView
3+
class Users::ThankYous::ShowView < ApplicationView
44
include Phlex::Rails::Helpers::LinkTo
55

66
def view_template
@@ -27,6 +27,10 @@ def view_template
2727
strong { link_to("articles", "/articles") }
2828
whitespace
2929
plain "I’ve written on Ruby, Rails, and Hotwire."
30+
if ArticlePage.published.length < 5
31+
whitespace
32+
plain "I’m working on adding some new content, so check back soon!"
33+
end
3034
end
3135
li do
3236
plain "If you’re interested in learning how this app is built or even contributing to it, check out the"

config/routes.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@
3232
get "up" => "rails/health#show", :as => :rails_health_check
3333

3434
namespace :users do
35+
resource :thank_you, only: [:show]
3536
resource :header_navigation, only: [:show]
36-
resource :registration, only: [:new, :create, :edit, :update, :destroy] do
37-
collection do
38-
get :thanks
39-
end
40-
end
37+
resource :registration, only: [:new, :create, :edit, :update, :destroy]
4138
resources :confirmations, only: [:new, :create, :edit, :update], param: :token
4239
resources :passwords, only: [:new, :create, :edit, :update], param: :token
4340

spec/requests/users/registrations_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
params: {user: {email: email, password: "password", password_confirmation: "password"}}
3232
}.to change(User, :count).by(1)
3333

34-
expect(response).to redirect_to(thanks_users_registration_path)
34+
expect(response).to redirect_to(users_thank_you_path)
3535
expect(flash[:notice]).to eq("Welcome to Joy of Rails! Please check your email for confirmation instructions")
3636

3737
perform_enqueued_jobs_and_subsequently_enqueued_jobs

spec/system/users/newsletter_subscriptions_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
fill_in "user[email]", with: "[email protected]"
1313
click_button "Subscribe"
1414

15-
expect(page).to have_content("You are subscribed to the Joy of Rails newsletter! Please check your email for a confirmation link.")
15+
expect(page).to have_content("Thank you for subscribing to the Joy of Rails newsletter! Please check your email for a confirmation link.")
1616

1717
user = User.last
1818
expect(user.email).to eq("[email protected]")
1919
expect(user.subscribed_to_newsletter?).to eq(true)
20+
21+
click_link "Thank you"
22+
23+
expect(page).to have_content("Welcome to Joy of Rails!")
24+
expect(page).to have_content("Thank you for signing up")
2025
end
2126

2227
it "allows a logged-in user to subscribe to the newsletter" do
@@ -28,7 +33,7 @@
2833

2934
click_button "Subscribe"
3035

31-
expect(page).to have_content("You are subscribed to the Joy of Rails newsletter! Please check your email for a confirmation link.")
36+
expect(page).to have_content("Thank you for subscribing to the Joy of Rails newsletter! Please check your email for a confirmation link.")
3237

3338
expect(user.reload.subscribed_to_newsletter?).to be_truthy
3439

0 commit comments

Comments
 (0)