Sha256: 351a1d153b6f7d1b8be43a1a179fd49cc7ee6029e2db7460797f2dfdf88980c3

Contents?: true

Size: 1012 Bytes

Versions: 2

Compression:

Stored size: 1012 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(NameError) }
    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.2.2 spec/findable/associations/utils_spec.rb
findable-0.2.1 spec/findable/associations/utils_spec.rb