From 8ae01dc608f1a52d01e0209994ac8d80b517c7da Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Sat, 12 Jul 2008 21:32:03 +0000 Subject: [PATCH] ActionItem498: fixing tests for manage_products --- app/controllers/my_profile/manage_products_controller.rb | 2 +- app/models/article.rb | 2 +- test/functional/manage_products_controller_test.rb | 16 ++++++++-------- test/unit/article_test.rb | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 0d4c82a..ea5cd40 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -63,7 +63,7 @@ class ManageProductsController < ApplicationController @current_category = ProductCategory.top_level_for(environment).first @categories = @current_category.nil? ? [] : @current_category.children end - render :partial => 'shared/select_categories', :locals => {:object_name => 'product'}, :layout => false + render :partial => 'shared/select_categories', :locals => {:object_name => 'product', :multiple => false}, :layout => false end def new_consumption diff --git a/app/models/article.rb b/app/models/article.rb index 63cb33d..3073822 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -29,7 +29,7 @@ class Article < ActiveRecord::Base def category_ids=(ids) ArticleCategorization.remove_all_for(self) - ids.each do |item| + ids.uniq.each do |item| add_category(Category.find(item)) end end diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index e5d2615..281b6cf 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -118,7 +118,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) get :new, :profile => @enterprise.identifier - assert_tag :tag => 'h3', :content => /Select a category:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ } + assert_tag :tag => 'h3', :content => /Categories:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ } end should 'show current category' do @@ -126,7 +126,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) - get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id + get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id assert_tag :tag => 'h3', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ } end @@ -135,24 +135,24 @@ class ManageProductsControllerTest < Test::Unit::TestCase category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) - get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id + get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id assert !assigns(:categories).empty? - assert_tag :tag => 'h3', :content => /Select a subcategory:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ } + assert_tag :tag => 'h3', :content => /Categories:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ } end should 'update subcategories' do environment = Environment.default category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) - get 'update_subcategories', :profile => @enterprise.identifier, :id => category1.id + get 'update_categories', :profile => @enterprise.identifier, :category_id => category1.id assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ end should 'not show subcategories list when no subcategories' do environment = Environment.default - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) - get 'update_subcategories', :profile => @enterprise.identifier, :id => category1.id - assert_no_tag :tag => 'p', :content => 'Select a subcategory:' + category1 = @enterprise.products.create!(:name => 'Category 1') + get 'update_categories', :profile => @enterprise.identifier, :id => category1.id + assert_no_tag :tag => 'h3', :content => 'Categories:' end should "create new product categorized" do diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 0efc56a..5b0d3a6 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -354,7 +354,7 @@ class ArticleTest < Test::Unit::TestCase should 'not add a category twice to article' do c1 = Category.create!(:environment => Environment.default, :name => 'c1') c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3') + c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') owner = create_user('testuser').person art = owner.articles.create!(:name => 'ytest') art.category_ids = [c2,c3,c3].map(&:id) -- libgit2 0.21.2