public
Description: routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
Homepage: http://www.artweb-design.de
Clone URL: git://github.com/svenfuchs/routing-filter.git
svenfuchs (author)
Wed Apr 15 08:49:37 -0700 2009
commit  d4e0f1f2b8f4c0476d3ea3a6a391d2a341d25881
tree    bff82b5a8129fef1020a8b2fcf4d671434c0be68
parent  d646cbb08b1fa23eaa4c2dd77f3b6195a2c37e5e
routing-filter / spec / routing_filter_spec.rb
100644 55 lines (44 sloc) 2.308 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require File.dirname(__FILE__) + '/spec_helper.rb'
 
describe 'RoutingFilter' do
  include RoutingFilterHelpers
 
  before :each do
    setup_environment :locale, :pagination
  end
 
  def recognize_path(path = '/de/sections/1', options = {})
    @set.recognize_path path, options
  end
 
  it 'installs filters to the route set' do
    @locale_filter.should be_instance_of(RoutingFilter::Locale)
    @pagination_filter.should be_instance_of(RoutingFilter::Pagination)
  end
 
  it 'calls the first filter for route recognition' do
    @locale_filter.should_receive(:around_recognize).and_return :foo => :bar
    recognize_path.should == {:foo => :bar}
  end
 
  it 'calls the second filter for route recognition' do
    @pagination_filter.should_receive(:around_recognize).and_return :foo => :bar
    recognize_path.should == {:foo => :bar}
  end
 
  it 'calls the first filter for url generation' do
    @locale_filter.should_receive(:around_generate).and_return '/en/sections/1'
    url_for :controller => 'sections', :action => 'show', :section_id => 1
  end
 
  it 'calls the second filter for url generation' do
    @pagination_filter.should_receive(:around_generate).and_return '/en/sections/1'
    url_for :controller => 'sections', :action => 'show', :section_id => 1
  end
 
  it 'calls the first filter for named route url_helper' do
    @locale_filter.should_receive(:around_generate).and_return '/en/sections/1'
    section_path :section_id => 1
  end
 
  it 'calls the filter for named route url_helper with "optimized" generation blocks' do
    # at_least(1) since the inline code comments in ActionController::Routing::RouteSet::NamedRouteCollection#define_url_helper also call us (as of http://github.com/rails/rails/commit/a2270ef2594b97891994848138614657363f2806)
    @locale_filter.should_receive(:around_generate).at_least(1).and_return '/en/sections/1'
    section_path 1
  end
 
  it 'calls the filter for named route polymorphic_path' do
    # at_least(1) since the inline code comments in ActionController::Routing::RouteSet::NamedRouteCollection#define_url_helper also call us (as of http://github.com/rails/rails/commit/a2270ef2594b97891994848138614657363f2806)
    @locale_filter.should_receive(:around_generate).at_least(1).and_return '/en/sections/1'
    section_path Section.new
  end
end