Skip to content

Commit 4fe989e

Browse files
authored
Merge pull request #409 from rom-rb/fix-specs-in-compat-mode
Fix specs in compat mode
2 parents 80dab2c + 549511a commit 4fe989e

File tree

14 files changed

+92
-6
lines changed

14 files changed

+92
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
- name: Bundle install
7777
run: bundle install --jobs 4 --retry 3
7878
- name: Run all tests
79-
run: bundle exec rake
79+
run: bundle exec rake spec spec:compat
8080
- name: Run codacy-coverage-reporter
8181
uses: codacy/codacy-coverage-reporter-action@master
8282
if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != ''

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
# frozen_string_literal: true
2+
13
require "rspec/core/rake_task"
24

35
RSpec::Core::RakeTask.new(:spec)
46

7+
desc "Run all specs in compat mode"
8+
task "spec:compat" do
9+
ENV["ROM_COMPAT"] = "true"
10+
Rake::Task["spec"].invoke
11+
end
12+
513
task default: [:spec]

lib/rom/sql/relation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
require "rom/sql/relation/reading"
1212
require "rom/sql/relation/writing"
13+
require "rom/sql/schema/dsl"
1314

1415
module ROM
1516
module SQL
@@ -34,6 +35,7 @@ class Relation < ROM::Relation
3435
config.attr_class = SQL::Attribute
3536
config.inferrer = ROM::SQL::Schema::Inferrer.new.freeze
3637
config.plugins << :indexes
38+
config.dsl_class = SQL::Schema::DSL
3739
end
3840

3941
dataset(abstract: true) do |schema|

lib/rom/sql/schema/dsl.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require "rom/compat/schema/dsl"
4+
require_relative "index_dsl"
5+
6+
module ROM
7+
module SQL
8+
class Schema < ROM::Schema
9+
# Specialized schema DSL with SQL-specific features
10+
#
11+
# @api public
12+
# @deprecated
13+
class DSL < ROM::Schema::DSL
14+
# @!attribute [r] index_dsl
15+
# @return [IndexDSL] Index DSL instance (created only if indexes block is called)
16+
attr_reader :index_dsl
17+
18+
# Define indexes within a block
19+
#
20+
# @api public
21+
def indexes(&block)
22+
@index_dsl = IndexDSL.new(**options, &block)
23+
end
24+
25+
private
26+
27+
# Return schema options
28+
#
29+
# @api private
30+
def opts
31+
if index_dsl
32+
opts = super
33+
34+
{**opts, indexes: index_dsl.(relation, opts[:attributes])}
35+
else
36+
super
37+
end
38+
end
39+
end
40+
end
41+
end
42+
end

spec/integration/associations/many_to_many/from_view_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
end
7979

8080
it "prepares joined relations using custom FK" do
81+
pending_if_compat_mode
82+
8183
relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:user_id].qualified)
8284

8385
expect(relation.schema.map(&:to_sql_name))

spec/integration/associations/many_to_one/from_view_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
end
7373

7474
it "prepares joined relations using custom view in target relation" do
75+
pending_if_compat_mode
76+
7577
relation = assoc_inter.()
7678

7779
expect(relation.schema.map(&:to_sql_name))

spec/integration/associations/one_to_many/from_view_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
end
5151

5252
it "prepares joined relations using custom view" do
53+
pending_if_compat_mode
54+
5355
relation = assoc.()
5456

5557
expect(relation.schema.map(&:to_sql_name))

spec/integration/auto_migrations/file_based_migrations_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def migrations
3939
end
4040

4141
it "creates migration files by schema definitions" do
42+
pending_if_compat_mode
43+
4244
gateway.auto_migrate!(conf, options)
4345
expect(migrations.size).to eql(1)
4446

@@ -83,6 +85,8 @@ def migrations
8385
end
8486

8587
it "creates migration files by schema definitions" do
88+
pending_if_compat_mode
89+
8690
gateway.auto_migrate!(conf, options)
8791
expect(migrations.size).to eql(1)
8892

spec/integration/auto_migrations/indexes_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def indexdef(index)
4545
end
4646

4747
it "creates ordinary b-tree indexes" do
48+
pending_if_compat_mode
49+
4850
gateway.auto_migrate!(conf, inline: true)
4951

5052
expect(attributes.map(&:to_ast))
@@ -98,6 +100,8 @@ def indexdef(index)
98100
end
99101

100102
it "supports custom names" do
103+
pending_if_compat_mode
104+
101105
conn.create_table :users do
102106
primary_key :id
103107
end
@@ -124,6 +128,8 @@ def indexdef(index)
124128
end
125129

126130
it "adds index to existing column" do
131+
pending_if_compat_mode
132+
127133
conn.create_table :users do
128134
primary_key :id
129135
column :name, String
@@ -150,6 +156,8 @@ def indexdef(index)
150156
end
151157

152158
it "supports unique indexes" do
159+
pending_if_compat_mode
160+
153161
conn.create_table :users do
154162
primary_key :id
155163
column :name, String
@@ -177,6 +185,8 @@ def indexdef(index)
177185

178186
if metadata[:postgres]
179187
it "uses index method" do
188+
pending_if_compat_mode
189+
180190
conn.create_table :users do
181191
primary_key :id
182192
column :props, :jsonb, null: false
@@ -200,6 +210,8 @@ def indexdef(index)
200210
end
201211

202212
it "supports partial indexes" do
213+
pending_if_compat_mode
214+
203215
conn.create_table :users do
204216
primary_key :id
205217
column :name, String

spec/integration/plugins/auto_restrictions_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class Test::Tasks < ROM::Relation[:sql]
7070

7171
include_context "auto-generated restriction view"
7272

73-
it "generates restrictrions by a composite index" do
73+
it "generates restrictions by a composite index" do
74+
pending_if_compat_mode
75+
7476
expect(tasks.by_user_id_and_title(1, "Jane's task").first).to eql(id: 2, user_id: 1, title: "Jane's task")
7577
end
7678
end

0 commit comments

Comments
 (0)