Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OHR Support
Manage
Activity
Members
Labels
Plan
Issues
97
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
OHR Support
Commits
b5b36844
Commit
b5b36844
authored
14 years ago
by
Gregor Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
[
#282
] Make safe_attributes work with sub classes
parent
40dbfd77
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/redmine/safe_attributes.rb
+7
-2
7 additions, 2 deletions
lib/redmine/safe_attributes.rb
test/unit/lib/redmine/safe_attributes_test.rb
+20
-1
20 additions, 1 deletion
test/unit/lib/redmine/safe_attributes_test.rb
with
27 additions
and
3 deletions
lib/redmine/safe_attributes.rb
+
7
−
2
View file @
b5b36844
...
...
@@ -31,14 +31,19 @@ module Redmine
def
safe_attributes
(
*
args
)
@safe_attributes
||=
[]
if
args
.
empty?
@safe_attributes
if
superclass
<
Redmine
::
SafeAttributes
superclass
.
safe_attributes
+
@safe_attributes
else
@safe_attributes
end
else
options
=
args
.
last
.
is_a?
(
Hash
)
?
args
.
pop
:
{}
@safe_attributes
<<
[
args
,
options
]
safe_attributes
end
end
end
# Returns an array that can be safely set by user or current user
#
# Example:
...
...
This diff is collapsed.
Click to expand it.
test/unit/lib/redmine/safe_attributes_test.rb
+
20
−
1
View file @
b5b36844
...
...
@@ -35,11 +35,16 @@ class Redmine::SafeAttributesTest < ActiveSupport::TestCase
end
class
Book
<
Base
attr_accessor
:title
attr_accessor
:title
,
:isbn
include
Redmine
::
SafeAttributes
safe_attributes
:title
end
class
PublishedBook
<
Book
safe_attributes
:isbn
end
def
test_safe_attribute_names
p
=
Person
.
new
assert_equal
[
'firstname'
,
'lastname'
],
p
.
safe_attribute_names
(
User
.
anonymous
)
...
...
@@ -84,4 +89,18 @@ class Redmine::SafeAttributesTest < ActiveSupport::TestCase
assert_equal
'Smith'
,
p
.
lastname
assert_equal
'jsmith'
,
p
.
login
end
def
test_use_safe_attributes_in_subclasses
b
=
Book
.
new
p
=
PublishedBook
.
new
b
.
safe_attributes
=
{
'title'
=>
'My awesome Ruby Book'
,
'isbn'
=>
'1221132343'
}
p
.
safe_attributes
=
{
'title'
=>
'The Pickaxe'
,
'isbn'
=>
'1934356085'
}
assert_equal
'My awesome Ruby Book'
,
b
.
title
assert_nil
b
.
isbn
assert_equal
'The Pickaxe'
,
p
.
title
assert_equal
'1934356085'
,
p
.
isbn
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment