Sha256: def461e7255884a0446b7ea927efb09369fe91be210aef294c02560f05074324

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require File.expand_path('../spec_helper', __FILE__)

describe Mongoid::Permalinks do
  it 'adds permalink field' do
    Document.fields['permalink'].type.must_equal String
  end


  describe 'setting permalink' do
    subject { Document.create(permalink: permalink, name: 'Name') }
    let(:value) { subject.permalink }


    describe 'providing an empty permalink' do
      let(:permalink) { '' }


      it 'parameterizes name instead' do
        value.must_equal 'name'
      end
    end


    describe 'providing an permalink' do
      let(:permalink) { 'custom permalink' }


      it 'parameterizes it' do
        value.must_equal 'custom-permalink'
      end
    end


    describe 'providing an permalink with trailing spaces' do
      let(:permalink) { '  custom permalink  ' }


      it 'parameterizes it and removes the spaces' do
        value.must_equal 'custom-permalink'
      end
    end


    describe 'providing an permalink with special characters' do
      let(:permalink) { 'Donald E. Knuth' }


      it 'parameterizes it and makes it pretty' do
        value.must_equal 'donald-e-knuth'
      end
    end
  end


  describe 'having localized permalink fields' do
    subject { Localized.new }


    it 'works too' do
      { en: 'English', de: 'Deutsch' }.each do |locale, permalink|
        I18n.locale = locale
        subject.permalink = permalink
        subject.save
        
        subject.permalink.must_equal permalink.parameterize
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-permalinks-0.2.0 spec/permalinks_spec.rb