Sha256: 31417eeff2ffc985e09a0cda9b24699aa2f785c2ec3633f0c85b6731e0b4a944

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

RSpec.describe 'Plugins / :auto_restrictions', seeds: true do
  include_context 'users and tasks'

  with_adapters do
    before do
      conn.add_index :tasks, :title, unique: true
    end

    shared_context 'auto-generated restriction view' do
      it 'defines restriction views for all indexed attributes' do
        expect(tasks.select(:id).by_title("Jane's task").one).to eql(id: 2)
      end

      it 'defines curried methods' do
        expect(tasks.by_title.("Jane's task").first).to eql(id: 2, user_id: 1, title: "Jane's task")
      end
    end

    context 'with an inferred schema' do
      before do
        conf.plugin(:sql, relations: :auto_restrictions)
      end

      include_context 'auto-generated restriction view'
    end

    context 'with explicit schema' do
      before do
        conf.relation(:tasks) do
          schema do
            attribute :id, ROM::SQL::Types::Serial
            attribute :user_id, ROM::SQL::Types::Int
            attribute :title, ROM::SQL::Types::String.meta(index: true)
          end

          use :auto_restrictions
        end
      end

      include_context 'auto-generated restriction view'
    end

    it 'raises error when enabled w/o a schema' do
      expect {
        conf.relation(:tasks) do
          use :auto_restrictions
        end
      }.to raise_error(
             ROM::Plugins::Relation::SQL::AutoRestrictions::EmptySchemaError,
             "ROM::Relation[Tasks] relation has no schema. Make sure :auto_restrictions is enabled after defining a schema"
           )
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-sql-1.3.5 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.3.4 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.3.3 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.3.2 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.3.1 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.3.0 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.2.2 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.2.1 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.2.0 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.1.2 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.1.1 spec/integration/plugins/auto_restrictions_spec.rb
rom-sql-1.1.0 spec/integration/plugins/auto_restrictions_spec.rb