Sha256: 7ce677a7cadd28cc3e5978020a06f2622608a952892df3d3e4e39ebea69c9527

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 Bytes

Contents

require "spec_helper"

describe Findable::Associations::Utils do
  let(:utils) { Findable::Associations::Utils }

  describe "#model_for" do
    include_context "TemporaryModel"
    let(:model_name) { model.model_name }

    it { expect(utils.model_for(model_name.singular)).to eq(model) }
    it { expect(utils.model_for(model_name.plural, collection: true)).to eq(model) }
    it { expect(utils.model_for("invalid", class_name: model_name.name)).to eq(model) }

    it { expect { utils.model_for("invalid") }.to raise_error }
    it { expect { utils.model_for("invalid", safe: true) }.not_to raise_error }
    it { expect(utils.model_for("invalid", safe: true)).to be_nil }
  end

  describe "#parse_args" do
    let(:parsed_args) { [:some_name, {class_name: "SomeClass"}] }
    let(:args) { [parsed_args.first, **parsed_args.last] }

    it { expect(utils.parse_args(args)).to eq(parsed_args) }

    it {
      expect {
        utils.parse_args(args)
      }.not_to change { args }
    }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
findable-0.2.0 spec/findable/associations/utils_spec.rb
findable-0.1.5 spec/findable/associations/utils_spec.rb
findable-0.1.4 spec/findable/associations/utils_spec.rb