Author: Anthony Caliendo

Accessing the Icon for a Button Programmatically in Flex 3

flex_logo

The other day, I was trying to get the icon for a button in flex programmatically for a FlexUnit test. The code I was testing set the icon of a button using setStyle('icon', ICON). I attempted the obvious button.getStyle('icon') in the test, but was surprised that this always returned null.

A little bit of digging revealed that the I needed to go through the style declaration for the button. When changing my test to assert on button.styleDeclaration.getStyle('icon'), I was able to successfully access the icon.

I found this a bit non-intuitive, but fortunately it only involved some investigation and minimal code changes.

Topics:

acts_without_database: Now a Rails Plugin

Ruby on Rails

Quite a while ago, I wrote a blog post which included some code which allowed you to use ActiveRecord without needing a database table.

I recently needed that functionality again, so I converted that code into a plugin and put it on github so that I could easily include it in another project. While doing this, I also cleaned up and simplified the code quite a bit.

The github page is here: http://github.com/AnthonyCaliendo/acts_without_database/

Related Services: Ruby on Rails Development
, Custom Software Development

Topics: ,

Using Mocha for ActiveRecord Partial Mocks with Finders

Mocha is the mocking library used by the Rails team, so it has understandably gained some traction among Rails developers. I have started using it over flexmock lately, but ran into some problems with partial mocks on ActiveRecord objects. The problem stemmed from the fact that ActiveRecord instantiates new records when returning records from finders, which meant that creating partial mocks for a particular record was difficult.

I created a helper method to make this easier, and so far it has cleaned up a bit of my tests.
Continue reading »

3 Misuses of Code Comments

hammer-and-screw
Photo Credit: by dpascoe

Not many people talk about good practices to use for comments in code. Many people see them as an extra or freebie, so not a lot of thought gets put into them. The truth is, though, that comments are a great tool for giving insight into the thought process when the code was being written. Unfortunately like any tool, comments can be misused.

Here are three of the most common misuses of comments which I tend to run into.

Continue reading »

Grails: Custom Parent/Child Aware Tags

grails_logo

Recently, I needed to create a special tag in Grails which would render specific children in a way that is aware of their order. I wanted to stick entirely with markup (not passing an array to a tag), and also wanted to avoid putting lots of logic inside a .tag file. While it was possible to write a tag lib which first parsed the children in a "non-render" mode, I preferred a solution which did not require doing my own parsing before render. The solution I came up with isn't the most flexible, but it got the job done in a relatively clean way with minimal custom code.

The following is an example solution with the associated code and tests.
Continue reading »

Topics: , ,

Remove/Cancel Bubbling for an Event in Flex3

fx_icon_special_100x100

I recently had an issue in flex where I needed the click event for a component in an ItemRenderer to not bubble up to the parent list. Since the click event was being dispatched by Flex SDK code, I could not directly do this by passing false into the event's constructor. I had hoped to find a property I could set on the object, something like "clickBubbles", which I could set which would accomplish this.

Either that property doesn't exist or I could not find it. My solution was to basically hijack the event and send an impersonator in its place.

Continue reading »

Topics: , ,

Unit Testing: Can You Afford Not To?

fitty_cent

50 Cent's unit test based savings

Unit testing is fairly common these days as more and more people understand the benefits; however, you may still run into a client or manager who is not convinced. These people tend to think unit testing increases development time and cost, or they feel that unit tests are redundant since a QA department is also testing the application. If you've ever heard "we don't have time for unit tests", "you're a developer, leave testing to QA", or "I'm not paying you to write tests" then you know what I'm talking about.

These encounters can be quite frustrating for a developer or project manager who wants to leverage unit testing. While there might be a temptation to just unit test anyway without the blessing of a client or manager, it is more useful to help these people understand why they are mistaken about unit tests. I have found that this misunderstanding is often because they don't realize that testing is actually a cost saver instead of just an additional cost.

But how to vocalize this point in a way they will understand?

Continue reading »

Topics:

Notification Testing with PureMVC and FlexUnit

flex-puremvc

One of the nice extensions available for FlexUnit is the ability to easily unit test event behavior using EventfulTestCase.

This library has support for testing Cairngorm, but unfortunately support is lacking for PureMVC. I searched for existing solutions which added PureMVC notification support, but was not satisfied with their APIs. Luckily, it was not difficult to write some code to support PureMVC which mirrored the API of EventfulTestCase.

Continue reading »

Grails: Delegating to GORM Persistence in Java

For a recent project, I needed to plug some Java code into a Grails app. I wanted to use GORM for persistence, but couldn't introduce the interfaces, proxies, and factories into the java code which is required for existing solutions to this problem.

Basically, my constraint was that the java code itself couldn't be altered to work inside the grails app. The solution I came up with is pretty simple, but works well.

Continue reading »

Topics: , , ,

ActionMailer Callbacks: In the Spirit of ActionController Filters

One of the most useful features of ActionController is the ability to add filters before, after, or around actions.  This tool is made even more powerful by the ability to chain filters together.  Allowing an AOP approach is indispensable for addressing cross cutting concerns (or simply separating concerns), and is one of the things which makes a framework valuable to a developer (Spring is an excellent example of this).

A while back, I had a requirement to persist a record of which email addresses were sent an email through the system.  I expected to find callback support for ActionMailer, but was surprised to find that it didn't exist.

I had three options: put the logic inline in each ActionMailer method which is not DRY and muddles concerns, put the logic in the ActionContoller as filters which break encapsulation in terrible ways (and is at the wrong layer), or extend ActionMailler to allow callback methods.

I choose the latter...

Continue reading »

Getting Rid of the “handler.call: handler undefined” Error

If you're using prototype (or rails, which uses prototype by default), you've probably seen this javascript error before:

handler is undefined

While not particularly threatening (no ill side effects seem to occur), the error causes a lot of noise and, quite frankly, is pretty annoying. Fortunately, there is a quick and painless patch to keep your error log free from this bane.

Continue reading »

acts_without_database: Leverage ActiveRecord with Non-Database Backed Objects

ActiveRecord comes with a lot of nice things that aren't really dependent on having a database backed model. The most obvious example of this is the validation framework baked into ActiveRecord. Also, there are several plugins which add some useful behavior to ActiveRecord objects but don't rely on having a database.

In the future, I believe the rails team aims to make certain things more modular and easier to pull out and use separately from ActiveRecord (validation being one of those). However, if you are working on a project which is locked into a certain version of rails or you're impatient, there is a very simple plugin which can solve your needs.

Enter acts_without_database...
Continue reading »

Scriptaculous Drag and Drop with AJAX Update Fix for IE

If you have used scriptaculous to do drag and drop interactions which result in a replacement of the DOM element you are dropping into, you may have noticed that you can only do one drag and drop before it breaks in IE. The problem occurs when you replace a DOM element which is defined as a Droppable; IE will fail because it will still have the original element registered as a Droppable but it does not handle the fact that it no longer exists in the DOM. Firefox and safari have no issue with this, so this is another frustrating IE specific issue.

Fortunately, this problem is easily solved with a single line of javascript.
Continue reading »

Subtle OpenGL Projection Matrix Difference Between iPhone Simulator and Device

iPhone in Dock

If you are deploying to the iPhone simulator instead of to a device, you can get away with not loading the identity matrix for the projection matrix so long as you do not want to draw over any bound textures which are drawn.  However, on an iPhone device, you will notice some serious artifacting if you attempt this.  The artifacts will be related to the last drawn textures, even if they were drawn from a different application (except if the phone was turned off in the interim, in which case you will get a black strobe effect).

This implies that the simulator loads the identity matrix automatically for GL_PROJECTION when loading your application, where as the iPhone itself will maintain the matrix's state between applications.

Related Services: iPhone Application Development, Custom Software Development

Topics: ,

Installing Edge Ferret/acts_as_ferret

If you do a gem install ferret, you will be getting 0.11.6. The latest stable version of acts_as_ferret is 0.4.3. Both of these versions were released nearly a year ago in November 2007. Since then, there have been various performance improvements and bug fixes which you'll be missing out on. In order to get the latest versions, you'll need to do a little bit of work but I would recommend it if an update is feasible for you.

Since it will be the easiest, let's begin with acts_as_ferret.
Continue reading »

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com