Sha256: 691cf9af1916143128312e1a90ff2e92baf6ade25ef72bf264a143c56224855f

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe 'ROM::CommandRegistry' do
  include_context 'container'

  let(:users) { container.command(:users) }

  before do
    configuration.relation(:users)

    configuration.register_command(Class.new(ROM::Commands::Create[:memory]) do
      register_as :create
      relation :users
      validator proc { |input| raise(ROM::CommandError) unless input[:name] }
    end)
  end

  describe '#try' do
    it 'returns a success result object on successful execution' do
      result = users.try { users.create.call(name: 'Jane') }

      expect(result).to match_array([{ name: 'Jane' }])
    end

    it 'returns a success result on successful curried-command execution' do
      result = users.try { users.create.curry(name: 'Jane') }

      expect(result).to match_array([{ name: 'Jane' }])
    end

    it 'returns a failure result object on failed execution' do
      result = users.try { users.create.call({}) }

      expect(result.value).to be(nil)
    end

    it 'returns a failure result on unsuccessful curried-command execution' do
      result = users.try { users.create.curry({}) }

      expect(result.value).to be(nil)
    end

    it 'allows checking if a command is available using respond_to?' do
      expect(users).to respond_to(:create)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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