Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/safe_attributes_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../../../test_helper', __FILE__) | 18 require File.expand_path('../../../../test_helper', __FILE__) |
19 | 19 |
20 class Redmine::SafeAttributesTest < ActiveSupport::TestCase | 20 class Redmine::SafeAttributesTest < ActiveSupport::TestCase |
21 fixtures :users | |
21 | 22 |
22 class Base | 23 class Base |
23 def attributes=(attrs) | 24 def attributes=(attrs) |
24 attrs.each do |key, value| | 25 attrs.each do |key, value| |
25 send("#{key}=", value) | 26 send("#{key}=", value) |
40 safe_attributes :title | 41 safe_attributes :title |
41 end | 42 end |
42 | 43 |
43 def test_safe_attribute_names | 44 def test_safe_attribute_names |
44 p = Person.new | 45 p = Person.new |
45 assert_equal ['firstname', 'lastname'], p.safe_attribute_names(User.anonymous) | 46 user = User.anonymous |
46 assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names(User.find(1)) | 47 assert_equal ['firstname', 'lastname'], p.safe_attribute_names(user) |
48 assert p.safe_attribute?('firstname', user) | |
49 assert !p.safe_attribute?('login', user) | |
50 | |
51 p = Person.new | |
52 user = User.find(1) | |
53 assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names(user) | |
54 assert p.safe_attribute?('firstname', user) | |
55 assert p.safe_attribute?('login', user) | |
47 end | 56 end |
48 | 57 |
49 def test_safe_attribute_names_without_user | 58 def test_safe_attribute_names_without_user |
50 p = Person.new | 59 p = Person.new |
51 User.current = nil | 60 User.current = nil |
52 assert_equal ['firstname', 'lastname'], p.safe_attribute_names | 61 assert_equal ['firstname', 'lastname'], p.safe_attribute_names |
62 assert p.safe_attribute?('firstname') | |
63 assert !p.safe_attribute?('login') | |
64 | |
65 p = Person.new | |
53 User.current = User.find(1) | 66 User.current = User.find(1) |
54 assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names | 67 assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names |
68 assert p.safe_attribute?('firstname') | |
69 assert p.safe_attribute?('login') | |
55 end | 70 end |
56 | 71 |
57 def test_set_safe_attributes | 72 def test_set_safe_attributes |
58 p = Person.new | 73 p = Person.new |
59 p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.anonymous) | 74 p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.anonymous) |