Commit 8ae01dc608f1a52d01e0209994ac8d80b517c7da

Authored by JoenioCosta
1 parent d614abf8

ActionItem498: fixing tests for manage_products

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2244 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/manage_products_controller.rb
@@ -63,7 +63,7 @@ class ManageProductsController < ApplicationController @@ -63,7 +63,7 @@ class ManageProductsController < ApplicationController
63 @current_category = ProductCategory.top_level_for(environment).first 63 @current_category = ProductCategory.top_level_for(environment).first
64 @categories = @current_category.nil? ? [] : @current_category.children 64 @categories = @current_category.nil? ? [] : @current_category.children
65 end 65 end
66 - render :partial => 'shared/select_categories', :locals => {:object_name => 'product'}, :layout => false 66 + render :partial => 'shared/select_categories', :locals => {:object_name => 'product', :multiple => false}, :layout => false
67 end 67 end
68 68
69 def new_consumption 69 def new_consumption
app/models/article.rb
@@ -29,7 +29,7 @@ class Article < ActiveRecord::Base @@ -29,7 +29,7 @@ class Article < ActiveRecord::Base
29 29
30 def category_ids=(ids) 30 def category_ids=(ids)
31 ArticleCategorization.remove_all_for(self) 31 ArticleCategorization.remove_all_for(self)
32 - ids.each do |item| 32 + ids.uniq.each do |item|
33 add_category(Category.find(item)) 33 add_category(Category.find(item))
34 end 34 end
35 end 35 end
test/functional/manage_products_controller_test.rb
@@ -118,7 +118,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase @@ -118,7 +118,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase
118 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) 118 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
119 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) 119 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
120 get :new, :profile => @enterprise.identifier 120 get :new, :profile => @enterprise.identifier
121 - assert_tag :tag => 'h3', :content => /Select a category:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ } 121 + assert_tag :tag => 'h3', :content => /Categories:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ }
122 end 122 end
123 123
124 should 'show current category' do 124 should 'show current category' do
@@ -126,7 +126,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase @@ -126,7 +126,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase
126 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) 126 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment)
127 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) 127 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
128 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) 128 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
129 - get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id 129 + get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id
130 assert_tag :tag => 'h3', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ } 130 assert_tag :tag => 'h3', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ }
131 end 131 end
132 132
@@ -135,24 +135,24 @@ class ManageProductsControllerTest < Test::Unit::TestCase @@ -135,24 +135,24 @@ class ManageProductsControllerTest < Test::Unit::TestCase
135 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) 135 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment)
136 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) 136 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
137 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) 137 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
138 - get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id 138 + get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id
139 assert !assigns(:categories).empty? 139 assert !assigns(:categories).empty?
140 - assert_tag :tag => 'h3', :content => /Select a subcategory:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ } 140 + assert_tag :tag => 'h3', :content => /Categories:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ }
141 end 141 end
142 142
143 should 'update subcategories' do 143 should 'update subcategories' do
144 environment = Environment.default 144 environment = Environment.default
145 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) 145 category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment)
146 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) 146 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
147 - get 'update_subcategories', :profile => @enterprise.identifier, :id => category1.id 147 + get 'update_categories', :profile => @enterprise.identifier, :category_id => category1.id
148 assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ 148 assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/
149 end 149 end
150 150
151 should 'not show subcategories list when no subcategories' do 151 should 'not show subcategories list when no subcategories' do
152 environment = Environment.default 152 environment = Environment.default
153 - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment)  
154 - get 'update_subcategories', :profile => @enterprise.identifier, :id => category1.id  
155 - assert_no_tag :tag => 'p', :content => 'Select a subcategory:' 153 + category1 = @enterprise.products.create!(:name => 'Category 1')
  154 + get 'update_categories', :profile => @enterprise.identifier, :id => category1.id
  155 + assert_no_tag :tag => 'h3', :content => 'Categories:'
156 end 156 end
157 157
158 should "create new product categorized" do 158 should "create new product categorized" do
test/unit/article_test.rb
@@ -354,7 +354,7 @@ class ArticleTest < Test::Unit::TestCase @@ -354,7 +354,7 @@ class ArticleTest < Test::Unit::TestCase
354 should 'not add a category twice to article' do 354 should 'not add a category twice to article' do
355 c1 = Category.create!(:environment => Environment.default, :name => 'c1') 355 c1 = Category.create!(:environment => Environment.default, :name => 'c1')
356 c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') 356 c2 = c1.children.create!(:environment => Environment.default, :name => 'c2')
357 - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3') 357 + c3 = c1.children.create!(:environment => Environment.default, :name => 'c3')
358 owner = create_user('testuser').person 358 owner = create_user('testuser').person
359 art = owner.articles.create!(:name => 'ytest') 359 art = owner.articles.create!(:name => 'ytest')
360 art.category_ids = [c2,c3,c3].map(&:id) 360 art.category_ids = [c2,c3,c3].map(&:id)