<?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>Meta Bates &#187; rails</title>
	<atom:link href="http://www.metabates.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Sun, 15 Aug 2010 12:49:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Fixtures v. Factories &#8211; Can&#8217;t We All Just Get Along?</title>
		<link>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/</link>
		<comments>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 12:49:37 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[factories]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=358</guid>
		<description><![CDATA[Testing in Ruby on Rails is incredibly easy. I mean stupidly easily. So easy that if you&#8217;re not doing it, you are a very, very bad developer and should re-evaluate your career choices. (Yes, I believe in testing that much!) One thing that is not all that easy, however, is object creation and populating your [...]]]></description>
			<content:encoded><![CDATA[<p>Testing in Ruby on Rails is incredibly easy. I mean stupidly easily. So easy that if you&#8217;re not doing it, you are a very, very bad developer and should re-evaluate your career choices. (Yes, I believe in testing that much!) One thing that is not all that easy, however, is object creation and populating your test database. Five years ago when I first started working with Rails the only options we had to get data into the database were fixtures, or hastily written &#8216;factory&#8217;-esque methods custom to each application.</p>
<p>Fixtures, for those who don&#8217;t know, are YAML files that contain YAML-ized versions of objects that then get loaded into the test database when you run your test suite. These objects can then be pulled back from the database during your tests. Sounds great, doesn&#8217;t it? Well, not everybody thinks so. One of the biggest problems with fixtures is they can very quickly get out of control. Keeping track of all the different scenarios your tests needs can get very confusing and frustrating to deal with.</p>
<p><img class="alignleft" title="Factory Workers" src="http://www.uni.edu/schneidj/webquests/adayinthelife/lotsofworkers.jpg" alt="" width="360" height="283" />So how do we fix this problem? Well, most developers have turned to using factories. Factories allow us to quickly build the data we need for each test, now the building of the data you need for your test is right there in a setup or before method. Easy to manage and keep track of. Now there are a plethora of different factory libraries meant to make this task nicer, a few of the popular ones are <a href="http://github.com/thoughtbot/factory_girl" target="_blank">Factory Girl</a>, <a href="http://github.com/notahat/machinist">Machinist</a>, and <a href="http://github.com/flogic/object_daddy" target="_blank">Object Daddy</a>. The problem with this approach, however, is that it can slow down your tests as you are building database objects for nearly every test, and as we all know, object creation and database inserting can be expensive.</p>
<p>So, what can we do to help solve both of these problems? Well, we can use both of these technologies. Together. Yeah, that&#8217;s right I&#8217;m saying you should use fixtures as well as factories. Sound crazy? Not really. Let me explain.</p>
<p>Most Rails applications have most, if not all, of their functionality behind a login. So whenever we&#8217;re testing some controller action that sites behind a login we need a user to login with. If we were using factories we would have a setup or before method that would create a new User object and save it to the database, and it would do that for every variant of the test, as well as every other test in our suite that needs a user object.</p>
<p>Why not, create one user object and use that repeatedly through our tests? What I like to do is stick one or two users in my fixtures, so that they&#8217;re there whenever I need one. I like to do this with most of my major models. Then, when I need to have some custom scenarios, I can break out the factories and build those custom scenarios.</p>
<p>So what does this achieve? Well, I&#8217;ve sped up my tests by already having a few objects in the database, and not having to create them (and roll them back) with each single test. I&#8217;ve also cleaned up my tests significantly by eliminating a lot of setup and/or before methods where these objects were being created. I&#8217;ve also eliminated the biggest problems with fixtures, that they can get overwhelming, because we are only keeping one or two objects in them and using factories for the rest.</p>
<p>I hoped this helped you to understand that we don&#8217;t have to throw the baby out with the bath water when it comes to fixtures and factories, we can use both. Not go forth and test! Test like your life depends on it (because it does!!).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CoverMe &#8211; Code Coverage for Ruby 1.9</title>
		<link>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/</link>
		<comments>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 17:49:44 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=343</guid>
		<description><![CDATA[Ruby 1.9(.2) is an amazing language to develop applications in. It&#8217;s faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language. When making a move of this size it&#8217;s important to have the right tools to help [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby 1.9(.2) is an amazing language to develop applications in. It&#8217;s faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language.</p>
<div id="_mcePaste">When making a move of this size it&#8217;s important to have the right tools to help us along. Unfortunately, one of the most useful tools as a Ruby developer, <a href="http://github.com/relevance/rcov">RCov</a>, does not work with Ruby 1.9.</div>
<div id="_mcePaste">RCov, for those unfamiliar analyzes your code and tells you which part of your code was not executed. This is INCREDIBLY useful when hooked up to your test suite. While, it&#8217;s not the only metric you should use when determining how good your test coverage it, it certainly is a great first step to point out exactly which parts of your code haven&#8217;t been touched at all!</div>
<p>Enter <a href="http://github.com/markbates/cover_me">CoverMe</a>.</p>
<h2>History</h2>
<p>While working on a Ruby 1.9/Rails 3 project, and loving everything about it (except for the lack of RCov), I came across a <a href="http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/">post</a> by Aaron Patterson (of <a href="http://github.com/tenderlove/nokogiri">Nokogiri</a> fame). In this post he quickly outlined a very basic coverage tool using the new built-in Coverage module in Ruby 1.9.</p>
<p>After spending a morning playing with it, I was quickly able to grow the idea into something useful for the project. Later that day the company I was consulting for (<a href="http://www.biddingforgood.com">BiddingForGood.com</a>), and in particular their chief architect, <a href="http://twitter.com/stuartmg">Stuart Garner</a>, told me to take a day or two and clean it up and release it for the world to use, and so <a href="http://github.com/markbates/cover_me">here</a> it is.</p>
<h2>Features</h2>
<p>Here is a brief overview of the features of CoverMe:</p>
<h3>Index Page</h3>
<ul>
<li>Sortable column headers (File, Lines, Lines of Code, Tested %).</li>
<li>Searching/filtering by file name.</li>
<li>Filtering by coverage percent.</li>
<li>Color coded list of files to quickly see which ones are 100% covered, &gt; 90% covered, or less than 90% covered.</li>
<li>Large color coded average coverage percent, for quick reference.</li>
</ul>
<h3>Detail Page</h3>
<ul>
<li>Line by line coverage report</li>
<li>Color coded lines to quickly see which lines where executed and which ones were not.</li>
<li>Side by side viewing with the corresponding test/spec file (if one exists).</li>
</ul>
<p>See the <a href="http://github.com/markbates/cover_me">README</a> file for more information on installation and usage.</p>
<h2>Thanks</h2>
<p>I would just quickly like to give another quick thanks to Aaron Patterson for pointing out the Coverage module in Ruby 1.9 and inspiring this, hopefully, helpful little gem. Also another big thanks to Stuart Garner for pushing me to package this up and release it to the world.</p>
<h2>Screenshots</h2>

<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/detail_side_by_side/' title='detail_side_by_side'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/detail_side_by_side-150x150.png" class="attachment-thumbnail" alt="detail_side_by_side" title="detail_side_by_side" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/detail/' title='detail'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/detail-150x150.png" class="attachment-thumbnail" alt="detail" title="detail" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index_filter/' title='index_filter'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index_filter-150x150.png" class="attachment-thumbnail" alt="index_filter" title="index_filter" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index_search/' title='index_search'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index_search-150x150.png" class="attachment-thumbnail" alt="index_search" title="index_search" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index/' title='index'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index-150x150.png" class="attachment-thumbnail" alt="index" title="index" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Testing is NOT an Option</title>
		<link>http://www.metabates.com/2010/07/01/testing-is-not-an-option/</link>
		<comments>http://www.metabates.com/2010/07/01/testing-is-not-an-option/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 14:04:38 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=337</guid>
		<description><![CDATA[Five years ago I left the world of contracting and reentered the world of the full time employee, and I enjoyed every minute of it (well, almost). Now fast forward five years and I find myself once again at a crossroads. Do I continue on as an FTE or do I become a contractor, and [...]]]></description>
			<content:encoded><![CDATA[<p>Five years ago I left the world of contracting and reentered the world of the full time employee, and I enjoyed every minute of it (well, almost). Now fast forward five years and I find myself once again at a crossroads. Do I continue on as an FTE or do I become a contractor, and play the field, so to speak? Looks like I&#8217;m going to go with the hired gun route for a little while, but that&#8217;s not really the point of this post.</p>
<p>During the past week or so I&#8217;ve spoken with many great companies and people. I&#8217;ve been fortunate enough to have a high degree of interest in what I can bring to the table. During those discussions I talked with a really nice guy at a what seems to be a really cool company, I won&#8217;t name names, because this isn&#8217;t about either the person or the company, but rather something the engineer said during our phone conversation that got me to thinking.</p>
<p><img class="alignleft" title="Failure Testing" src="http://www.commercialventvac.com/finao/failure_testing.jpg" alt="" width="400" height="240" />&#8220;We don&#8217;t have any tests because I couldn&#8217;t convince the company to allocate the time for them.&#8221; That statement really hung with me. After I got off the phone I started thinking really hard about that statement, and all I could think of was how testing is not an option and people shouldn&#8217;t need to be convinced to have time allocated to them.</p>
<p>As developers it is our responsibility to insist on testing. Always include testing in your time estimates. Never give the client (or your company) an option that includes a time estimate without testing. If a feature takes 2 days to code and a day to write tests, then your estimate is 3 days, never 2. You should never say, &#8220;Well, I can get it done in two days if I don&#8217;t write any tests.&#8221; That&#8217;s just an unacceptable thing to say. What you should be saying is, &#8220;That feature will take three days to code&#8221;.</p>
<p>I don&#8217;t feel I should sit here and tell you all the reasons why you should test, you should know them already, and frankly, they&#8217;re all very obvious! But, if you need a few bullet points to &#8216;convince&#8217; your client, here are a few:</p>
<ul>
<li>Less bugs &#8211; The more tests you have the less bugs you will have. It&#8217;s just a fact. You won&#8217;t have 100% bug free code, that&#8217;s a nearly impossible goal, but you highly reduce the likely hood that as soon as you get your code into production your users will find all the breaking points of your code.</li>
<li>Better maintainability, means faster feature turn around &#8211; When you have a large test suite it means adding, updating, or even removing features because a whole lot easier, which means it SAVES time! Why? Simple, you don&#8217;t have to go through and manually test every aspect of your code to make sure you didn&#8217;t break something elsewhere by adding that validation, or by refactoring that bit of code, etc&#8230; That translates into real $ savings.</li>
<li>Test driven development saves time &#8211; this isn&#8217;t quite the same as my last bullet point. Imagine, if you will, you are writing a four step wizard in your application. If you write a few test scripts using something like Cucumber first before you write your code you can simply keep re-running those to make sure your code is working. If you don&#8217;t have those test scripts written then you continually have to keep going to a browser and entering all the information in each of the steps so you can test something in step four. Which one do you think takes longer, having a few test scripts you can run, or manually going through the four page wizard each time you make a change?</li>
<li>It&#8217;s an investment &#8211; thinking of having test scripts like owning a house. When you don&#8217;t have tests and you just keep testing in the browser or the command line what you are doing is a kin to &#8220;renting&#8221;. There is money being spent, but at the end of the day you have nothing to show for it. You&#8217;ve spent hours &#8220;testing&#8221;, but tomorrow when you come in you have to do it all over again. When you spend those hours writing tests you are actually &#8220;buying&#8221; something. You have something to show for that time and money you&#8217;ve spent. Tomorrow, next week, next month, next year, those scripts will still be there, they&#8217;ll still be working for you, giving  you a return on your investment.</li>
</ul>
<p>Well, I hope I have hopefully made a case to you the engineer as to why you should insist on testing. It&#8217;s the right thing to do, for you, for your application and for you client. If if anyone tries to give you grief about it, send them my way, I&#8217;ll sort em out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/07/01/testing-is-not-an-option/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby 1.9 &amp; Rails 3.0</title>
		<link>http://www.metabates.com/2010/02/08/ruby-1-9-rails-3-0/</link>
		<comments>http://www.metabates.com/2010/02/08/ruby-1-9-rails-3-0/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:06:27 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=313</guid>
		<description><![CDATA[I&#8217;ve always been a big proponent of Ruby 1.9, I make no bones about it. My question is why wouldn&#8217;t you be? It&#8217;s faster, more powerful, easier to use, and makes things a lot clearer and cleaner than 1.8. So why then are pretty much all of us still running our applications on 1.8.x? Great [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been a big proponent of Ruby 1.9, I make no bones about it. My question is why wouldn&#8217;t you be? It&#8217;s faster, more powerful, easier to use, and makes things a lot clearer and cleaner than 1.8. So why then are pretty much all of us still running our applications on 1.8.x? Great question, and as far as I can tell there is really only 1 answer.</p>
<p>That answer? Because no one else is. It&#8217;s stupid really, but it&#8217;s the truth. We&#8217;re all afraid to run our applications in 1.9 because we don&#8217;t know many other people that are. Because of that it makes it hard for you to make your application work with 1.9 because all those gems and libraries  you use aren&#8217;t 1.9 compatible, so you&#8217;re forced to keep running your app on 1.8. And so the cycle continues.</p>
<p>Enter Rails 3.0. Here is a major upgrade to the most prominent web framework in the Ruby community, and I would argue the reason that most of us got into Ruby in the first place. This upgrade will force us all to make some pretty severe changes to our applications to make them fully compatible.  The changes in ActiveRecord alone are so sweeping and massive that we, as a community, are going to have to put some serious time into upgrade our applications. Yet, despite this, we are all going to do it.</p>
<p>Why are we all going to upgrade to Rails 3.0? Because it  looks cool and sexy, and we want those great new features and all those performance enhancements to make our applications run faster. Which leads me back to Ruby 1.9.</p>
<p>In Rails 3.0 they are dropping support for Ruby 1.8.6 and below in favor of Ruby &gt;1.8.7 and &gt;1.9.1. I propose that Rails 3.0 becomes Ruby 1.9 compatible only. Think about it. What a perfect opportunity for us all. We are all going to have to upgrade the libraries and gems we maintain to support Rails 3.0 and we are going to be upgrading our applications to Rails 3.0, so why not go full steam into Ruby 1.9?</p>
<p>There is no better time than now to push forward into the future as a whole community. Let&#8217;s put Ruby 1.8 behind and reap the benefits of what Ruby 1.9 has to offer. What do you say? Can we do it? I think we can.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/02/08/ruby-1-9-rails-3-0/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>APN on Rails Needs a Home</title>
		<link>http://www.metabates.com/2009/12/21/apn-on-rails-needs-a-home/</link>
		<comments>http://www.metabates.com/2009/12/21/apn-on-rails-needs-a-home/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 16:30:41 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[apn]]></category>
		<category><![CDATA[apn_on_rails]]></category>
		<category><![CDATA[apple push notifications]]></category>
		<category><![CDATA[push notification]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=304</guid>
		<description><![CDATA[Hey there everyone, recently I have been getting a lot of requests for bug fixes and new features for the APN on Rails gem that I wrote. While I appreciate that the gem is getting a lot of use and helping a lot of people out, I, unfortunately, no longer have the time to maintain [...]]]></description>
			<content:encoded><![CDATA[<p>Hey there everyone, recently I have been getting a lot of requests for bug fixes and new features for the APN on Rails gem that I wrote. While I appreciate that the gem is getting a lot of use and helping a lot of people out, I, unfortunately, no longer have the time to maintain the gem.</p>
<p>Recent changes in my career have meant that I have moved away from doing a lot o iPhone development, and because of that I no longer have the time, nor the desire, to keep maintaining a gem I&#8217;m no longer using.</p>
<p>So, because of that, I would to find a new home for the APN on Rails gem so that it gets the love and attention it so desires. Are there any takers out there? Is someone willing to take on the ownership of this, apparently, very useful gem? If you are willing to take it on, please let me know and we can workout the details.</p>
<p>Thanks to everyone who has said good things about the gem, and I&#8217;m glad that it has helped people get to using push notifications quicker, hopefully, one of you can take this project and run with it. Thanks again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/12/21/apn-on-rails-needs-a-home/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introducing Warp Drive for Rails</title>
		<link>http://www.metabates.com/2009/10/07/introducing-warp-drive-for-rails/</link>
		<comments>http://www.metabates.com/2009/10/07/introducing-warp-drive-for-rails/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 13:00:19 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[engines]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[warp drive]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=269</guid>
		<description><![CDATA[At work recently we had a need to build a large Rails application that we then wanted to, for lack of a better word, subclass. Unfortunately there is no real good way of doing that. Rails Engines and templates have way too may limitations. We wanted to bundle up the entire Rails app (models, controllers, [...]]]></description>
			<content:encoded><![CDATA[<p>At work recently we had a need to build a large Rails application that we then wanted to, for lack of a better word, subclass. Unfortunately there is no real good way of doing that. Rails Engines and templates have way too may limitations. We wanted to bundle up the entire Rails app (models, controllers, views, routes, migrations, configurations, libs, assets, etc&#8230; everything!), but there was no good way of doing that. Well, now there is, it&#8217;s called the Warp Drive.</p>
<p>I&#8217;ve decided to just include my README file below to explain what it is, since it&#8217;s a bit lengthy, and I don&#8217;t feel like retyping.</p>
<p>This is still in it&#8217;s early stages, so use with care, but it does seem to be working for us on a daily basis. Let me know what you think!</p>
<h2>What is Warp Drive?</h2>
<p>Warp Drive is what Rails Engines wish they could be, and more! They kick Rails templates in the ass, and they beat keeping an ever evolving base Rails app up to date.</p>
<h3>What are Rails Engines?</h3>
<p>Rails Engines allow you to package up some of a Rails app (controllers, models, views, routes, libs) and put them in a plugin that can be included into a new Rails app, thereby giving it the functionality you had in the engine. That sounds good, but what about the downsides of using an engine? Well, you can&#8217;t override or extend any of the functionality from the engine in your main application. You can hack at the plugin, but now you&#8217;ve made it difficult to update. So what do you do if you want to add or alter a method to a controller or model? What do you do if you want to change the look and feel of a view? You have to copy everything into your main application. Boo!</p>
<p>Rails Engines also don&#8217;t allow you to package up migrations, assets, plugins, initializers, etc&#8230; All the fun stuff that you&#8217;ve come to know and love about a Rails application.</p>
<h3>Enter the Warp Drive!</h3>
<p>So what is a Warp Drive? Great question. To put it simply a Warp Drive is a standard, full featured, Rails application that you can easily bundle up into a Ruby Gem, and include into another Rails app. That second Rails app now has all the power of the first Rails. That is all there is to it.</p>
<h2>Creating a Warp Drive.</h2>
<p>Let&#8217;s assume we have an application that implements AuthLogic for handling user registration/authentication. We have controllers, views, models, plugins, initializers, configurations, migrations, tasks, etc&#8230; it&#8217;s a full featured fully functional Rails application, we call it authenticator.</p>
<p>We want to turn our authenticator application into a Warp Drive. We can do it in three simple steps, the first two steps you only need to do the first time, to set everything up.</p>
<ol>
<li><code>$ gem install warp_drive</code></li>
<li><code>$ warpify</code><br />
That will add a little bit of code to your <code>Rakefile</code>. That code simply requires the Warp Drive gem, and gives you hooks to configure the gem of your Warp Drive application.</li>
<li>$ <code>rake warp_drive:compile</code> (<code>rake warp_drive:install</code>)This will either compile your gem for your (<code>warp_drive:compile</code>) or compile and install your gem (<code>warp_drive:install</code>)</li>
</ol>
<p>That&#8217;s it! You should now have your Rails application bundled up and/or installed as a RubyGem!</p>
<h2>Using a Warp Drive.</h2>
<p>With your fancy new Warp Drive, authenticator, built and installed how do you use it in that new application your building? Again, it&#8217;s stupid easy, and it only takes one step, that only needs to be run once:</p>
<ol> <code>$ install_warp_drive authenticator</code></ol>
<p>That will put a few lines of code in your <code>Rakefile</code>, so you have access to all the <code>Rakefile</code> tasks in your Warp Drive, and a line in your <code>config/environment.rb</code> so that it will load your Warp Drive when you launch your application.</p>
<p>That&#8217;s it! You&#8217;re done. Now you can run <code>rake db:migrate</code> to run the migrations from both your Warp Drive and your new application. Enjoy!</p>
<h2>Overriding, Extending, and Other Such Fun Things</h2>
<h3>Overriding and Extending</h3>
<p>You&#8217;ve been enjoying your new Warp Drive back application for a little while now, but you decide you really need to change an action in your controller, how do you go about that? Simple, just like you would any normal alteration to a Ruby class.</p>
<p>Example:<br />
Here is what the action looks like in our Warp Drive UsersController:</p>
<pre><code>
  def new
    @user = User.new
  end
</code></pre>
<p>In our new application we can just open up the UsersController like this:</p>
<pre><code>
  class UsersController &lt; ApplicationController

    def new_with_default_name
      new_without_default_name
      @user.login = 'default_name'
    end

    alias_method_chain :new, :default_name

  end
</code></pre>
<p>Viola! The same works for any thing else in the system, models, libs, etc&#8230; In our example we used <code>alias_method_chain</code> to retain the original method, but we could have completely rewritten the method as well.</p>
<p>You can also plop in a new view and it will override the view that was in your Warp Drive. The sky is really the limit.</p>
<h3>Assets</h3>
<p>You can easily bundle assets from your public directory in your Warp Drive. Just make sure they are in folders called <code>warp_drive</code>. Those folders will then be symlinked to your new project&#8217;s public directory when the application starts up.</p>
<h3>Keep Those Rake Tasks Private!</h3>
<p>We all them, Rake tasks we have created to help us do all sorts of things, and we usually don&#8217;t want them to ship. Well, Warp Drive has you covered there. Just place your tasks in folders called <code>private</code> and Bob&#8217;s your uncle they won&#8217;t be available in the compiled gem.</p>
<pre><code>
  lib/
    tasks/
      foo.rake
      private/
        bar.rake
</code></pre>
<p>In this example <code>foo.rake</code> will be available to clients of your Warp Drive, but <code>bar.rake</code> will not be.</p>
<p>Copyright (c) 2009 Mark Bates</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/10/07/introducing-warp-drive-for-rails/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>A Few Rails Nuggets</title>
		<link>http://www.metabates.com/2009/09/07/a-few-rails-nuggets/</link>
		<comments>http://www.metabates.com/2009/09/07/a-few-rails-nuggets/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 01:23:28 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[delayed job]]></category>
		<category><![CDATA[distributed programming with ruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=282</guid>
		<description><![CDATA[So with my book, Distributed Programming with Ruby, finally finished, and a nice long weekend I was able to sit down and work on a little pet project of mine. I decided to work on a little site that I could use to track my rather large Pez collection. (Yes, I know, I collect Pez [...]]]></description>
			<content:encoded><![CDATA[<p>So with my book, <a href="http://my.safaribooksonline.com:80/9780321669919">Distributed Programming with Ruby</a>, finally finished, and a nice long weekend I was able to sit down and work on a little pet project of mine. I decided to work on a little site that I could use to track my rather large Pez collection. (Yes, I know, I collect Pez &#8211; so what!)</p>
<p>While working on it I got to use some new technologies that I really haven&#8217;t had a chance to play, so I thought I would talk a bit about some of the ones I liked the most.</p>
<h3>Authlogic</h3>
<p>Love it! Finally a decent authentication system! The thing I love most about it? It doesn&#8217;t generate a lot of crap in your project. If I were to say one bad thing about it, it would be that it doesn&#8217;t generate enough in your project. <img src='http://www.metabates.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I know that sounds silly, but it&#8217;s the truth. It gives you so much power, without having to generate a ton of lib code and crazy controller code, which is awesome. However, it would be nice if it had a generator that generated a &#8216;basic&#8217; application for you. Just a little thing, apart from that, love it!</p>
<p><a href="http://github.com/binarylogic/authlogic/tree/master">http://github.com/binarylogic/authlogic/tree/master</a></p>
<h3>Cucumber/Webrat</h3>
<p>I&#8217;m sure by now everyone has heard of Cucumber. I&#8217;m not going to pretend that I&#8217;m the first to that party! Over the last month or so I&#8217;ve really started to use it and it has completely changed my life. That&#8217;s not an overstatement.</p>
<p>Cucumber lets you write features and scenario in human readable format. Combine that with Webrat, which lets you do things like click buttons and follow links, you can write some amazing tests that look like something a project manager would write! Brilliant!</p>
<p>These tests beat the hell out of Rails integration tests. Trust me! I love watching Cucumber and Webrat click around my site while I just watch.</p>
<p><a href="http://cukes.info/">http://cukes.info/</a><br />
<a href="http://github.com/brynary/webrat/tree/master">http://github.com/brynary/webrat/tree/master</a></p>
<h3>Web App Theme Generator</h3>
<p>This cool little plugin helps you to quickly generate a very useful, and laid out, theme for your application. The themes would be familiar to anyone who has used sites like Lighthouse. They&#8217;re basic, but they are very well coded and get you on your quickly so you can have something that looks fairly decent.</p>
<p>My only gripe with this plugin is that it is a bit clumsy to use, but thankfully you don&#8217;t have to run it very often, only when you create a new controller/resource.</p>
<p><a href="http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/">http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/</a></p>
<h3>Delayed Job</h3>
<p>The last piece of tech is Delayed Job. I first discovered Delayed Job when I wrote about it in my <a href="http://my.safaribooksonline.com:80/9780321669919">book</a>. It is a great way to handle and process background tasks. It&#8217;s easy, reliable, and scales really well. I&#8217;ve been using the Collective Idea fork of the project. It has a generator to create the migration you need. It also has a nice binary to run in the background on your server.</p>
<p>I&#8217;ve also been using a little gem I wrote that gives me hooks into Hoptoad, the is_paranoid gem, and a nice subclass for writing workers.</p>
<p>I have been completely enamored with Delayed Job from the first moment I used it, and I&#8217;m sure if you haven&#8217;t checked it out yet, and you do, you&#8217;ll feel the same!</p>
<p><a href="http://github.com/collectiveidea/delayed_job/tree/master">http://github.com/collectiveidea/delayed_job/tree/master</a><br />
<a href="http://github.com/markbates/delayed_job_extras/tree/master ">http://github.com/markbates/delayed_job_extras/tree/master</a></p>
<p>There you go, that&#8217;s just a few things I&#8217;ve been playing with lately, that I think are going to become mainstays in any Rails project I work on. Hopefully this has given you a little for for thought on things you can use in your next project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/09/07/a-few-rails-nuggets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>APN on Rails 0.3.0 Released</title>
		<link>http://www.metabates.com/2009/07/31/apn-on-rails-0-3-0-released/</link>
		<comments>http://www.metabates.com/2009/07/31/apn-on-rails-0-3-0-released/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 04:51:02 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[apn]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[push notification]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=264</guid>
		<description><![CDATA[The latest version of Apple Push Notifications on Rails (APN on Rails) has been released. This release brings a few bug fixes, a new migration, and Feedback processing. Installing/upgrading is easy: $ sudo gem install apn_on_rails $ ruby script/generate apn_migrations $ rake db:migrate It&#8217;s important to always run the migrations generator after each update to [...]]]></description>
			<content:encoded><![CDATA[<p>The latest version of Apple Push Notifications on Rails (APN on Rails) has been released. This release brings a few bug fixes, a new migration, and Feedback processing.</p>
<p>Installing/upgrading is easy:</p>
<p><code>$ sudo gem install apn_on_rails<br />
$ ruby script/generate apn_migrations<br />
$ rake db:migrate<br />
</code></p>
<p>It&#8217;s important to always run the migrations generator after each update to get the latest database schema needed for the the gem.</p>
<p>To use the new Feedback integration you have to first make sure that you update the new <code>last_registered_at</code> column when your iPhone application calls home. This column is checked against the timestamp Apple returns with the device token. If the <code>last_registered_at</code> is older than Apple&#8217;s date then the device is deleted, otherwise the Feedback is ignored.</p>
<p>To get and process the list of devices from Apple&#8217;s Feedback service just run the following Rake task:</p>
<p><code>$ rake apn:feedback:process</code></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/07/31/apn-on-rails-0-3-0-released/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Apple Push Notifications on Rails</title>
		<link>http://www.metabates.com/2009/07/24/apple-push-notifications-on-rails/</link>
		<comments>http://www.metabates.com/2009/07/24/apple-push-notifications-on-rails/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 01:06:10 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[apn]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[push notification]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=250</guid>
		<description><![CDATA[The other night I submitted a new iPhone application to the Apple Store. The app, which I&#8217;ll speak about when, and if it gets approved, uses the new Apple Push Notification service available in iPhone OS 3.0. On the server side I have a Rails application that I am using to send the notifications to [...]]]></description>
			<content:encoded><![CDATA[<p>The other night I submitted a new iPhone application to the Apple Store. The app, which I&#8217;ll speak about when, and if it gets approved, uses the new Apple Push Notification service available in iPhone OS 3.0. On the server side I have a Rails application that I am using to send the notifications to Apple. The problem I ran into was how.</p>
<p>Enter the APN on Rails gem. While searching I found one plugin for Rails that mostly worked for me, Sam Soffes&#8217; apple_push_notification plugin. It was a great place to start, but I found that there were things that didn&#8217;t suite me. For starters, not having any tests is always a big turn off for me when it comes to any code. I also didn&#8217;t like that you didn&#8217;t need to save a notification in order to send it. That means you don&#8217;t have a record of what was sent and when. I also wanted to have devices stored separately from the notification. Finally, I wanted to be able to easily configure the plugin. Sam&#8217;s was using constants that would need to be changed when it hit production.</p>
<p>So, with all that said and done I took Sam&#8217;s great work, ripped it apart, and put it back together again, this time in gem form instead of a plugin, and here it is.</p>
<p>There are a few migrations, a few models, and a few Rake tasks, but here is the basic idea of how it works:</p>
<p><script src="http://gist.github.com/154516.js"></script></p>
<p>To get a better understanding of exactly how it works, and what it does, I highly recommend reading the <a href="http://apnonrails.metabates.com/">RDOC</a>.</p>
<p>There are a few things I still would like to add, for example, a controller to do CRUD for devices so iPhones can register with the Rails app. I&#8217;d also like to add a task that talks to Apple and finds out which devices are no longer accepting messages so they can be removed.</p>
<p>If you&#8217;d like to contribute, please feel free and for the project on GitHub:<br />
<a href="http://github.com/markbates/apn_on_rails/tree">http://github.com/markbates/apn_on_rails/tree</a></p>
<p>Again, a special thanks to Fabien Penso and Sam Soffes for their initial work on this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/07/24/apple-push-notifications-on-rails/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Cachetastic 3.0.0 Released</title>
		<link>http://www.metabates.com/2009/06/18/cachetastic-3-0-0-released/</link>
		<comments>http://www.metabates.com/2009/06/18/cachetastic-3-0-0-released/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 02:07:10 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[cachetastic]]></category>
		<category><![CDATA[configatron]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=237</guid>
		<description><![CDATA[After more than two years powering production level applications I found that Cachetastic was starting to get a bit long in the tooth. I felt that there was a lot I could to make Cachetastic an even better library than it already was. I thought that I had added a bunch of cruft to the [...]]]></description>
			<content:encoded><![CDATA[<p>After more than two years powering production level applications I found that Cachetastic was starting to get a bit long in the tooth. I felt that there was a lot I could to make Cachetastic an even better library than it already was. I thought that I had added a bunch of cruft to the framework that people were just not using and maintaining it all seemed like a bit of a pointless chore.</p>
<p>So what was I unhappy about?</p>
<h3>Configuration:</h3>
<p>I was pretty unhappy with the way configuration was being done. I liked using Configatron to power the configuration, but I didn&#8217;t like the way I implemented the way I was using Configatron. For example, to set up one of the default settings, like the expiry time, you would configure it like such:</p>
<pre>configatron.cachetastic_default_options.expiry_time = 30.minutes</pre>
<p>Now you would configure that same option like this:</p>
<pre>configatron.cachetastic.defaults.expiry_time = 30.minutes</pre>
<p>That&#8217;s a little savings, but it really hits when you want to configure a particular cache. Let&#8217;s say we a cache called My::Super::AwesomeCache, to configure it in past versions of Cachetastic we would do this:</p>
<pre>configatron.my_super_awesome_cache_options.expiry_time = 15.minutes</pre>
<p>Now in Cachetastic 3.0.0 we configure like this:</p>
<pre>configatron.cachetastic.my.super.awesome_cache.expire_time = 15.minutes.</pre>
<p>As you can see all configuration now happens under the cachetastic namespace in Configatron. Then it&#8217;s a matter of using a Configatron namespace for each of your modules. I find it a lot easier to manage.</p>
<p>Another change in configuration is that in previous versions if you wanted to override one default configuration value for a particular cache,  you had to override them all. Now, you can just override the one value  you want, and the rest will be nicely inherited from the defaults.</p>
<h3>Speed</h3>
<p>Cachetastic has always been a very fast library, but I knew that more could be squeezed from that stone. With Cachetastic 3.0.0 you now get a hefty 25% improvement in the Memcached adapter and a whopping 99% in the LocalMemory adapter! Those are pretty awesome numbers. These numbers were easy to achieve when I stepped back and examined what it was I really wanted to do, and picked the most straightforward path to that goal.</p>
<h3>Bloat</h3>
<p>After more than two years Cachetastic was starting to suffer from a severe case of bloat. For example, I&#8217;ve never used the DRb adapter, have you? So why is it there? The same goes for the HtmlFile adapter. I wrote that because at my last job the operations team weren&#8217;t savvy  enough to be able to get Apache to talk to Memcached, so they wanted to serve HTML files, hence the rather awful adapter. Both of those adapters are now history.</p>
<p>There also used to be support for Rails Session Caching. Considering that most people are now using the Cookie store for sessions, there really is no need for this cache. It could also be argued that it should not have been bundled with Cachetastic at all. I would agree with those arguments. Cachetastic is, and should always be, a standalone caching framework, that can be plugged into Rails or any plain old Ruby project that needs caching support.</p>
<p>Also purged is automatic support for mixing in the Cachetastic::Cacheable module into ActiveRecord. If you want this functionality, it is very easy to include in your application. I don&#8217;t want to force it on anyone, so that is gone now.</p>
<p>Finally there are a handful of smaller features that I&#8217;m sure no one will miss that I&#8217;ve yanked out in the name of performance, reliability, and ease of maintenance.</p>
<h3>Nice and Clean</h3>
<p>When I realized what I really wanted, and what I didn&#8217;t want, it became clear that what was needed was a fresh code base. With that said, I hit delete (well, not really) and started over again. The code is now smooth, so much easier to read, and fast. In previous versions even my eyes went a bit crossed when I tried to figure out exactly what was going on. There where quite a few levels of indirection, and things just weren&#8217;t place where they probably should&#8217;ve been. That has all been fixed.</p>
<p>With a nice, clean code base comes a brand new set of tests. The tests are now extremely comprehensive, and while 2.x was very well tested, I know that 3.0.0, is tested to the hilt.</p>
<p>Because 3.0.0 is a brand new code base, I should probably stress the fact that is <strong>NOT</strong> backward compatible. So please be advised.</p>
<h3>Installation:</h3>
<pre>$ sudo gem install cachetastic</pre>
<h3>Conclusion</h3>
<p>I really hope everyone likes this brand new version of Cachetastic. I&#8217;m very happy with it, and I think if you give it a chance, you will be too.</p>
<p>If you&#8217;d like to have a peek at the RDoc, it can be found at:<br />
<a href="http://cachetastic-api.mackframework.com/">http://cachetastic-api.mackframework.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2009/06/18/cachetastic-3-0-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.549 seconds -->
