Module: Cuprum::Collections::RSpec::Contracts::Basic::CommandContracts::WithBasicCommandContextsContract

Extended by:
RSpec::SleepingKingStudios::Contract
Defined in:
lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb

Overview

Contract defining contexts for validating basic commands.

Instance Method Summary collapse

Instance Method Details

#apply(example_group) ⇒ Object

Adds the contract to the example group.

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    the example group to which the contract is applied.



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb', line 418

contract do
  shared_context 'with parameters for a basic contract' do
    let(:collection_name)     { 'books' }
    let(:data)                { [] }
    let(:mapped_data)         { data }
    let(:constructor_options) { {} }
    let(:expected_options)    { {} }
    let(:primary_key_name)    { :id }
    let(:primary_key_type)    { Integer }
    let(:entity_type) do
      Stannum::Constraints::Types::HashWithStringKeys.new
    end
    let(:fixtures_data) do
      Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup
    end
    let(:query) do
      Cuprum::Collections::Basic::Query.new(mapped_data)
    end
    let(:scope) do
      Cuprum::Collections::Basic::Query
        .new(mapped_data).where(scope_filter)
    end
  end

  shared_context 'with a custom primary key' do
    let(:primary_key_name) { :uuid }
    let(:primary_key_type) { String }
    let(:constructor_options) do
      super().merge(
        primary_key_name: primary_key_name,
        primary_key_type: primary_key_type
      )
    end
    let(:mapped_data) do
      data.map do |item|
        item.dup.tap do |hsh|
          value = hsh.delete('id').to_s.rjust(12, '0')

          hsh['uuid'] = "00000000-0000-0000-0000-#{value}"
        end
      end
    end
    let(:invalid_primary_key_value) do
      '00000000-0000-0000-0000-000000000100'
    end
    let(:valid_primary_key_value) do
      '00000000-0000-0000-0000-000000000000'
    end
    let(:invalid_primary_key_values) do
      %w[
        00000000-0000-0000-0000-000000000100
        00000000-0000-0000-0000-000000000101
        00000000-0000-0000-0000-000000000102
      ]
    end
    let(:valid_primary_key_values) do
      %w[
        00000000-0000-0000-0000-000000000000
        00000000-0000-0000-0000-000000000001
        00000000-0000-0000-0000-000000000002
      ]
    end
  end
end