The Refactoring While adding tests to my Redmine Invoice plugin, I found the following nasty bit of logic. Before 1 2 3 4 5 6 7 class Invoice < ActiveRecord::Base def self.open invoices = self.find(:all) return invoices.select { |invoice| !invoice.fully_paid? && !invoice.late? } end endclass Invoice < ActiveRecord::Base def self.open invoices = self.find(:all) return …
Tag: extract-method
Daily Refactor #71: Extract Method in KanbansController to before_filter
The code in the Redmine Merge plugin looks pretty good so I’m going back to my Redmine Kanban plugin. Today’s refactoring was guided by the Rails Best Practices gem. This gem uses static code analysis to search for common smells in Rails applications. Running it on Redmine Kanban showed several smells I can tackle: ./app/controllers/kanbans_controller.rb:8,13 …
Daily Refactor #63: Extract Method to before_filter in IssuesController
The Refactoring Mark Thomas pointed out some odd code in Redmine’s IssuesController#build_new_issue_from_params, specifically that it’s doing some error checking in the middle of a method body. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 # …
Daily Refactor #62: Extract Method in IssuesController
The Refactoring Today’s refactoring follows up on yesterday’s. Now that I have the #new and #create actions for REST, I can start to remove the duplication I introduced. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 …
Daily Refactor #61: Extract Method in IssuesController for REST
Now I’m starting to refactor Redmine’s IssuesController again in order to have it match the standard Rails REST controllers. This time I’m working on the new/create action pair. The Refactoring This refactoring splits the single #new action into the two separate actions. Before 1 2 3 4 5 6 7 8 9 10 11 12 …