Posted by Rick DeNatale
Tue, 07 Aug 2007 19:24:00 GMT
Not long ago while working on an existing Rails application, (i.e. code I hadn’t written). I was mystified
when a logical expression seemed to be returning an odd result. The expression had been written with not,
and, and or, and was the right hand side of an assignment statement. ventually I changed to using !,
&&, and || which fixed the problem.
I never completely
understood what was going on, until I encountered this
blog entry by Jay Fields.
One of the big differences between Ruby and Smalltalk is the use of operator precedence. In Smalltalk, the grammar is
very simple, unary message selectors bind tighter than binary selectors, which bind tighter than keyword selectors.
The assignment operator binds more loosely than any of these. This is often a stumbling block for newcomers to Smalltalk
when they find that in Smalltalk 3 + 5 * 2 evaluates to 16.
Ruby in comparison has quite a rich and flexible syntax.
Usually, it’s quite intutitive, but, depending on where you come from there can be some surprises.
I understood the relative precendences of, say && vs. and in Ruby, but the fact that
and had weaker precedence than = escaped me, until Jay’s article turned the light on for
me.
As they say, you learn something new everyday, or at least you hope you do. I don’t expect that I’ll forget this little
corner of Ruby in future
Posted in ruby, smalltalk, ruby_for_nubys | Tags gotchas, syntax | 1 comment | 1 trackback
Posted by Rick DeNatale
Fri, 03 Aug 2007 00:11:00 GMT
This looks interesting.
I wish I had a nickel for every time I’ve typed something like:
grep whatever -R . | grep -v .svn
Posted in ruby, rails | Tags grep, svn, yeah_its_perl_but | 1 comment | no trackbacks
Posted by Rick DeNatale
Thu, 02 Aug 2007 16:23:00 GMT
I live in the fastest growing corner of one of the fastest growing counties in the US.
Lately that has seemed to come with more than my share of power interruptions.
This blog is hosted on a ‘server’ in my home office, which also hosts several other things, some for internal use, and
others, like talklikeaduck are public facing. Besides this blog I have a
wikimedia based site on the technical history of
Project Mercury, a personal interest of mine.
One of my frustrations of late has been the fact that the blog doesn’t suffer those power interruptions well.
For deployment, I’m using a combination of Apache 2.0, with pen for load balancing, and mongrel_cluster. That last has
been the main source of that minor annoyance. The version of mongrel_cluster I’ve been using doesn’t properly deal with
stale pid files, so that when the system reboots after a power outage, the blog doesn’t come back without manual
intervention.
My frustration level finally rose to the point where I started to look for a solution.
Read more...
Posted in rails | Tags deployment, mongrel, mongrel_cluster, monit, server, ubuntu | 1 comment | no trackbacks
Posted by Rick DeNatale
Mon, 23 Jul 2007 00:59:06 GMT
If you subscribe to my feed, you might have noticed a mysterious "Testing Testing" article today.
I was trying a desktop blogging client called BloGTK, and it doesn't appear to honor the checkbox in the UI which is suppose to prevent actually posting an article.
Posted in best_practices | no comments | no trackbacks
Posted by Rick DeNatale
Fri, 20 Jul 2007 02:49:00 GMT
Charlie Savage just posted a long article about how he reduced the rendering time on his rails app by an order of magnitude.
The article is full of advice on what to do and not to do in coding rails apps. The important message though is the approach to performance tuning by profiling.
t
Posted in rails | Tags performance | no comments | no trackbacks
Posted by Rick DeNatale
Thu, 19 Jul 2007 18:19:00 GMT

Yesterday I wrote about some code I wrote to control what Time.now and Date.today return to support time-dependent testing.
This afternoon I discovered a critical, but easy to fix bug. I’ve updated the original article.
The good news is that the testcase for the time machine now has another test!
Posted in rails | Tags culpas, mea, testing | no comments | no trackbacks
Posted by Rick DeNatale
Wed, 18 Jul 2007 19:45:00 GMT

I’ve been working on adding support for localization of the user’s time zone on an existing Rails app for a client. In order to test this, I found myself building a time machine.
At first, I did a fairly simple hack which monkey patched the system methods Time.now, and Date.today. This worked until I got into some testcases of code which was triggered off of updated_at fields in various ActiveRecord models. Since I had to deal with these implicit dates, I found that I needed to have finer control than my simple patch gave.
The code has now evolved to the point where I think that it shows some interesting aspects of basic Ruby metaprogramming.
Read more...
Posted in ruby, rails | Tags metaprogramming, testing | 1 comment | 1 trackback
Posted by Rick DeNatale
Wed, 18 Jul 2007 01:51:00 GMT
Good article about a
basic principle of UI goodness by Jef Raskin’s son Aza.
Have you ever had that sinking feeling when you realize—just a split second too late—that you shouldn’t have clicked “Okay” in the “Are you sure you want to quit?” dialog?
Posted in psychology, best_practices | Tags ui_design | no comments | no trackbacks
Posted by Rick DeNatale
Tue, 17 Jul 2007 17:50:00 GMT
The other day I wrote about
problems with undeclared fixtures in Rails ActiveRecord tests.
Here’s a little code snippet which might be useful in tracking down such problems.
Read more...
Posted in rails | Tags fixtures, testing | no comments | no trackbacks
Posted by Rick DeNatale
Sat, 14 Jul 2007 19:28:00 GMT
The other day I was working on adding support for user selected time-zones to an existing rails app for a client. As usual I was doing test-first development. One of the things that makes rails such a pleasure is that a good set of tests give confidence that you aren’t breaking “legacy” code.
I also use, and really like, the rails plugin for vim which does lots of nice things like making navigation between the files of rails apps much easier. It also has a nice feature which adds a :Rake command to vim which “does the right” thing contextually. For example if you are editing a migration and enter :Rake, it runs rake db:migrate. If you are in a test file it runs just the single test selected by the cursor, or just that test file if you aren’t positioned to a particular test.
I was doing the latter, and my test was failing, and I was having a hard time debugging it. I tried executing just that single test from the bash command line with:
$ruby test/unit/my_test.rb -n"test_mytest"
and it still failed, no surprise. The same thing happened if I ran the entire test file, in fact, other tests which had worked before were now failing, and I was really mystified now because I didn’t see how I had done anything which had a remote chance of breaking those.
So I figured I probably should test everthing so:
$rake test
And, surprise of surprises, but every test worked. Not only my failing unit tests, but the functional and integration tests as well.
To make a long story short, the problem turned out to be that the tests were failing because, now that the particular model was sensitive to the user’s timezone, it needed access to it’s associated user model, and I hadn’t told the testcase that the users fixture was needed. Running the testcase in isolation, the users table wasn’t being populated for the test case. But running rake test, or rake test:units meant that other tests run before had left the data I needed behind.
Just a little thing that makes fixtures less than ideal.
Posted in ruby, rails | Tags fixtures, gotchas, testing | no comments | no trackbacks