Sha256: 03742f760aee8c4455818b38015ce648faee9c29f3a295f1dc5646f045b7bf29

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe PolymorphicUrlCache do
  before do
    @view = Class.new(ActionView::Base) { include Rails.application.routes.url_helpers }.new
    PolymorphicUrlCache::URL_FOR_CACHE.clear
  end

  describe 'url_for' do
    context 'when an AR object was given' do
      describe 'conferences_path' do
        before do
          @view.url_for(Conference.new)
        end
        specify do
          assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 1 }
          assert { PolymorphicUrlCache::URL_FOR_CACHE.first == [[Conference, nil], "/conferences"] }
        end
      end

      describe 'conference_path' do
        before do
          @conference = Conference.create!
          @view.url_for(@conference)
        end
        specify do
          assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 1 }
          assert { PolymorphicUrlCache::URL_FOR_CACHE.first == [[Conference, @conference.id.to_s], "/conferences/#{@conference.id.to_s}"] }
        end
      end
    end

    context 'when something else than an AR object was given' do
      before do
        @view.url_for('/foo')
      end
      specify do
        assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 0 }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polymorphic_url_cache-0.0.1 spec/polymorphic_url_cache_spec.rb