Sha256: f372cd20d8cd24965929e6281c9cf1c0199c55e6169e27ff624c2c962e73f7eb

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe ForeignKeyValidation do

  describe ".configuration" do

    it "initializes configuration as open struct" do
      expect(subject.configuration).to be_instance_of OpenStruct
    end

    it "defaults to true for injecting subclasses" do
      expect(subject.configuration.inject_subclasses).to eq true
    end

    it "defaults to proc for error messages" do
      expect(subject.configuration.error_message).to be_a Proc
      expect(subject.configuration.error_message.call(nil,nil,nil)).to match /does not match/
    end

    it "defaults to :user for validate against key" do
      expect(subject.configuration.validate_against).to eq :user
    end

    it "defaults to nil for unknown config options" do
      expect(subject.configuration.foo_bar).to eq nil
    end

  end

  describe ".configure" do

    it "allow change of inject_subclasses config" do
      subject.configure {|c| c.inject_subclasses = false}
      expect(subject.configuration.inject_subclasses).to eq false
    end

    it "allow change of error_message config" do
      subject.configure {|c| c.error_message = proc { "MY MSG" }}
      expect(subject.configuration.error_message.call).to eq "MY MSG"
    end

    it "allow change of validate_against config" do
      subject.configure {|c| c.validate_against = :my_user}
      expect(subject.configuration.validate_against).to eq :my_user
    end

  end

  describe ".reset_configuration" do

    it "allow reset of config" do
      subject.configure {|c| c.validate_against = :my_user}
      subject.reset_configuration
      expect(subject.configuration.validate_against).to eq :user
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreign_key_validation-1.1.2 spec/config_spec.rb