Sha256: b3aed2e504f1cd687213f14392a68c69c0b91703b7d042c6df2cda0853549fc4

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Breadcrumby::Viewer, '.i18n_name' do
  subject { described_class.new object, options, view }

  let!(:object)  { build :school }
  let!(:options) { {} }
  let!(:view)    { double }

  context 'when :method_name responds with value' do
    before do
      allow(object).to receive(:breadcrumby_options) do
        {
          i18n_key:    :i18n_key,
          method_name: :custom_method_name
        }
      end

      allow(I18n).to receive(:t).with(:edit, default: 'Edition') { 'edit || Edition' }

      allow(I18n).to receive(:t).with(
        :name, scope: %i[breadcrumby i18n_key], default: :custom_method_name
      ) { 'translation' }
    end

    it 'uses the returned value as the object name' do
      expect(subject.i18n_name(object)).to eq 'translation'
    end
  end

  context 'when :method_name does not respond with value' do
    before do
      allow(object).to receive(:breadcrumby_options) do
        {
          i18n_key:    :i18n_key,
          method_name: :custom_method_name_nil
        }
      end

      allow(I18n).to receive(:t).with(:edit, default: 'Edition') { 'edit || Edition' }

      allow(I18n).to receive(:t).with(
        :name, scope: %i[breadcrumby i18n_key], default: '--'
      ) { 'translation' }
    end

    it 'uses a default name as fallback' do
      expect(subject.i18n_name(object)).to eq 'translation'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
breadcrumby-0.1.0 spec/lib/breadcrumby/models/viewer/i18n_name_spec.rb