From caa6c62d1e7033ca3fd85cd29b414a48bde69c1e Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Sat, 12 Jul 2008 22:10:40 +0000 Subject: [PATCH] ActionItem498: fixing tests for new categories selector --- app/controllers/my_profile/cms_controller.rb | 2 +- app/controllers/my_profile/profile_editor_controller.rb | 11 ++++++++--- app/models/profile.rb | 2 +- app/views/profile_editor/edit.rhtml | 2 +- test/functional/cms_controller_test.rb | 2 +- test/functional/profile_editor_controller_test.rb | 6 +++--- test/unit/profile_test.rb | 9 +++++++++ 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 1d70d8f..c9e567a 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -121,7 +121,7 @@ class CmsController < MyProfileController @current_category = Category.find(params[:category_id]) @categories = @current_category.children else - @categories = @categories = environment.top_level_categories.select{|i| !i.children.empty?} + @categories = environment.top_level_categories.select{|i| !i.children.empty?} end render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false end diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 191aab7..164cf7f 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -39,9 +39,14 @@ class ProfileEditorController < MyProfileController end def update_categories - @current_category = Category.find(params[:category_id]) - @categories = @current_category.children - render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data'}, :layout => false + @object = profile + if params[:category_id] + @current_category = Category.find(params[:category_id]) + @categories = @current_category.children + else + @categories = environment.top_level_categories.select{|i| !i.children.empty?} + end + render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false end end diff --git a/app/models/profile.rb b/app/models/profile.rb index a5ce5fb..f15586b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -127,7 +127,7 @@ class Profile < ActiveRecord::Base def category_ids=(ids) ProfileCategorization.remove_all_for(self) - ids.each do |item| + ids.uniq.each do |item| add_category(Category.find(item)) end end diff --git a/app/views/profile_editor/edit.rhtml b/app/views/profile_editor/edit.rhtml index fdfe34d..27cf4ab 100644 --- a/app/views/profile_editor/edit.rhtml +++ b/app/views/profile_editor/edit.rhtml @@ -36,7 +36,7 @@

- <%= select_categories(:profile_data, _('Select the categories of your interest'), 1) %> + <%= select_categories(:profile_data, _('Select the categories of your interest'), :title_size => 1, :multiple => true) %> <% button_bar do %> <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index f3aae69..2607e78 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -296,7 +296,7 @@ class CmsControllerTest < Test::Unit::TestCase post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] } saved = profile.articles.find_by_name('adding-categories-test') - assert_equal [c1, c3, c3], saved.categories + assert_equal [c1, c3], saved.categories end should 'filter html from textile article name' do diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 40ff945..db7ff4c 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -83,7 +83,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase get :edit, :profile => 'test_user' assert_response :success assert_template 'edit' - assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id} + assert_tag :tag => 'a', :attributes => { :id => "select-category-#{cat1.id}-link" } end should 'save categorization of profile' do @@ -259,12 +259,12 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' } end - should 'show categories field on edit profile' do + should 'show categories links on edit profile' do cat1 = Environment.default.categories.create!(:display_in_menu => true, :name => 'top category') cat2 = Environment.default.categories.create!(:display_in_menu => true, :name => 'sub category', :parent => cat1) person = create_user('testuser').person get :edit, :profile => 'testuser' - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]', :value => cat2.id} + assert_tag :tag => 'a', :attributes => { :id => "select-category-#{cat1.id}-link" } end should 'render edit template' do diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index bf45970..5820fed 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -677,6 +677,15 @@ class ProfileTest < Test::Unit::TestCase assert_kind_of TinyMceArticle, profile.home_page end + should 'not add a category twice to profile' do + c1 = Category.create!(:environment => Environment.default, :name => 'c1') + c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') + c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') + profile = create_user('testuser').person + profile.category_ids = [c2,c3,c3].map(&:id) + assert_equal [c2, c3], profile.categories(true) + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2