Actions
Defect #4446
closedIncorrect using ruby syntax
Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
-
Start date:
2009-12-18
Due date:
% Done:
0%
Estimated time:
Resolution:
Fixed
Affected version:
Description
In many points redmine code use costruction same:
def function
...
if condition
some_one and return
end
some_another
end
Trouble in "and return".
As example, users_controller.rb:65 in trunk.
I got:
1) Error:
test_show_should_not_reveal_users_with_no_visible_activity_or_project(UsersControllerTest):
ActionController::DoubleRenderError: Can only render or redirect once per action
app/controllers/users_controller.rb:67:in `show'
test/functional/users_controller_test.rb:116:in `test_show_should_not_reveal_users_with_no_visible_activity_or_project'
I wrote simple example:
def test
if true
puts "+++" and return "@@@"
end
puts "---"
end
puts test()
In your opinion, which will result?
Surprise! result is:
+++ --- nil
[puts "+++"] return nil and second part not run. Tested in ruby 1.8.7, 1.8.6.
Imho, correct use is:
if condition some return end
or
(some; return) if condition
It require many fixes in Redmine code. Patch attached.
Thanks.
Files
Updated by Jean-Philippe Lang almost 16 years ago
- Status changed from New to Closed
- Resolution set to Fixed
Patch applied in r3185. Thanks.
Actions