Commit c54ef437ad4a9ff89e8c99e078db34d7306333e3
Committed by
Antonio Terceiro
1 parent
ea44d410
Exists in
master
and in
29 other branches
ActionItem1194: made code handles "0" on check_box values
* changed category_ids on profile and article * changed update_roles on profile_members controller * updated a test that passed categories objects instead of ids to category_ids
Showing
7 changed files
with
34 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
| ... | ... | @@ -8,7 +8,7 @@ class ProfileMembersController < MyProfileController |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | def update_roles |
| 11 | - @roles = params[:roles] ? environment.roles.find(params[:roles]) : [] | |
| 11 | + @roles = params[:roles] ? environment.roles.find(params[:roles].select{|r|!r.to_i.zero?}) : [] | |
| 12 | 12 | @roles = @roles.select{|r| r.has_kind?('Profile') } |
| 13 | 13 | @person = profile.members.find { |m| m.id == params[:person].to_i } |
| 14 | 14 | if @person && @person.define_roles(@roles, profile) | ... | ... |
app/models/article.rb
| ... | ... | @@ -54,7 +54,7 @@ class Article < ActiveRecord::Base |
| 54 | 54 | def category_ids=(ids) |
| 55 | 55 | ArticleCategorization.remove_all_for(self) |
| 56 | 56 | ids.uniq.each do |item| |
| 57 | - add_category(Category.find(item)) | |
| 57 | + add_category(Category.find(item)) unless item.to_i.zero? | |
| 58 | 58 | end |
| 59 | 59 | end |
| 60 | 60 | ... | ... |
app/models/profile.rb
| ... | ... | @@ -176,7 +176,7 @@ class Profile < ActiveRecord::Base |
| 176 | 176 | def category_ids=(ids) |
| 177 | 177 | ProfileCategorization.remove_all_for(self) |
| 178 | 178 | ids.uniq.each do |item| |
| 179 | - add_category(Category.find(item)) | |
| 179 | + add_category(Category.find(item)) unless item.to_i.zero? | |
| 180 | 180 | end |
| 181 | 181 | end |
| 182 | 182 | ... | ... |
test/functional/profile_members_controller_test.rb
| ... | ... | @@ -253,4 +253,16 @@ class ProfileMembersControllerTest < Test::Unit::TestCase |
| 253 | 253 | assert_includes assigns(:users_found), daniela |
| 254 | 254 | end |
| 255 | 255 | |
| 256 | + should 'ignore roles with id zero' do | |
| 257 | + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') | |
| 258 | + p = create_user_with_permission('test_user', 'manage_memberships', ent) | |
| 259 | + login_as :test_user | |
| 260 | + r = ent.environment.roles.create!(:name => 'test_role', :permissions => ['some_perm']) | |
| 261 | + get :update_roles, :profile => ent.identifier, :person => p.id, :roles => ["0", r.id, nil] | |
| 262 | + | |
| 263 | + p_roles = p.find_roles(ent).map(&:role).uniq | |
| 264 | + | |
| 265 | + assert p_roles, [r] | |
| 266 | + end | |
| 267 | + | |
| 256 | 268 | end | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -741,4 +741,12 @@ class ArticleTest < Test::Unit::TestCase |
| 741 | 741 | assert_not_includes as, a1 |
| 742 | 742 | end |
| 743 | 743 | |
| 744 | + should 'ignore category with zero as id' do | |
| 745 | + a = profile.articles.create!(:name => 'a test article') | |
| 746 | + c = Category.create!(:name => 'test category', :environment => profile.environment) | |
| 747 | + a.category_ids = ['0', c.id, nil] | |
| 748 | + assert a.save | |
| 749 | + assert_equal [c], a.categories | |
| 750 | + end | |
| 751 | + | |
| 744 | 752 | end | ... | ... |
test/unit/category_test.rb
| ... | ... | @@ -288,9 +288,9 @@ class CategoryTest < Test::Unit::TestCase |
| 288 | 288 | c = @env.categories.build(:name => 'my category'); c.save! |
| 289 | 289 | person = create_user('testuser').person |
| 290 | 290 | |
| 291 | - a1 = person.articles.build(:name => 'art1', :category_ids => [c]); a1.save! | |
| 292 | - a2 = person.articles.build(:name => 'art2', :category_ids => [c]); a2.save! | |
| 293 | - a3 = person.articles.build(:name => 'art3', :category_ids => [c]); a3.save! | |
| 291 | + a1 = person.articles.build(:name => 'art1', :category_ids => [c.id]); a1.save! | |
| 292 | + a2 = person.articles.build(:name => 'art2', :category_ids => [c.id]); a2.save! | |
| 293 | + a3 = person.articles.build(:name => 'art3', :category_ids => [c.id]); a3.save! | |
| 294 | 294 | |
| 295 | 295 | c1 = a1.comments.build(:title => 'test', :body => 'asdsa', :author => person); c1.save! |
| 296 | 296 | c2 = a2.comments.build(:title => 'test', :body => 'asdsa', :author => person); c2.save! | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -1385,6 +1385,14 @@ class ProfileTest < Test::Unit::TestCase |
| 1385 | 1385 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'join'}, profile.join_url) |
| 1386 | 1386 | end |
| 1387 | 1387 | |
| 1388 | + should 'ignore categgory with id zero' do | |
| 1389 | + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
| 1390 | + c = Category.create!(:name => 'test cat', :environment => profile.environment) | |
| 1391 | + profile.category_ids = ['0', c.id, nil] | |
| 1392 | + | |
| 1393 | + assert_equal [c], profile.categories | |
| 1394 | + end | |
| 1395 | + | |
| 1388 | 1396 | private |
| 1389 | 1397 | |
| 1390 | 1398 | def assert_invalid_identifier(id) | ... | ... |