rom-sql 1.0.0.beta3 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -5
- data/.yardopts +2 -0
- data/CHANGELOG.md +4 -1
- data/lib/rom/plugins/relation/sql/auto_combine.rb +4 -0
- data/lib/rom/plugins/relation/sql/auto_wrap.rb +4 -0
- data/lib/rom/sql/{type.rb → attribute.rb} +8 -5
- data/lib/rom/sql/commands/update.rb +10 -0
- data/lib/rom/sql/dsl.rb +1 -0
- data/lib/rom/sql/extensions/postgres/inferrer.rb +2 -1
- data/lib/rom/sql/extensions/sqlite.rb +1 -0
- data/lib/rom/sql/extensions/sqlite/inferrer.rb +9 -0
- data/lib/rom/sql/extensions/sqlite/types.rb +11 -0
- data/lib/rom/sql/function.rb +4 -1
- data/lib/rom/sql/gateway.rb +64 -28
- data/lib/rom/sql/migration.rb +21 -29
- data/lib/rom/sql/migration/migrator.rb +8 -0
- data/lib/rom/sql/order_dsl.rb +1 -0
- data/lib/rom/sql/plugin/associates.rb +21 -0
- data/lib/rom/sql/plugin/timestamps.rb +131 -0
- data/lib/rom/sql/plugins.rb +3 -0
- data/lib/rom/sql/projection_dsl.rb +1 -0
- data/lib/rom/sql/relation/reading.rb +256 -75
- data/lib/rom/sql/restriction_dsl.rb +1 -0
- data/lib/rom/sql/schema/associations_dsl.rb +119 -1
- data/lib/rom/sql/schema/dsl.rb +44 -2
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +2 -2
- data/spec/extensions/sqlite/types_spec.rb +11 -0
- data/spec/integration/plugins/associates_spec.rb +79 -0
- data/spec/integration/schema/inferrer/postgres_spec.rb +3 -1
- data/spec/integration/schema/inferrer/sqlite_spec.rb +2 -0
- data/spec/shared/database_setup.rb +10 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers.rb +2 -2
- data/spec/unit/plugin/timestamp_spec.rb +77 -0
- data/spec/unit/types_spec.rb +1 -1
- metadata +37 -24
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rom/sql/plugin/timestamps'
|
2
|
+
|
3
|
+
RSpec.describe 'Plugin / Timestamp' do
|
4
|
+
include_context 'database setup'
|
5
|
+
|
6
|
+
with_adapters do
|
7
|
+
before do
|
8
|
+
conf.commands(:notes) do
|
9
|
+
define :create do
|
10
|
+
result :one
|
11
|
+
use :timestamps
|
12
|
+
timestamp :updated_at, :created_at
|
13
|
+
datestamp :written
|
14
|
+
end
|
15
|
+
|
16
|
+
define :create_many, type: :create do
|
17
|
+
result :many
|
18
|
+
use :timestamps
|
19
|
+
timestamp :updated_at, :created_at
|
20
|
+
end
|
21
|
+
|
22
|
+
define :update do
|
23
|
+
use :timestamps
|
24
|
+
timestamp :updated_at
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "applies timestamps by default" do
|
30
|
+
time = DateTime.now
|
31
|
+
result = container.command(:notes).create.call(text: "This is a test")
|
32
|
+
|
33
|
+
created = DateTime.parse(result[:created_at].to_s)
|
34
|
+
updated = DateTime.parse(result[:updated_at].to_s)
|
35
|
+
|
36
|
+
expect(created).to be_within(1).of(time)
|
37
|
+
expect(updated).to eq created
|
38
|
+
end
|
39
|
+
|
40
|
+
it "applies datestamps by default" do
|
41
|
+
result = container.command(:notes).create.call(text: "This is a test")
|
42
|
+
expect(Date.parse(result[:written].to_s)).to eq Date.today
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sets timestamps on multi-tuple inputs" do
|
46
|
+
time = DateTime.now
|
47
|
+
input = [{text: "note one"}, {text: "note two"}]
|
48
|
+
|
49
|
+
results = container.command(:notes).create_many.call(input)
|
50
|
+
|
51
|
+
results.each do |result|
|
52
|
+
created = DateTime.parse(result[:created_at].to_s)
|
53
|
+
|
54
|
+
expect(created).to be_within(1).of(time)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "only updates specified timestamps" do
|
59
|
+
initial = container.command(:notes).create.call(text: "testing")
|
60
|
+
sleep 1 # Unfortunate, but unless I start injecting clocks into the
|
61
|
+
# command, this is needed to make sure the time actually changes
|
62
|
+
updated = container.command(:notes).update.call(text: "updated test").first
|
63
|
+
|
64
|
+
expect(updated[:created_at]).to eq initial[:created_at]
|
65
|
+
expect(updated[:updated_at]).not_to eq initial[:updated_at]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "allows overriding timestamps" do
|
69
|
+
tomorrow = (Time.now + (60 * 60 * 24))
|
70
|
+
|
71
|
+
container.command(:notes).create.call(text: "testing")
|
72
|
+
updated = container.command(:notes).update.call(text: "updated test", updated_at: tomorrow).first
|
73
|
+
|
74
|
+
expect(updated[:updated_at].iso8601).to eq tomorrow.iso8601
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/unit/types_spec.rb
CHANGED
@@ -68,7 +68,7 @@ RSpec.describe ROM::SQL::Types, :postgres do
|
|
68
68
|
|
69
69
|
specify do
|
70
70
|
expect { sql_literal }.
|
71
|
-
to raise_error(ROM::SQL::
|
71
|
+
to raise_error(ROM::SQL::Attribute::QualifyError, "can't qualify :age (#{func.inspect})")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
metadata
CHANGED
@@ -1,59 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: sequel
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '4.42'
|
20
|
-
|
19
|
+
name: sequel
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.42'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-equalizer
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0.2'
|
34
|
-
|
33
|
+
name: dry-equalizer
|
35
34
|
prerelease: false
|
35
|
+
type: :runtime
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: dry-types
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '0.9'
|
48
|
-
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.9.4
|
50
|
+
name: dry-types
|
49
51
|
prerelease: false
|
52
|
+
type: :runtime
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '0.9'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.9.4
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: dry-core
|
57
62
|
requirement: !ruby/object:Gem::Requirement
|
58
63
|
requirements:
|
59
64
|
- - "~>"
|
@@ -62,8 +67,9 @@ dependencies:
|
|
62
67
|
- - ">="
|
63
68
|
- !ruby/object:Gem::Version
|
64
69
|
version: 0.2.3
|
65
|
-
|
70
|
+
name: dry-core
|
66
71
|
prerelease: false
|
72
|
+
type: :runtime
|
67
73
|
version_requirements: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
75
|
- - "~>"
|
@@ -73,42 +79,42 @@ dependencies:
|
|
73
79
|
- !ruby/object:Gem::Version
|
74
80
|
version: 0.2.3
|
75
81
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: rom
|
77
82
|
requirement: !ruby/object:Gem::Requirement
|
78
83
|
requirements:
|
79
84
|
- - "~>"
|
80
85
|
- !ruby/object:Gem::Version
|
81
|
-
version: 3.0.0.
|
82
|
-
|
86
|
+
version: 3.0.0.rc
|
87
|
+
name: rom
|
83
88
|
prerelease: false
|
89
|
+
type: :runtime
|
84
90
|
version_requirements: !ruby/object:Gem::Requirement
|
85
91
|
requirements:
|
86
92
|
- - "~>"
|
87
93
|
- !ruby/object:Gem::Version
|
88
|
-
version: 3.0.0.
|
94
|
+
version: 3.0.0.rc
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
|
-
name: bundler
|
91
96
|
requirement: !ruby/object:Gem::Requirement
|
92
97
|
requirements:
|
93
98
|
- - ">="
|
94
99
|
- !ruby/object:Gem::Version
|
95
100
|
version: '0'
|
96
|
-
|
101
|
+
name: bundler
|
97
102
|
prerelease: false
|
103
|
+
type: :development
|
98
104
|
version_requirements: !ruby/object:Gem::Requirement
|
99
105
|
requirements:
|
100
106
|
- - ">="
|
101
107
|
- !ruby/object:Gem::Version
|
102
108
|
version: '0'
|
103
109
|
- !ruby/object:Gem::Dependency
|
104
|
-
name: rake
|
105
110
|
requirement: !ruby/object:Gem::Requirement
|
106
111
|
requirements:
|
107
112
|
- - "~>"
|
108
113
|
- !ruby/object:Gem::Version
|
109
114
|
version: '10.0'
|
110
|
-
|
115
|
+
name: rake
|
111
116
|
prerelease: false
|
117
|
+
type: :development
|
112
118
|
version_requirements: !ruby/object:Gem::Requirement
|
113
119
|
requirements:
|
114
120
|
- - "~>"
|
@@ -124,6 +130,7 @@ files:
|
|
124
130
|
- ".gitignore"
|
125
131
|
- ".rspec"
|
126
132
|
- ".travis.yml"
|
133
|
+
- ".yardopts"
|
127
134
|
- CHANGELOG.md
|
128
135
|
- Gemfile
|
129
136
|
- Guardfile
|
@@ -142,6 +149,7 @@ files:
|
|
142
149
|
- lib/rom/sql/association/one_to_many.rb
|
143
150
|
- lib/rom/sql/association/one_to_one.rb
|
144
151
|
- lib/rom/sql/association/one_to_one_through.rb
|
152
|
+
- lib/rom/sql/attribute.rb
|
145
153
|
- lib/rom/sql/commands.rb
|
146
154
|
- lib/rom/sql/commands/create.rb
|
147
155
|
- lib/rom/sql/commands/delete.rb
|
@@ -162,6 +170,7 @@ files:
|
|
162
170
|
- lib/rom/sql/extensions/rails_log_subscriber.rb
|
163
171
|
- lib/rom/sql/extensions/sqlite.rb
|
164
172
|
- lib/rom/sql/extensions/sqlite/inferrer.rb
|
173
|
+
- lib/rom/sql/extensions/sqlite/types.rb
|
165
174
|
- lib/rom/sql/function.rb
|
166
175
|
- lib/rom/sql/gateway.rb
|
167
176
|
- lib/rom/sql/migration.rb
|
@@ -170,6 +179,7 @@ files:
|
|
170
179
|
- lib/rom/sql/order_dsl.rb
|
171
180
|
- lib/rom/sql/plugin/associates.rb
|
172
181
|
- lib/rom/sql/plugin/pagination.rb
|
182
|
+
- lib/rom/sql/plugin/timestamps.rb
|
173
183
|
- lib/rom/sql/plugins.rb
|
174
184
|
- lib/rom/sql/projection_dsl.rb
|
175
185
|
- lib/rom/sql/qualified_attribute.rb
|
@@ -186,13 +196,13 @@ files:
|
|
186
196
|
- lib/rom/sql/spec/support.rb
|
187
197
|
- lib/rom/sql/tasks/migration_tasks.rake
|
188
198
|
- lib/rom/sql/transaction.rb
|
189
|
-
- lib/rom/sql/type.rb
|
190
199
|
- lib/rom/sql/types.rb
|
191
200
|
- lib/rom/sql/version.rb
|
192
201
|
- log/.gitkeep
|
193
202
|
- rom-sql.gemspec
|
194
203
|
- spec/extensions/postgres/integration_spec.rb
|
195
204
|
- spec/extensions/postgres/types_spec.rb
|
205
|
+
- spec/extensions/sqlite/types_spec.rb
|
196
206
|
- spec/fixtures/migrations/20150403090603_create_carrots.rb
|
197
207
|
- spec/integration/association/many_to_many/custom_fks_spec.rb
|
198
208
|
- spec/integration/association/many_to_many/from_view_spec.rb
|
@@ -249,6 +259,7 @@ files:
|
|
249
259
|
- spec/unit/migrator_spec.rb
|
250
260
|
- spec/unit/order_dsl_spec.rb
|
251
261
|
- spec/unit/plugin/pagination_spec.rb
|
262
|
+
- spec/unit/plugin/timestamp_spec.rb
|
252
263
|
- spec/unit/projection_dsl_spec.rb
|
253
264
|
- spec/unit/relation/assoc_spec.rb
|
254
265
|
- spec/unit/relation/associations_spec.rb
|
@@ -288,7 +299,7 @@ homepage: http://rom-rb.org
|
|
288
299
|
licenses:
|
289
300
|
- MIT
|
290
301
|
metadata: {}
|
291
|
-
post_install_message:
|
302
|
+
post_install_message:
|
292
303
|
rdoc_options: []
|
293
304
|
require_paths:
|
294
305
|
- lib
|
@@ -303,14 +314,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
314
|
- !ruby/object:Gem::Version
|
304
315
|
version: 1.3.1
|
305
316
|
requirements: []
|
306
|
-
rubyforge_project:
|
307
|
-
rubygems_version: 2.
|
308
|
-
signing_key:
|
317
|
+
rubyforge_project:
|
318
|
+
rubygems_version: 2.6.8
|
319
|
+
signing_key:
|
309
320
|
specification_version: 4
|
310
321
|
summary: SQL databases support for ROM
|
311
322
|
test_files:
|
312
323
|
- spec/extensions/postgres/integration_spec.rb
|
313
324
|
- spec/extensions/postgres/types_spec.rb
|
325
|
+
- spec/extensions/sqlite/types_spec.rb
|
314
326
|
- spec/fixtures/migrations/20150403090603_create_carrots.rb
|
315
327
|
- spec/integration/association/many_to_many/custom_fks_spec.rb
|
316
328
|
- spec/integration/association/many_to_many/from_view_spec.rb
|
@@ -367,6 +379,7 @@ test_files:
|
|
367
379
|
- spec/unit/migrator_spec.rb
|
368
380
|
- spec/unit/order_dsl_spec.rb
|
369
381
|
- spec/unit/plugin/pagination_spec.rb
|
382
|
+
- spec/unit/plugin/timestamp_spec.rb
|
370
383
|
- spec/unit/projection_dsl_spec.rb
|
371
384
|
- spec/unit/relation/assoc_spec.rb
|
372
385
|
- spec/unit/relation/associations_spec.rb
|