Skip to content

Commit 15f6f99

Browse files
committed
Spec suite clean up
- Isolate spec:compat group that describes deprecated behavior - Merge unit and integration specs into spec/suite/rom - Update remaining places that still relied on rom/compat - Mark view-related specs as pending - this feature will be rebuild as a component which will simplify implementation and make it more powerful - Disable flaky specs for now - unfortunately there's still some state leakage between various specs which make them fail sometimes, this will be fixed in separate PRs or directly in master
1 parent ad3cc9b commit 15f6f99

File tree

224 files changed

+1721
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+1721
-1345
lines changed

.env

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
BASE_DB_URI=postgres@postgres/rom
2-
1+
BASE_DB_URI=rom:password@postgres/rom

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# TODO: re-add both as a separate workflow because it's just too slow
3333
# - jruby
3434
# - truffleruby
35-
group: [rom, compat, legacy]
35+
group: [rom, compat]
3636
include:
3737
- ruby: '3.0'
3838
coverage: 'false'

Rakefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ RSpec::Core::RakeTask.new("spec:rom") do |t|
99
t.pattern = ["spec/suite/rom/**/*_spec.rb"]
1010
end
1111

12-
RSpec::Core::RakeTask.new("spec:legacy") do |t|
13-
t.pattern = ["spec/suite/legacy/**/*_spec.rb"]
14-
end
15-
1612
RSpec::Core::RakeTask.new("spec:compat") do |t|
1713
t.pattern = ["spec/suite/compat/**/*_spec.rb"]
1814
end
1915

2016
desc "Run all spec examples from all groups"
21-
task spec: ["spec:rom", "spec:legacy", "spec:compat"]
17+
task spec: ["spec:rom", "spec:compat"]
2218

2319
task default: :spec
2420

lib/rom/commands/class_interface.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ def create_class(type: self, meta: {}, rel_meta: {}, plugins: {}, **, &block)
8888
klass = Dry::Core::ClassBuilder.new(name: type.name, parent: type).call
8989

9090
result = meta.fetch(:result, :one)
91-
klass.result(rel_meta.fetch(:combine_type, result))
91+
klass.config.result = rel_meta.fetch(:combine_type, result)
9292

9393
meta.each do |name, value|
94-
klass.public_send(name, value)
94+
if klass.respond_to?(name)
95+
klass.public_send(name, value)
96+
else
97+
klass.config[name] = value
98+
end
9599
end
96100

97101
plugins.each do |plugin, options|
@@ -123,6 +127,15 @@ def use(plugin, **options)
123127
ROM.plugins[:command].fetch(plugin, adapter).apply_to(self, **options)
124128
end
125129

130+
# Return configured adapter identifier
131+
#
132+
# @return [Symbol]
133+
#
134+
# @api public
135+
def adapter
136+
config.component.adapter
137+
end
138+
126139
# Set before-execute hooks
127140
#
128141
# @overload before(hook)

lib/rom/commands/delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Commands
1010
#
1111
# @abstract
1212
class Delete < Command
13-
restrictable true
13+
config.restrictable = true
1414
end
1515
end
1616
end

lib/rom/commands/graph.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Graph
3535
# Graph results are mappable through `combine` operation in mapper DSL
3636
#
3737
# @example
38-
# create_user = rom.commands[:users].create
39-
# create_task = rom.commands[:tasks].create
38+
# create_user = rom.commands[:users][:create]
39+
# create_task = rom.commands[:tasks][:create]
4040
#
4141
# command = create_user
4242
# .curry(name: 'Jane')

lib/rom/commands/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Commands
1010
#
1111
# @abstract
1212
class Update < Command
13-
restrictable true
13+
config.restrictable = true
1414
end
1515
end
1616
end

lib/rom/compat.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
require "rom/core"
66
require "rom/resolver"
7+
require "rom/runtime"
78
require "rom/container"
8-
require "rom/configuration"
99
require "rom/global"
1010

1111
require_relative "compat/auto_registration"
@@ -23,8 +23,10 @@ module Global
2323
alias_method :container, :runtime
2424
end
2525

26+
Configuration = Runtime
27+
2628
# @api public
27-
class Configuration
29+
class Runtime
2830
# @api public
2931
# @deprecated
3032
def inflector=(inflector)

lib/rom/compat/components/dsl/schema.rb

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ module ROM
99
module Components
1010
module DSL
1111
# @private
12+
#
13+
# rubocop:disable Metrics/AbcSize
14+
# rubocop:disable Metrics/CyclomaticComplexity
15+
# rubocop:disable Metrics/PerceivedComplexity
1216
class Schema < Core
1317
mod = Module.new do
1418
# @api private
1519
def call
16-
return super unless config.dsl_class
20+
return super unless config.dsl_class || config.view
1721

1822
configure
1923

@@ -37,6 +41,13 @@ def call
3741
end
3842
end
3943

44+
# @api public
45+
#
46+
# @deprecated
47+
def associations(&block)
48+
backend.associations(&block)
49+
end
50+
4051
private
4152

4253
# @api private
@@ -64,26 +75,24 @@ def backend
6475

6576
# @api private
6677
def configure
67-
if !config.view
68-
if provider.config.component.type == :relation
69-
provider.config.component.update(dataset: config.dataset) if config.dataset
70-
provider.config.component.update(id: config.as) if config.as
71-
72-
if provider.config.component.id == :anonymous
73-
provider.config.component.update(id: config.id)
74-
end
75-
76-
if config.id.nil?
77-
config.update(id: provider.config.component.id)
78-
end
79-
80-
if config.relation.nil?
81-
config.update(relation: provider.config.component.id)
82-
end
83-
84-
if config.adapter.nil?
85-
config.update(adapter: provider.config.component.adapter)
86-
end
78+
if !config.view && provider.config.component.type == :relation
79+
provider.config.component.update(dataset: config.dataset) if config.dataset
80+
provider.config.component.update(id: config.as) if config.as
81+
82+
if provider.config.component.id == :anonymous
83+
provider.config.component.update(id: config.id)
84+
end
85+
86+
if config.id.nil?
87+
config.update(id: provider.config.component.id)
88+
end
89+
90+
if config.relation.nil?
91+
config.update(relation: provider.config.component.id)
92+
end
93+
94+
if config.adapter.nil?
95+
config.update(adapter: provider.config.component.adapter)
8796
end
8897
end
8998

@@ -110,6 +119,9 @@ def inferrer
110119
config.inferrer.with(enabled: config.infer)
111120
end
112121
end
122+
# rubocop:enable Metrics/AbcSize
123+
# rubocop:enable Metrics/CyclomaticComplexity
124+
# rubocop:enable Metrics/PerceivedComplexity
113125

114126
prepend(mod)
115127
end

lib/rom/components/dsl/association.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "rom/schema/associations_dsl"
4+
require "rom/relation/name"
45

56
require_relative "core"
67

@@ -31,7 +32,14 @@ def backend
3132

3233
# @api private
3334
def source
34-
config.source || config.id
35+
if provider.config.component.key?(:id)
36+
# TODO: decouple associations DSL from Relation::Name
37+
ROM::Relation::Name[
38+
provider.config.component.id, provider.config.component.dataset
39+
]
40+
else
41+
config.source
42+
end
3543
end
3644
end
3745
end

0 commit comments

Comments
 (0)