Sha256: 538f42dbf360ec39f19b5f7dc5b524088c4581dbb2f0ca7f11b1d56288b2313c

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe MetaTags::TextNormalizer, '.normalize_title' do
  context 'when site_title is blank' do
    it 'should return title when site_title is blank' do
      expect(subject.normalize_title(nil, 'title', '-')).to eq('title')
      expect(subject.normalize_title('', 'title', '-')).to eq('title')
    end

    it 'should join title parts with separator' do
      expect(subject.normalize_title('', %w[title subtitle], '-')).to eq('title-subtitle')
    end

    it 'should reverse title parts when reverse is true' do
      expect(subject.normalize_title('', %w[title subtitle], '-', true)).to eq('subtitle-title')
    end
  end

  context 'when site_title is specified' do
    it 'should join title and site_title with separator' do
      expect(subject.normalize_title('site', 'title', '-')).to eq('site-title')
    end

    it 'should join title parts and site_title with separator' do
      expect(subject.normalize_title('site', %w[title subtitle], '-')).to eq('site-title-subtitle')
    end

    it 'should reverse title parts when reverse is true' do
      expect(subject.normalize_title('site', %w[title subtitle], '-', true)).to eq('subtitle-title-site')
    end

    it 'should not add title when site title is longer than limit' do
      site_title = 'a' * (MetaTags.config.title_limit - 2)
      expect(subject.normalize_title(site_title, 'title', '---')).to eq(site_title[0..-2])
    end

    it 'should truncate title when limit is reached' do
      site_title = 'a' * 20
      title = 'b' * (MetaTags.config.title_limit + 10)
      expect(subject.normalize_title(site_title, title, '-')).to eq("#{site_title}-#{'b' * (MetaTags.config.title_limit - 21)}")
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
meta_tags-rails-1.1.1 spec/text_normalizer/normalize_title_spec.rb
meta_tags-rails-1.1.0 spec/text_normalizer/normalize_title_spec.rb
meta_tags-rails-1.0.0 spec/text_normalizer/normalize_title_spec.rb
meta-tags-2.1.0 spec/text_normalizer/normalize_title_spec.rb