rails/rails — pull request #7376 by dmitriy-kiriyenko (2012-08-17 12:41:21+00:00)
Title: Prevent callback from being set twice.

When you add one callack in two separate `set_callback` calls - it is only called once.

When you do it in one `set_callback` call - it is called twice.

This violates the principle of least astonishment for me. Duplicating callback is usually an error. There is a correct and obvious way to do anything without this "feature".

If you want to do:

```ruby
before_save :clear_balance, :calculate_tax, :clear_balance
```

or whatever, you should better do:

```ruby
before_save :carefully_calculate_tax

def carefully_calculate_tax
clear_balance
calculate_tax
clear_balance
end
```

And this even opens gates for some advanced refactorings, unlike the first approach.

My assumptions are:

- Principle of least astonishment is violated, when callbacks are either prevented from duplication, or not.
- Duplicating callbacks is usually an error. When it is intentional - it's a smell of a bad design and can be approached without abusing this "feature".

My suggestion is: do not allow duplicating callbacks in one callback call, like it is not allowed in separate callbacks call.

P.S. It's currently one test on railties failing in __master__ and so in this branch __also__. It's not me!

```
1) Failure:
test_0006_reload constants on development(LoadingTest) [test/application/loading_test.rb:135]:
Expected: "2"
Actual: "1"
```