Sha256: 90f3a2ab57cd8662289ba6fe0d789f10682b57a0ab38c0621bd14e3f0f3ab48c

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 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

2 entries across 2 versions & 1 rubygems

Version Path
findable-0.1.3 spec/findable/associations/utils_spec.rb
findable-0.1.2 spec/findable/associations/utils_spec.rb