Sha256: c8e7da9b2b344e78dff8c8211794b5a78f3ca7b99482727a9aff3457e460179c

Contents?: true

Size: 1.94 KB

Versions: 7

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

describe Rewritten::Document do

  before do
    class Product
      include Rewritten::Document
    end
    @instance = Product.new
    def @instance.polymorphic_url(object, options={}); '/products/123'; end
    def @instance.persisted?; true; end
  end

  it 'must add the rewritten methods to the class' do
    @instance.respond_to?(:rewritten_url=).must_equal true
    @instance.respond_to?(:rewritten_url).must_equal true
    @instance.respond_to?(:has_rewritten_url?).must_equal true
  end

  it 'must return empty string when not persisted' do

    def @instance.persisted?; false; end

    @instance.rewritten_url.must_equal "" 
  end

  it 'must return translation when persisted' do
    Rewritten.add_translation('/foo/bar', '/products/123') 
    @instance.rewritten_url.must_equal '/foo/bar'
  end

  it 'must return all translations as array' do

    Rewritten.add_translation('/foo/bar', '/products/123')
    Rewritten.add_translation('/foo/baz', '/products/123')

    @instance.rewritten_urls.must_equal ['/foo/bar', '/foo/baz']         
  end

  it 'must add a new translation' do
    @instance.has_rewritten_url?.must_equal false
    @instance.rewritten_url = '/foo/baz'  
    Rewritten.get_current_translation('/products/123').must_equal '/foo/baz'
    @instance.has_rewritten_url?.must_equal true
  end

  it 'must remove all translation' do
    @instance.rewritten_url = '/foo/bar'  
    @instance.rewritten_url = '/foo/baz'  
    @instance.remove_rewritten_urls
    @instance.rewritten_urls.must_equal []
  end

  it 'must won\'t add blank and similar translations' do
    @instance.rewritten_url = '/foo/bar'  
    @instance.rewritten_urls.must_equal ['/foo/bar']
    @instance.rewritten_url = nil
    @instance.rewritten_urls.must_equal ['/foo/bar']
    @instance.rewritten_url = ""
    @instance.rewritten_urls.must_equal ['/foo/bar']
    @instance.rewritten_url = "/foo/bar"
    @instance.rewritten_urls.must_equal ['/foo/bar']
  end

end




Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rewritten-0.15.0 test/rewritten/document_test.rb
rewritten-0.14.2 test/rewritten/document_test.rb
rewritten-0.14.1 test/rewritten/document_test.rb
rewritten-0.14.0 test/rewritten/document_test.rb
rewritten-0.13.1 test/rewritten/document_test.rb
rewritten-0.13.0 test/rewritten/document_test.rb
rewritten-0.12.1 test/rewritten/document_test.rb