activerecord-spanner-adapter 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +7 -0
- data/.github/sync-repo-settings.yaml +16 -0
- data/.github/workflows/acceptance-tests-on-emulator.yaml +45 -0
- data/.github/workflows/acceptance-tests-on-production.yaml +36 -0
- data/.github/workflows/ci.yaml +33 -0
- data/.github/workflows/nightly-acceptance-tests-on-emulator.yaml +52 -0
- data/.github/workflows/nightly-acceptance-tests-on-production.yaml +35 -0
- data/.github/workflows/nightly-unit-tests.yaml +40 -0
- data/.github/workflows/release-please-label.yml +25 -0
- data/.github/workflows/release-please.yml +39 -0
- data/.github/workflows/rubocop.yaml +31 -0
- data/.gitignore +67 -5
- data/.kokoro/populate-secrets.sh +77 -0
- data/.kokoro/release.cfg +33 -0
- data/.kokoro/release.sh +15 -0
- data/.kokoro/trampoline_v2.sh +489 -0
- data/.rubocop.yml +46 -0
- data/.toys/release.rb +18 -0
- data/.trampolinerc +48 -0
- data/.yardopts +11 -0
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +9 -4
- data/LICENSE +6 -6
- data/README.md +67 -30
- data/Rakefile +79 -3
- data/SECURITY.md +7 -0
- data/acceptance/cases/associations/has_many_associations_test.rb +119 -0
- data/acceptance/cases/associations/has_many_through_associations_test.rb +63 -0
- data/acceptance/cases/associations/has_one_associations_test.rb +79 -0
- data/acceptance/cases/associations/has_one_through_associations_test.rb +98 -0
- data/acceptance/cases/interleaved_associations/has_many_associations_using_interleaved_test.rb +211 -0
- data/acceptance/cases/migration/change_schema_test.rb +433 -0
- data/acceptance/cases/migration/change_table_test.rb +115 -0
- data/acceptance/cases/migration/column_attributes_test.rb +122 -0
- data/acceptance/cases/migration/column_positioning_test.rb +48 -0
- data/acceptance/cases/migration/columns_test.rb +201 -0
- data/acceptance/cases/migration/command_recorder_test.rb +406 -0
- data/acceptance/cases/migration/create_join_table_test.rb +216 -0
- data/acceptance/cases/migration/ddl_batching_test.rb +80 -0
- data/acceptance/cases/migration/foreign_key_test.rb +297 -0
- data/acceptance/cases/migration/index_test.rb +211 -0
- data/acceptance/cases/migration/references_foreign_key_test.rb +259 -0
- data/acceptance/cases/migration/references_index_test.rb +135 -0
- data/acceptance/cases/migration/references_statements_test.rb +166 -0
- data/acceptance/cases/migration/rename_column_test.rb +96 -0
- data/acceptance/cases/models/calculation_query_test.rb +128 -0
- data/acceptance/cases/models/generated_column_test.rb +126 -0
- data/acceptance/cases/models/mutation_test.rb +122 -0
- data/acceptance/cases/models/query_test.rb +147 -0
- data/acceptance/cases/sessions/session_not_found_test.rb +121 -0
- data/acceptance/cases/transactions/optimistic_locking_test.rb +141 -0
- data/acceptance/cases/transactions/read_only_transactions_test.rb +67 -0
- data/acceptance/cases/transactions/read_write_transactions_test.rb +248 -0
- data/acceptance/cases/type/all_types_test.rb +152 -0
- data/acceptance/cases/type/binary_test.rb +59 -0
- data/acceptance/cases/type/boolean_test.rb +31 -0
- data/acceptance/cases/type/date_test.rb +32 -0
- data/acceptance/cases/type/date_time_test.rb +30 -0
- data/acceptance/cases/type/float_test.rb +27 -0
- data/acceptance/cases/type/integer_test.rb +44 -0
- data/acceptance/cases/type/numeric_test.rb +27 -0
- data/acceptance/cases/type/string_test.rb +79 -0
- data/acceptance/cases/type/text_test.rb +30 -0
- data/acceptance/cases/type/time_test.rb +87 -0
- data/acceptance/models/account.rb +13 -0
- data/acceptance/models/address.rb +9 -0
- data/acceptance/models/album.rb +12 -0
- data/acceptance/models/all_types.rb +8 -0
- data/acceptance/models/author.rb +11 -0
- data/acceptance/models/club.rb +12 -0
- data/acceptance/models/comment.rb +9 -0
- data/acceptance/models/customer.rb +9 -0
- data/acceptance/models/department.rb +9 -0
- data/acceptance/models/firm.rb +10 -0
- data/acceptance/models/member.rb +13 -0
- data/acceptance/models/member_type.rb +9 -0
- data/acceptance/models/membership.rb +10 -0
- data/acceptance/models/organization.rb +9 -0
- data/acceptance/models/post.rb +10 -0
- data/acceptance/models/singer.rb +10 -0
- data/acceptance/models/track.rb +20 -0
- data/acceptance/models/transaction.rb +9 -0
- data/acceptance/schema/schema.rb +143 -0
- data/acceptance/test_helper.rb +260 -0
- data/activerecord-spanner-adapter.gemspec +32 -17
- data/assets/solidus-db.png +0 -0
- data/benchmarks/README.md +17 -0
- data/benchmarks/Rakefile +14 -0
- data/benchmarks/application.rb +308 -0
- data/benchmarks/config/database.yml +8 -0
- data/benchmarks/config/environment.rb +12 -0
- data/benchmarks/db/migrate/01_create_tables.rb +25 -0
- data/benchmarks/db/schema.rb +29 -0
- data/benchmarks/models/album.rb +9 -0
- data/benchmarks/models/singer.rb +9 -0
- data/bin/console +6 -7
- data/examples/rails/README.md +262 -0
- data/examples/snippets/README.md +29 -0
- data/examples/snippets/Rakefile +57 -0
- data/examples/snippets/array-data-type/README.md +45 -0
- data/examples/snippets/array-data-type/Rakefile +13 -0
- data/examples/snippets/array-data-type/application.rb +45 -0
- data/examples/snippets/array-data-type/config/database.yml +8 -0
- data/examples/snippets/array-data-type/db/migrate/01_create_tables.rb +24 -0
- data/examples/snippets/array-data-type/db/schema.rb +26 -0
- data/examples/snippets/array-data-type/db/seeds.rb +5 -0
- data/examples/snippets/array-data-type/models/entity_with_array_types.rb +18 -0
- data/examples/snippets/bin/create_emulator_instance.rb +18 -0
- data/examples/snippets/bulk-insert/README.md +21 -0
- data/examples/snippets/bulk-insert/Rakefile +13 -0
- data/examples/snippets/bulk-insert/application.rb +64 -0
- data/examples/snippets/bulk-insert/config/database.yml +8 -0
- data/examples/snippets/bulk-insert/db/migrate/01_create_tables.rb +21 -0
- data/examples/snippets/bulk-insert/db/schema.rb +26 -0
- data/examples/snippets/bulk-insert/db/seeds.rb +5 -0
- data/examples/snippets/bulk-insert/models/album.rb +9 -0
- data/examples/snippets/bulk-insert/models/singer.rb +9 -0
- data/examples/snippets/commit-timestamp/README.md +18 -0
- data/examples/snippets/commit-timestamp/Rakefile +13 -0
- data/examples/snippets/commit-timestamp/application.rb +53 -0
- data/examples/snippets/commit-timestamp/config/database.yml +8 -0
- data/examples/snippets/commit-timestamp/db/migrate/01_create_tables.rb +26 -0
- data/examples/snippets/commit-timestamp/db/schema.rb +29 -0
- data/examples/snippets/commit-timestamp/db/seeds.rb +5 -0
- data/examples/snippets/commit-timestamp/models/album.rb +9 -0
- data/examples/snippets/commit-timestamp/models/singer.rb +9 -0
- data/examples/snippets/config/environment.rb +21 -0
- data/examples/snippets/create-records/README.md +12 -0
- data/examples/snippets/create-records/Rakefile +13 -0
- data/examples/snippets/create-records/application.rb +42 -0
- data/examples/snippets/create-records/config/database.yml +8 -0
- data/examples/snippets/create-records/db/migrate/01_create_tables.rb +21 -0
- data/examples/snippets/create-records/db/schema.rb +26 -0
- data/examples/snippets/create-records/db/seeds.rb +5 -0
- data/examples/snippets/create-records/models/album.rb +9 -0
- data/examples/snippets/create-records/models/singer.rb +9 -0
- data/examples/snippets/date-data-type/README.md +19 -0
- data/examples/snippets/date-data-type/Rakefile +13 -0
- data/examples/snippets/date-data-type/application.rb +35 -0
- data/examples/snippets/date-data-type/config/database.yml +8 -0
- data/examples/snippets/date-data-type/db/migrate/01_create_tables.rb +20 -0
- data/examples/snippets/date-data-type/db/schema.rb +21 -0
- data/examples/snippets/date-data-type/db/seeds.rb +16 -0
- data/examples/snippets/date-data-type/models/singer.rb +8 -0
- data/examples/snippets/generated-column/README.md +41 -0
- data/examples/snippets/generated-column/Rakefile +13 -0
- data/examples/snippets/generated-column/application.rb +37 -0
- data/examples/snippets/generated-column/config/database.yml +8 -0
- data/examples/snippets/generated-column/db/migrate/01_create_tables.rb +23 -0
- data/examples/snippets/generated-column/db/schema.rb +21 -0
- data/examples/snippets/generated-column/db/seeds.rb +18 -0
- data/examples/snippets/generated-column/models/singer.rb +8 -0
- data/examples/snippets/interleaved-tables/README.md +152 -0
- data/examples/snippets/interleaved-tables/Rakefile +13 -0
- data/examples/snippets/interleaved-tables/application.rb +109 -0
- data/examples/snippets/interleaved-tables/config/database.yml +8 -0
- data/examples/snippets/interleaved-tables/db/migrate/01_create_tables.rb +44 -0
- data/examples/snippets/interleaved-tables/db/schema.rb +32 -0
- data/examples/snippets/interleaved-tables/db/seeds.rb +40 -0
- data/examples/snippets/interleaved-tables/models/album.rb +15 -0
- data/examples/snippets/interleaved-tables/models/singer.rb +20 -0
- data/examples/snippets/interleaved-tables/models/track.rb +25 -0
- data/examples/snippets/migrations/README.md +43 -0
- data/examples/snippets/migrations/Rakefile +13 -0
- data/examples/snippets/migrations/application.rb +26 -0
- data/examples/snippets/migrations/config/database.yml +8 -0
- data/examples/snippets/migrations/db/migrate/01_create_tables.rb +28 -0
- data/examples/snippets/migrations/db/schema.rb +33 -0
- data/examples/snippets/migrations/db/seeds.rb +5 -0
- data/examples/snippets/migrations/models/album.rb +10 -0
- data/examples/snippets/migrations/models/singer.rb +10 -0
- data/examples/snippets/migrations/models/track.rb +9 -0
- data/examples/snippets/mutations/README.md +34 -0
- data/examples/snippets/mutations/Rakefile +13 -0
- data/examples/snippets/mutations/application.rb +47 -0
- data/examples/snippets/mutations/config/database.yml +8 -0
- data/examples/snippets/mutations/db/migrate/01_create_tables.rb +22 -0
- data/examples/snippets/mutations/db/schema.rb +27 -0
- data/examples/snippets/mutations/db/seeds.rb +25 -0
- data/examples/snippets/mutations/models/album.rb +9 -0
- data/examples/snippets/mutations/models/singer.rb +9 -0
- data/examples/snippets/optimistic-locking/README.md +12 -0
- data/examples/snippets/optimistic-locking/Rakefile +13 -0
- data/examples/snippets/optimistic-locking/application.rb +48 -0
- data/examples/snippets/optimistic-locking/config/database.yml +8 -0
- data/examples/snippets/optimistic-locking/db/migrate/01_create_tables.rb +26 -0
- data/examples/snippets/optimistic-locking/db/schema.rb +29 -0
- data/examples/snippets/optimistic-locking/db/seeds.rb +25 -0
- data/examples/snippets/optimistic-locking/models/album.rb +9 -0
- data/examples/snippets/optimistic-locking/models/singer.rb +9 -0
- data/examples/snippets/quickstart/README.md +26 -0
- data/examples/snippets/quickstart/Rakefile +13 -0
- data/examples/snippets/quickstart/application.rb +51 -0
- data/examples/snippets/quickstart/config/database.yml +8 -0
- data/examples/snippets/quickstart/db/migrate/01_create_tables.rb +21 -0
- data/examples/snippets/quickstart/db/schema.rb +26 -0
- data/examples/snippets/quickstart/db/seeds.rb +24 -0
- data/examples/snippets/quickstart/models/album.rb +9 -0
- data/examples/snippets/quickstart/models/singer.rb +9 -0
- data/examples/snippets/read-only-transactions/README.md +13 -0
- data/examples/snippets/read-only-transactions/Rakefile +13 -0
- data/examples/snippets/read-only-transactions/application.rb +49 -0
- data/examples/snippets/read-only-transactions/config/database.yml +8 -0
- data/examples/snippets/read-only-transactions/db/migrate/01_create_tables.rb +21 -0
- data/examples/snippets/read-only-transactions/db/schema.rb +26 -0
- data/examples/snippets/read-only-transactions/db/seeds.rb +24 -0
- data/examples/snippets/read-only-transactions/models/album.rb +9 -0
- data/examples/snippets/read-only-transactions/models/singer.rb +9 -0
- data/examples/snippets/read-write-transactions/README.md +12 -0
- data/examples/snippets/read-write-transactions/Rakefile +13 -0
- data/examples/snippets/read-write-transactions/application.rb +39 -0
- data/examples/snippets/read-write-transactions/config/database.yml +8 -0
- data/examples/snippets/read-write-transactions/db/migrate/01_create_tables.rb +22 -0
- data/examples/snippets/read-write-transactions/db/schema.rb +27 -0
- data/examples/snippets/read-write-transactions/db/seeds.rb +25 -0
- data/examples/snippets/read-write-transactions/models/album.rb +9 -0
- data/examples/snippets/read-write-transactions/models/singer.rb +9 -0
- data/examples/snippets/timestamp-data-type/README.md +17 -0
- data/examples/snippets/timestamp-data-type/Rakefile +13 -0
- data/examples/snippets/timestamp-data-type/application.rb +42 -0
- data/examples/snippets/timestamp-data-type/config/database.yml +8 -0
- data/examples/snippets/timestamp-data-type/db/migrate/01_create_tables.rb +21 -0
- data/examples/snippets/timestamp-data-type/db/schema.rb +21 -0
- data/examples/snippets/timestamp-data-type/db/seeds.rb +6 -0
- data/examples/snippets/timestamp-data-type/models/meeting.rb +19 -0
- data/examples/solidus/README.md +172 -0
- data/lib/active_record/connection_adapters/spanner/database_statements.rb +224 -269
- data/lib/active_record/connection_adapters/spanner/quoting.rb +42 -50
- data/lib/active_record/connection_adapters/spanner/schema_cache.rb +43 -0
- data/lib/active_record/connection_adapters/spanner/schema_creation.rb +125 -9
- data/lib/active_record/connection_adapters/spanner/schema_definitions.rb +122 -0
- data/lib/active_record/connection_adapters/spanner/schema_dumper.rb +19 -0
- data/lib/active_record/connection_adapters/spanner/schema_statements.rb +553 -139
- data/lib/active_record/connection_adapters/spanner/type_metadata.rb +37 -0
- data/lib/active_record/connection_adapters/spanner_adapter.rb +182 -78
- data/lib/active_record/tasks/spanner_database_tasks.rb +74 -0
- data/lib/active_record/type/spanner/array.rb +32 -0
- data/lib/active_record/type/spanner/bytes.rb +26 -0
- data/lib/active_record/type/spanner/spanner_active_record_converter.rb +32 -0
- data/lib/active_record/type/spanner/time.rb +37 -0
- data/lib/activerecord-spanner-adapter.rb +23 -0
- data/lib/activerecord_spanner_adapter/base.rb +217 -0
- data/lib/activerecord_spanner_adapter/connection.rb +324 -0
- data/lib/activerecord_spanner_adapter/errors.rb +13 -0
- data/lib/activerecord_spanner_adapter/foreign_key.rb +29 -0
- data/lib/activerecord_spanner_adapter/index/column.rb +38 -0
- data/lib/activerecord_spanner_adapter/index.rb +80 -0
- data/lib/activerecord_spanner_adapter/information_schema.rb +261 -0
- data/lib/activerecord_spanner_adapter/primary_key.rb +31 -0
- data/lib/activerecord_spanner_adapter/table/column.rb +59 -0
- data/lib/activerecord_spanner_adapter/table.rb +61 -0
- data/lib/activerecord_spanner_adapter/transaction.rb +113 -0
- data/lib/activerecord_spanner_adapter/version.rb +9 -0
- data/lib/arel/visitors/spanner.rb +35 -0
- data/lib/spanner_client_ext.rb +82 -0
- data/renovate.json +5 -0
- metadata +387 -34
- data/.travis.yml +0 -5
- data/lib/active_record/connection_adapters/spanner/client.rb +0 -190
- data/lib/active_record/connection_adapters/spanner.rb +0 -10
- data/lib/activerecord-spanner-adapter/version.rb +0 -3
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class BooleanTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "BOOL", connection.type_to_sql(:boolean)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_boolean_value_in_create
|
21
|
+
record = TestTypeModel.create(active: true)
|
22
|
+
record.reload
|
23
|
+
assert_equal true, record.active
|
24
|
+
|
25
|
+
record = TestTypeModel.create(active: false)
|
26
|
+
record.reload
|
27
|
+
assert_equal false, record.active
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class DateTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "DATE", connection.type_to_sql(:date)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_date
|
21
|
+
expected_date = ::Date.new 2020, 1, 31
|
22
|
+
record = TestTypeModel.new start_date: expected_date
|
23
|
+
|
24
|
+
assert_equal expected_date, record.start_date
|
25
|
+
|
26
|
+
record.save!
|
27
|
+
record.reload
|
28
|
+
assert_equal expected_date, record.start_date
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class DateTimeTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "TIMESTAMP", connection.type_to_sql(:datetime)
|
18
|
+
assert_equal "TIMESTAMP", connection.type_to_sql(:datetime, limit: 128)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_datetime_seconds_precision_applied_to_timestamp
|
22
|
+
expected_time = ::Time.now
|
23
|
+
record = TestTypeModel.new start_datetime: expected_time
|
24
|
+
|
25
|
+
assert_equal expected_time, record.start_datetime
|
26
|
+
assert_equal expected_time.usec, record.start_datetime.usec
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class FloatTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "FLOAT64", connection.type_to_sql(:float)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_float_value_in_create
|
21
|
+
record = TestTypeModel.create(weight: 123.32199)
|
22
|
+
record.reload
|
23
|
+
assert_equal 123.32199, record.weight
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class IntegerTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "INT64", connection.type_to_sql(:integer)
|
18
|
+
assert_equal "INT64", connection.type_to_sql(:primary_key)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_set_integer_value_in_create
|
22
|
+
record = TestTypeModel.create(length: 123)
|
23
|
+
|
24
|
+
record.reload
|
25
|
+
assert_equal 123, record.length
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_casting_models
|
29
|
+
type = Type::Integer.new
|
30
|
+
|
31
|
+
record = TestTypeModel.create(name: "Google")
|
32
|
+
assert_nil type.cast(record)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_values_out_of_range_can_re_assigned
|
36
|
+
model = TestTypeModel.new
|
37
|
+
model.length = 2147483648
|
38
|
+
model.length = 1
|
39
|
+
|
40
|
+
assert_equal 1, model.length
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright 2021 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class NumericTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "NUMERIC", connection.type_to_sql(:numeric)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_numeric_value_in_create
|
21
|
+
record = TestTypeModel.create(price: 9750.99)
|
22
|
+
record.reload
|
23
|
+
assert_equal 9750.99, record.price
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class StringTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "STRING(MAX)", connection.type_to_sql(:string)
|
18
|
+
assert_equal "STRING(1024)", connection.type_to_sql(:string, limit: 1024)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_set_string_in_create
|
22
|
+
description = "a" * 1000
|
23
|
+
name = "Test name"
|
24
|
+
record = TestTypeModel.create(description: description, name: name)
|
25
|
+
record.reload
|
26
|
+
|
27
|
+
assert_equal description, record.description
|
28
|
+
assert_equal name, record.name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_set_string_with_max_limit_in_create
|
32
|
+
str = "a" * 256
|
33
|
+
|
34
|
+
assert_raise(ActiveRecord::StatementInvalid) {
|
35
|
+
TestTypeModel.create(name: str)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_escape_special_charaters_and_save
|
40
|
+
str = [
|
41
|
+
"Newline \n",
|
42
|
+
"`Backtick`",
|
43
|
+
"'Quote'",
|
44
|
+
"Bell \a",
|
45
|
+
"Backspace \b",
|
46
|
+
"Formfeed \f",
|
47
|
+
"Carriage Return \r",
|
48
|
+
"Tab \t",
|
49
|
+
"Vertical Tab \v",
|
50
|
+
"Backslash \\",
|
51
|
+
"Question Mark \?",
|
52
|
+
"Double Quote \"",
|
53
|
+
].join (" ")
|
54
|
+
|
55
|
+
record = TestTypeModel.new(description: str)
|
56
|
+
assert_equal str, record.description
|
57
|
+
|
58
|
+
record.save!
|
59
|
+
assert_equal str, record.description
|
60
|
+
|
61
|
+
record.reload
|
62
|
+
assert_equal str, record.description
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_save_special_charaters
|
66
|
+
str = "Hello Seocial Chars : € à ö ¿ © 😎"
|
67
|
+
|
68
|
+
record = TestTypeModel.new(description: str)
|
69
|
+
assert_equal str, record.description
|
70
|
+
|
71
|
+
record.save!
|
72
|
+
assert_equal str, record.description
|
73
|
+
|
74
|
+
record.reload
|
75
|
+
assert_equal str, record.description
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class TextTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "STRING(MAX)", connection.type_to_sql(:text)
|
18
|
+
assert_equal "STRING(1024)", connection.type_to_sql(:text, limit: 1024)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_set_text_in_create
|
22
|
+
text = "a" * 1000
|
23
|
+
record = TestTypeModel.create(bio: text)
|
24
|
+
record.reload
|
25
|
+
|
26
|
+
assert_equal text, record.bio
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require "test_helper"
|
10
|
+
|
11
|
+
module ActiveRecord
|
12
|
+
module Type
|
13
|
+
class TimeTest < SpannerAdapter::TestCase
|
14
|
+
include SpannerAdapter::Types::TestHelper
|
15
|
+
|
16
|
+
def test_convert_to_sql_type
|
17
|
+
assert_equal "TIMESTAMP", connection.type_to_sql(:time)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_assign_time
|
21
|
+
expected_time = ::Time.now
|
22
|
+
record = TestTypeModel.new start_time: expected_time
|
23
|
+
|
24
|
+
assert_equal expected_time, record.start_time
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_assign_empty_time
|
28
|
+
record = TestTypeModel.new start_time: ""
|
29
|
+
assert_nil record.start_time
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_assign_nil_time
|
33
|
+
record = TestTypeModel.new start_time: nil
|
34
|
+
assert_nil record.start_time
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_set_and_save_time
|
38
|
+
expected_time = ::Time.now.utc
|
39
|
+
record = TestTypeModel.create! start_time: expected_time
|
40
|
+
|
41
|
+
assert_equal expected_time, record.start_time
|
42
|
+
|
43
|
+
record.reload
|
44
|
+
assert_equal expected_time, record.start_time
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_date_time_string_value_with_subsecond_precision
|
48
|
+
expected_time = ::Time.local 2017, 07, 4, 14, 19, 10, 897761
|
49
|
+
|
50
|
+
string_value = "2017-07-04 14:19:10.897761"
|
51
|
+
|
52
|
+
record = TestTypeModel.new start_time: string_value
|
53
|
+
assert_equal expected_time, record.start_time.utc
|
54
|
+
|
55
|
+
record.save!
|
56
|
+
assert_equal expected_time, record.start_time.utc
|
57
|
+
|
58
|
+
assert_equal record, TestTypeModel.find_by(start_time: string_value)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_date_time_with_string_value_with_non_iso_format
|
62
|
+
string_value = "04/07/2017 2:19pm"
|
63
|
+
expected_time = ::Time.local 2017, 07, 4, 14, 19
|
64
|
+
|
65
|
+
record = TestTypeModel.new start_time: string_value
|
66
|
+
assert_equal expected_time, record.start_time
|
67
|
+
|
68
|
+
record.save!
|
69
|
+
assert_equal expected_time, record.start_time.utc
|
70
|
+
|
71
|
+
assert_equal record, TestTypeModel.find_by(start_time: string_value)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_default_year_is_correct
|
75
|
+
expected_time = ::Time.utc(2000, 1, 1, 10, 30, 0)
|
76
|
+
record = TestTypeModel.new start_time: { 4 => 10, 5 => 30 }
|
77
|
+
|
78
|
+
assert_equal expected_time, record.start_time
|
79
|
+
|
80
|
+
record.save!
|
81
|
+
record.reload
|
82
|
+
|
83
|
+
assert_equal expected_time, record.start_time
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
class Account < ActiveRecord::Base
|
8
|
+
belongs_to :firm
|
9
|
+
belongs_to :customer
|
10
|
+
has_many :transactions
|
11
|
+
|
12
|
+
alias_attribute :available_credit, :credit_limit
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Copyright 2021 Google LLC
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style
|
4
|
+
# license that can be found in the LICENSE file or at
|
5
|
+
# https://opensource.org/licenses/MIT.
|
6
|
+
|
7
|
+
class Album < ActiveRecord::Base
|
8
|
+
# The relationship with singer is not really a foreign key, but an INTERLEAVE IN relationship. We still need to
|
9
|
+
# use the `foreign_key` attribute to indicate which column to use for the relationship.
|
10
|
+
belongs_to :singer, foreign_key: "singerid"
|
11
|
+
has_many :tracks, foreign_key: "albumid", dependent: :delete_all
|
12
|
+
end
|