Skip to content

Commit

Permalink
Comment out config.auth.user_admin when --skip-account passed to inst…
Browse files Browse the repository at this point in the history
…all generator
  • Loading branch information
spohlenz committed Sep 30, 2024
1 parent 74e067a commit 2b2a078
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/generators/trestle/auth/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/trestle/auth/install/templates/basic.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions spec/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b2a078

Please sign in to comment.