Sha256: 4f6df55ab477abb8d67cd762289b6e9680e47c91571eb3a33ddc75fc89dffd8c

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe 'ROM::CommandRegistry' do
  subject(:env) { setup.finalize }

  let(:setup) { ROM.setup(:memory) }
  let(:users) { env.command(:users) }

  before do
    setup.relation(:users)

    setup.commands(:users) do
      define(:create) do
        validator proc { |input| raise(ROM::CommandError) unless input[:name] }
      end
    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

9 entries across 9 versions & 1 rubygems

Version Path
rom-0.9.1 spec/unit/rom/command_registry_spec.rb
rom-0.9.0 spec/unit/rom/command_registry_spec.rb
rom-0.9.0.rc1 spec/unit/rom/command_registry_spec.rb
rom-0.9.0.beta1 spec/unit/rom/command_registry_spec.rb
rom-0.8.1 spec/unit/rom/command_registry_spec.rb
rom-0.8.0 spec/unit/rom/command_registry_spec.rb
rom-0.7.1 spec/unit/rom/command_registry_spec.rb
rom-0.7.0 spec/unit/rom/command_registry_spec.rb
rom-0.6.2 spec/unit/rom/command_registry_spec.rb