diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9a351a7..c4c385ff 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 != '' diff --git a/Rakefile b/Rakefile index 571441d1..63c0d9b2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,13 @@ +# frozen_string_literal: true + 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/lib/rom/sql/relation.rb b/lib/rom/sql/relation.rb index 79d37b04..6c6b3aa9 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 00000000..5233e7d9 --- /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 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 9fc19018..e471c240 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 deed2094..b670a5f9 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 82f5fe76..c8191d1b 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 d117ffec..98bdc2af 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 108f7e34..f30c9933 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 b4e87deb..d21c27ab 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 b4f01e53..29a4f20b 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/integration/setup_spec.rb b/spec/integration/setup_spec.rb index bbf8fec7..e2a33927 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2719e462..1b5a3e5b 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" diff --git a/spec/support/env_helper.rb b/spec/support/env_helper.rb index c8233bf6..9797c052 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