From 00ff0a6776aca4977dc6eab5ec130c67e36c36ac Mon Sep 17 00:00:00 2001 From: Nikita Pomyashchiy Date: Fri, 8 Jun 2012 01:00:34 +0400 Subject: [PATCH] Compact array of values added to PermissionSet instance --- .../active_model/mass_assignment_security/permission_set.rb | 2 +- .../cases/mass_assignment_security/permission_set_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/mass_assignment_security/permission_set.rb b/activemodel/lib/active_model/mass_assignment_security/permission_set.rb index 9661349503..415ab0ad17 100644 --- a/activemodel/lib/active_model/mass_assignment_security/permission_set.rb +++ b/activemodel/lib/active_model/mass_assignment_security/permission_set.rb @@ -5,7 +5,7 @@ module ActiveModel class PermissionSet < Set def +(values) - super(values.map(&:to_s)) + super(values.compact.map(&:to_s)) end def include?(key) diff --git a/activemodel/test/cases/mass_assignment_security/permission_set_test.rb b/activemodel/test/cases/mass_assignment_security/permission_set_test.rb index d005b638e4..8082c49852 100644 --- a/activemodel/test/cases/mass_assignment_security/permission_set_test.rb +++ b/activemodel/test/cases/mass_assignment_security/permission_set_test.rb @@ -13,6 +13,12 @@ class PermissionSetTest < ActiveModel::TestCase assert new_list.include?('admin'), "did not add collection to #{@permission_list.inspect}}" end + test "+ compacts added collection values" do + added_collection = [ nil ] + new_list = @permission_list + added_collection + assert_equal new_list, @permission_list, "did not add collection to #{@permission_list.inspect}}" + end + test "include? normalizes multi-parameter keys" do multi_param_key = 'admin(1)' new_list = @permission_list += [ 'admin' ]