categories_menu_test.rb
1.67 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
require "#{File.dirname(__FILE__)}/../test_helper"
class CategoriesMenuTest < ActionController::IntegrationTest
def setup
HomeController.any_instance.stubs(:get_layout).returns('application')
SearchController.any_instance.stubs(:get_layout).returns('application')
Category.delete_all
@cat1 = Category.create!(:display_in_menu => true, :name => 'Food', :environment => Environment.default, :display_color => 1)
@cat2 = Category.create!(:display_in_menu => true, :name => 'Vegetables', :environment => Environment.default, :parent => @cat1)
# all categories must be shown for these tests
Category.any_instance.stubs(:display_in_menu?).returns(true)
end
should 'display link to categories' do
get '/'
assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
end
should 'display link to sub-categories' do
get '/cat/food'
# there must be a link to the subcategory
assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
end
should "always link to category's initial page in category menu" do
get '/search/products/food/vegetables'
assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
assert_no_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/searchh/products/food/vegetables' } }
end
should 'cache the categories menu' do
ActionView::Base.any_instance.expects(:cache).with(Environment.default.id.to_s + "_categories_menu")
get '/'
end
end