Sha256: c11268c65e7c1d27f7d1fbcd441567151b5f57508ea86e64454293b3365794f5

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Azeroth::Options do
  subject(:options) { described_class.new }

  describe 'validation' do
    context 'when initializing with invalid options' do
      it do
        expect { described_class.new(invalid_option: 1) }
          .to raise_error(Azeroth::Exception::InvalidOptions)
      end
    end
  end

  describe '#actions' do
    it 'returns default actions' do
      expect(options.actions)
        .to eq(%i[create destroy edit index new show update])
    end

    context 'when passing only options' do
      subject(:options) { described_class.new(only: [:index]) }

      it 'returns defined actions' do
        expect(options.actions)
          .to eq(%i[index])
      end

      context 'when not passing an array' do
        subject(:options) { described_class.new(only: :index) }

        it 'returns defined actions as array' do
          expect(options.actions)
            .to eq(%i[index])
        end
      end
    end

    context 'when passing except options' do
      subject(:options) do
        described_class.new(except: %i[index create])
      end

      it 'returns not excluded actions' do
        expect(options.actions)
          .to eq(%i[destroy edit new show update])
      end

      context 'when not passing an array' do
        subject(:options) { described_class.new(except: :index) }

        it 'returns not excluded actions' do
          expect(options.actions)
            .to eq(%i[create destroy edit new show update])
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
azeroth-0.6.1 spec/lib/azeroth/options_spec.rb
azeroth-0.6.0 spec/lib/azeroth/options_spec.rb
azeroth-0.5.0 spec/lib/azeroth/options_spec.rb
azeroth-0.4.0 spec/lib/azeroth/options_spec.rb