David Goudreau's blog
Ask for Help
"Paperclip and fixture builder - we're getting some strange errors that for some reason are fixed when you rerun fixture builder - any ideas?"
No one has run into this specifically, but a few people said to make sure you're mocking out Paperclip.
"Fakeweb, Webmock, VCR, artifice - what's a good Ruby/Rails developer to use?"
It was mentioned that Artifice is good for Selenium tests while Fakeweb and Webmock are good for rSpec tests. VCR's got some fans as well. Sounds like you can't go all that wrong whatever you choose.
Interesting-y
Interestings
Get your Rails mentoring on at RailsBridge this April 8th & 9th @ the Modcloth offices in downtown SF. It's very rewarding.
If you have nested_attributes updating an attribute that is NOT in your attr_accessible attribute list on your ActiveRecord model you won't get an exception - it will just silently fail. It will, however, output a warning line to your Rails log file. Fun for the whole family.
Using popen to open a process actually calls 'sh -c' to open your process, so the process you just ran is actually the child of the 'sh -c' process you just ran. This makes tracking down PIDs simply wonderful. :-) You can use 'exec' instead and your process will be the parent process. But if you're using the new hotness you can instead use Process.spawn in Ruby 1.9.
Ask for Help
"Is there a better way to work on a feature, set that feature set aside, do a small change, check that small change in, then resume work on the feature, all using Git?"
git stash was originally used. There were also suggestions to use a feature branch or use one of the Git GUI tools (gitx, tower, smartgit, gitti) that let you partially stage your changes then check in. Or git-friendly workflow scripts or the ol' reliable git cherry-pick.
Help
- Does anyone know how to set a caching header for urls that end with a cachebusting string (e.g. ?123456789)? Apparently you're not allowed to get the query string when mucking with rewrite rules. A couple of people think that you are able to get your hands on it...somehow.
- How do you do a screen capture from the Mac command line? We want to do a screen capture of a running emulator. Maybe something like this?
Interesting Things
Rails 2.3.8 - for nested attributes, '_destroy' is the new '_delete'. Looks like the Rails team is on top of it. Use
@foo.update_attributes(:foo_attributes => {'0' => {:id => '1', '_destroy' => '1'}})instead of
@foo.update_attributes(:foo_attributes => {'0' => {:id => '1', '_delete' => '1'}})
Help
- Determining a users default time zone - someone must have solved this already, right? Well, Javascript only gives you the time offset, which isn't that useful, but Fleegix has some good support we've used on other projects.
- The after_commit gem - we wanted to create an audit entry every time a particular model failed to create successfully. We tried using the after_rollback hook in both our tests and our development environment but it just didn't work. The before_rollback callback also didn't work, but the non-rollback callbacks in the gem seemed to behave. Anyone have any thoughts outside of overriding ActiveRecord ourselves?
Interesting Things
- Vows - real async Javascript testing for Node.js. Jasmine does support some async testing, but it sounds like it's a bit clunky to do.
- Using RVM on the server - is anybody doing this? Apparently not yet, but we had some strongly differing opinions on the matter as to how useful it would be and if it's the right tool for the job. To be continued...
Rails 2.3.8 + mongrel_rails + Rack 1.1.0 - cookies do not work. At all. Apparently with Rack, cookies get fed into mongrel_rails as an array, while Mongrel expects them to be a String. Looks like someone already ran into this. The fix is to throw this in a Rails initializer file:
class Mongrel::CGIWrapper def header_with_rails_fix(options = 'text/html') @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie'] header_without_rails_fix(options) end alias_method_chain(:header, :rails_fix) end if Rails.version == '2.3.8' and Gem.available?('mongrel', Gem::Requirement.new('~>1.1.5')) and self.class.const_defined?(:Mongrel)(As an aside, running mongrel_rails by using script/server works fine, we only found this issue when running our Webrat Selenium tests, which calls mongrel_rails in some different way that causes this bug to be exposed.)
Help!
- Ey cloud deploy - has anyone done a deploy to EY cloud and seen the Mongrel instances not get bounced?
- Does anyone have any tips on testing distributed applications? We're looking for the least ugly/painful way to do it well.
Interesting Things
- Rvm and sudo - for goodness sake don't do it.
- Sass not recompiling on deploys - a few of our projects have seen Sass files not recompile/update for some reason that we've yet to track down. So instead of spelunking through Sass code we just force the issue by having a rake task that forces the recompile - see this post for details.
- Rails xhr redirect - one of our projects is using the xhr_redirect plugin to support ajax redirects - careful if you want to use it in your tests - it self-destructs if your Rails environment == 'test'
- Android meetup tonight at 6:30 PM - check out the details.
- New Redis recipe from EY - following up from yesterday, the new EY recipe to set up Redis appears to work fine with a little tweaking.
Interesting Things
Redis at EngineYard - EY recently fixed a bug in their system chef scripts that was unintentionally installing Redis, so if you're relying on it being there you may find it missing on your next deploy. EY has apparently just added a recipe for running Redis on a utility slice in ey-cloud-recipes. We haven't tried it out yet but at first glance it looks ok. This new recipe doesn't support running Redis on a solo instance, but it doesn't look too hard to change it to do that.
Library reorganization - we here at Pivotal have a library of books we let people 'check out'. We've just reorganized it a bit. Let our local librarians know if it's working for ya.
Mobile meetup - there's a mobile meetup tonight from 6-8 PM tonight at Horatius in Potrero Hill. They're expecting people from top mobile companies including entrepreneurs, application developers, designers, marketing/business, etc - please RSVP at the Facebook to attend.
Help!
Does Git have keyword substitution like Subversion?
Well, yes and no. You can use gitattributes to do this, though one person wonders why you'd even want to do this in the first place.
Help!
Git branch best practices - we have a customer who doesn't do acceptance often enough so we'd like to keep production code in a different branch from demo code. Any suggestions?
Our friend Josh Susser has a good blog post on git branching workflow. Some other suggestions are to have a separate 'deploy' branch which you cherrypick changes from your 'development' branch with and deploy to production with (this would, however, require a separate integration test process to integrate the cherrypicked changes). Or, of course, round up your customer and have them do acceptance more regularly.
RubyMine - some Pivots are having issues running RSpec in their Rails projects.
The usual steps we take are to make sure you can Command-click the rspec and spec/rails references in your spec_helper.rb and get to the gems they correspond to and to make sure your spec directory is flagged as a test directory in Settings => Project Structure in RubyMine. That didn't seem to solve this particular issue, though. There was some talk about commenting out arbitrary 'require' statements in your files and that change somehow making RSpec run correctly. Strange.
Testing paperclip - tests don't behave correctly when running them in RubyMine. There are issues with the 'identify' command.
A possible issue is that ghostscript is not installed. Paperclip uses ImageMagick which uses ghostscript to identify attachment file types. You can install ghostscript using MacPorts. This can be tough to track down because paperclip appears to just swallow the exception that occurs when using ghostscript. Some other projects are mocking out paperclip in their tests to avoid the issue completely.
validates_associated fun in 2.3.5 - it's changed from 2.3.4. Another change is depending on rack 1.0.1
You can now boot from ebs on Amazon
It appears that ActiveRecord now validates all associated objects by default, for any type of validation. Given this example:
class User < AR::Base has_many :wibbles end class Wibble < AR::Base validates_presence_of :name endwhen you save a User, it will validate all associated wibbles and fail validation if any wibble fails validation. This always happens on create, and it appears happens on update if the association is an auto-save association, which it implicitly becomes if you allow nested attribute create/update for the association.
Before Rails 2.3.4 a failed validation on an association would give you a moderately nonsensical validation error. In the case of the above example, if the name validation failed on an associated wibble then the user would have the error "Name can't be blank," which is, of course, misleading. The attribute name for the error would just be "name", so tests for the validation would be something like @user.should have(1).error_on(:name)
As of Rails 2.3.4 (possibly 2.3.3) the error message for a validation failure on an associated object changed to include the object type, so if the name validation failed on an associated wibble then the user would have the error "Wibbles name can't be blank." They accomplished this by changing the attribute name for the error to "#{association_name}_#{attribute_name}", thus "wibbles_name". Tests for the validation would have to change to @user.should have(1).error_on(:wibbles_name)
As of Rails 2.3.5, the error message for a validation failure on an associated object is back to what it was pre-2.3.4 ("Name can't be blank"). However, this is because the attribute name for the error is now "#{association_name}.#{attribute_name}. So, tests have to change again to @user.should have(1).error_on('wibbles.name')
Not really a huge difference, just an annoyance that it keeps changing.
Interesting Things
SMSW - this is an annual supermarket street sweep that benefits the San Francisco Food Bank. Ride on bikes, pick up foodstuffs from supermarkets and win prizes while helping the Food Bank! This Saturday 12/5 at noon.
Check out the AAU Future Tense exhibit at 688 Sutter Street Gallery - a showing of art that you can actually pick up with your hands! Exhibit is open thru January.
Help!
- Heroku logs - how do you get more than 20 lines? Is there an option to get the entire log? Apparently there used to be an option to get the whole thing. Looks like we're not the only ones looking for this.
- Webrat - is it really as incomplete as it appears? The answer is yes. We've had to create a bunch of the api ourselves to facilitate using it. If you know you're just going to use the Selenium portion of it without the Rails integration option then you might just call the Selenium API directly (which Webrat does make available to you) from your Selenium tests.
Interesting Things
Rails XML parameter rudeness - sometimes when only a single model is posted, it does not generate the second array, and instead gives you a hash (i.re. not wrapped in []). This is apparently a well-known bug. Workaround is pretty straightforward:
widgets = params[:widgets][:widget] if widgets.is_a?(Hash) widgets = [widgets] endMovember is over but you can revel in the 'stashes all year long at Pivotal Movember.
