Sha256: 8dc5bae470038bd15f75f79471854b22a78a8e5c7b4b97e369a47e97cd50307e

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe AffairsOfState::Config do
  let(:config) do
    AffairsOfState::Config.new(
      statuses: statuses,
      column: column,
      allow_blank: allow_blank,
      scopes: scopes,
      if: if_condition,
      prefix: prefix
    )
  end
  let(:column) { "state" }
  let(:statuses) { [ :created, [ :destroyed ] ] }
  let(:allow_blank) { "sure" }
  let(:scopes) { nil }
  let(:if_condition) { "false" }
  let(:prefix) { nil }

  subject { config }

  describe "accessors" do
    it "has :column" do
      expect(subject.column).to eq(column)
    end

    it "has :allow_blank" do
      expect(subject.allow_blank).to be(true)
    end

    it "has :scopes" do
      expect(subject.scopes).to be(false)
    end

    it "has :if" do
      expect(subject.if).to eq(if_condition)
    end

    it "has :statuses and converts to strings and flattens" do
      expect(subject.statuses).to eq(["created", "destroyed"])
    end

    it "has :methods_for_statuses which is the same key values" do
      expect(subject.methods_for_statuses).to eq({ "created" => "created", "destroyed" => "destroyed" })
    end
  end

  context "with invalid status" do
    let(:statuses) { [ "new" ] }

    it "makes sure no invalid statuses are allowed" do
      expect { subject }.to raise_error(ArgumentError, "Affairs of State: 'new' is not a valid status")
    end
  end

  context "with prefix" do
    let(:prefix) { :admin }

    it "has :statuses just the same" do
      expect(subject.statuses).to eq(["created", "destroyed"])
    end

    it "has :methods_for_statuses" do
      expect(subject.methods_for_statuses).to eq({ "created" => "admin_created", "destroyed" => "admin_destroyed" })
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
affairs_of_state-0.7.2 spec/config_spec.rb
affairs_of_state-0.7.1 spec/config_spec.rb