Sha256: 0b14ca527de860f1686fa4f62d35099e496a80896d6cc9bdb4d95a1c33c38b75

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

RSpec.describe HasStates do
  it 'has a version number' do
    expect(HasStates::VERSION).not_to be_nil
  end

  it 'has a configuration' do
    expect(described_class.configuration).to be_a(HasStates::Configuration)
  end

  describe 'configuration' do
    before do
      described_class.configure do |config|
        # User configuration
        config.configure_model User do |model|
          model.state_type :kyc do |type|
            type.statuses = %w[pending completed]
          end

          model.state_type :onboarding do |type|
            type.statuses = %w[started finished]
          end
        end

        # Company configuration
        config.configure_model Company do |model|
          model.state_type :procurement do |type|
            type.statuses = %w[in_progress completed failed]
          end
        end
      end
    end

    it 'configures the state types for User' do
      expect(described_class.configuration.state_types_for(User).keys).to eq(%w[kyc onboarding])
    end

    it 'configures the statuses for User' do
      expect(described_class.configuration.statuses_for(User, 'kyc')).to eq(%w[pending completed])
      expect(described_class.configuration.statuses_for(User, 'onboarding')).to eq(%w[started finished])
    end

    it 'configures the state types for Company' do
      expect(described_class.configuration.state_types_for(Company).keys).to eq(['procurement'])
    end

    it 'configures the statuses for Company' do
      expect(described_class.configuration.statuses_for(Company, 'procurement')).to eq(%w[in_progress completed failed])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stateful_models-0.0.3 spec/has_states_spec.rb
stateful_models-0.0.2 spec/has_states_spec.rb
stateful_models-0.0.1 spec/has_states_spec.rb