From 2b2a0787bb5abf54dab7cffe0de13588cce62bd8 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Mon, 30 Sep 2024 10:20:42 +0930 Subject: [PATCH] Comment out config.auth.user_admin when --skip-account passed to install generator --- .../trestle/auth/install/install_generator.rb | 6 ++++- .../auth/install/templates/basic.rb.erb | 2 +- .../auth/install/templates/devise.rb.erb | 2 +- spec/generators/install_generator_spec.rb | 24 +++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/generators/trestle/auth/install/install_generator.rb b/lib/generators/trestle/auth/install/install_generator.rb index b4da3c1..750febd 100644 --- a/lib/generators/trestle/auth/install/install_generator.rb +++ b/lib/generators/trestle/auth/install/install_generator.rb @@ -32,13 +32,17 @@ def generate_admin end def generate_account - generate "trestle:auth:account", model, *("--devise" if devise?) unless options[:skip_account] + generate "trestle:auth:account", model, *("--devise" if devise?) unless skip_account? end def devise? options[:devise] end + def skip_account? + options[:skip_account] + end + def configuration_template devise? ? "devise.rb.erb" : "basic.rb.erb" end diff --git a/lib/generators/trestle/auth/install/templates/basic.rb.erb b/lib/generators/trestle/auth/install/templates/basic.rb.erb index 50a8f62..e46dce9 100644 --- a/lib/generators/trestle/auth/install/templates/basic.rb.erb +++ b/lib/generators/trestle/auth/install/templates/basic.rb.erb @@ -11,7 +11,7 @@ config.auth.user_class = -> { <%= model %> } # Specify the Trestle admin for managing the current user (My Account). # -config.auth.user_admin = -> { :"auth/account" } +<% if skip_account? %># <% end %>config.auth.user_admin = -> { :"auth/account" } # Specify the parameter (along with a password) to be used to # authenticate an administrator. Defaults to :email. diff --git a/lib/generators/trestle/auth/install/templates/devise.rb.erb b/lib/generators/trestle/auth/install/templates/devise.rb.erb index 3b25290..2bcf952 100644 --- a/lib/generators/trestle/auth/install/templates/devise.rb.erb +++ b/lib/generators/trestle/auth/install/templates/devise.rb.erb @@ -14,7 +14,7 @@ config.auth.user_class = -> { <%= model %> } # Specify the Trestle admin for managing the current user (My Account). # -config.auth.user_admin = -> { :"auth/account" } +<% if skip_account? %># <% end %>config.auth.user_admin = -> { :"auth/account" } # Specify the parameter (along with a password) to be used to # authenticate an administrator. Defaults to :email if not specified below. diff --git a/spec/generators/install_generator_spec.rb b/spec/generators/install_generator_spec.rb index e970eab..4bb0511 100644 --- a/spec/generators/install_generator_spec.rb +++ b/spec/generators/install_generator_spec.rb @@ -44,6 +44,18 @@ expect(generator(generator_params)).not_to receive(:generate).with("trestle:auth:account", "Administrator") run_generator generator_params end + + describe "the generated files" do + before do + run_generator generator_params + end + + describe "the Trestle configuration" do + subject { file("config/initializers/trestle.rb") } + + it { is_expected.to contain "# config.auth.user_admin = -> { :\"auth/account\" }" } + end + end end describe "the generated files" do @@ -88,6 +100,18 @@ expect(generator(generator_params)).not_to receive(:generate).with("trestle:auth:account", "User", "--devise") run_generator generator_params end + + describe "the generated files" do + before do + run_generator generator_params + end + + describe "the Trestle configuration" do + subject { file("config/initializers/trestle.rb") } + + it { is_expected.to contain "# config.auth.user_admin = -> { :\"auth/account\" }" } + end + end end describe "the generated files" do