#11
Mar 28, 2007

Refactoring User Name Part 2

Testing and refactoring go hand in hand. Refactoring is all about improving code without changing its behavior. Testing is all about making sure you don't change the behavior while you are improving the code.
Download (13.1 MB, 6:34)
alternative download for iPod & Apple TV (9 MB, 6:34)
# models/user.rb
def full_name
  [first_name, middle_initial_with_period, last_name].compact.join(' ')
end

def middle_initial_with_period
  "#{middle_initial}." unless middle_initial.blank?
end

RSS Feed for Episode Comments -4 comments

1. steve D Oct 05, 2007 at 04:12

Hi Ryan,

Testing is about proving that the code is fit for purpose.

Regression testing is about proving that the modified/new code does not impact on the existing code - which is what you are hinting at above.


2. Eric Anderson Oct 16, 2007 at 20:48

One other thing to consider is if first name or last name is an empty string. You can do something like:

[first_name, middle_initial_with_period, last_name].reject(&:blank?) * ' '

This will reject all blank values.


3. Syn Oct 23, 2007 at 10:47

I think you mean something like this:

[f, m, l].reject{|i| i.empty?}.compact.join(" ")

Yay Ruby. ^.^


4. David Beckwith Feb 07, 2008 at 15:58

Hello,
  Great site and great coding! I would like to see a railscast on Rspec. Any plans for that?
  David :)


5. Allen Feng Apr 21, 2008 at 02:07

I cannot get autotest to work on XP. I get error message "couldn't find HOME environment.." What should I add to the environment variable setting in Window?


6. Angelika Feb 21, 2010 at 11:32

Thanks for very good information.


7. Anikusha Mar 18, 2010 at 11:51

[url=http://incyprus.ru/]Anikusha[/url]

Thanks)


8. Vadik Mar 25, 2010 at 04:08

I loved this one! <a href="http://www.strategya.com/">букмекерские конторы</a> I bookmarked your blog


9. Alex_Jet Mar 25, 2010 at 04:10

Regression testing is about proving that the modified/new code does not impact on the existing code - which is what you are hinting at above.


10. Angelika Apr 24, 2010 at 07:22

Thanks for You good information


11. Bluehost Jul 09, 2010 at 03:25

Thanks for the download


12. free directory list Aug 11, 2010 at 22:03

Thanks! It is beautiful!!


13. free directory list Aug 11, 2010 at 22:03

Thanks! It is beautiful!!


14. free directory list Aug 11, 2010 at 22:03

Thanks! It is beautiful!!


15. mbt shoes sale Aug 14, 2010 at 18:41

It is a nice article,i appreciate it,i will keep it on my dashboad.


16. mbt sport Aug 14, 2010 at 18:42

I just want to say the spirit is positive,but the content is simply.


17. snow boots Aug 31, 2010 at 02:09

I would like to see a railscast on Rspec. Any plans for that?


18. Dolce & Gabbana Belts Sep 01, 2010 at 22:56

Good post, I can’t say that I agree with everything that was said, but very good information overall:)

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player
Give Back to Open Source