<?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>Mission Data Blog &#187; ruby</title>
	<atom:link href="http://www.missiondata.com/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.missiondata.com/blog</link>
	<description>Louisville-based Web Development &#38; Software Engineering</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:58:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>RailsConf Reflections</title>
		<link>http://www.missiondata.com/blog/software-development/590/railsconf-reflections/</link>
		<comments>http://www.missiondata.com/blog/software-development/590/railsconf-reflections/#comments</comments>
		<pubDate>Tue, 24 May 2011 13:59:10 +0000</pubDate>
		<dc:creator>Ernie</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[railsconf]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/?p=590</guid>
		<description><![CDATA[Today, I&#8217;m feeling mostly recovered from my first ever RailsConf, so I thought I would take some time to reflect on what I learned there, and share it with you, my dear reader. So, here we go, in no particular order&#8230; CoffeeScript is happening&#8230; &#8230;whether you like it or not. Personally, I&#8217;m psyched &#8212; it [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m feeling mostly recovered from my first ever RailsConf, so I thought I would take some time to reflect on what I learned there, and share it with you, my dear reader. So, here we go, in no particular order&#8230;</p>
<h3>CoffeeScript is happening&#8230;</h3>
<p>&#8230;whether you like it or not. Personally, I&#8217;m psyched &#8212; it looks like it solves a lot of the annoyances I&#8217;ve had with Javascript syntax, and I got a sweet deal on <a href="http://www.amazon.com/gp/product/1934356786/ref=as_li_ss_tl?ie=UTF8&amp;tag=metautonomous-20&amp;linkCode=as2&amp;camp=217145&amp;creative=399349&amp;creativeASIN=1934356786">CoffeeScript: Accelerated JavaScript Development</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=&amp;l=as2&amp;o=1&amp;a=1934356786&amp;camp=217145&amp;creative=399349" border="0" alt="" width="1" height="1" /> during the conference, which I hope to put to good use starting this week.</p>
<h3>The Rails Community is Awesome</h3>
<p>My wife&#8217;s response after she read my <a href="http://twitter.com/erniemiller">tweets</a> upon my return:</p>
<blockquote><p>&#8220;Just wondered, who is this guy? Dinner anyone? Share a cab? You became an extrovert on your mothership.&#8221;</p></blockquote>
<p>It&#8217;s true, I did. It&#8217;s weird. I&#8217;ve never been to Baltimore before (save time spent between flights at BWI), but among my fellow Rails coders, I&#8217;ve never felt more &#8220;at home.&#8221;</p>
<p>As I thought about all of the people I finally got to thank in person for all they&#8217;ve done to make my time in the Rails community more enjoyable, it really drove home what an awesome community we have. It&#8217;s easy to lose sight of this while working away in Louisville, my little corner of Kentucky.</p>
<p>Aside from this, getting a chance to put a real face to a name, make and receive thank-yous for all the hard work we put in on Rails patches, plugins, and the like, has the effect of re-energizing a developer. I&#8217;d go on and list all of the awesome people I got to meet in person here, but I think it&#8217;d just make <a href="http://twitter.com/casron">@casron</a> more jealous.</p>
<p>I would like to say, however, that Emilio Tagua (<a href="http://twitter.com/miloops">@miloops</a>) has got to be one of the friendliest guys I&#8217;ve ever met. I&#8217;d hoped to catch up with him to thank him for helping me get commits added to ARel back in the 1.x days that were needed for MetaSearch and MetaWhere. Instead, he ended up two seats over from me at Ignite, noticed I was hacking on a Squeel bug, and introduced himself first. Every time I saw him during the remainder of the conference, he had a smile and a kind word. Just an all-around great guy to have met.</p>
<h3>PostgreSQL is awesome, too!</h3>
<p>Now, I should have known this. I had started out using MySQL many years ago, when it had solid speed advantages over PostgreSQL, but far fewer features. Somewhere along the line, that balance shifted, but I stuck with MySQL due to familiarity. Nick Gauthier&#8217;s <a href="http://knowsql.heroku.com/">KnowSQL</a> presentation has made a believer out of me. I&#8217;ll be using PostgreSQL as my RDBMS of choice from here on, and making sure that Squeel works as well as possible with it, too.</p>
<h3>The Fundamentals are ALWAYS Relevant</h3>
<p>There were tons of talks on design patterns, best practices, and so on, and even as long as I&#8217;ve been doing this whole coding thing, there are plenty of areas in which I can improve. In particular, Avdi Grimm&#8217;s talk, <a href="http://avdi.org/talks/confident-code-railsconf-2011/">Confident Code</a>, José Valim&#8217;s talk about the design principles behind the Rails 3 refactoring, and the talk on <a href="http://assets.en.oreilly.com/1/event/59/Building%20Bulletproof%20Views%20Presentation.pdf">Building Bulletproof Views</a> by John Athayde and Bruce Williams all challenged me to elevate my game in these areas.</p>
<h3>HTML5 is sooooo much more than semantic tags</h3>
<p>LocalStorage, audio, video, canvas drawing, web sockets, web workers &#8212; this stuff is all crazy cool and I can&#8217;t wait until more browsers support it. Mike Subelsky&#8217;s <a href="https://github.com/subelsky/html5tutorial/raw/master/tutorial.html">HTML5 tutorial</a> was a real eye-opener.</p>
<p>That&#8217;s about it, for now. What were some of your takeaways from RailsConf this year?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/software-development/590/railsconf-reflections/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Webby for Figment</title>
		<link>http://www.missiondata.com/blog/design/543/webby-for-figment/</link>
		<comments>http://www.missiondata.com/blog/design/543/webby-for-figment/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 20:48:27 +0000</pubDate>
		<dc:creator>Cindi</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>
		<category><![CDATA[webby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/?p=543</guid>
		<description><![CDATA[And the envelope please….we are proud to announce that our recent work on figment.com, a community for young folks to read, write and connect is a Webby Award Official Honoree in the Youth category. The 15th annual Webby Award winners were announced yesterday. Some say The Webby Award is the Internet&#8217;s most respected symbol of [...]]]></description>
			<content:encoded><![CDATA[<p>And the envelope please….we are proud to announce that our recent work on <a href="http://figment.com">figment.com</a>, a community for young folks to read, write and connect is a Webby Award <a href="http://bit.ly/dZaZ67">Official Honoree</a> in the Youth category.</p>
<p>The 15th annual Webby Award winners were announced yesterday. Some say The Webby Award is the Internet&#8217;s most respected symbol of success. We’re just delighted to receive Honoree status for our work and rank in the top ten percent of the nearly 10,000 entrants. We&#8217;re in good company too, Disney and Lego also received the Honoree nod.</p>
<p>Website and mobile winners were selected for recognition based on excellence in Content, Structure and Navigation, Visual Design, Functionality, Interactivity and Overall Experience. Winners were selected by <a href="http://www.iadas.net/">The International Academy of Digital Arts and Sciences (IADAS)</a>, a global collection of experts and technology innovaters, including David Bowie, Arianna Huffington, Harvey Weinstein, Martha Stewart, Vinton Cerf, Biz Stone.</p>
<p>We&#8217;re proud to be recognized by our peers with this gesture but we&#8217;re even more proud of our work and the success of Figment. Tell us what you think&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/design/543/webby-for-figment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Languages Are Slow</title>
		<link>http://www.missiondata.com/blog/software-development/252/programming-languages-are-slow/</link>
		<comments>http://www.missiondata.com/blog/software-development/252/programming-languages-are-slow/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 17:02:19 +0000</pubDate>
		<dc:creator>Ernie</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/?p=252</guid>
		<description><![CDATA[I was chatting with a friend of mine who&#8217;s been working toward getting his company to consider a migration to Ruby on Rails. It&#8217;s interesting to me, because they&#8217;ve been using frameworks that are heavily influenced by Rails, but the developers there are resistant to moving to the real deal. They&#8217;ve started to lean away [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-271" style="float:left; margin:0 15px 15px 0;" title="Moore's Law" src="http://www.missiondata.com/blog/wp-content/uploads/2010/10/moores_law.png" alt="Moore's Law" width="200" height="134" />I was chatting with a friend of mine who&#8217;s been working toward getting his company to consider a migration to Ruby on Rails. It&#8217;s interesting to me, because they&#8217;ve been using frameworks that are heavily influenced by Rails, but the developers there are resistant to moving to the real deal. They&#8217;ve started to lean away from PHP and toward Java lately, so naturally I suggested they take a look at <a href="http://jruby.org/">JRuby</a>, which provides all the awesome of Ruby but runs on the JVM, thereby keeping the suits happy. The  response from one of his co-workers when he passed on my suggestion? &#8220;Ruby was (and is) terribly slow.&#8221; Argh. This, again? I <a href="http://twitter.com/#!/erniemiller/status/27339661019">tweeted</a> my response:</p>
<blockquote><p><em>If your best argument against using Ruby is a perception that it&#8217;s slow, a reminder: Moore&#8217;s Law is on our side. :)</em></p></blockquote>
<p><span id="more-252"></span><br />
Ruby&#8217;s been fighting the &#8220;Ruby is slow&#8221; meme for years now, and not without good reason &#8212; every day, new strides are being made in one Ruby implementation or another that show there is ample opportunity for efficiency improvements.</p>
<p><strong>That being said, do the people making this argument realize how old and tired it is? I don&#8217;t mean, &#8220;bashing Ruby for being slow is so <a href="http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/d624d496b21d5453/95b69bf6605e6cee">2002</a>.&#8221; I mean, &#8220;bashing programming languages for being slow is so <a href="http://books.google.com/books?id=vg_QRDVR7hgC&amp;lpg=PA183&amp;dq=compiler%20inefficient&amp;pg=PA183#v=onepage&amp;q=compiler%20inefficient&amp;f=false">1972</a> (at least).&#8221;</strong></p>
<p>&#8220;Ruby is slow. Java is better.&#8221;<br />
&#8220;Java is slow. C is better.&#8221;<br />
&#8220;Forget about compilers, they&#8217;re inefficient. Program in assembly!&#8221;</p>
<p><strong>Resisting a programming language because it&#8217;s perceived to be &#8220;slow&#8221; is one of the most short-sighted decisions one could ever make.</strong> Over time, VMs get more efficient, compilers produce better machine language, and bandwidth, storage, and compute cycles become cheaper and more abundant. However, I have yet to hear of a single developer who has succeeded in performing more than one hour of work per hour.</p>
<p>Choose the programming language that is &#8220;fast enough&#8221; for your needs, maximizes your source code&#8217;s expressiveness, and increased your developers&#8217; happiness and productivity, because:</p>
<ol>
<li><em>&#8220;Fast enough&#8221; isn&#8217;t nearly as fast as you think it is.</em> The dissenting developer in the story above, who rejected Ruby because it was slower than Java, is writing a web-based document management system that needs to support user concurrency in the tens, not thousands.</li>
<li>A project with a highly expressive codebase will be easier to develop and maintain.</li>
<li>It&#8217;s hard enough to attract and retain strong developers even when you aren&#8217;t hamstringing their productivity.</li>
</ol>
<p>And one last reminder: It&#8217;s easy to write non-performant code in any language. Sometimes it pays to check up on the carpenter before you blame the hammer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/software-development/252/programming-languages-are-slow/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Treetop: Grammar&#8217;s Cool</title>
		<link>http://www.missiondata.com/blog/web-development/85/treetop-grammars-cool/</link>
		<comments>http://www.missiondata.com/blog/web-development/85/treetop-grammars-cool/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 01:27:39 +0000</pubDate>
		<dc:creator>darrend</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Treetop]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/uncategorized/85/treetop-grammars-cool/</guid>
		<description><![CDATA[Treetop was one of the more exciting projects I saw at last year&#8217;s RubyConf. Nathan Sobo&#8217;s Treetop talk is available online and I urge you to watch it. Nathan did a great job of explaining the basics of syntactic analysis, and then got into the specifics of using Treetop&#8217;s implementation of parsing expression grammars to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://treetop.rubyforge.org/">Treetop</a> was one of the more exciting projects I saw at last year&#8217;s RubyConf. <a href="http://rubyconf2007.confreaks.com/d1t1p5_treetop.html">Nathan Sobo&#8217;s Treetop talk</a> is available online and I urge you to watch it. Nathan did a great job of explaining the basics of syntactic analysis, and then got into the specifics of using Treetop&#8217;s implementation of <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar">parsing expression grammars</a> to put the concepts to work.</p>
<p>Treetop appeared to gather all the concepts together into an understandable domain specific language. All of the tokenization and node structure can go into a single file, and the interactive nature of Ruby makes for the perfect sand box. I felt like I could get somewhere if I invested just an hour into this. I was happy to find that my impressions were correct.</p>
<p>After a short time I had caught on enough to start writing my own code. Once over the hump the rest was easy. I was able to write and test a Treetop grammar for parsing CSV files within a few hours. I chose CSV parsing because I was already familiar with the format, and I could compare my implementation to not just one but two existing Ruby libraries.<br />
<span id="more-85"></span></p>
<pre><code>commaseparatedfile.treetop</code></pre>
<pre><code>grammar CommaSeparatedFile
  rule lines
    line (newline line)*
    {
      def values
        vals = []
        vals &amp;lt;&amp;lt; line.values
        more.elements.each { |additional| vals &amp;lt;&amp;lt; additional.line.values }
        vals
      end
    }
  end

  rule line
    valueline / emptyline
  end

  rule emptyline
    '' {
      def values
        []
      end
    }
  end

  rule valueline
    leading:(value separator)* trailing:value
    {
      def values
        list = []
        list += leading.elements.collect { |lead| lead.value.text_value } if leading
        list &amp;lt;&amp;lt; trailing.text_value if trailing
        list
      end
    }
  end

  rule value
    quotedvalue / nakedvalue
  end

  rule quotedvalue
    '"' wrapped:( !'"' . / '""' )* '"' {
      def text_value
        wrapped.text_value.gsub(/""/,'"')
      end
    }
  end

  rule nakedvalue
    (!(separator / newline ) .)*
  end

  rule separator
    ','
  end

  rule newline
    [\n]
  end
end</code></pre>
<p>One concept that became clear to me is that the tokens that are defined in the grammar are objects in the resulting tree returned after input is parsed. Ruby code embedded in the Treetop&#8217;s node definitions are added as methods to the object declared by that node.</p>
<p>In the simple harness below, the <code>lines</code> object returned from the parse call below is the object representation of the <code>rule lines</code> node above, defined as the root of the parse tree. The <code>values</code> method I call below is defined above in the definition of the <code>lines</code> node.</p>
<pre><code>require 'rubygems'
require 'treetop'
require 'commaseparatedfile' 

parser = CommaSeparatedFileParser.new
lines = parser.parse("this,that,these,those")
puts lines.values.inspect #-&amp;gt; [["this", "that", "these", "those"]]</code></pre>
<p>I think it was much simpler for me to write this parsing as a grammar instead of trying to combine regular expressions with Ruby code. The grammar above handles multiple lines and quote-wrapped values, and escaped quotes.</p>
<p>It was actually fun to write as well, and I&#8217;m still learning a lot. Notice that my <code>lines</code> node and my <code>valueline</code> node both approach a similar problem (a list of 0 or more items) differently. For the lines the grammar grabs one line followed by 0 or more separators followed by lines. For the valueline I grab 0 ore more values followed by separators and terminate on the last value. Is one approach better than the other? Are they both junk? I can&#8217;t wait to figure that out.</p>
<p>My poor parser is left in the dust by both Ruby&#8217;s <a href="http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html">stdlib csv library</a>, and the <a href="http://fastercsv.rubyforge.org/">fastercsv gem</a>. I ran these tests under the 1.8.5 version of Ruby. The <a href="http://www.missiondata.com/blog/wp-content/uploads/2008/02/kentuckycsv.gz">dataset I used</a> is 44k in total and has 961 records.</p>
<pre>                       user     system      total        real
stdlib_csv:        0.210000   0.000000   0.210000 (  0.217275)
faster_csv:        0.040000   0.000000   0.040000 (  0.060788)
treetop_grammar:   2.910000   0.010000   2.920000 (  3.126020)</pre>
<p>I don&#8217;t know what sort of speed I should reasonably expect, actually. I&#8217;d hoped that my compiler would be competitive with the standard library&#8217;s csv parsing. It&#8217;s possible that my grammar&#8217;s definition could be innefficient. If anyone has any ideas let me know.</p>
<p>After playing around with Treetop I&#8217;ll definitely tinker some more. There are many other features I haven&#8217;t explored yet, like extending a base grammar to create a new grammar. PEGs have implementations in other languages so this isn&#8217;t a Ruby-only facility, either.</p>
<p>On a side note, I used stdlib&#8217;s benchmark to generate the numbers above. Pretty swank stuff.</p>
<pre><code>require 'rubygems'
require 'treetop'
require 'commaseparatedfile'
require 'fastercsv'
require 'csv'
require 'benchmark'

def with_stdlib_csv(csv)
  parsed = CSV.parse(csv)
  parsed.size
end

def with_fastercsv(csv)
  rows = FasterCSV.parse(csv)
  rows.size
end

def with_treetop_parser(csv)
  parser = CommaSeparatedFileParser.new
  parsed = parser.parse(csv)
  parsed.values.size
end

csv = File.read('../kentucky.csv')

Benchmark.bmbm("treetop_parser:".length) do |x|
  x.report("stdlib_csv:") { with_stdlib_csv(csv) }
  x.report("faster_csv:") { with_fastercsv(csv) }
  x.report("treetop_grammar:") { with_treetop_parser(csv) }
end</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/85/treetop-grammars-cool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying a Subversion branch with Capistrano</title>
		<link>http://www.missiondata.com/blog/system-administration/84/deploying-an-svn-branch-with-capistrano/</link>
		<comments>http://www.missiondata.com/blog/system-administration/84/deploying-an-svn-branch-with-capistrano/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 15:39:34 +0000</pubDate>
		<dc:creator>steveny</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/ruby/84/deploying-an-svn-branch-with-capistrano/</guid>
		<description><![CDATA[Capistrano is a tool for automating tasks via SSH on remote servers. It has many uses, I (and many others) use it to deploy their (rails) applications. The best I can tell there is no built in way to deploy a branch from your source code control system. There are a couple ways of accomplishing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.capify.org/">Capistrano</a> is a tool for automating tasks via SSH on remote servers.  It has many uses, I (and many others) use it to deploy their (rails) applications.  The best I can tell there is no built in way to deploy a branch from your source code control system.  There are a couple <a href="http://blog.aisleten.com/2007/09/04/deploying-svn-tags-using-capistrano/">ways of accomplishing</a> this.  I chose passing in the branch as a parameter to the Capistrano command:</p>
<pre><code>cap --set-before branch=testbranch  deploy</code></pre>
<p><span id="more-84"></span><br />
&#8230;where &#8216;testbranch&#8217; is the name of my subversion branch, and &#8216;deploy&#8217; is the action to take.  The &#8216;&#8211;set-before option&#8217; sets a variable before the recipes are loaded (<a href="http://osdir.com/ml/lang.ruby.capistrano.general/2006-11/msg00012.html">sort of)</a>.  All you need to do to make this work you just need to set the repository URL correctly based on if the branch variable exists or not.  In my case, that is editing the top of deploy.rb in the config section of my rails app:</p>
<pre><code>if variables.include?(:branch)
  set :repository,  "http://svn.example.com/project/branches/#{branch}"
else
  set :repository,  "http://svn.example.com/project/trunk"
end</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/system-administration/84/deploying-an-svn-branch-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails fixtures with models using set_table_name</title>
		<link>http://www.missiondata.com/blog/systems-integration/80/rails-fixtures-with-models-using-set_table_name/</link>
		<comments>http://www.missiondata.com/blog/systems-integration/80/rails-fixtures-with-models-using-set_table_name/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 03:13:47 +0000</pubDate>
		<dc:creator>darrend</dc:creator>
				<category><![CDATA[Systems Integration]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/uncategorized/80/rails-fixtures-with-models-using-set_table_name/</guid>
		<description><![CDATA[If you have a model that uses set_table_name you may hit a snag when trying to use fixtures and unit tests. The solution is twofold: name the fixture file using the legacy table name, and use the set_fixture_class method in your unit test. I coudn&#8217;t find this method mentioned in Agile Web Development with Rails, [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a model that uses <tt>set_table_name</tt> you may hit a snag when trying to use fixtures and unit tests. The solution is twofold: name the fixture file using the legacy table name, and use the <tt>set_fixture_class</tt> method in your unit test. I coudn&#8217;t find this method mentioned in <em>Agile Web Development with Rails</em>, and there&#8217;s only a brief mention on the <a href="http://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemas">rubyonrails.com site</a>. Still, some web searches turned up the answers.</p>
<p>Here is a simple example:</p>
<p><span id="more-80"></span></p>
<p>We&#8217;ll start with a table named <code>libris_book</code> that contains book entries. The name <em>libris_book</em> won&#8217;t really fly with the Rails pluralized table name approach. It&#8217;s easy, however, to fix that disconnect in the model:</p>
<pre><code>class Book &amp;lt; ActiveRecord::Base
  set_table_name 'libris_book'
end</code></pre>
<p>Let&#8217;s take a look at our data:</p>
<pre><code class="console">~/src/libris$ script/console
Loading development environment.
&amp;gt;&amp;gt; Book.count
=&amp;gt; 1230</code></pre>
<p>Good enough. Now, we&#8217;ll be good little coders and write some unit tests using fixtures. We&#8217;ll create a fixture file and our test class:</p>
<p><tt>books.yml</tt></p>
<pre><code>test_book:
  title: Life in Lawrenceburg
  author: Darren Day</code></pre>
<p><tt>book_test.rb</tt></p>
<pre><code>require File.dirname(__FILE__) + '/../test_helper'

class BookTest &amp;lt; Test::Unit::TestCase
  fixtures :books

  def test_fixtures
    assert_equal(2,Book.count)
    test_book = books(:test_book)
  end
end</code></pre>
<p>Looks good, but it won&#8217;t work!</p>
<pre><code class="console">~/src/libris$ rake test
(in /home/darrend/src/libris)
/usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb" "test/unit/book_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader
Started
E
Finished in 0.01133 seconds.

  1) Error:
test_fixtures(BookTest):
ActiveRecord::StatementInvalid: Mysql::Error: Table 'libris_test.books' doesn't exist: DELETE FROM books
...</code></pre>
<p>Ugh. That doesn&#8217;t look pretty. After some <a href="http://www.google.com/search?q=set_table_name+fixtures">googling around</a> the following comes together</p>
<ul>
<li>Rename <tt>books.yml</tt> to <tt>libris_book.yml</tt>. The fixture yaml file has to share the same name as the database table name.</li>
<li>Change the <tt>fixtures</tt> declaration to <code>fixtures :libris_book</code>.</li>
<li> Use <tt>set_fixture_class</tt> to connect the fixture to the model class.</li>
</ul>
<p>Here is our new and improved <tt>book_test.rb</tt> file:</p>
<pre><code>require File.dirname(__FILE__) + '/../test_helper'

class BookTest &amp;lt; Test::Unit::TestCase
  set_fixture_class :libris_book =&amp;gt; Book
  fixtures :libris_book

  def test_fixtures
    assert_equal(2,Book.count)
    test_book = libris_book(:test_book)
  end
end</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/systems-integration/80/rails-fixtures-with-models-using-set_table_name/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mongrel vs. WEBrick</title>
		<link>http://www.missiondata.com/blog/system-administration/71/mongrel-vs-webrick/</link>
		<comments>http://www.missiondata.com/blog/system-administration/71/mongrel-vs-webrick/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 16:08:13 +0000</pubDate>
		<dc:creator>steveny</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Mongrel vs WEBrick]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/ruby/71/mongrel-vs-webrick/</guid>
		<description><![CDATA[We had the need to hook up a simple ruby web process (non-rails) to our production apache server. As Leslie Hensley pointed out, fcgi and scgi are on the way out, and mongrel + mod_proxy_balancer is the new way to go. We use mongrel extensively in our rails deploys, but always just used WEBrick to [...]]]></description>
			<content:encoded><![CDATA[<p>We had the need to hook up a simple ruby web process (non-rails) to our production apache server.  As <a href="http://www.papermountain.org/">Leslie Hensley</a> pointed out, fcgi and scgi are on the way out, and <a href="http://mongrel.rubyforge.org/">mongrel</a> + <a href="http://mongrel.rubyforge.org/docs/apache.html">mod_proxy_balancer</a> is the new way to go.  We use mongrel extensively in our rails deploys, but always just used <a href="http://www.webrick.org/">WEBrick</a> to do simple serving.  To make a long story short, we had to ask ourselves&#8230;.is mongrel that much better (and in this case better == faster) than WEBrick?</p>
<p><span id="more-71"></span></p>
<p>At first I decided my test would just respond with the yamlized request (just like the <a href="http://mongrel.rubyforge.org/rdoc/index.html">mongrel sample</a> did).  This worked fine but there was a significant size difference in the two documents (WEBrick&#8217;s was much bigger).  In the end, I just decided to respond with a few bytes of text.</p>
<h3>The Code</h3>
<p><strong>mongrel_service.rb:</strong></p>
<pre><code>require 'rubygems'
require 'mongrel'
require 'yaml'

class SimpleHandler &amp;lt; Mongrel::HttpHandler
  def process(request, response)
    response.start do |head,out|
      head["Content-Type"] = "text/html"
      out &amp;lt;&amp;lt; "I am mongrel, hear me roar"
    end
  end
end

config = Mongrel::Configurator.new :host =&amp;gt; "localhost", :port =&amp;gt; 4000 do
  listener {uri "/", :handler =&amp;gt; SimpleHandler.new}
  trap("INT") { stop }
  run
end

config.join</code></pre>
<p><strong>webrick_service.rb:</strong></p>
<pre><code>require 'webrick'
require 'yaml'
include WEBrick

class SimpleServlet &amp;lt; HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response["Content-Type"] = "text/html"
    response.body = "I am WEBrick, hear me roar"
  end
end

s = HTTPServer.new( :Port =&amp;gt; 4001 )
s.mount("/", SimpleServlet)
trap('INT'){ s.shutdown }
s.start</code></pre>
<h3>The Test</h3>
<p>There are <a href="http://www.joedog.org/JoeDog/Siege">serveral</a> <a href="http://www.hpl.hp.com/research/linux/httperf/">good</a> benchmarking tools available, but I had <a href="http://en.wikipedia.org/wiki/ApacheBench">apache bench (ab)</a> handy, so that is what I used.  I just used the stock gem install of mongrel and the WEBrick that comes with ruby 1.8.4 (the one non-stock change I made was to comment out access logging for WEBrick since mongrel doesn&#8217;t log by default).</p>
<h3>The Results</h3>
<table border="1">
<tbody>
<tr>
<th>Total Requests</th>
<th>Concurrent Connections</th>
<th>WEBrick (seconds)</th>
<th>Mongrel (seconds)</th>
</tr>
<tr>
<td>1000</td>
<td>1</td>
<td>1.889523</td>
<td>0.365838</td>
</tr>
<tr>
<td>10000</td>
<td>10</td>
<td>19.443034</td>
<td>4.411788</td>
</tr>
<tr>
<td>10000</td>
<td>100</td>
<td>20.906522</td>
<td>4.174591</td>
</tr>
</tbody>
</table>
<h3>The Conclusion</h3>
<p>Looks like mongrel it is&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/system-administration/71/mongrel-vs-webrick/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Latest on Rails Performance</title>
		<link>http://www.missiondata.com/blog/web-development/70/latest-on-rails-performance/</link>
		<comments>http://www.missiondata.com/blog/web-development/70/latest-on-rails-performance/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 01:02:53 +0000</pubDate>
		<dc:creator>carsonm</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails performance test]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/uncategorized/70/latest-on-rails-performance/</guid>
		<description><![CDATA[Updated Rails 1.2 performance numbers have been released. While these number look pretty good it is hard to get a good idea of exactly what the performance of Rails is. A couple of other benchmarks that include Rails such as performance tests for 6 frameworks and Grails vs Rails benchmarks show a different picture. Both [...]]]></description>
			<content:encoded><![CDATA[<p>Updated <a href="http://railsexpress.de/blog/articles/2007/04/01/rails-1-2-performance">Rails 1.2 performance</a> numbers have been released. While these number look pretty good it is hard to get a good idea of exactly what the performance of Rails is. A couple of other benchmarks that include Rails such as <a href="http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-frameworks/">performance tests for 6 frameworks</a> and <a href="http://grails.org/Grails+vs+Rails+Benchmark">Grails vs Rails benchmarks</a> show a different picture. Both of these come up with much worse performance than the first. Maybe the issue is that the second two benchmarks are using <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">Apache ab</a> but the first uses a <a href="http://railsexpress.de/blog/articles/2007/04/01/new-railsbench-release-0-9-2">new version</a> of <a href="http://railsbench.rubyforge.org/">rails bench</a>. Of course most people probably aren&#8217;t that worried about the benchmarks that much because you can find ways to make anything fast as shown with <a href="http://joyeur.com/2007/02/04/a-brief-update-with-some-numbers-for-hardware-load-balanced-mongrels">Rails doing 4000 requests a second</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/70/latest-on-rails-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a better world with Google Spreadsheets</title>
		<link>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/</link>
		<comments>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 15:51:04 +0000</pubDate>
		<dc:creator>steveny</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blogs.missiondata.com/uncategorized/65/building-a-better-world-with-google-spreadsheets/</guid>
		<description><![CDATA[I was tickled when I ran across the GoogleLookup and GoogleFinance functions in Google Spreadsheets. I was very tickled when I found there was a REST API for interacting with the spreadsheets. So not only can you lookup the current volume of Google stock in a spreadsheet (=GoogleFinance(&#8220;GOOG&#8221;, &#8220;volume&#8221;)) or find out Roger Clemens&#8217;s ERA [...]]]></description>
			<content:encoded><![CDATA[<p>I was tickled when I ran across the <a href="http://docs.google.com/support/spreadsheets/bin/answer.py?answer=54199&#038;ctx=sibling">GoogleLookup</a> and <a href="http://docs.google.com/support/spreadsheets/bin/answer.py?answer=54198&#038;ctx=sibling">GoogleFinance</a> functions in <a href="">Google Spreadsheets</a>.  I was <b>very</b> tickled when I found there was a <a href="http://code.google.com/apis/gdata/spreadsheets.html">REST API</a> for interacting with the spreadsheets.</p>
<p>So not only can you lookup the current volume of Google stock in a spreadsheet (=GoogleFinance(&#8220;GOOG&#8221;, &#8220;volume&#8221;)) or find out Roger Clemens&#8217;s ERA (=GoogleLookup(&#8220;Roger Clemens&#8221;,&#8221;earned run average&#8221;)) you can access those values real time using an open API.  I cobbled together a quick ruby program that can retrieve values from a private or public (published) Google spreadsheet.  </p>
<p><span id="more-65"></span></p>
<p>The public sample should work for everyone since I published that spreadsheet for the world to see.  You will need to provide your own credentials and spreadsheet key to use the authenticated example.  I will caution that this is just a proof of concept that has limited functionality, weak parsing, and no error checking.</p>
<pre>
<code>#!/usr/bin/env ruby

require 'net/http'
require 'net/https'
require 'uri'
require 'rubygems'
require 'hpricot'

#
# Make it east to use some of the convenience methods using https
#
module Net
  class HTTPS &lt; HTTP
    def initialize(address, port = nil)
      super(address, port)
      self.use_ssl = true
    end
  end
end

class GoogleSpreadSheet
  def initialize(spreadsheet_key)
    @spreadsheet_key = spreadsheet_key
    @headers = nil
  end

  def authenticate(email, password)
    url = URI.parse('https://www.google.com/accounts/ClientLogin')
    response = Net::HTTPS.post_form(url,
      {'Email'=&gt;email,
       'Passwd'=&gt;password,
       'source'=&gt;"ruby-ss-example-1",
       'service'=&gt;'wise' })
    @headers = {
     'Authorization' =&gt; "GoogleLogin auth=#{response.body.split(/=/).last}",
     'Content-Type'  =&gt; 'application/atom+xml'
    }
  end

  def evaluate_cell(cell)
    path = "/feeds/cells/#{@spreadsheet_key}/1/#{@headers ? "private" : "public"}/basic/#{cell}"
    doc = Hpricot(request(path))
    result = (doc/"content[@type='text']").inner_html
  end

  private
  def request(path)
    http = Net::HTTP.new('spreadsheets.google.com', 80)
    response,data = http.get(path, @headers)
    data
  end
end

gs = GoogleSpreadSheet.new('p39irgfu5fsFokTPyPCG8Lg')
puts gs.evaluate_cell("A1")
puts gs.evaluate_cell("A2")
puts gs.evaluate_cell("B1")

gs = GoogleSpreadSheet.new(&lt;your spreadsheet key&gt;)
gs.authenticate(&lt;your email&gt;, &lt;your password&gt;)
puts gs.evaluate_cell("E132")</code>
</pre>
<p>The fun really just starts here.  You can edit existing spreadsheets too (although you can &#8216;t create or delete them yet).  As <a href='http://blogs.missiondata.com/author/richier/'>Rich</a> pointed out to me a few days ago, it won&#8217;t be too long before we are adding &#8216;export to Google spreadsheet&#8217; functions to our web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cleaning Up Rails Sessions, Revisited</title>
		<link>http://www.missiondata.com/blog/web-development/63/cleaning-up-rails-sessions-revisited/</link>
		<comments>http://www.missiondata.com/blog/web-development/63/cleaning-up-rails-sessions-revisited/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 16:15:30 +0000</pubDate>
		<dc:creator>Rich Rodriguez</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blogs.missiondata.com/?p=63</guid>
		<description><![CDATA[In an earlier post, we detailed a method for removing stale Rails session files. In more recent version of Rails, there is a Rake task built in for this administration task. rake tmp:sessions:clear # Clears all files in tmp/sessions]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://blogs.missiondata.com/?p=58">post</a>, we detailed a method for removing stale Rails session files. In more recent version of Rails, there is a Rake task built in for this administration task.</p>
<p><code class="console">rake tmp:sessions:clear # Clears all files in tmp/sessions</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/63/cleaning-up-rails-sessions-revisited/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

