From b26766efe7cd44b2dbd7a6c7b2c46a04ead2b155 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 08:01:58 +0000 Subject: [PATCH 1/7] Add spec:compat task --- Rakefile | 6 ++++++ spec/spec_helper.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Rakefile b/Rakefile index 571441d1a..cd9d4173f 100644 --- a/Rakefile +++ b/Rakefile @@ -2,4 +2,10 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +desc "Run all specs in compat mode" +task "spec:compat" do + ENV["ROM_COMPAT"] = "true" + Rake::Task["spec"].invoke +end + task default: [:spec] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2719e462f..1b5a3e5b5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,6 +34,10 @@ require "pry" end +if ENV["ROM_COMPAT"] == "true" + require "rom/compat" +end + require "rom/sql" require "rom/sql/rake_task" From 0a717ede44885c91e6a39b8069251f6c9e7abee6 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 08:40:32 +0000 Subject: [PATCH 2/7] Skip setup spec if not compat mode --- spec/integration/setup_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/integration/setup_spec.rb b/spec/integration/setup_spec.rb index bbf8fec7f..e2a33927e 100644 --- a/spec/integration/setup_spec.rb +++ b/spec/integration/setup_spec.rb @@ -21,10 +21,10 @@ rom.gateways[:default].connection.drop_table(:dragons) end - it "creates tables within the setup block" do - pending "FIXME: restore access to gateways within the block?" - - expect(rom.relations[:dragons]).to be_kind_of(ROM::SQL::Relation) + if ENV["ROM_COMPAT"] == "true" + it "creates tables within the setup block" do + expect(rom.relations[:dragons]).to be_kind_of(ROM::SQL::Relation) + end end end end From 1196f269d23864c8318d8787805d88e266413674 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 08:40:51 +0000 Subject: [PATCH 3/7] [compat] re-add custom schema DSL class --- lib/rom/sql/relation.rb | 2 ++ lib/rom/sql/schema/dsl.rb | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/rom/sql/schema/dsl.rb diff --git a/lib/rom/sql/relation.rb b/lib/rom/sql/relation.rb index 79d37b04b..6c6b3aa97 100644 --- a/lib/rom/sql/relation.rb +++ b/lib/rom/sql/relation.rb @@ -10,6 +10,7 @@ require "rom/sql/relation/reading" require "rom/sql/relation/writing" +require "rom/sql/schema/dsl" module ROM module SQL @@ -34,6 +35,7 @@ class Relation < ROM::Relation config.attr_class = SQL::Attribute config.inferrer = ROM::SQL::Schema::Inferrer.new.freeze config.plugins << :indexes + config.dsl_class = SQL::Schema::DSL end dataset(abstract: true) do |schema| diff --git a/lib/rom/sql/schema/dsl.rb b/lib/rom/sql/schema/dsl.rb new file mode 100644 index 000000000..46ff87449 --- /dev/null +++ b/lib/rom/sql/schema/dsl.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require "rom/compat/schema/dsl" +require_relative "index_dsl" + +module ROM + module SQL + class Schema < ROM::Schema + # Specialized schema DSL with SQL-specific features + # + # @api public + # @deprecated + class DSL < ROM::Schema::DSL + # @!attribute [r] index_dsl + # @return [IndexDSL] Index DSL instance (created only if indexes block is called) + attr_reader :index_dsl + + # Define indexes within a block + # + # @api public + def indexes(&block) + @index_dsl = IndexDSL.new(**options, &block) + end + + private + + # Return schema options + # + # @api private + def opts + if index_dsl + opts = super + + { **opts, indexes: index_dsl.(relation, opts[:attributes]) } + else + super + end + end + end + end + end +end From 1fdb82cc68f910a17785a240a7adb853ca26a1e9 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 09:06:37 +0000 Subject: [PATCH 4/7] [compat] mark failing specs as pending for now --- .../associations/many_to_many/from_view_spec.rb | 2 ++ .../associations/many_to_one/from_view_spec.rb | 2 ++ .../associations/one_to_many/from_view_spec.rb | 2 ++ .../auto_migrations/file_based_migrations_spec.rb | 4 ++++ spec/integration/auto_migrations/indexes_spec.rb | 12 ++++++++++++ spec/integration/plugins/auto_restrictions_spec.rb | 4 +++- spec/integration/schema/view_spec.rb | 2 ++ spec/support/env_helper.rb | 4 ++++ 8 files changed, 31 insertions(+), 1 deletion(-) diff --git a/spec/integration/associations/many_to_many/from_view_spec.rb b/spec/integration/associations/many_to_many/from_view_spec.rb index 9fc190189..e471c240f 100644 --- a/spec/integration/associations/many_to_many/from_view_spec.rb +++ b/spec/integration/associations/many_to_many/from_view_spec.rb @@ -78,6 +78,8 @@ end it "prepares joined relations using custom FK" do + pending_if_compat_mode + relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:user_id].qualified) expect(relation.schema.map(&:to_sql_name)) diff --git a/spec/integration/associations/many_to_one/from_view_spec.rb b/spec/integration/associations/many_to_one/from_view_spec.rb index deed20942..b670a5f97 100644 --- a/spec/integration/associations/many_to_one/from_view_spec.rb +++ b/spec/integration/associations/many_to_one/from_view_spec.rb @@ -72,6 +72,8 @@ end it "prepares joined relations using custom view in target relation" do + pending_if_compat_mode + relation = assoc_inter.() expect(relation.schema.map(&:to_sql_name)) diff --git a/spec/integration/associations/one_to_many/from_view_spec.rb b/spec/integration/associations/one_to_many/from_view_spec.rb index 82f5fe764..c8191d1b3 100644 --- a/spec/integration/associations/one_to_many/from_view_spec.rb +++ b/spec/integration/associations/one_to_many/from_view_spec.rb @@ -50,6 +50,8 @@ end it "prepares joined relations using custom view" do + pending_if_compat_mode + relation = assoc.() expect(relation.schema.map(&:to_sql_name)) diff --git a/spec/integration/auto_migrations/file_based_migrations_spec.rb b/spec/integration/auto_migrations/file_based_migrations_spec.rb index d117ffec0..98bdc2afc 100644 --- a/spec/integration/auto_migrations/file_based_migrations_spec.rb +++ b/spec/integration/auto_migrations/file_based_migrations_spec.rb @@ -39,6 +39,8 @@ def migrations end it "creates migration files by schema definitions" do + pending_if_compat_mode + gateway.auto_migrate!(conf, options) expect(migrations.size).to eql(1) @@ -83,6 +85,8 @@ def migrations end it "creates migration files by schema definitions" do + pending_if_compat_mode + gateway.auto_migrate!(conf, options) expect(migrations.size).to eql(1) diff --git a/spec/integration/auto_migrations/indexes_spec.rb b/spec/integration/auto_migrations/indexes_spec.rb index 108f7e349..f30c99330 100644 --- a/spec/integration/auto_migrations/indexes_spec.rb +++ b/spec/integration/auto_migrations/indexes_spec.rb @@ -45,6 +45,8 @@ def indexdef(index) end it "creates ordinary b-tree indexes" do + pending_if_compat_mode + gateway.auto_migrate!(conf, inline: true) expect(attributes.map(&:to_ast)) @@ -98,6 +100,8 @@ def indexdef(index) end it "supports custom names" do + pending_if_compat_mode + conn.create_table :users do primary_key :id end @@ -124,6 +128,8 @@ def indexdef(index) end it "adds index to existing column" do + pending_if_compat_mode + conn.create_table :users do primary_key :id column :name, String @@ -150,6 +156,8 @@ def indexdef(index) end it "supports unique indexes" do + pending_if_compat_mode + conn.create_table :users do primary_key :id column :name, String @@ -177,6 +185,8 @@ def indexdef(index) if metadata[:postgres] it "uses index method" do + pending_if_compat_mode + conn.create_table :users do primary_key :id column :props, :jsonb, null: false @@ -200,6 +210,8 @@ def indexdef(index) end it "supports partial indexes" do + pending_if_compat_mode + conn.create_table :users do primary_key :id column :name, String diff --git a/spec/integration/plugins/auto_restrictions_spec.rb b/spec/integration/plugins/auto_restrictions_spec.rb index b4e87deb3..d21c27ab5 100644 --- a/spec/integration/plugins/auto_restrictions_spec.rb +++ b/spec/integration/plugins/auto_restrictions_spec.rb @@ -70,7 +70,9 @@ class Test::Tasks < ROM::Relation[:sql] include_context "auto-generated restriction view" - it "generates restrictrions by a composite index" do + it "generates restrictions by a composite index" do + pending_if_compat_mode + expect(tasks.by_user_id_and_title(1, "Jane's task").first).to eql(id: 2, user_id: 1, title: "Jane's task") end end diff --git a/spec/integration/schema/view_spec.rb b/spec/integration/schema/view_spec.rb index b4f01e537..29a4f20b8 100644 --- a/spec/integration/schema/view_spec.rb +++ b/spec/integration/schema/view_spec.rb @@ -23,6 +23,8 @@ end it "automatically projects a relation view" do + pending_if_compat_mode + expect(relations[:users].names.to_a) .to eql([{name: "Jade"}, {name: "Jane"}, {name: "Joe"}]) end diff --git a/spec/support/env_helper.rb b/spec/support/env_helper.rb index c8233bf64..9797c0525 100644 --- a/spec/support/env_helper.rb +++ b/spec/support/env_helper.rb @@ -24,4 +24,8 @@ def oracle?(example) def jruby? defined? JRUBY_VERSION end + + def pending_if_compat_mode + pending "FIXME: not working in compat mode yet" if ENV["ROM_COMPAT"] == "true" + end end From 85a4a20db79dcedaf84e479dc27e74364e2a02d1 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 09:07:08 +0000 Subject: [PATCH 5/7] [ci] run spec:compat --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9a351a7a..c4c385ffb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,7 @@ jobs: - name: Bundle install run: bundle install --jobs 4 --retry 3 - name: Run all tests - run: bundle exec rake + run: bundle exec rake spec spec:compat - name: Run codacy-coverage-reporter uses: codacy/codacy-coverage-reporter-action@master if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != '' From ec36fd538212a653da579c76cf49d3f903c12f17 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 09:15:46 +0000 Subject: [PATCH 6/7] [rubocop] address Layout/SpaceInsideHashLiteralBraces --- lib/rom/sql/schema/dsl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rom/sql/schema/dsl.rb b/lib/rom/sql/schema/dsl.rb index 46ff87449..5233e7d94 100644 --- a/lib/rom/sql/schema/dsl.rb +++ b/lib/rom/sql/schema/dsl.rb @@ -31,7 +31,7 @@ def opts if index_dsl opts = super - { **opts, indexes: index_dsl.(relation, opts[:attributes]) } + {**opts, indexes: index_dsl.(relation, opts[:attributes])} else super end From 549511a17ff16394fe8c6c5da9d9a1f5d5b116f9 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 15 Apr 2022 09:16:33 +0000 Subject: [PATCH 7/7] [rubocop] address offenses in Rakefile --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index cd9d4173f..63c0d9b2d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec)