Project

General

Profile

Actions

Defect #4446

closed

Incorrect using ruby syntax

Added by Alexander Oryol over 14 years ago. Updated over 14 years ago.

Status:
Closed
Priority:
Normal
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

and_return.patch (11.2 KB) and_return.patch Alexander Oryol, 2009-12-18 14:27
Actions #1

Updated by Jean-Philippe Lang over 14 years ago

  • Status changed from New to Closed
  • Resolution set to Fixed

Patch applied in r3185. Thanks.

Actions

Also available in: Atom PDF