Commit caa6c62d1e7033ca3fd85cd29b414a48bde69c1e
1 parent
7bc4e5ce
Exists in
master
and in
28 other branches
ActionItem498: fixing tests for new categories selector
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2248 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
7 changed files
with
24 additions
and
10 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -121,7 +121,7 @@ class CmsController < MyProfileController |
121 | 121 | @current_category = Category.find(params[:category_id]) |
122 | 122 | @categories = @current_category.children |
123 | 123 | else |
124 | - @categories = @categories = environment.top_level_categories.select{|i| !i.children.empty?} | |
124 | + @categories = environment.top_level_categories.select{|i| !i.children.empty?} | |
125 | 125 | end |
126 | 126 | render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false |
127 | 127 | end | ... | ... |
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -39,9 +39,14 @@ class ProfileEditorController < MyProfileController |
39 | 39 | end |
40 | 40 | |
41 | 41 | def update_categories |
42 | - @current_category = Category.find(params[:category_id]) | |
43 | - @categories = @current_category.children | |
44 | - render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data'}, :layout => false | |
42 | + @object = profile | |
43 | + if params[:category_id] | |
44 | + @current_category = Category.find(params[:category_id]) | |
45 | + @categories = @current_category.children | |
46 | + else | |
47 | + @categories = environment.top_level_categories.select{|i| !i.children.empty?} | |
48 | + end | |
49 | + render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false | |
45 | 50 | end |
46 | 51 | |
47 | 52 | end | ... | ... |
app/models/profile.rb
app/views/profile_editor/edit.rhtml
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | </div> |
37 | 37 | </p> |
38 | 38 | |
39 | - <%= select_categories(:profile_data, _('Select the categories of your interest'), 1) %> | |
39 | + <%= select_categories(:profile_data, _('Select the categories of your interest'), :title_size => 1, :multiple => true) %> | |
40 | 40 | |
41 | 41 | <% button_bar do %> |
42 | 42 | <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -296,7 +296,7 @@ class CmsControllerTest < Test::Unit::TestCase |
296 | 296 | post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] } |
297 | 297 | |
298 | 298 | saved = profile.articles.find_by_name('adding-categories-test') |
299 | - assert_equal [c1, c3, c3], saved.categories | |
299 | + assert_equal [c1, c3], saved.categories | |
300 | 300 | end |
301 | 301 | |
302 | 302 | should 'filter html from textile article name' do | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -83,7 +83,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
83 | 83 | get :edit, :profile => 'test_user' |
84 | 84 | assert_response :success |
85 | 85 | assert_template 'edit' |
86 | - assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id} | |
86 | + assert_tag :tag => 'a', :attributes => { :id => "select-category-#{cat1.id}-link" } | |
87 | 87 | end |
88 | 88 | |
89 | 89 | should 'save categorization of profile' do |
... | ... | @@ -259,12 +259,12 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
259 | 259 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' } |
260 | 260 | end |
261 | 261 | |
262 | - should 'show categories field on edit profile' do | |
262 | + should 'show categories links on edit profile' do | |
263 | 263 | cat1 = Environment.default.categories.create!(:display_in_menu => true, :name => 'top category') |
264 | 264 | cat2 = Environment.default.categories.create!(:display_in_menu => true, :name => 'sub category', :parent => cat1) |
265 | 265 | person = create_user('testuser').person |
266 | 266 | get :edit, :profile => 'testuser' |
267 | - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]', :value => cat2.id} | |
267 | + assert_tag :tag => 'a', :attributes => { :id => "select-category-#{cat1.id}-link" } | |
268 | 268 | end |
269 | 269 | |
270 | 270 | should 'render edit template' do | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -677,6 +677,15 @@ class ProfileTest < Test::Unit::TestCase |
677 | 677 | assert_kind_of TinyMceArticle, profile.home_page |
678 | 678 | end |
679 | 679 | |
680 | + should 'not add a category twice to profile' do | |
681 | + c1 = Category.create!(:environment => Environment.default, :name => 'c1') | |
682 | + c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') | |
683 | + c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') | |
684 | + profile = create_user('testuser').person | |
685 | + profile.category_ids = [c2,c3,c3].map(&:id) | |
686 | + assert_equal [c2, c3], profile.categories(true) | |
687 | + end | |
688 | + | |
680 | 689 | private |
681 | 690 | |
682 | 691 | def assert_invalid_identifier(id) | ... | ... |