Sha256: 6f59e25021f2b37bf7562d5ef5f1169c4157ecf6877356b0704e106023047673

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

describe ServiceObjects::Helpers::Parameters do

  let(:test_class) { Class.new }
  before  { test_class.include described_class }
  subject { test_class.new }

  describe "#params" do

    subject { test_class.new }

    it "returns a hash" do
      expect(subject.params).to be_kind_of Hash
    end

  end # describe #params

  describe ".whitelist" do

    it "is defined" do
      expect(test_class).to respond_to :whitelist
      expect { test_class.instance_eval "@whitelist = [:foo]" }
        .to change { test_class.whitelist }
        .to [:foo]
    end

    it "returns empty array by default" do
      expect(test_class.whitelist).to eq []
    end

  end # describe #whitelist

  describe ".new" do

    before { allow(test_class).to receive(:whitelist) { [:foo, :bar] } }

    it "allows options" do
      expect(test_class).to respond_to(:new).with(1).argument
    end

    it "makes params optional" do
      expect(test_class).to respond_to(:new).with(0).argument
    end

    it "assings parameters from options" do
      options = { foo: "foo" }

      subject = test_class.new options
      expect(subject.params).to eq options
    end

    it "symbolizes options keys at any level" do
      source_options = { "foo" => "foo", "bar" => { "bar" => "baz" } }
      target_options = { foo: "foo", bar: { bar: "baz" } }

      subject = test_class.new(source_options)
      expect(subject.params).to eq target_options
    end

    it "filters options" do
      source_options = { foo: "foo", baz: "baz" }
      target_options = { foo: "foo" }

      subject = test_class.new(source_options)
      expect(subject.params).to eq target_options
    end

  end # describe .new

end # describe ServiceObjects::Helpers::Whitelist

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
service_objects-0.1.0 spec/tests/helpers/parameters_spec.rb
service_objects-0.0.2 spec/tests/helpers/parameters_spec.rb
service_objects-0.0.1 spec/tests/helpers/parameters_spec.rb