Sha256: 36fb480c4228ba7f1282e08df9574971cde70531d3976cd91c22aafb90d02c18

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Article do
  context 'on reload' do
    subject { described_class.create id: 42, title: 'title' }

    it 'reloads' do
      record = described_class.find(subject.to_param)

      record.update_attribute :title, 'title.updated'

      expect(subject.title).to        eq 'title'
      expect(subject.reload.title).to eq 'title.updated'
    end

    context 'while locking' do
      it 'does not throw an error' do
        expect(-> { subject.lock! }).not_to raise_error
      end
    end
  end

  context 'finding one record as id' do
    subject { described_class.find record.id }

    let!(:record) { described_class.create id: 42, title: 'title-1' }

    specify { expect(subject).to eq record }
  end

  context 'finding one record as idy' do
    subject { described_class.find record.to_param }

    let!(:record) { described_class.create id: 42, title: 'title-1' }

    specify { expect(subject).to eq record }
  end

  context 'finding multiple records' do
    subject { described_class.find [record_1.to_param, record_2.to_param] }

    let!(:record_1) { described_class.create id: 42, title: 'title-1' }
    let!(:record_2) { described_class.create id: 1 , title: 'title-2' }

    it 'finds all' do
      expect(subject).to eq [record_1, record_2]
    end
  end

  context 'finding via has_many' do
    let!(:article) { described_class.create }
    let!(:comment) { Comment.create article: article }

    specify { expect(article.comments.find(comment.id)).to eq comment }
  end

  context 'finding a class with no callback declared' do
    let!(:record) { Clean.create }

    context 'of one record' do
      specify { expect(Clean.find(record.id)).to eq record }
    end

    context 'of multiple record' do
      let!(:record_2) { Clean.create }

      specify do
        expect(Clean.find([record.id, record_2.id])).to eq [record, record_2]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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