Sha256: 8b84c1a36632b84c827c6af30ee4659c5c6b3083a78a0fa111593b39b4cb0f85

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe 'Commands' do
  include_context 'container'
  include_context 'users and tasks'

  before do
    configuration.relation(:users) do
      def by_id(id)
        restrict(id: id)
      end
    end
    configuration.commands(:users) do
      define(:update)
    end
  end

  let(:command) { container.command(:users)[:update] }

  describe '#method_missing' do
    it 'forwards known relation view methods' do
      expect(command.by_id(1).relation).to eql(users_relation.by_id(1))
    end

    it 'raises no-method error when a non-view relation method was sent' do
      expect { command.as(:foo) }.to raise_error(NoMethodError, /as/)
    end
  end

  describe 'extending command with a db-specific behavior' do
    before do
      gateway.instance_exec do
        def extend_command_class(klass, _)
          klass.class_eval do
            def super_command?
              true
            end
          end
          klass
        end
      end
    end

    it 'applies to defined classes' do
      klass = Class.new(ROM::Commands::Create[:memory]) { relation :users }
      configuration.register_command(klass)
      container
      command = klass.build(users_relation)
      expect(command).to be_super_command
    end

    it 'applies to generated classes' do
      klass = ROM::ConfigurationDSL::Command.build_class(:create, :users, adapter: :memory)
      configuration.register_command(klass)
      container
      command = klass.build(users_relation)
      expect(command).to be_super_command
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-1.0.0 spec/integration/commands_spec.rb
rom-1.0.0.rc1 spec/integration/commands_spec.rb
rom-1.0.0.beta2 spec/integration/commands_spec.rb
rom-1.0.0.beta1 spec/integration/commands_spec.rb