Skip to content

Commit

Permalink
Fixing test coverage after mega-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitytakei committed Feb 18, 2025
1 parent 534f454 commit d423199
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/models/generated_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def apply_ingredient(ingredient, configuration = {})

template_path = DataRepositoryService.new(user:).template_path(ingredient)

unless File.exist?(template_path)
@logger.error("Template file not found", { path: template_path })
raise "Template file not found: #{template_path}"
end

command = "rails app:template LOCATION=#{template_path}"
CommandExecutionService.new(self, @logger, command).execute

Expand Down
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@
config.active_record.encryption.primary_key = "test" * 8
config.active_record.encryption.deterministic_key = "test" * 8
config.active_record.encryption.key_derivation_salt = "test" * 8

# Configure Active Storage to use the test service
config.active_storage.service = :test
end
26 changes: 24 additions & 2 deletions test/models/generated_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,12 @@ def setup

@logger.expects(:info).with("Applying ingredient: #{ingredient.name}")
@logger.expects(:info).with("Committing ingredient changes")
git_service.expects(:commit_changes).with(<<~COMMIT_MESSAGE)
Applied ingredient:
#{ingredient.to_commit_message}
COMMIT_MESSAGE
@logger.expects(:info).with("Ingredient #{ingredient.name} applied successfully")
git_service.expects(:commit_changes).with(message: ingredient.to_commit_message)
end

@generated_app.apply_ingredients
Expand All @@ -394,7 +398,19 @@ def setup

test "to_commit_message for an app without ingredients doesn't contain message about ingredients" do
app = generated_apps(:no_ingredients_app)
assert_equal "Initial commit by railsnew.io\n\ncommand line flags:\n\n--minimal\n\n\n", app.to_commit_message
commit_message = <<~COMMIT_MESSAGE
Initial commit by railsnew.io
===================
Command line flags:
===================
#{app.recipe.cli_flags.squish.strip}
COMMIT_MESSAGE

assert_equal commit_message, app.to_commit_message
end

test "raises error when template path doesn't exist" do
Expand All @@ -405,6 +421,12 @@ def setup
.expects(:template_path)
.returns("/nonexistent/path/template.rb")

@logger.stubs(:debug)

# Mock File.exist? to return false for the template path
File.stubs(:exist?).returns(true) # default for other files
File.stubs(:exist?).with("/nonexistent/path/template.rb").returns(false)

@logger.expects(:error).with(
"Template file not found",
{ path: "/nonexistent/path/template.rb" }
Expand Down

0 comments on commit d423199

Please sign in to comment.