Sha256: 9b2ded02a3ba86aa10dd161f9466a4f0efc6f1c8a4f13e96c489dce830f45e66

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'

RSpec.describe 'Fish0::Base' do
  let!(:headline) { FFaker::Lorem.sentence }
  let!(:article) { create(:article, headline: headline) }
  let!(:other_article) { create(:article) }

  describe '.find_one' do
    subject { Article.find_one(query) }

    context 'when article with such headline exists in the database' do
      let(:query) { { headline: headline } }
      it { is_expected.to eq(article) }
    end

    context 'when there is no such article in database' do
      let(:query) { { headline: 'кирриллица' } }
      it { is_expected.to be_nil }
    end
  end

  describe '.find_one!' do
    subject { Article.find_one!(query) }

    context 'when article with such headline exists in the database' do
      let(:query) { { headline: headline } }
      it { is_expected.to eq(article) }
    end

    context 'when there is no such article in database' do
      let(:query) { { headline: 'кирриллица' } }
      it 'raises exception' do
        expect { subject }.to raise_error(Fish0::RecordNotFound)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fish0-0.0.16 spec/base_spec.rb
fish0-0.0.15 spec/base_spec.rb