Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ or a file under `app/assets/` changes. Open <http://127.0.0.1:3000>.
The web template is deliberately small:

- Amber from `amberframework/amber`, pinned to `2.0.0-beta.10` by commit
(`d291e0930dd22b14a2d10f75a9de063abb0e64e4`), with its checksum (`sha256-v2:8d354db3b41625db0362162a34836fe10a8b11a378f3837d34cc6bbcece1cb94`) checked in `shard.lock`
(`d775841a0af43bf512f1c9b704906fccdf8863f7`), with its checksum (`sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d`) checked in `shard.lock`
- ECR views (Slang and Kilt are not supported in Amber V2)
- typed development, test, and production YAML
- branded homepage, controller spec, and fingerprinted CSS, JavaScript, SVG,
Expand Down
8 changes: 4 additions & 4 deletions docs/BETA_WEB_APP.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ grep -E '^(template|database|model):' .amber.yml
```

The dependency must be `amberframework/amber` at commit
`d291e0930dd22b14a2d10f75a9de063abb0e64e4` (`v2.0.0-beta.10`); the
`d775841a0af43bf512f1c9b704906fccdf8863f7` (`2.0.0-beta.10` on `v2-dev`); the
template must be `ecr`, the database must be `sqlite`, and the model layer must
be `grant`. `shard.yml` must include Grant, Asset Pipeline, and
`crystal-sqlite3`, but it must not include Gemma, Slang, PostgreSQL, or MySQL
unless you selected that database.
be `grant`. `shard.yml` must include Grant and Asset Pipeline pinned by commit,
and no database driver shard unless you selected MySQL. Grant ships its own
Postgres and SQLite drivers.

The first page carries a compact version of Amber's V2 visual language: warm
paper colors, a fingerprinted SVG crystal, editorial heading scale, status
Expand Down
4 changes: 2 additions & 2 deletions docs/ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ Pin the release's commit and move the lock:
dependencies:
amber:
github: amberframework/amber
commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10
commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev
```

```bash
minecart update amber
grep -A3 '^ amber:' shard.lock # checksum: sha256-v2:8d354db3b41625db0362162a34836fe10a8b11a378f3837d34cc6bbcece1cb94
grep -A3 '^ amber:' shard.lock # checksum: sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d
amber setup:agent
```

Expand Down
12 changes: 6 additions & 6 deletions scripts/check_beta_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ test "$shard_version" = "2.0.10"
test "$cli_version" = "$shard_version"

grep -F 'github: amberframework/amber' src/amber_cli/commands/new_command.cr
grep -F 'commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10' src/amber_cli/commands/new_command.cr
grep -F 'COMMIT = "d291e0930dd22b14a2d10f75a9de063abb0e64e4"' src/amber_cli/amber_release.cr
grep -F 'TREE = "fb4574c6b15b60357abd43ed0a1a8d7a0957e574"' src/amber_cli/amber_release.cr
grep -F 'CHECKSUM = "sha256-v2:8d354db3b41625db0362162a34836fe10a8b11a378f3837d34cc6bbcece1cb94"' src/amber_cli/amber_release.cr
grep -F 'commit: #{AmberRelease::COMMIT} # #{AmberRelease::VERSION} on v2-dev' src/amber_cli/commands/new_command.cr
grep -F 'COMMIT = "d775841a0af43bf512f1c9b704906fccdf8863f7"' src/amber_cli/amber_release.cr
grep -F 'TREE = "e06f26daef02a30e91114b2c71224920e0c097de"' src/amber_cli/amber_release.cr
grep -F 'CHECKSUM = "sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d"' src/amber_cli/amber_release.cr
grep -F 'template: ecr' src/amber_cli/commands/new_command.cr
grep -F 'model: grant' src/amber_cli/commands/new_command.cr
grep -F 'database: #{database}' src/amber_cli/commands/new_command.cr
grep -F 'github: crimson-knight/grant' src/amber_cli/commands/new_command.cr
grep -F 'github: amberframework/asset_pipeline' src/amber_cli/commands/new_command.cr
grep -F 'version: 0.37.1' src/amber_cli/commands/new_command.cr
grep -F 'commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1' src/amber_cli/commands/new_command.cr
grep -F 'github: amberframework/asset_pipeline' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'version: 0.37.1' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'github: amberframework/amber' src/amber_cli/generators/native_app.cr
grep -F 'commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10' src/amber_cli/generators/native_app.cr
grep -F 'version: ~> 0.37.1' src/amber_cli/generators/native_app.cr
Expand Down
12 changes: 6 additions & 6 deletions scripts/smoke_generated_web.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ $amberConfig = [System.IO.File]::ReadAllText($amberConfigPath)
if (-not $manifest.Contains("github: amberframework/amber")) {
throw "Generated shard.yml does not include Amber"
}
if (-not $manifest.Contains("commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10")) {
if (-not $manifest.Contains("commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev")) {
throw "Generated shard.yml does not pin the supported Amber beta"
}
if (-not $manifest.Contains("github: crimson-knight/grant")) {
throw "Generated shard.yml does not include Grant"
}
if (-not $manifest.Contains("github: crystal-lang/crystal-sqlite3")) {
throw "Generated shard.yml does not include SQLite"
if ($manifest.Contains("crystal-sqlite3")) {
throw "Generated shard.yml lists a SQLite driver; Grant owns it"
}
if (-not $manifest.Contains("github: amberframework/asset_pipeline")) {
throw "Generated shard.yml does not include Asset Pipeline"
}
if (-not $manifest.Contains("version: 0.37.1")) {
if (-not $manifest.Contains("commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1")) {
throw "Generated shard.yml does not pin the supported Asset Pipeline release"
}
if (-not (Test-Path (Join-Path $appPath ".claude/CLAUDE.md"))) {
Expand All @@ -74,7 +74,7 @@ if (-not $amberConfig.Contains("database: sqlite") -or -not $amberConfig.Contain

if ($FrameworkCommit) {
$releasedRepository = " github: amberframework/amber"
$releasedFramework = " commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10"
$releasedFramework = " commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev"
if (-not $manifest.Contains($releasedRepository)) {
throw "Generated shard.yml does not contain the expected Amber repository"
}
Expand Down Expand Up @@ -118,7 +118,7 @@ try {
$expectedAmberCommit = $FrameworkCommit
$expectedAmberGit = "https://github.com/$FrameworkRepository.git"
} else {
$expectedAmberCommit = "d291e0930dd22b14a2d10f75a9de063abb0e64e4"
$expectedAmberCommit = "d775841a0af43bf512f1c9b704906fccdf8863f7"
$expectedAmberGit = "https://github.com/amberframework/amber.git"
}
if ($amberEntry -notmatch "(?m)^ git: $([regex]::Escape($expectedAmberGit))\r?$") {
Expand Down
18 changes: 9 additions & 9 deletions scripts/smoke_generated_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ grep -F 'AMBER_ENV=test crystal spec' "$script_dir/../src/amber_cli/templates/ap
! grep -F 'crystal-alpha' "$script_dir/../src/amber_cli/templates/app/.amber.yml.ecr"

grep -F "github: amberframework/amber" "$app_path/shard.yml"
grep -F "commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10" "$app_path/shard.yml"
grep -F "commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev" "$app_path/shard.yml"
grep -F "github: crimson-knight/grant" "$app_path/shard.yml"
grep -F "github: amberframework/asset_pipeline" "$app_path/shard.yml"
grep -F "version: 0.37.1" "$app_path/shard.yml"
grep -F "commit: 6c9da3c8180e612f76ff9ad9c76242a0402ce6d9" "$app_path/shard.yml"
grep -F "github: crystal-lang/crystal-sqlite3" "$app_path/shard.yml"
grep -F "commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1" "$app_path/shard.yml"
grep -F "commit: 623c4bcad284fcee000244c8b26651f925e23ceb" "$app_path/shard.yml"
! grep -F "crystal-sqlite3" "$app_path/shard.yml"
grep -F "template: ecr" "$app_path/.amber.yml"
grep -F "database: sqlite" "$app_path/.amber.yml"
grep -F "model: grant" "$app_path/.amber.yml"
Expand All @@ -68,7 +68,7 @@ fi

if [[ -n "$framework_commit" ]]; then
sed -i.bak -E "s# github: amberframework/amber# github: ${framework_repository}#" "$app_path/shard.yml"
sed -i.bak -E "s/ commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4( # v[^ ]+)?$/ commit: ${framework_commit}/" "$app_path/shard.yml"
sed -i.bak -E "s/ commit: d775841a0af43bf512f1c9b704906fccdf8863f7( # [^#]+)?$/ commit: ${framework_commit}/" "$app_path/shard.yml"
rm -f "$app_path/shard.yml.bak"
fi

Expand All @@ -86,7 +86,7 @@ else
minecart install --frozen
fi
test -s shard.lock
grep -F "version: 0.23.4+git.commit.6c9da3c8180e612f76ff9ad9c76242a0402ce6d9" shard.lock
grep -F "version: 0.23.4+git.commit.623c4bcad284fcee000244c8b26651f925e23ceb" shard.lock
grep -F "version: 0.14.0" shard.lock
# Each shard entry carries exactly one checksum.
awk '
Expand All @@ -100,14 +100,14 @@ if [[ -n "$framework_commit" ]]; then
expected_amber_commit="$framework_commit"
expected_amber_git="https://github.com/${framework_repository}.git"
else
expected_amber_commit="d291e0930dd22b14a2d10f75a9de063abb0e64e4"
expected_amber_commit="d775841a0af43bf512f1c9b704906fccdf8863f7"
expected_amber_git="https://github.com/amberframework/amber.git"
fi
grep -qxF " git: ${expected_amber_git}" <<<"$amber_entry"
grep -qE "^ version: [^ ]+\+git\.commit\.${expected_amber_commit}$" <<<"$amber_entry"
if [[ -z "$framework_commit" ]]; then
grep -qxF " version: 2.0.0-beta.10+git.commit.d291e0930dd22b14a2d10f75a9de063abb0e64e4" <<<"$amber_entry"
grep -qxF " checksum: sha256-v2:8d354db3b41625db0362162a34836fe10a8b11a378f3837d34cc6bbcece1cb94" <<<"$amber_entry"
grep -qxF " version: 2.0.0-beta.10+git.commit.d775841a0af43bf512f1c9b704906fccdf8863f7" <<<"$amber_entry"
grep -qxF " checksum: sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d" <<<"$amber_entry"
fi
"$cli_path" assets build
"$cli_path" assets check
Expand Down
24 changes: 24 additions & 0 deletions spec/commands/database_command_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "../spec_helper"

describe AmberCLI::Commands::DatabaseCommand do
describe ".connection_url_for_migrations" do
it "points the migration driver at the socket file of a socket directory URL" do
url = "postgres:///app_production?host=/var/run/postgresql"
expected = URI.parse("postgres:///app_production?host=#{URI.encode_www_form("/var/run/postgresql/.s.PGSQL.5432")}").to_s

AmberCLI::Commands::DatabaseCommand.connection_url_for_migrations(url).should eq(expected)
end

it "leaves a URL that already names the socket file alone" do
url = "postgres:///app?host=/tmp/.s.PGSQL.5432"
AmberCLI::Commands::DatabaseCommand.connection_url_for_migrations(url).should eq(url)
end

it "leaves non-socket URLs alone" do
tcp_url = "postgres://localhost:5432/app"
sqlite_url = "sqlite3:./db/app.db"
AmberCLI::Commands::DatabaseCommand.connection_url_for_migrations(tcp_url).should eq(tcp_url)
AmberCLI::Commands::DatabaseCommand.connection_url_for_migrations(sqlite_url).should eq(sqlite_url)
end
end
end
66 changes: 65 additions & 1 deletion spec/commands/generate_command_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,77 @@ describe AmberCLI::Commands::GenerateCommand do
AmberCLI::Commands::GenerateCommand.new("generate").parse_and_execute(["scaffold", "Pet", "name:string"])
AmberCLI::Commands::GenerateCommand.new("generate").parse_and_execute(["api", "Toy", "name:string"])

File.read("src/controllers/pet_controller.cr").should contain("Pet.order(id: :desc).to_a")
File.read("src/controllers/pet_controller.cr").should contain("Pet.order(id: :desc).limit(ROWS_PER_PAGE + 1)")
File.read("src/controllers/pet_controller.cr").should_not contain("Pet.all.to_a")
File.read("src/controllers/api/toy_controller.cr").should contain("Toy.order(id: :desc).to_a")
File.read("src/controllers/api/toy_controller.cr").should_not contain("Toy.all.to_a")
end
end

it "answers scaffold reads from the page cache and clears exactly what a write changed" do
SpecHelper.within_temp_directory do
File.write(".amber.yml", "template: ecr\ndatabase: sqlite\nmodel: grant\n")

AmberCLI::Commands::GenerateCommand.new("generate").parse_and_execute(["scaffold", "Pet", "name:string:required", "adopted:bool"])

controller = File.read("src/controllers/pet_controller.cr")
controller.should contain(%(page_cache.answer(context, list_page_key(page_number))))
controller.should contain(%(page_cache.answer(context, show_page_key(record_id))))
controller.should contain("clear_pages_after_create")
controller.should contain("clear_pages_after_update(pet)")
controller.should contain("clear_pages_after_destroy(pet, list_page_number)")
controller.should contain("clear_pages_numbered_from")
controller.should contain("clear_fragments(fragment_keys_of(pet))")
controller.should contain("per-visitor")

row = File.read("src/views/pet/_row.ecr")
row.should contain("escape_text(@pet.name)")
row.should contain("escape_text(@pet.adopted)")
File.read("src/views/pet/_details.ecr").should contain("escape_text(@pet.name)")
File.read("src/components/pet_row.cr").should contain("struct PetRow < Components::StatelessView")
File.read("src/components/pet_details.cr").should contain(%("details:pet:\#{@pet.id}"))

spec = File.read("spec/controllers/pet_controller_spec.cr")
spec.should contain("Components::Cache.configure(&.use_memory_cache)")
spec.should contain("shows the change on the next read of a stored page")
end
end

it "puts scaffold reads on the lean read routes of a tuned application" do
SpecHelper.within_temp_directory do
File.write(".amber.yml", "template: ecr\ndatabase: sqlite\nmodel: grant\n")
Dir.mkdir_p("config")
File.write("config/routes.cr", <<-CRYSTAL)
Amber::Server.configure do
routes :lean_read do
end

routes :web do
end
end
CRYSTAL

AmberCLI::Commands::GenerateCommand.new("generate").parse_and_execute(["scaffold", "Pet", "name:string"])

routes = File.read("config/routes.cr")
routes.should contain(%(get "/pets", PetController, :index))
routes.should contain(%(get "/pets/:id", PetController, :show, constraints: {"id" => :numeric}))
routes.should contain(%(resources "/pets", PetController, except: [:index, :show]))
routes.index!(%(get "/pets", PetController)).should be < routes.index!("routes :web do")
end
end

it "indexes the foreign key column of a reference field" do
SpecHelper.within_temp_directory do
File.write(".amber.yml", "template: ecr\ndatabase: sqlite\nmodel: grant\n")

AmberCLI::Commands::GenerateCommand.new("generate").parse_and_execute(["scaffold", "Comment", "post:reference"])

migration = File.read(Dir.glob("db/migrations/*_create_comments.sql").first)
migration.should contain("CREATE INDEX IF NOT EXISTS index_comments_on_post_id ON comments (post_id);")
end
end

it "generates a belongs_to and a foreign key for reference fields" do
SpecHelper.within_temp_directory do
File.write(".amber.yml", "template: ecr\ndatabase: sqlite\nmodel: grant\n")
Expand Down
Loading
Loading