groonga-client-model 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +30 -0
- data/groonga-client-model.gemspec +1 -1
- data/lib/groonga_client_model/log_subscriber.rb +1 -3
- data/lib/groonga_client_model/migration.rb +493 -0
- data/lib/groonga_client_model/migrator.rb +240 -0
- data/lib/groonga_client_model/railtie.rb +4 -2
- data/lib/groonga_client_model/railties/groonga.rake +55 -2
- data/lib/groonga_client_model/record.rb +39 -1
- data/lib/groonga_client_model/schema.rb +8 -0
- data/lib/groonga_client_model/schema_loader.rb +4 -9
- data/lib/groonga_client_model/test/groonga_server_runner.rb +19 -3
- data/lib/groonga_client_model/version.rb +1 -1
- data/lib/rails/generators/groonga_client_model/migration/templates/create_table_migration.rb +14 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/delete_config_migration.rb +9 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/migration.rb +12 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/set_config_migration.rb +10 -0
- data/lib/rails/generators/groonga_client_model/migration_generator.rb +125 -0
- data/lib/rails/generators/groonga_client_model/{model/model_generator.rb → model_generator.rb} +18 -4
- data/test/apps/rails4/Gemfile.lock +2 -2
- data/test/apps/rails4/db/groonga/migrate/20170303120517_create_posts.rb +8 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120527_create_terms.rb +7 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120536_create_ages.rb +6 -0
- data/test/apps/rails4/log/development.log +22 -0
- data/test/apps/rails4/log/test.log +1350 -0
- data/test/apps/rails4/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails4/test/tmp/db/groonga/migrate/20170307045825_set_config_alias_column.rb +10 -0
- data/test/apps/rails5/Gemfile.lock +8 -8
- data/test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb +8 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb +7 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb +6 -0
- data/test/apps/rails5/log/development.log +350 -0
- data/test/apps/rails5/log/test.log +3260 -0
- data/test/apps/rails5/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails5/test/tmp/db/groonga/migrate/20170307081511_remove_title_from_posts.rb +5 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/5C/5Cws9GLWcOju_f3tIpY01qSaj7zkLAU0a2bQmpf7sS8.cache +1 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/XH/XH9pWZvGgK476BpPGID5z8hjzRmGJjtzV0cHBLXhIKc.cache +1 -0
- data/test/unit/fixtures/migrate/20170301061420_create_posts.rb +8 -0
- data/test/unit/fixtures/migrate/20170303115054_create_terms.rb +7 -0
- data/test/unit/fixtures/migrate/20170303115135_create_ages.rb +6 -0
- data/test/unit/migration/test_config.rb +62 -0
- data/test/unit/migration/test_copy.rb +117 -0
- data/test/unit/migration/test_create_table.rb +528 -0
- data/test/unit/migration/test_exist.rb +47 -0
- data/test/unit/migration/test_load.rb +83 -0
- data/test/unit/record/test_active_model.rb +31 -0
- data/test/unit/record/test_readers.rb +45 -0
- data/test/unit/record/test_timestamps.rb +76 -0
- data/test/unit/record/test_validators.rb +295 -0
- data/test/unit/run-test.rb +1 -2
- data/test/unit/test_helper.rb +109 -0
- data/test/unit/test_load_value_generator.rb +8 -7
- data/test/unit/test_migrator.rb +156 -0
- metadata +64 -11
- data/test/apps/rails4/db/schema.grn +0 -9
- data/test/apps/rails5/db/schema.grn +0 -11
- data/test/unit/test_record.rb +0 -345
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMigrationExist < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
include TestHelper::Migration
|
20
|
+
|
21
|
+
test("table") do
|
22
|
+
expected_up_report = <<-REPORT
|
23
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
24
|
+
-> 0.0s
|
25
|
+
-- add_column(:posts, :title, {:flags=>["COLUMN_SCALAR"], :value_type=>"ShortText"})
|
26
|
+
-> 0.0s
|
27
|
+
REPORT
|
28
|
+
expected_down_report = <<-REPORT
|
29
|
+
-- remove_table(:posts)
|
30
|
+
-> 0.0s
|
31
|
+
REPORT
|
32
|
+
expected_dump = <<-DUMP.chomp
|
33
|
+
table_create posts TABLE_NO_KEY
|
34
|
+
column_create posts title COLUMN_SCALAR ShortText
|
35
|
+
DUMP
|
36
|
+
assert_migrate(expected_up_report,
|
37
|
+
expected_down_report,
|
38
|
+
expected_dump) do |migration|
|
39
|
+
migration.instance_eval do
|
40
|
+
create_table(:posts)
|
41
|
+
unless reverting?
|
42
|
+
add_column(:posts, :title, :short_text) if exist?(:posts)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMigrationLoad < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
include TestHelper::Migration
|
20
|
+
|
21
|
+
def assert_migrate_load(values, expected_values_dump)
|
22
|
+
expected_up_report = <<-REPORT
|
23
|
+
-- create_table(:posts, {:type=>"TABLE_HASH_KEY", :key_type=>"ShortText"})
|
24
|
+
-> 0.0s
|
25
|
+
-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
|
26
|
+
-> 0.0s
|
27
|
+
-- load(:posts)
|
28
|
+
-> 0.0s
|
29
|
+
REPORT
|
30
|
+
expected_down_report = nil
|
31
|
+
expected_dump = <<-DUMP.chomp
|
32
|
+
table_create posts TABLE_HASH_KEY ShortText
|
33
|
+
column_create posts content COLUMN_SCALAR Text
|
34
|
+
|
35
|
+
load --table posts
|
36
|
+
[
|
37
|
+
["_key","content"],
|
38
|
+
#{expected_values_dump}
|
39
|
+
]
|
40
|
+
DUMP
|
41
|
+
assert_migrate(expected_up_report,
|
42
|
+
expected_down_report,
|
43
|
+
expected_dump) do |migration|
|
44
|
+
migration.instance_eval do
|
45
|
+
create_table(:posts,
|
46
|
+
:type => :hash_table,
|
47
|
+
:key_type => :short_text) do |t|
|
48
|
+
t.text(:content)
|
49
|
+
end
|
50
|
+
load(:posts, values)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test("Hash") do
|
56
|
+
assert_migrate_load({"_key" => "Groonga", "content" => "Very good!"},
|
57
|
+
<<-DUMP.chomp)
|
58
|
+
["Groonga","Very good!"]
|
59
|
+
DUMP
|
60
|
+
end
|
61
|
+
|
62
|
+
test("Array") do
|
63
|
+
assert_migrate_load([
|
64
|
+
{"_key" => "Groonga", "content" => "Very good!"},
|
65
|
+
{"_key" => "Ruby", "content" => "Very exciting!"},
|
66
|
+
],
|
67
|
+
<<-DUMP.chomp)
|
68
|
+
["Groonga","Very good!"],
|
69
|
+
["Ruby","Very exciting!"]
|
70
|
+
DUMP
|
71
|
+
end
|
72
|
+
|
73
|
+
test("JSON") do
|
74
|
+
assert_migrate_load([
|
75
|
+
{"_key" => "Groonga", "content" => "Very good!"},
|
76
|
+
{"_key" => "Ruby", "content" => "Very exciting!"},
|
77
|
+
].to_json,
|
78
|
+
<<-DUMP.chomp)
|
79
|
+
["Groonga","Very good!"],
|
80
|
+
["Ruby","Very exciting!"]
|
81
|
+
DUMP
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRecordActiveModel < Test::Unit::TestCase
|
18
|
+
class EmptyModel < GroongaClientModel::Record
|
19
|
+
class << self
|
20
|
+
def columns
|
21
|
+
TestHelper::Columns.build
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
include ActiveModel::Lint::Tests
|
27
|
+
|
28
|
+
setup do
|
29
|
+
@model = EmptyModel.new
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRecordReaders < Test::Unit::TestCase
|
18
|
+
class Memo < GroongaClientModel::Record
|
19
|
+
class << self
|
20
|
+
def columns
|
21
|
+
TestHelper::Columns.build("published" => {
|
22
|
+
"value_type" => {
|
23
|
+
"name" => "Bool",
|
24
|
+
},
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
setup do
|
31
|
+
@memo = Memo.new
|
32
|
+
end
|
33
|
+
|
34
|
+
test "#id" do
|
35
|
+
@memo._id = 29
|
36
|
+
assert_equal(29, @memo.id)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "predicate" do
|
40
|
+
@memo.published = true
|
41
|
+
assert do
|
42
|
+
@memo.published?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRecordTimestamps < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
|
20
|
+
setup do
|
21
|
+
schema = <<-SCHEMA
|
22
|
+
table_create timestamps TABLE_NO_KEY
|
23
|
+
column_create timestamps created_at COLUMN_SCALAR Time
|
24
|
+
column_create timestamps created_on COLUMN_SCALAR Time
|
25
|
+
column_create timestamps updated_at COLUMN_SCALAR Time
|
26
|
+
column_create timestamps updated_on COLUMN_SCALAR Time
|
27
|
+
SCHEMA
|
28
|
+
schema_loader = GroongaClientModel::SchemaLoader.new(schema)
|
29
|
+
schema_loader.load
|
30
|
+
end
|
31
|
+
|
32
|
+
class Timestamp < GroongaClientModel::Record
|
33
|
+
end
|
34
|
+
|
35
|
+
test("created_at") do
|
36
|
+
now = Time.now
|
37
|
+
timestamp = Timestamp.create
|
38
|
+
saved_timestamp = Timestamp.find(timestamp)
|
39
|
+
assert do
|
40
|
+
saved_timestamp.created_at > now
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test("created_on") do
|
45
|
+
now = Time.now
|
46
|
+
timestamp = Timestamp.create
|
47
|
+
saved_timestamp = Timestamp.find(timestamp)
|
48
|
+
assert do
|
49
|
+
saved_timestamp.created_on > now
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test("updated_at") do
|
54
|
+
timestamp = Timestamp.create
|
55
|
+
saved_timestamp = Timestamp.find(timestamp)
|
56
|
+
created_at = saved_timestamp.created_at
|
57
|
+
saved_timestamp.save
|
58
|
+
updated_timestamp = Timestamp.find(timestamp)
|
59
|
+
updated_timestamp.save
|
60
|
+
assert do
|
61
|
+
saved_timestamp.updated_at > created_at
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test("updated_on") do
|
66
|
+
timestamp = Timestamp.create
|
67
|
+
saved_timestamp = Timestamp.find(timestamp)
|
68
|
+
created_on = saved_timestamp.created_on
|
69
|
+
saved_timestamp.save
|
70
|
+
updated_timestamp = Timestamp.find(timestamp)
|
71
|
+
updated_timestamp.save
|
72
|
+
assert do
|
73
|
+
saved_timestamp.updated_on > created_on
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRecordValidators < Test::Unit::TestCase
|
18
|
+
sub_test_case("_key") do
|
19
|
+
class NoKey < GroongaClientModel::Record
|
20
|
+
class << self
|
21
|
+
def columns
|
22
|
+
TestHelper::Columns.build
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Key < GroongaClientModel::Record
|
28
|
+
class << self
|
29
|
+
def columns
|
30
|
+
TestHelper::Columns.build("_key" => {
|
31
|
+
"value_type" => {
|
32
|
+
"name" => key_type,
|
33
|
+
},
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class ShortTextKey < Key
|
40
|
+
class << self
|
41
|
+
def key_type
|
42
|
+
"ShortText"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class UInt8Key < Key
|
48
|
+
class << self
|
49
|
+
def key_type
|
50
|
+
"UInt8"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class UInt16Key < Key
|
56
|
+
class << self
|
57
|
+
def key_type
|
58
|
+
"UInt16"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class UInt32Key < Key
|
64
|
+
class << self
|
65
|
+
def key_type
|
66
|
+
"UInt32"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class UInt64Key < Key
|
72
|
+
class << self
|
73
|
+
def key_type
|
74
|
+
"UInt64"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Int8Key < Key
|
80
|
+
class << self
|
81
|
+
def key_type
|
82
|
+
"Int8"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Int16Key < Key
|
88
|
+
class << self
|
89
|
+
def key_type
|
90
|
+
"Int16"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class Int32Key < Key
|
96
|
+
class << self
|
97
|
+
def key_type
|
98
|
+
"Int32"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Int64Key < Key
|
104
|
+
class << self
|
105
|
+
def key_type
|
106
|
+
"Int64"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class FloatKey < Key
|
112
|
+
class << self
|
113
|
+
def key_type
|
114
|
+
"Float"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class TimeKey < Key
|
120
|
+
class << self
|
121
|
+
def key_type
|
122
|
+
"Time"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
sub_test_case("presence") do
|
128
|
+
test "no key" do
|
129
|
+
record = NoKey.new
|
130
|
+
assert do
|
131
|
+
record.valid?
|
132
|
+
end
|
133
|
+
assert_equal({}, record.errors.messages)
|
134
|
+
end
|
135
|
+
|
136
|
+
test "missing key" do
|
137
|
+
record = ShortTextKey.new
|
138
|
+
assert do
|
139
|
+
not record.valid?
|
140
|
+
end
|
141
|
+
message = record.errors.generate_message(:_key, :blank)
|
142
|
+
assert_equal({
|
143
|
+
:_key => [message],
|
144
|
+
},
|
145
|
+
record.errors.messages)
|
146
|
+
end
|
147
|
+
|
148
|
+
test "blank key" do
|
149
|
+
record = UInt32Key.new(_key: "")
|
150
|
+
assert do
|
151
|
+
not record.valid?
|
152
|
+
end
|
153
|
+
message = record.errors.generate_message(:_key, :blank)
|
154
|
+
assert_equal({
|
155
|
+
:_key => [message],
|
156
|
+
},
|
157
|
+
record.errors.messages)
|
158
|
+
end
|
159
|
+
|
160
|
+
test "have key" do
|
161
|
+
record = ShortTextKey.new(_key: "String")
|
162
|
+
assert do
|
163
|
+
record.valid?
|
164
|
+
end
|
165
|
+
assert_equal({},
|
166
|
+
record.errors.messages)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
sub_test_case("type") do
|
171
|
+
def assert_invalid(klass, key, message_key)
|
172
|
+
record = klass.new(_key: key)
|
173
|
+
assert do
|
174
|
+
not record.valid?
|
175
|
+
end
|
176
|
+
options = {
|
177
|
+
inspected_value: key.inspect
|
178
|
+
}
|
179
|
+
message = record.errors.generate_message(:_key, message_key, options)
|
180
|
+
assert_equal({
|
181
|
+
:_key => [message],
|
182
|
+
},
|
183
|
+
record.errors.messages)
|
184
|
+
end
|
185
|
+
|
186
|
+
sub_test_case("UInt8") do
|
187
|
+
test("invalid") do
|
188
|
+
assert_invalid(UInt8Key, "String", :not_a_positive_integer)
|
189
|
+
end
|
190
|
+
|
191
|
+
test("too large") do
|
192
|
+
assert_invalid(UInt8Key, 2 ** 8, :invalid_uint8)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
sub_test_case("UInt16") do
|
197
|
+
test("invalid") do
|
198
|
+
assert_invalid(UInt16Key, "String", :not_a_positive_integer)
|
199
|
+
end
|
200
|
+
|
201
|
+
test("too large") do
|
202
|
+
assert_invalid(UInt16Key, 2 ** 16, :invalid_uint16)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
sub_test_case("UInt32") do
|
207
|
+
test("invalid") do
|
208
|
+
assert_invalid(UInt32Key, "String", :not_a_positive_integer)
|
209
|
+
end
|
210
|
+
|
211
|
+
test("too large") do
|
212
|
+
assert_invalid(UInt32Key, 2 ** 32, :invalid_uint32)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
sub_test_case("UInt64") do
|
217
|
+
test("invalid") do
|
218
|
+
assert_invalid(UInt64Key, "String", :not_a_positive_integer)
|
219
|
+
end
|
220
|
+
|
221
|
+
test("too large") do
|
222
|
+
assert_invalid(UInt64Key, 2 ** 64, :invalid_uint64)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
sub_test_case("Int8") do
|
227
|
+
test("invalid") do
|
228
|
+
assert_invalid(Int8Key, "String", :not_an_integer)
|
229
|
+
end
|
230
|
+
|
231
|
+
test("too small") do
|
232
|
+
assert_invalid(Int8Key, -(2 ** 7) - 1, :invalid_int8)
|
233
|
+
end
|
234
|
+
|
235
|
+
test("too large") do
|
236
|
+
assert_invalid(Int8Key, 2 ** 7, :invalid_int8)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
sub_test_case("Int16") do
|
241
|
+
test("invalid") do
|
242
|
+
assert_invalid(Int16Key, "String", :not_an_integer)
|
243
|
+
end
|
244
|
+
|
245
|
+
test("too small") do
|
246
|
+
assert_invalid(Int16Key, -(2 ** 15) - 1, :invalid_int16)
|
247
|
+
end
|
248
|
+
|
249
|
+
test("too large") do
|
250
|
+
assert_invalid(Int16Key, 2 ** 15, :invalid_int16)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
sub_test_case("Int32") do
|
255
|
+
test("invalid") do
|
256
|
+
assert_invalid(Int32Key, "String", :not_an_integer)
|
257
|
+
end
|
258
|
+
|
259
|
+
test("too small") do
|
260
|
+
assert_invalid(Int32Key, -(2 ** 31) - 1, :invalid_int32)
|
261
|
+
end
|
262
|
+
|
263
|
+
test("too large") do
|
264
|
+
assert_invalid(Int32Key, 2 ** 31, :invalid_int32)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
sub_test_case("Int64") do
|
269
|
+
test("invalid") do
|
270
|
+
assert_invalid(Int64Key, "String", :not_an_integer)
|
271
|
+
end
|
272
|
+
|
273
|
+
test("too small") do
|
274
|
+
assert_invalid(Int64Key, -(2 ** 63) - 1, :invalid_int64)
|
275
|
+
end
|
276
|
+
|
277
|
+
test("too large") do
|
278
|
+
assert_invalid(Int64Key, 2 ** 63, :invalid_int64)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
sub_test_case("Float") do
|
283
|
+
test("invalid") do
|
284
|
+
assert_invalid(FloatKey, "String", :not_a_number)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
sub_test_case("Time") do
|
289
|
+
test("invalid") do
|
290
|
+
assert_invalid(TimeKey, "String", :not_a_time)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|