- Functional tests running slowly after upgrade to Rails 2.2
A project upgraded to Rails 2.2 which was previously able to complete its functional suite in under 300 seconds now takes a leisurely 6000 seconds to finish. Speculation about possible causes is welcomed. Meanwhile, I suspect ghosts.
UPDATE: apparently the functional tests were running slow due to memory swappage (the memory swappage, in turn, caused by ghosts, no doubt).
- Rails 2.2 may break Selenium tests
- FixtureScenarios and slow test suites
A pivot installed FixtureScenarios on a project and found that the addition of the plugin alone (with no configured fixtures) doubled the time the project’s test suites took to complete. FixtureScenarios are now dead to Adam. Dead!
- No Pivotal Breakfast tomorrow
Karen Tsui and Ling-Wen Chang tirelessly prepare the world-famous Pivotal breakfast each day and generally make the San Francisco office an awesome place to work. They’re finally taking a much deserved break tomorrow, so now is a wonderful time to publicly recognize their much appreciated work. Thanks, and happy holidays!
- Helper tests failing after Rails 2.2 upgrade.
A project was upgraded to run on Rails 2.2 and now has a handful of hate for helper tests. The tests in question use a stub Controller to generate a template and end up getting some nil variables. cache_classes is off. Suggestions welcome.
- Pivotal Tracker Team Strength Reminder
If team members are out sick or on vacation, you can adjust your team strength settings by clicking on the blue icon at the end of the current iterations release marker. This will recalculate your current iteration velocity accordingly.
It is bad form to name your partials ‘flash’, because they attempt to populate a flash variable which has the nasty side effect of blowing away your notification array. Naming a partial ‘phlash’ produces no adverse effects outside of looking a little silly. ‘shazzam’ and ‘booyakkasha’ are also acceptable although somewhat less descriptive.
A default deploy with capistrano and git appears to prefer using the local working set instead of the configured repo (in this case, github). This may end up surprising you a great deal if you do a deploy from a machine that isn’t an exact copy of HEAD. It was suggested that best practice is to deploy tags from a dedicated CI box rather than a development workstation.
- Ruby On Rails Noteworthy Applications
http://rubyonrails.org has a new design, and with it came a page of noteworthy apps running RoR. Are you a Pivotal client who’d like to see your site up there? Get in touch!
- Removing class definitions with Object.send(:remove_const, :Foo)
Sometimes it is necessary to reload or replace a stub/test class during testing (apparently rspec is particularly susceptible to this). This can be achieved using Object.send(:remove_const, :Foo) where Foo is the camel-cased name of the class. If your class is defined within a module, it may be necessary to use Module.send(:remove_const, :Foo)
Ask for help
- foo.bar.reload versus foo.bar(true)
As a point of curiosity, does anybody know when has_many relationship reloading moved from (or to?) foo.bar(true) to foo.bar.reload? The reload syntax seems preferable for readability; will foo.bar(true) continue to work in the future?
- has_many_polymorphs preloads models
has_many_polymorphs will scan through the models directory for any files that include the plugin and preload them. This can cause problems if these models depend on other plugins (that have not yet been loaded) to operate correctly. The has_many_polymorphs source mentions this behavior in a comment and includes a fix:
Searches for models that use has_many_polymorphs or acts_as_double_polymorphic_join and makes sure that they get loaded during app initialization. This ensures that helper methods are injected into the target classes.
Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_polymorphs_options. For example, if you need an application extension to be required before has_many_polymorphs loads your models, add an after_initialize block in config/environment.rb that appends to the ‘requirements’ key:
Rails::Initializer.run do |config|
# your other configuration here
config.has_many_polymorphs_options['requirements'] << 'lib/my_extension'
Instead of using config.has_many_polymorphs_options, we were able to achieve the same effect by simply dropping our required plugins into the after_initialize block. If we decide to remove has_many_polymorphs in the future, the config file should still run correctly. It’s worth noting that the UltraSphinx search plugin operates in a similar fashion.
Ask for help
- Ajax click_and_wait for Selenium?
assert_text_present offers a simple way to test Ajax behaviors in Selenium, as it will wait 5 seconds (during which the Ajax callback can complete) while looking for the specified text (which can be the body of your Ajax response). Another strategy with which we’ve had some luck is to write a custom method that will wait a specified amount of time before continuing (particularly useful if your Ajax call takes a lengthy amount of time to complete).
- before_save and after_save may not perform as you expect!
Previously, returning false from before or after
filters callbacks would halt the chain entirely. This is no longer the case, except with before_save and after_save — returning false in a before_save will stop the filter callback chain and prevent a save, returning false in an after_save will stop the filter chain silently, and NOT rollback the save. This can be troublesome if you have after_save filters callbacks you expect to execute, especially if you have conditional clauses in an after_save, as they can easily return a false value where you did not intend it.
Please see Brandon Keepers’ clarification regarding filters vs. callbacks below — thanks Brandon!
Ask for help
- Bootstrapping data into an existing system?
Using migrations for one-time data inserts can be problematic (for example, when changing seed data; additionally, it’s advisable to create a database from the schema.rb rather than migrations) , it can be useful to create a class that is responsible for inserting the seed data into the database. This class can be wrapped in a capistrano or rake task. The db-populate plugin is designed to aid in this task.
- Multiple Routes/One controller
It is possible to point multiple routes at a single controller, however, this situation may suggest a need for multiple controllers, possibly inheriting from a single base controller containing any shared logic. This prevents a excessive switching logic in controllers, which can help minimize the possibility of argument-related bugs.