rom-sql 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
- data/lib/rom/sql.rb +1 -1
- data/lib/rom/sql/attribute.rb +17 -18
- data/lib/rom/sql/errors.rb +3 -0
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
- data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
- data/lib/rom/sql/extensions/postgres/types.rb +24 -477
- data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
- data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
- data/lib/rom/sql/extensions/sqlite.rb +1 -1
- data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
- data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
- data/lib/rom/sql/foreign_key.rb +17 -0
- data/lib/rom/sql/function.rb +86 -8
- data/lib/rom/sql/gateway.rb +26 -26
- data/lib/rom/sql/index.rb +4 -0
- data/lib/rom/sql/migration.rb +3 -3
- data/lib/rom/sql/migration/inline_runner.rb +9 -83
- data/lib/rom/sql/migration/migrator.rb +35 -12
- data/lib/rom/sql/migration/recorder.rb +21 -0
- data/lib/rom/sql/migration/runner.rb +115 -0
- data/lib/rom/sql/migration/schema_diff.rb +108 -53
- data/lib/rom/sql/migration/writer.rb +61 -0
- data/lib/rom/sql/relation.rb +2 -1
- data/lib/rom/sql/relation/reading.rb +63 -3
- data/lib/rom/sql/relation/writing.rb +38 -0
- data/lib/rom/sql/schema.rb +9 -3
- data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
- data/lib/rom/sql/schema/inferrer.rb +99 -18
- data/lib/rom/sql/schema/type_builder.rb +94 -0
- data/lib/rom/sql/type_dsl.rb +30 -0
- data/lib/rom/sql/type_extensions.rb +11 -6
- data/lib/rom/sql/type_serializer.rb +46 -0
- data/lib/rom/sql/types.rb +12 -0
- data/lib/rom/sql/version.rb +1 -1
- metadata +26 -244
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -17
- data/.rspec +0 -3
- data/.travis.yml +0 -39
- data/.yardopts +0 -2
- data/Gemfile +0 -33
- data/Guardfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -19
- data/circle.yml +0 -10
- data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
- data/lib/rom/sql/relation/sequel_api.rb +0 -133
- data/log/.gitkeep +0 -0
- data/rom-sql.gemspec +0 -29
- data/spec/extensions/postgres/attribute_spec.rb +0 -217
- data/spec/extensions/postgres/integration_spec.rb +0 -59
- data/spec/extensions/postgres/types_spec.rb +0 -252
- data/spec/extensions/sqlite/types_spec.rb +0 -11
- data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
- data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
- data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
- data/spec/integration/associations/many_to_many_spec.rb +0 -162
- data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
- data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
- data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
- data/spec/integration/associations/many_to_one_spec.rb +0 -117
- data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
- data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
- data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
- data/spec/integration/associations/one_to_many_spec.rb +0 -86
- data/spec/integration/associations/one_to_one_spec.rb +0 -69
- data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
- data/spec/integration/auto_migrations/errors_spec.rb +0 -31
- data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
- data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
- data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
- data/spec/integration/combine_with_spec.rb +0 -43
- data/spec/integration/commands/create_spec.rb +0 -304
- data/spec/integration/commands/delete_spec.rb +0 -84
- data/spec/integration/commands/update_spec.rb +0 -90
- data/spec/integration/commands/upsert_spec.rb +0 -83
- data/spec/integration/gateway_spec.rb +0 -107
- data/spec/integration/migration_spec.rb +0 -55
- data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
- data/spec/integration/plugins/associates_spec.rb +0 -250
- data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
- data/spec/integration/relation_schema_spec.rb +0 -271
- data/spec/integration/schema/call_spec.rb +0 -24
- data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
- data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
- data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
- data/spec/integration/schema/inferrer_spec.rb +0 -390
- data/spec/integration/schema/prefix_spec.rb +0 -16
- data/spec/integration/schema/qualified_spec.rb +0 -16
- data/spec/integration/schema/rename_spec.rb +0 -21
- data/spec/integration/schema/view_spec.rb +0 -29
- data/spec/integration/sequel_api_spec.rb +0 -36
- data/spec/integration/setup_spec.rb +0 -26
- data/spec/integration/support/active_support_notifications_spec.rb +0 -24
- data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
- data/spec/integration/wrap_spec.rb +0 -91
- data/spec/shared/accounts.rb +0 -48
- data/spec/shared/database_setup.rb +0 -70
- data/spec/shared/notes.rb +0 -23
- data/spec/shared/posts.rb +0 -34
- data/spec/shared/puppies.rb +0 -15
- data/spec/shared/relations.rb +0 -8
- data/spec/shared/users.rb +0 -32
- data/spec/shared/users_and_tasks.rb +0 -50
- data/spec/spec_helper.rb +0 -122
- data/spec/support/env_helper.rb +0 -25
- data/spec/support/helpers.rb +0 -24
- data/spec/support/oracle/create_users.sql +0 -7
- data/spec/support/oracle/set_sys_passwords.sql +0 -2
- data/spec/support/test_configuration.rb +0 -16
- data/spec/unit/attribute_spec.rb +0 -104
- data/spec/unit/function_spec.rb +0 -48
- data/spec/unit/gateway_spec.rb +0 -70
- data/spec/unit/logger_spec.rb +0 -14
- data/spec/unit/migration_tasks_spec.rb +0 -111
- data/spec/unit/migrator_spec.rb +0 -25
- data/spec/unit/order_dsl_spec.rb +0 -43
- data/spec/unit/plugin/associates_spec.rb +0 -94
- data/spec/unit/plugin/pagination_spec.rb +0 -91
- data/spec/unit/plugin/timestamp_spec.rb +0 -117
- data/spec/unit/projection_dsl_spec.rb +0 -110
- data/spec/unit/relation/assoc_spec.rb +0 -87
- data/spec/unit/relation/associations_spec.rb +0 -27
- data/spec/unit/relation/avg_spec.rb +0 -11
- data/spec/unit/relation/by_pk_spec.rb +0 -62
- data/spec/unit/relation/dataset_spec.rb +0 -50
- data/spec/unit/relation/distinct_spec.rb +0 -15
- data/spec/unit/relation/exclude_spec.rb +0 -11
- data/spec/unit/relation/exist_predicate_spec.rb +0 -25
- data/spec/unit/relation/exists_spec.rb +0 -18
- data/spec/unit/relation/fetch_spec.rb +0 -21
- data/spec/unit/relation/group_spec.rb +0 -61
- data/spec/unit/relation/having_spec.rb +0 -22
- data/spec/unit/relation/inner_join_spec.rb +0 -158
- data/spec/unit/relation/inspect_spec.rb +0 -11
- data/spec/unit/relation/instrument_spec.rb +0 -45
- data/spec/unit/relation/invert_spec.rb +0 -11
- data/spec/unit/relation/left_join_spec.rb +0 -55
- data/spec/unit/relation/lock_spec.rb +0 -93
- data/spec/unit/relation/map_spec.rb +0 -16
- data/spec/unit/relation/max_spec.rb +0 -11
- data/spec/unit/relation/min_spec.rb +0 -11
- data/spec/unit/relation/order_spec.rb +0 -51
- data/spec/unit/relation/pluck_spec.rb +0 -11
- data/spec/unit/relation/prefix_spec.rb +0 -29
- data/spec/unit/relation/primary_key_spec.rb +0 -27
- data/spec/unit/relation/project_spec.rb +0 -24
- data/spec/unit/relation/qualified_columns_spec.rb +0 -30
- data/spec/unit/relation/qualified_spec.rb +0 -25
- data/spec/unit/relation/read_spec.rb +0 -25
- data/spec/unit/relation/rename_spec.rb +0 -23
- data/spec/unit/relation/right_join_spec.rb +0 -57
- data/spec/unit/relation/select_append_spec.rb +0 -21
- data/spec/unit/relation/select_spec.rb +0 -40
- data/spec/unit/relation/sum_spec.rb +0 -11
- data/spec/unit/relation/union_spec.rb +0 -19
- data/spec/unit/relation/unique_predicate_spec.rb +0 -18
- data/spec/unit/relation/where_spec.rb +0 -133
- data/spec/unit/restriction_dsl_spec.rb +0 -34
- data/spec/unit/schema_spec.rb +0 -25
- data/spec/unit/types_spec.rb +0 -65
@@ -1,59 +0,0 @@
|
|
1
|
-
RSpec.describe 'PostgreSQL extension', :postgres do
|
2
|
-
include_context 'database setup'
|
3
|
-
|
4
|
-
before do
|
5
|
-
conn.drop_table?(:pg_people)
|
6
|
-
conn.drop_table?(:people)
|
7
|
-
|
8
|
-
conn.create_table :pg_people do
|
9
|
-
primary_key :id
|
10
|
-
String :name
|
11
|
-
column :tags, "text[]"
|
12
|
-
end
|
13
|
-
|
14
|
-
conf.relation(:people) do
|
15
|
-
schema(:pg_people, infer: true)
|
16
|
-
end
|
17
|
-
|
18
|
-
conf.commands(:people) do
|
19
|
-
define(:create)
|
20
|
-
define(:update)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:people_relation) { relations[:people] }
|
25
|
-
|
26
|
-
describe 'using arrays' do
|
27
|
-
let(:people) { commands[:people] }
|
28
|
-
|
29
|
-
it 'inserts array values' do
|
30
|
-
people.create.call(name: 'John Doe', tags: ['foo'])
|
31
|
-
expect(people_relation.to_a).to eq([id: 1, name: 'John Doe', tags: ['foo']])
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'inserts empty arrays' do
|
35
|
-
people.create.call(name: 'John Doe', tags: [])
|
36
|
-
expect(people_relation.to_a).to eq([id: 1, name: 'John Doe', tags: []])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'using retrurning' do
|
41
|
-
let(:create_person) { commands[:people].create }
|
42
|
-
let(:update_person) { commands[:people].update }
|
43
|
-
let(:composite_relation) { people_relation >> -> r { r.to_a.map { |x| x.fetch(:name).upcase } } }
|
44
|
-
|
45
|
-
context 'with pipeline' do
|
46
|
-
it 'works with create' do
|
47
|
-
mapped_people = create_person.new(composite_relation).call(name: 'John Doe', tags: ['foo'])
|
48
|
-
expect(mapped_people).to eql(['JOHN DOE'])
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'works with update' do
|
52
|
-
create_person.call(name: 'John Doe', tags: ['foo'])
|
53
|
-
|
54
|
-
mapped_people = update_person.new(composite_relation).call(name: 'Jane Doe')
|
55
|
-
expect(mapped_people).to eql(['JANE DOE'])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,252 +0,0 @@
|
|
1
|
-
RSpec.describe 'ROM::SQL::Types' do
|
2
|
-
describe 'ROM::SQL::Types::PG::JSON' do
|
3
|
-
it 'coerces to pg json hash' do
|
4
|
-
input = { foo: 'bar' }
|
5
|
-
|
6
|
-
expect(ROM::SQL::Types::PG::JSON[input]).to eql(Sequel.pg_json(input))
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'coerces to pg json array' do
|
10
|
-
input = [1, 2, 3]
|
11
|
-
output = ROM::SQL::Types::PG::JSON[input]
|
12
|
-
|
13
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONArray)
|
14
|
-
expect(output.to_a).to eql(input)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'ROM::SQL::Types::PG::Bytea' do
|
19
|
-
it 'coerces strings to Sequel::SQL::Blob' do
|
20
|
-
input = 'sutin'
|
21
|
-
output = ROM::SQL::Types::PG::Bytea[input]
|
22
|
-
|
23
|
-
expect(output).to be_instance_of(Sequel::SQL::Blob)
|
24
|
-
expect(output).to eql('sutin')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe ROM::SQL::Types::PG::UUID do
|
29
|
-
it 'coerces strings to UUID' do
|
30
|
-
input = SecureRandom.uuid
|
31
|
-
output = described_class[input]
|
32
|
-
|
33
|
-
expect(output).to be_instance_of(String)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe ROM::SQL::Types::PG::Array do
|
38
|
-
it 'coerces to pg array' do
|
39
|
-
input = [1, 2, 3]
|
40
|
-
output = ROM::SQL::Types::PG::Array('integer')[input]
|
41
|
-
|
42
|
-
expect(output).to be_instance_of(Sequel::Postgres::PGArray)
|
43
|
-
expect(output.to_a).to eql(input)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'accepts any other type of objects' do
|
47
|
-
input = [nil, 1, 'sutin', :sutin, 1.0, {}].sample
|
48
|
-
output = ROM::SQL::Types::PG::Array('integer')[input]
|
49
|
-
|
50
|
-
expect(output).to be_instance_of(Sequel::Postgres::ArrayOp)
|
51
|
-
expect(output.value).to eql(input)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe ROM::SQL::Types::PG::JSON do
|
56
|
-
it 'coerces to pg json hash' do
|
57
|
-
input = { foo: 'bar' }
|
58
|
-
output = described_class[input]
|
59
|
-
|
60
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONHash)
|
61
|
-
expect(output).to eql(Sequel.pg_json(input))
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'coerces to pg json array' do
|
65
|
-
input = [1, 2, 3]
|
66
|
-
output = described_class[input]
|
67
|
-
|
68
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONArray)
|
69
|
-
expect(output.to_a).to eql(input)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'accepts any other type of objects' do
|
73
|
-
input = [nil, 1, 'sutin', :sutin, 1.0].sample
|
74
|
-
output = described_class[input]
|
75
|
-
|
76
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONOp)
|
77
|
-
expect(output.value).to eql(input)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe ROM::SQL::Types::PG::JSONB do
|
82
|
-
it 'coerces to pg jsonb hash' do
|
83
|
-
input = { foo: 'bar' }
|
84
|
-
output = described_class[input]
|
85
|
-
|
86
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONBHash)
|
87
|
-
expect(output).to eql(Sequel.pg_jsonb(input))
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'coerces to pg jsonb array' do
|
91
|
-
input = [1, 2, 3]
|
92
|
-
output = described_class[input]
|
93
|
-
|
94
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONBArray)
|
95
|
-
expect(output.to_a).to eql(input)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'accepts any other type of objects' do
|
99
|
-
input = [nil, 1, 'sutin', :sutin, 1.0].sample
|
100
|
-
output = described_class[input]
|
101
|
-
|
102
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONBOp)
|
103
|
-
expect(output.value).to eql(input)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe ROM::SQL::Types::PG::Money do
|
108
|
-
it 'coerces to pg Money' do
|
109
|
-
input = BigDecimal.new(1.0, 2)
|
110
|
-
output = described_class[input]
|
111
|
-
|
112
|
-
expect(output).to be_instance_of(BigDecimal)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe ROM::SQL::Types::PG::IPAddress do
|
117
|
-
it 'converts IPAddr to a string' do
|
118
|
-
expect(described_class[IPAddr.new('127.0.0.1')]).to eql('127.0.0.1')
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'coerces to builtin IPAddr type on read' do
|
122
|
-
expect(described_class.meta[:read]['127.0.0.1']).to eql(IPAddr.new('127.0.0.1'))
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'supports networks' do
|
126
|
-
class_a = described_class.meta[:read]['10.0.0.0/8']
|
127
|
-
|
128
|
-
expect(class_a).to eql(IPAddr.new('10.0.0.0/8'))
|
129
|
-
expect(class_a).to include(IPAddr.new('10.8.8.8'))
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe ROM::SQL::Types::PG::PointT do
|
134
|
-
let(:point) { ROM::SQL::Types::PG::Point.new(7.5, 30.5) }
|
135
|
-
|
136
|
-
it 'serializes a point down to a string' do
|
137
|
-
expect(described_class[point]).to eql('(7.5,30.5)')
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'reads serialized format' do
|
141
|
-
expect(described_class.meta[:read]['(7.5,30.5)']).to eql(point)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe ROM::SQL::Types::PG::HStore do
|
146
|
-
let(:mapping) { Hash['hot' => 'cold'] }
|
147
|
-
let(:read_type) { described_class.meta[:read] }
|
148
|
-
|
149
|
-
it 'covertss data to Sequel::Postgres::HStore' do
|
150
|
-
expect(described_class[mapping]).to be_a Sequel::Postgres::HStore
|
151
|
-
expect(described_class[mapping]).to eql(Sequel.hstore(hot: :cold))
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'reads Sequel::Postgres::HStore as a Hash object' do
|
155
|
-
expect(read_type[Sequel.hstore(mapping)]).to eql(mapping)
|
156
|
-
expect(read_type[Sequel.hstore(mapping)]).to be_a(Hash)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe ROM::SQL::Types::PG::LineT do
|
161
|
-
let(:line) { ROM::SQL::Types::PG::Line.new(2.3, 4.9, 3.1415) }
|
162
|
-
|
163
|
-
it 'serializes a line using the {A,B,C} format' do
|
164
|
-
expect(described_class[line]).to eql('{2.3,4.9,3.1415}')
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'reads the {A,B,C} format' do
|
168
|
-
expect(described_class.meta[:read]['{2.3,4.9,3.1415}']).to eql(line)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe ROM::SQL::Types::PG::CircleT do
|
173
|
-
let(:center) { ROM::SQL::Types::PG::Point.new(7.5, 30.5) }
|
174
|
-
let(:circle) { ROM::SQL::Types::PG::Circle.new(center, 1.2) }
|
175
|
-
|
176
|
-
it 'serializes a circle using the <(x,y),r> format' do
|
177
|
-
expect(described_class[circle]).to eql('<(7.5,30.5),1.2>')
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'reads the <(x,y),r> format' do
|
181
|
-
expect(described_class.meta[:read]['<(7.5,30.5),1.2>']).to eql(circle)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe ROM::SQL::Types::PG::BoxT do
|
186
|
-
let(:lower_left) { ROM::SQL::Types::PG::Point.new(7.5, 20.5) }
|
187
|
-
let(:upper_right) { ROM::SQL::Types::PG::Point.new(8.5, 30.5) }
|
188
|
-
|
189
|
-
let(:box) { ROM::SQL::Types::PG::Box.new(upper_right, lower_left) }
|
190
|
-
|
191
|
-
it 'serializes a box' do
|
192
|
-
expect(described_class[box]).to eql('((8.5,30.5),(7.5,20.5))')
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'reads serialized format' do
|
196
|
-
expect(described_class.meta[:read]['((8.5,30.5),(7.5,20.5))']).to eql(box)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe ROM::SQL::Types::PG::LineSegmentT do
|
201
|
-
let(:first) { ROM::SQL::Types::PG::Point.new(8.5, 30.5) }
|
202
|
-
let(:second) { ROM::SQL::Types::PG::Point.new(7.5, 20.5) }
|
203
|
-
|
204
|
-
let(:lseg) { ROM::SQL::Types::PG::LineSegment.new(first, second) }
|
205
|
-
|
206
|
-
it 'serializes a lseg using [ ( x1 , y1 ) , ( x2 , y2 ) ] format' do
|
207
|
-
expect(described_class[lseg]).to eql('[(8.5,30.5),(7.5,20.5)]')
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'reads serialized format' do
|
211
|
-
expect(described_class.meta[:read]['[(8.5,30.5),(7.5,20.5)]']).to eql(lseg)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe ROM::SQL::Types::PG::PolygonT do
|
216
|
-
let(:first) { ROM::SQL::Types::PG::Point.new(8.5, 30.5) }
|
217
|
-
let(:second) { ROM::SQL::Types::PG::Point.new(7.5, 20.5) }
|
218
|
-
let(:third) { ROM::SQL::Types::PG::Point.new(6.5, 10.5) }
|
219
|
-
|
220
|
-
let(:polygon) { ROM::SQL::Types::PG::Polygon[[first, second, third]] }
|
221
|
-
|
222
|
-
it 'serializes a polygon using ( ( x1 , y1 ) ... ( xn , yn ) ) format' do
|
223
|
-
expect(described_class[polygon]).to eql('((8.5,30.5),(7.5,20.5),(6.5,10.5))')
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'reads serialized format' do
|
227
|
-
expect(described_class.meta[:read]['((8.5,30.5),(7.5,20.5),(6.5,10.5))']).to eql(polygon)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe ROM::SQL::Types::PG::PathT do
|
232
|
-
let(:first) { ROM::SQL::Types::PG::Point.new(8.5, 30.5) }
|
233
|
-
let(:second) { ROM::SQL::Types::PG::Point.new(7.5, 20.5) }
|
234
|
-
let(:third) { ROM::SQL::Types::PG::Point.new(6.5, 10.5) }
|
235
|
-
|
236
|
-
let(:closed_path) { ROM::SQL::Types::PG::Path.new([first, second, third], :closed) }
|
237
|
-
let(:open_path) { ROM::SQL::Types::PG::Path.new([first, second, third], :open) }
|
238
|
-
|
239
|
-
it 'serializes a closed path using ( ( x1 , y1 ) ... ( xn , yn ) ) format' do
|
240
|
-
expect(described_class[closed_path]).to eql('((8.5,30.5),(7.5,20.5),(6.5,10.5))')
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'serializes an open path' do
|
244
|
-
expect(described_class[open_path]).to eql('[(8.5,30.5),(7.5,20.5),(6.5,10.5)]')
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'reads serialized format' do
|
248
|
-
expect(described_class.meta[:read]['((8.5,30.5),(7.5,20.5),(6.5,10.5))']).to eql(closed_path)
|
249
|
-
expect(described_class.meta[:read]['[(8.5,30.5),(7.5,20.5),(6.5,10.5)]']).to eql(open_path)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
RSpec.describe 'ROM::SQL::Types' do
|
2
|
-
describe 'ROM::SQL::Types::SQLite::Object' do
|
3
|
-
let(:type) { ROM::SQL::Types::SQLite::Object }
|
4
|
-
|
5
|
-
it 'passes an object of any type' do
|
6
|
-
[Object.new, 1, true, BasicObject.new].each do |obj|
|
7
|
-
expect(type[obj]).to be obj
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
|
2
|
-
include_context 'users'
|
3
|
-
|
4
|
-
before do
|
5
|
-
inferrable_relations.concat %i(puzzles puzzle_solvers)
|
6
|
-
end
|
7
|
-
|
8
|
-
subject(:assoc) do
|
9
|
-
relations[:users].associations[:puzzles]
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:puzzles) { relations[:puzzles] }
|
13
|
-
let(:puzzle_solvers) { relations[:puzzle_solvers] }
|
14
|
-
|
15
|
-
with_adapters do
|
16
|
-
before do
|
17
|
-
conn.create_table(:puzzles) do
|
18
|
-
primary_key :id
|
19
|
-
column :text, String, null: false
|
20
|
-
end
|
21
|
-
|
22
|
-
conn.create_table(:puzzle_solvers) do
|
23
|
-
foreign_key :solver_id, :users, null: false
|
24
|
-
foreign_key :puzzle_id, :puzzles, null: false
|
25
|
-
primary_key [:solver_id, :puzzle_id]
|
26
|
-
end
|
27
|
-
|
28
|
-
conf.relation(:puzzles) { schema(infer: true) }
|
29
|
-
|
30
|
-
conf.relation(:puzzle_solvers) do
|
31
|
-
schema(infer: true) do
|
32
|
-
associations do
|
33
|
-
belongs_to :user, foreign_key: :solver_id
|
34
|
-
belongs_to :puzzle
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
conf.relation(:users) do
|
40
|
-
schema(infer: true) do
|
41
|
-
associations do
|
42
|
-
has_many :puzzle_solvers
|
43
|
-
has_many :puzzles, through: :puzzle_solvers, foreign_key: :solver_id
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
p1_id = relations[:puzzles].insert(text: 'P1')
|
49
|
-
p2_id = relations[:puzzles].insert(text: 'P2')
|
50
|
-
p3_id = relations[:puzzles].insert(text: 'P3')
|
51
|
-
|
52
|
-
relations[:puzzle_solvers].insert(solver_id: joe_id, puzzle_id: p2_id)
|
53
|
-
relations[:puzzle_solvers].insert(solver_id: jane_id, puzzle_id: p2_id)
|
54
|
-
|
55
|
-
relations[:puzzle_solvers].insert(solver_id: joe_id, puzzle_id: p1_id)
|
56
|
-
relations[:puzzle_solvers].insert(solver_id: jane_id, puzzle_id: p3_id)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'prepares joined relations using custom FK' do
|
60
|
-
relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:solver_id].qualified)
|
61
|
-
|
62
|
-
expect(relation.schema.map(&:to_sql_name)).
|
63
|
-
to eql([Sequel.qualify(:puzzles, :id),
|
64
|
-
Sequel.qualify(:puzzles, :text),
|
65
|
-
Sequel.qualify(:puzzle_solvers, :solver_id)])
|
66
|
-
|
67
|
-
expect(relation.to_a).
|
68
|
-
to eql([
|
69
|
-
{ id: 1, solver_id: 2, text: 'P1' },
|
70
|
-
{ id: 2, solver_id: 1, text: 'P2' },
|
71
|
-
{ id: 2, solver_id: 2, text: 'P2' },
|
72
|
-
{ id: 3, solver_id: 1, text: 'P3' }
|
73
|
-
])
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
|
2
|
-
include_context 'users'
|
3
|
-
|
4
|
-
before do
|
5
|
-
inferrable_relations.concat %i(puzzles puzzle_solvers)
|
6
|
-
end
|
7
|
-
|
8
|
-
subject(:assoc) do
|
9
|
-
relations[:users].associations[:solved_puzzles]
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:puzzles) { relations[:puzzles] }
|
13
|
-
let(:puzzle_solvers) { relations[:puzzle_solvers] }
|
14
|
-
|
15
|
-
with_adapters do
|
16
|
-
before do
|
17
|
-
conn.create_table(:puzzles) do
|
18
|
-
primary_key :id
|
19
|
-
column :text, String, null: false
|
20
|
-
column :solved, TrueClass, null: false, default: false
|
21
|
-
end
|
22
|
-
|
23
|
-
conn.create_table(:puzzle_solvers) do
|
24
|
-
foreign_key :user_id, :users, null: false
|
25
|
-
foreign_key :puzzle_id, :puzzles, null: false
|
26
|
-
primary_key [:user_id, :puzzle_id]
|
27
|
-
end
|
28
|
-
|
29
|
-
conf.relation(:puzzles) do
|
30
|
-
schema(infer: true)
|
31
|
-
|
32
|
-
view(:solved, schema) do
|
33
|
-
where(solved: true)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
conf.relation(:puzzle_solvers) do
|
38
|
-
schema(infer: true) do
|
39
|
-
associations do
|
40
|
-
belongs_to :user
|
41
|
-
belongs_to :puzzle
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
conf.relation(:users) do
|
47
|
-
schema(infer: true) do
|
48
|
-
associations do
|
49
|
-
has_many :puzzle_solvers
|
50
|
-
has_many :puzzles, through: :puzzle_solvers
|
51
|
-
has_many :puzzles, through: :puzzle_solvers, as: :solved_puzzles, view: :solved
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
p1_id = relations[:puzzles].insert(text: 'P1')
|
57
|
-
p2_id = relations[:puzzles].insert(text: 'P2', solved: true)
|
58
|
-
p3_id = relations[:puzzles].insert(text: 'P3')
|
59
|
-
|
60
|
-
relations[:puzzle_solvers].insert(user_id: joe_id, puzzle_id: p2_id)
|
61
|
-
relations[:puzzle_solvers].insert(user_id: jane_id, puzzle_id: p2_id)
|
62
|
-
|
63
|
-
relations[:puzzle_solvers].insert(user_id: joe_id, puzzle_id: p1_id)
|
64
|
-
relations[:puzzle_solvers].insert(user_id: jane_id, puzzle_id: p3_id)
|
65
|
-
end
|
66
|
-
|
67
|
-
after do
|
68
|
-
conn.drop_table?(:puzzle_solvers)
|
69
|
-
conn.drop_table?(:puzzles)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'prepares joined relations using custom FK' do
|
73
|
-
relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:user_id].qualified)
|
74
|
-
|
75
|
-
expect(relation.schema.map(&:to_sql_name)).
|
76
|
-
to eql([Sequel.qualify(:puzzles, :id),
|
77
|
-
Sequel.qualify(:puzzles, :text),
|
78
|
-
Sequel.qualify(:puzzles, :solved),
|
79
|
-
Sequel.qualify(:puzzle_solvers, :user_id)])
|
80
|
-
|
81
|
-
expect(relation.to_a).
|
82
|
-
to eql([
|
83
|
-
{ id: 2, user_id: 1, solved: db_true, text: 'P2' },
|
84
|
-
{ id: 2, user_id: 2, solved: db_true, text: 'P2' }
|
85
|
-
])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|