diff --git a/lib/generators/trestle/auth/install/install_generator.rb b/lib/generators/trestle/auth/install/install_generator.rb index 750febd..d87e38a 100644 --- a/lib/generators/trestle/auth/install/install_generator.rb +++ b/lib/generators/trestle/auth/install/install_generator.rb @@ -18,7 +18,7 @@ def check_trestle_installed end def insert_configuration - inject_into_file "config/initializers/trestle.rb", before: /^end/ do + inject_into_file "config/initializers/trestle.rb", before: /end(?!.*end.*)/m do format_configuration(template_content(configuration_template)) end end diff --git a/spec/generators/install_generator_spec.rb b/spec/generators/install_generator_spec.rb index 4bb0511..e4f3066 100644 --- a/spec/generators/install_generator_spec.rb +++ b/spec/generators/install_generator_spec.rb @@ -132,4 +132,29 @@ end end end + + context "when the existing Trestle configuration is improperly indented" do + let(:configuration) do + <<~EOF + Trestle.configure do |config| + config.menu do + end + end + EOF + 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 have_correct_syntax } + it { is_expected.to contain "# == Authentication Options" } + it { is_expected.not_to contain /config.menu do\n\s*# == Authentication Options/ } + end + end + end end