Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions db/migrations/20180612221318_create_businesses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CreateBusinesses::V20180612221318 < Avram::Migrator::Migration::V1
create :email_addresses do
primary_key id : Int64
add_timestamps
add default : Bool, default: true
add address : String, case_sensitive: false
add_belongs_to business : Business?, on_delete: :cascade
end
Expand Down
3 changes: 2 additions & 1 deletion spec/avram/operations/nested_save_operation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
context "when all forms are valid" do
it "sets the relationship and creates both" do
params = FakeNestedParams.new business: {"name" => "Fubar", "latitude" => "46.383488", "longitude" => "22.774896"},
email_address: {"address" => "foo@bar.com"},
email_address: {"address" => "foo@bar.com", "default" => "false"},
tax_id: {"number" => "123"}

operation = SaveBusiness.new(params)
Expand All @@ -201,6 +201,7 @@
business = operation.record.as(Business)
business.name.should eq "Fubar"
business.email_address!.address.should eq "foo@bar.com"
business.email_address!.default.should eq false

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (ubuntu-latest, shard.yml, 18, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (ubuntu-latest, shard.yml, 14, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (macos-latest, shard.yml, 14, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (ubuntu-latest, shard.yml, 14, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (ubuntu-latest, shard.yml, 18, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (macos-latest, shard.yml, 14, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (windows-latest, shard.yml, 18, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (windows-latest, shard.yml, 14, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (windows-latest, shard.yml, 14, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (macos-latest, shard.yml, 18, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (macos-latest, shard.yml, 18, 1.16.3, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (windows-latest, shard.yml, 18, latest, false)

got: true

Check failure on line 204 in spec/avram/operations/nested_save_operation_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.edge.yml, latest, 18, true, ubuntu-latest)

got: true
business.tax_id!.number.should eq 123
end

Expand Down
16 changes: 13 additions & 3 deletions spec/avram/query_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe Avram::QueryBuilder do
.where(Avram::Where::Equal.new(:id, "1"))
.limit(1)

query.statement_for_update(params).should eq "UPDATE users SET first_name = $1, last_name = $2 WHERE id = $3 LIMIT 1 RETURNING *"
query.statement_for_update(params).should eq %(UPDATE users SET "first_name" = $1, "last_name" = $2 WHERE id = $3 LIMIT 1 RETURNING *)
query.args_for_update(params).should eq ["Paul", nil, "1"]
end

Expand All @@ -181,8 +181,18 @@ describe Avram::QueryBuilder do
.where(Avram::Where::Equal.new(:id, "1"))
.limit(1)

query.statement_for_update(params).should eq "UPDATE users SET first_name = $1, last_name = $2 WHERE id = $3 LIMIT 1 RETURNING *"
query.statement_for_update(params).should eq "UPDATE users SET first_name = $1, last_name = $2 WHERE id = $3 LIMIT 1 RETURNING *"
query.statement_for_update(params).should eq %(UPDATE users SET "first_name" = $1, "last_name" = $2 WHERE id = $3 LIMIT 1 RETURNING *)
query.statement_for_update(params).should eq %(UPDATE users SET "first_name" = $1, "last_name" = $2 WHERE id = $3 LIMIT 1 RETURNING *)
end

it "quotes the columns to ensure reserved keywords can be used" do
params = {:select => "foobar"}
query = new_query
.where(Avram::Where::Equal.new(:id, "1"))
.limit(1)

query.statement_for_update(params).should eq %(UPDATE users SET "select" = $1 WHERE id = $2 LIMIT 1 RETURNING *)
query.args_for_update(params).should eq ["foobar", "1"]
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/support/factories/email_address_factory.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class EmailAddressFactory < BaseFactory
def initialize
address "foo@bar.com"
default true
end
end
2 changes: 2 additions & 0 deletions spec/support/models/email_address.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class EmailAddress < BaseModel
table do
column address : String
# This will test that we can update records that use keyword names
column default : Bool = true
belongs_to business : Business?
end
end
2 changes: 1 addition & 1 deletion src/avram/query_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Avram::QueryBuilder

private def set_sql_clause(params) : String
"SET " + params.join(", ") do |key, _|
"#{key} = #{next_prepared_statement_placeholder}"
%("#{key}" = #{next_prepared_statement_placeholder})
end
end

Expand Down
Loading