<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Matthew Bass &#187; Rails</title>
	<atom:link href="http://matthewbass.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewbass.com</link>
	<description>Musings on software and life...</description>
	<lastBuildDate>Fri, 24 Feb 2012 16:48:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Announcing youtube_tags extension for Radiant</title>
		<link>http://matthewbass.com/2010/10/31/announcing-youtube_tags-extension-for-radiant/</link>
		<comments>http://matthewbass.com/2010/10/31/announcing-youtube_tags-extension-for-radiant/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 18:47:19 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=651</guid>
		<description><![CDATA[A recent project required the latest YouTube videos from a specific user to be listed inside a Radiant page. There wasn&#8217;t an existing extension that did this so I built my own. youtube_tags is based on the excellent twitter_tags extension. It enables inclusion of YouTube videos within Radiant pages using a series of Radius tags. [...]]]></description>
			<content:encoded><![CDATA[<p>A recent project required the latest YouTube videos from a specific user to be listed inside a Radiant page. There wasn&#8217;t an existing extension that did this so I built my own. <a href="http://ext.radiantcms.org/extensions/248-youtube-tags">youtube_tags</a> is based on the excellent <a href="http://ext.radiantcms.org/extensions/120-twitter-tags">twitter_tags</a> extension. It enables inclusion of YouTube videos within Radiant pages using a series of Radius tags. It leverages the youtube-g gem to pull data directly from the GData API.</p>
<p>For example, this is how you would display linked titles for the top 5 videos from my YouTube account (&#8220;pelargir&#8221;) using the Radius tags provided by the extension:</p>
<pre class="brush: xml;">
&lt;ul&gt;
  &lt;r:youtube user=&quot;pelargir&quot;&gt;
    &lt;r:videos count=&quot;5&quot;&gt;
      &lt;li&gt;&lt;a href=&quot;&lt;r:video:url /&gt;&quot;&gt;&lt;r:video:title /&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;/r:videos&gt;
  &lt;/r:youtube&gt;
&lt;/ul&gt;
</pre>
<p>To install in your own project, visit the <a href="http://ext.radiantcms.org/extensions/248-youtube-tags">youtube_tags profile</a> in the Radiant extension registry.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/10/31/announcing-youtube_tags-extension-for-radiant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spreedly extension for Radiant</title>
		<link>http://matthewbass.com/2010/08/19/spreedly-extension-for-radiant/</link>
		<comments>http://matthewbass.com/2010/08/19/spreedly-extension-for-radiant/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 03:56:32 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=647</guid>
		<description><![CDATA[I built the original Spreedly extension for Radiant a couple of years ago. It&#8217;s a nice little package that makes it really easy to integrate Spreedly&#8217;s subscription payment system with your Radiant site. You can choose which pages to require a subscription to view, manage subscribers from the admin backend, and so on. It&#8217;s long [...]]]></description>
			<content:encoded><![CDATA[<p>I built the original <a href="http://ext.radiantcms.org/extensions/133-spreedly">Spreedly extension</a> for Radiant a couple of years ago. It&#8217;s a nice little package that makes it really easy to integrate Spreedly&#8217;s subscription payment system with your Radiant site. You can choose which pages to require a subscription to view, manage subscribers from the admin backend, and so on. It&#8217;s long overdue, but I finally got around to upgrading the extension to work flawlessly with Radiant 0.9.1. <a href="http://ext.radiantcms.org/extensions/133-spreedly">Check it out</a> and have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/08/19/spreedly-extension-for-radiant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drop seconds when querying MySQL timestamps</title>
		<link>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/</link>
		<comments>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 20:35:36 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=600</guid>
		<description><![CDATA[One of the Rails apps I&#8217;ve been working on formats times as HH:MM in the view. No seconds are displayed. This is a pretty common way to format things. When doing timestamp comparisons in SQL, however, the seconds are taken into account. This is bad since it can cause discrepancies in the view.
For example, say [...]]]></description>
			<content:encoded><![CDATA[<p>One of the Rails apps I&#8217;ve been working on formats times as HH:MM in the view. No seconds are displayed. This is a pretty common way to format things. When doing timestamp comparisons in SQL, however, the seconds <em>are</em> taken into account. This is bad since it can cause discrepancies in the view.</p>
<p>For example, say I have a table of records with created_at timestamps. My view displays all records with timestamps equal to or before the current time. Let&#8217;s assume the current time is 15:00:00 precisely and I happen to have a record with a timestamp of 15:00:00 in the database. The SQL comparison would work fine in this case.</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE created_at &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; 1 row in set
</pre>
<p>What if the timestamp in the database is 15:00:03 though? Let&#8217;s run the query again.</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE created_at &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; Empty set
</pre>
<p>Since 15:00:03 is <em>greater</em> than the current time of 15:00:00, the record doesn&#8217;t get returned. This would be fine if we were displaying seconds in the view, but we&#8217;re not. From the user&#8217;s perspective, the timestamp on the record is still 15:00 and <strong>should</strong> appear in the view since it&#8217;s equal to the current time. But it doesn&#8217;t.</p>
<p>One way to fix this would be to handle the time comparisons in Ruby. This is certainly a legitimate option. For this particular project, though, performance was a big issue. (And we all know that <a href="http://canrailsscale.com">Rails can&#8217;t scale</a>.) I needed a way to continue letting the database handle the comparisons while disregarding seconds.</p>
<p>The solution I ended up with isn&#8217;t ideal (it relies on a couple of functions built into MySQL) but it works fine and runs fast:</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE (created_at - INTERVAL SECOND(created_at) SECOND) &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; 1 row in set
</pre>
<p>The number of seconds is extracted from the created_at timestamp and then subtracted from the timestamp. So if the timestamp was 15:00:03, MySQL subtracts 3 seconds to end up with 15:00:00.</p>
<p>This solved the comparison problem for me and made my client very happy. Double win.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails 2.3.8 &#8211; an embarrassing trip</title>
		<link>http://matthewbass.com/2010/06/10/rails-2-3-8-an-embarrassing-trip/</link>
		<comments>http://matthewbass.com/2010/06/10/rails-2-3-8-an-embarrassing-trip/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 18:33:46 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=560</guid>
		<description><![CDATA[November 30, 2009: Rails 2.3.5 has just been released. I upgrade my production Rails apps and rock on.
February 17 of this year: RubyGems 1.3.6 is released and my apps begin suffering from deprecation warnings. They&#8217;re all over the place: when I run a test, when I launch script/console&#8230; when I sneeze.

/Users/pelargir/Projects/teascript/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and [...]]]></description>
			<content:encoded><![CDATA[<p>November 30, 2009: Rails 2.3.5 has just been released. I upgrade my production Rails apps and rock on.</p>
<p>February 17 of this year: RubyGems 1.3.6 is released and my apps begin suffering from deprecation warnings. They&#8217;re all over the place: when I run a test, when I launch script/console&#8230; when I sneeze.</p>
<pre class="brush: bash;">
/Users/pelargir/Projects/teascript/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement
</pre>
<p>Rumor has it the deprecation warning will go away with 2.3.6. And 2.3.6 is expected to drop any day. Yay! Problem will be solved soon&#8230; or so I thought. I begin waiting.</p>
<p>May 23: 2.3.6 finally drops.<br />
May 24: 2.3.7 drops because of a bug in 2.3.6. What the heck?<br />
May 25: 2.3.8 drops because of a bug in 2.3.7. Okay, this is getting crazy.</p>
<p>Was anyone else embarrassed about the 6-month delay for 2.3.6 followed by two more point releases over the span of three days? This is exactly the kind of anecdote an exec at a Fortune 500 would raise to prevent a move towards Rails and keep the company locked into Java or .NET for another decade. Ugh.</p>
<p>We can do better than this.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/06/10/rails-2-3-8-an-embarrassing-trip/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Quick &#8216;n dirty Lindo step for Cucumber</title>
		<link>http://matthewbass.com/2010/05/11/quick-n-dirty-lindo-step-for-cucumber/</link>
		<comments>http://matthewbass.com/2010/05/11/quick-n-dirty-lindo-step-for-cucumber/#comments</comments>
		<pubDate>Tue, 11 May 2010 19:02:54 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=523</guid>
		<description><![CDATA[Lindo is great for verifying your Rails tests by opening the HTTP response body in a browser for inspection. It works with most popular testing frameworks including Test::Unit and RSpec. But what about Cucumber?
It&#8217;s actually pretty easy to build a custom Cucumber step that triggers Lindo from your cukes. First, install the Lindo gem in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.adeptware.com/blog/2009/06/29/lindo-makes-rails-testing-easier/">Lindo</a> is great for verifying your Rails tests by opening the HTTP response body in a browser for inspection. It works with most popular testing frameworks including Test::Unit and RSpec. But what about Cucumber?</p>
<p>It&#8217;s actually pretty easy to build a custom Cucumber step that triggers Lindo from your cukes. First, install the Lindo gem in your Rails app. Then create <code>features/steps/lindo_steps.rb</code> and insert this code:</p>
<pre class="brush: ruby;">
Then /^render the current page$/ do
  extend Lindo
  vr
end
</pre>
<p>The step can be named whatever you like best, but &#8220;render the current page&#8221; works for me. To trigger Lindo from within your cukes, simply reference the step like so:</p>
<pre class="brush: ruby;">
Given I am logged in
When I follow &quot;some link&quot;
Then render the current page
</pre>
<p>When Cucumber hits the last step, the default browser window will open and the contents of the page at that step in the scenario will be displayed. This is very handy when troubleshooting why a specific scenario is failing. It&#8217;s also useful for determining what you should be testing for on a given page.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/05/11/quick-n-dirty-lindo-step-for-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dirty date/time attrs in Rails lose their time zone</title>
		<link>http://matthewbass.com/2010/02/21/dirty-datetime-attrs-in-rails-lose-their-time-zone/</link>
		<comments>http://matthewbass.com/2010/02/21/dirty-datetime-attrs-in-rails-lose-their-time-zone/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 03:09:38 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=499</guid>
		<description><![CDATA[Dirty attributes were recently added to Rails and they&#8217;re quite useful. However, I ran into a problem where a dirty date/time attribute was losing its time zone information after a save. I was doing a comparison between two dates in a before_update callback like so:

before_update do
  if started_at.to_s(:abbrev_date) != started_at_was.to_s(:abbrev_date)
    errors.add [...]]]></description>
			<content:encoded><![CDATA[<p>Dirty attributes were recently added to Rails and they&#8217;re quite useful. However, I ran into a problem where a dirty date/time attribute was losing its time zone information after a save. I was doing a comparison between two dates in a before_update callback like so:</p>
<pre class="brush: ruby;">
before_update do
  if started_at.to_s(:abbrev_date) != started_at_was.to_s(:abbrev_date)
    errors.add :started_at, &quot;cannot be set to a different day&quot;
  end
end
</pre>
<p>The <code>started_at</code> date was coming back in the Eastern time zone as expected. The <code>started_at_was</code> attribute, which was supposed to reflect the value prior to the update, was coming back as a UTC date/time. I would expect it to be returned in the Eastern time zone too. Apparently, I&#8217;m not alone in this assumption because <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3658-dirty-datetime-attributes-lose-time-zone-info">a ticket</a> was opened for this issue last month.</p>
<p>An official fix hasn&#8217;t been made yet, but I got around the problem by calling <code>in_time_zone</code> on my dirty attribute:</p>
<pre class="brush: ruby;">
before_update do
  if started_at.to_s(:abbrev_date) != started_at_was.in_time_zone.to_s(:abbrev_date)
    errors.add :started_at, &quot;cannot be set to a different day&quot;
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/02/21/dirty-datetime-attrs-in-rails-lose-their-time-zone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mass rename files in UNIX</title>
		<link>http://matthewbass.com/2010/02/11/mass-rename-files-in-unix/</link>
		<comments>http://matthewbass.com/2010/02/11/mass-rename-files-in-unix/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 18:23:26 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[General Interest]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=459</guid>
		<description><![CDATA[Several of my Rails projects surface a RESTful API. I use integration tests to verify that the API calls work as expected. I also version my API calls so I can easily adapt the API to new circumstances while maintaining backwards compatibility.
To move to a new API version, I copy all of the existing integration [...]]]></description>
			<content:encoded><![CDATA[<p>Several of my Rails projects surface a RESTful API. I use integration tests to verify that the API calls work as expected. I also version my API calls so I can easily adapt the API to new circumstances while maintaining backwards compatibility.</p>
<p>To move to a new API version, I copy all of the existing integration tests and rename their prefix to the new version. Instead of renaming the files by hand, there is a nifty UNIX command that handles it for me. For example, to rename all the &#8220;v2_*.rb&#8221; files to &#8220;v3_*.rb&#8221; I would type:</p>
<pre class="brush: bash; light: true;">
for file in *; do mv &quot;$file&quot; &quot;v3_${file#v2_}&quot;; done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/02/11/mass-rename-files-in-unix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>test_spec_on_rails now runs on Rails 2.3</title>
		<link>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/</link>
		<comments>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 01:26:09 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=295</guid>
		<description><![CDATA[If anyone still happens to be using test_spec, you&#8217;ll be thrilled to know that the test_spec_on_rails plugin is now compatible with Rails 2.3. It has also been converted to a gem. Install with:

sudo gem install test_spec_on_rails

Add to your Rails app&#8217;s test.rb like so:

config.gem 'test_spec_on_rails'

Enjoy the goodness of test-spec helpers from inside your Rails tests. Fork [...]]]></description>
			<content:encoded><![CDATA[<p>If anyone still happens to be using <a href="http://github.com/relevance/test-spec/">test_spec</a>, you&#8217;ll be thrilled to know that the test_spec_on_rails plugin is now compatible with Rails 2.3. It has also been converted to a gem. Install with:</p>
<pre class="brush: bash; light: true;">
sudo gem install test_spec_on_rails
</pre>
<p>Add to your Rails app&#8217;s test.rb like so:</p>
<pre class="brush: ruby; light: true;">
config.gem 'test_spec_on_rails'
</pre>
<p>Enjoy the goodness of test-spec helpers from inside your Rails tests. Fork and submit patches via the <a href="http://github.com/pelargir/test_spec_on_rails">GitHub project</a>. Tell your friends. Donate money. Vote for Pedro.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time warping gem goodness</title>
		<link>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/</link>
		<comments>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 00:23:49 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=438</guid>
		<description><![CDATA[The time zone warp code I posted about last week is now a gem:

sudo gem install time-zone-warp

To configure in your Rails app, add this line to the bottom of test.rb:

config.gem 'time-zone-warp', :lib =&#62; 'time_zone_warp'

You can also fork the code from the project on GitHub.
]]></description>
			<content:encoded><![CDATA[<p>The <a href="2009/11/18/time-zone-warp/">time zone warp</a> code I posted about last week is now a gem:</p>
<pre class="brush: bash; light: true;">
sudo gem install time-zone-warp
</pre>
<p>To configure in your Rails app, add this line to the bottom of test.rb:</p>
<pre class="brush: ruby; light: true;">
config.gem 'time-zone-warp', :lib =&gt; 'time_zone_warp'
</pre>
<p>You can also fork the code from <a href="http://github.com/adeptware/time-zone-warp">the project on GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time zone warp</title>
		<link>http://matthewbass.com/2009/11/18/time-zone-warp/</link>
		<comments>http://matthewbass.com/2009/11/18/time-zone-warp/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 02:47:56 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=428</guid>
		<description><![CDATA[One of my Rails projects makes heavy use of time zones. I&#8217;ve run into some issues writing good tests for this type of thing. In particular, I&#8217;ve needed my tests to run within a time zone outside my own. But I don&#8217;t want to permanently change the time zone within the scope of the entire [...]]]></description>
			<content:encoded><![CDATA[<p>One of my Rails projects makes heavy use of time zones. I&#8217;ve run into some issues writing good tests for this type of thing. In particular, I&#8217;ve needed my tests to run within a time zone outside my own. But I don&#8217;t want to permanently change the time zone within the scope of the entire test run. I ended up coding this handler:</p>
<pre class="brush: ruby;">
module ZoneWarp
  def pretend_zone_is(zone)
    original_zone = Time.zone
    begin
      Time.zone = zone
      yield
    ensure
      Time.zone = original_zone
    end
  end
end

Test::Unit::TestCase.send(:include, ZoneWarp)
</pre>
<p>Simply stick this code in a file inside your <code>config/initializers</code> directory (or include it from test_helper.rb or spec_helper.rb if you insist on doing it the <em>right</em> way) and you&#8217;re all set to write tests like this:</p>
<pre class="brush: ruby;">
test &quot;code works in other time zones&quot; do
  pretend_zone_is &quot;Mountain Time (US &amp; Canada)&quot; do
    # assertions go here
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/11/18/time-zone-warp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

