We left off after writing the test for the
method. Now, we're going to make
that test pass by writing the code for it. First you'll need to create PostEntity.cfc in the xorblog/cfcs/src
directory, and make sure to surround it in the proper
What follows is that code:
<cfset var local = structNew()>
insert into post
(name, meat, originalDate, lastModifiedDate, author)
select max(id) as newID from post
<cfif local.result.recordcount is
"The new post was not properly inserted.">
There isn't really anything special here, unless you are new to Coldfusion. If that's the case, you'll
want to take note of the
tag - using it is considered a "best practice" by
most (if not all) experienced Coldfusion developers.
The other item of note is that if you were to run this code by itself,
it still wouldn't work, since we haven't defined
. Many developers
would do this in a function called
that they call each time they create an object. I've
done it as well.
I suppose if you were rigorously following the
principle, you might wait until creating the next
method that would use that variable before defining it. I certainly like YAGNI, but my
is not so bad that I won't occasionally allow
to tell me that I'm going to use something,
even if I don't yet need it. With that said, I try only do it in the most obvious of cases, such as this one.
Now that we've written the code for
, its time to run the test again. Doing so,
I see that I have two test that run green (this one, and our
We've gone red-green, so now it's time to refactor. Unfortunately, I don't see any places to do that
yet, but I think they'll reveal themselves next time when we write
our second test and second method in
. (To be continued...)
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
There are no comments for this entry yet.
Leave a comment