Sha256: a5f6c1a0bffcf53c202085f7d83ac40772db96a51d21874df095088377e509b9

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe '.to_param' do
  context 'when object does not acts as idy' do
    subject { Clean.new id: 1 }

    it 'behaves as default' do
      expect(subject.to_param).to eq '1'
    end
  end

  context 'when object acts as idy' do
    context 'with no given salt' do
      let!(:model_1) { Article.new id: 1 }

      it 'generates a hash' do
        expect(model_1.to_param).to eq 'My'
      end

      context 'with comparison' do
        let!(:model_2) { Post.new }

        context 'with other object with same id' do
          before { model_2.id = 1 }

          it 'generates different hash' do
            expect(model_1.to_param).not_to eq model_2.to_param
          end
        end
      end

      context 'when object is not persisted' do
        context 'and has no id' do
          subject { Article.new }

          specify { expect(subject.to_param).to be_nil }
        end

        context 'and has id' do
          subject { Article.new id: 1 }

          it 'generates a hash' do
            expect(model_1.to_param).to eq 'My'
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
idy-0.1.3 spec/lib/idy/extension/to_param_spec.rb
idy-0.1.2 spec/lib/idy/extension/to_param_spec.rb
idy-0.1.1 spec/lib/idy/extension/to_param_spec.rb