Commit f8f5e910c200f8d0df9c20b0d65d8327ac27e3da
1 parent
fce8bd40
Exists in
master
and in
22 other branches
Test CatalogHelper
ActionItem896
Showing
1 changed file
with
58 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,58 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class CatalogHelperTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + include CatalogHelper | |
| 6 | + include ActionView::Helpers::TextHelper | |
| 7 | + include ActionView::Helpers::UrlHelper | |
| 8 | + include ActionView::Helpers::TagHelper | |
| 9 | + include ActionController::Assertions::SelectorAssertions | |
| 10 | + | |
| 11 | + def url_for(opts) | |
| 12 | + #{:controller => 'catalog', :action => 'index', :level => category.id} | |
| 13 | + "#{opts[:controller]}-#{opts[:action]}-level=#{opts[:level]}" | |
| 14 | + end | |
| 15 | + | |
| 16 | + def new_productcategory(parent, name) | |
| 17 | + cat = ProductCategory.new( | |
| 18 | + :name => name, :environment => Environment.default, :parent => parent | |
| 19 | + ) | |
| 20 | + cat if cat.save | |
| 21 | + end | |
| 22 | + | |
| 23 | + def setup | |
| 24 | + @enterprise = Enterprise.create! :name => 'Test Enterprise', | |
| 25 | + :identifier => 'testenterprise', | |
| 26 | + :environment => Environment.default | |
| 27 | + @profile = @enterprise | |
| 28 | + @block = @enterprise.blocks.select{|b| b.class == ProductCategoriesBlock }[0] | |
| 29 | + @products = new_productcategory nil, 'Products' | |
| 30 | + @food = new_productcategory @products, 'Food' | |
| 31 | + @vegetables = new_productcategory @food, 'Vegetables' | |
| 32 | + @beans = new_productcategory @vegetables, 'Beans' | |
| 33 | + @rice = new_productcategory @vegetables, 'Rice' | |
| 34 | + @mineral = new_productcategory @products, 'Mineral' | |
| 35 | + @iron = new_productcategory @mineral, 'Iron' | |
| 36 | + @gold = new_productcategory @mineral, 'Gold' | |
| 37 | + end | |
| 38 | + attr_accessor :profile | |
| 39 | + | |
| 40 | + should 'list product category sub-list' do | |
| 41 | + @enterprise.products.create!(:name => 'Gold Ring', :product_category => @gold) | |
| 42 | + @enterprise.products.create!(:name => 'Uncle Jon Beans', :product_category => @beans) | |
| 43 | + @enterprise.products.create!(:name => 'Red Rice', :product_category => @rice) | |
| 44 | + | |
| 45 | + html = category_with_sub_list @products | |
| 46 | + | |
| 47 | + doc = HTML::Document.new "<body>#{html}</body>" | |
| 48 | + assert_select doc.root, 'div' do |divs| | |
| 49 | + assert_select divs[0], "a[href=catalog-index-level=#{@products.id}]" | |
| 50 | + assert_select divs[0], '.count', {:text=>'3'} | |
| 51 | + assert_select divs[1], "a[href=catalog-index-level=#{@food.id}]" | |
| 52 | + assert_select divs[1], '.count', {:text=>'2'} | |
| 53 | + assert_select divs[2], "a[href=catalog-index-level=#{@mineral.id}]" | |
| 54 | + assert_select divs[2], '.count', {:text=>'1'} | |
| 55 | + end | |
| 56 | + end | |
| 57 | + | |
| 58 | +end | ... | ... |