Skip to content

Commit

Permalink
Ensure auth config is inserted before final end in trestle.rb, even w…
Browse files Browse the repository at this point in the history
…hen improperly indented
  • Loading branch information
spohlenz committed Sep 30, 2024
1 parent 2b2a078 commit 7f707fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/generators/trestle/auth/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions spec/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7f707fb

Please sign in to comment.