Skip to content

Commit

Permalink
Add .keep file for app/relations, reorder expectations (#192)
Browse files Browse the repository at this point in the history
* Add .keep file for app/relations, reorder expectations

* Fix comment

* Create db/.keep

* Alphabetize DB generations

* Only generate db/.keep if sqlite
  • Loading branch information
cllns authored Jul 9, 2024
1 parent 0dc1374 commit af38319
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
16 changes: 12 additions & 4 deletions lib/hanami/cli/generators/gem/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ def generate_app(app, context) # rubocop:disable Metrics/AbcSize
end

if context.generate_db?
fs.write("app/db/repo.rb", t("repo.erb", context))
fs.write("app/db/relation.rb", t("relation.erb", context))
fs.write("app/relations/.keep", t("keep.erb", context))

fs.write("app/db/repo.rb", t("repo.erb", context))
fs.write("app/repos/.keep", t("keep.erb", context))

fs.write("app/db/struct.rb", t("struct.erb", context))
fs.touch("app/structs/.keep")
fs.touch("app/repos/.keep")
fs.touch("config/db/migrate/.keep")
fs.write("app/structs/.keep", t("keep.erb", context))

fs.write("config/db/migrate/.keep" , t("keep.erb", context))

if context.generate_sqlite?
fs.write("db/.keep" , t("keep.erb", context))
end
end

fs.write("app/operation.rb", t("operation.erb", context))
Expand Down
46 changes: 28 additions & 18 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -819,22 +819,8 @@ class Action < Hanami::Action
EXPECTED
expect(fs.read("app/action.rb")).to eq(action)
expect(output).to include("Created app/action.rb")

# app/repo.rb
repo = <<~EXPECTED
# frozen_string_literal: true
require "hanami/db/repo"
module #{inflector.camelize(app)}
module DB
class Repo < Hanami::DB::Repo
end
end
end
EXPECTED
expect(fs.read("app/db/repo.rb")).to eq(repo)
expect(output).to include("Created app/db/repo.rb")
expect(fs.read("app/actions/.keep")).to eq("")
expect(output).to include("Created app/actions/.keep")

# app/view.rb
view = <<~RUBY
Expand Down Expand Up @@ -923,6 +909,26 @@ class Relation < Hanami::DB::Relation
EXPECTED
expect(fs.read("app/db/relation.rb")).to eq(relation)
expect(output).to include("Created app/db/relation.rb")
expect(fs.read("app/relations/.keep")).to eq("")
expect(output).to include("Created app/relations/.keep")

# app/db/repo.rb
repo = <<~EXPECTED
# frozen_string_literal: true
require "hanami/db/repo"
module #{inflector.camelize(app)}
module DB
class Repo < Hanami::DB::Repo
end
end
end
EXPECTED
expect(fs.read("app/db/repo.rb")).to eq(repo)
expect(output).to include("Created app/db/repo.rb")
expect(fs.read("app/repos/.keep")).to eq("")
expect(output).to include("Created app/repos/.keep")

# app/db/struct.rb
struct = <<~EXPECTED
Expand All @@ -939,10 +945,14 @@ class Struct < Hanami::DB::Struct
EXPECTED
expect(fs.read("app/db/struct.rb")).to eq(struct)
expect(output).to include("Created app/db/struct.rb")

expect(fs.read("app/structs/.keep")).to eq("")
expect(fs.read("app/repos/.keep")).to eq("")
expect(output).to include("Created app/structs/.keep")

expect(fs.read("db/.keep")).to eq("")
expect(output).to include("Created db/.keep")

expect(fs.read("config/db/migrate/.keep")).to eq("")
expect(output).to include("Created config/db/migrate/.keep")

# lib/bookshelf/types.rb
types = <<~EXPECTED
Expand Down

0 comments on commit af38319

Please sign in to comment.