Sha256: c013af4ed71e8434d5fe11681ce2fa2d6daff7f18efd4c674ffb7ec2dffb195f

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

RSpec.describe PlaceholderHelper, type: :helper do
  before do
    allow(helper).to receive(:controller_name).and_return('products')
    allow(helper).to receive(:action_name).and_return('index')
  end

  it 'fetches default key by controller action first' do
    I18n.backend.store_translations :en, placeholders: { products: { index: 'Nothing found' } }
    expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
  end

  it 'fetches default key by controller second' do
    I18n.backend.store_translations :en, placeholders: { products: { default: 'Nothing found' } }
    expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
  end

  it 'fetches default key by action third' do
    I18n.backend.store_translations :en, placeholders: { defaults: { index: 'Nothing found' } }
    expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
  end

  it 'fetches custom default key' do
    I18n.backend.store_translations :en, placeholders: { defaults: { foo: 'Nothing found' } }
    expect(helper.placeholder(:foo)).to eql('<p class="placeholder">Nothing found</p>')
  end

  it 'uses plain string' do
    expect(helper.placeholder('Nothing found')).to eql('<p class="placeholder">Nothing found</p>')
  end

  it 'allows using a custom tag' do
    expect(helper.placeholder('Nothing found', tag: :span)).to eql('<span class="placeholder">Nothing found</span>')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stationed-0.6.0 spec/helpers/placeholder_helper_spec.rb