<?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; rails</title>
	<atom:link href="http://www.missiondata.com/blog/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.missiondata.com/blog</link>
	<description>Louisville-based Web Development &#038; Software Engineering</description>
	<lastBuildDate>Tue, 18 May 2010 14:24:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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[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 &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.
&gt;&gt; Book.count
=&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:<br />
<br />
<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 &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>Change the <tt>fixtures</tt> declaration to <code>fixtures :libris_book</code>.
<li> Use <tt>set_fixture_class</tt> to connect the fixture to the model class.
</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 &lt; Test::Unit::TestCase
  set_fixture_class :libris_book =&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>2</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[Web Development]]></category>
		<category><![CDATA[rails]]></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>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>
		<item>
		<title>Cleaning up stale rails sessions (removing ruby_sess files)</title>
		<link>http://www.missiondata.com/blog/web-development/58/cleaning-up-stale-rails-sessions-removing-ruby_sess-files/</link>
		<comments>http://www.missiondata.com/blog/web-development/58/cleaning-up-stale-rails-sessions-removing-ruby_sess-files/#comments</comments>
		<pubDate>Thu, 08 Jun 2006 11:59:02 +0000</pubDate>
		<dc:creator>carsonm</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://blogs.missiondata.com/?p=58</guid>
		<description><![CDATA[I&#8217;m not sure if something isn&#8217;t set up correctly of if this is just a fact of life with rails but the sessions it creates never seem to go away. I think before rails 1.1 the sessions where stored in /tmp and now they are stored in the apps directory along with everything else so [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure if something isn&#8217;t set up correctly of if this is just a fact of life with rails but the sessions it creates never seem to go away. I think before rails 1.1 the sessions where stored in /tmp and now they are stored in the apps directory along with everything else so they is probably no internal mechanism to delete them. I only noticed because after about a month of an certain app running the disk on the machine started to fill up. After digging a little I found 50K ruby_sess.* files hanging out in the rails session directory.</p>
<p>Anyway it was easy enough to clean up the stale ruby_sess files by going into the rails webapp/session directory and then running the following command:</p>
<pre>
<code>find -type f -name "ruby_sess*" -exec rm -f {} \;</code>
</pre>
<p>I&#8217;m not sure why the app is creating sessions but it isn&#8217;t something that stores state so I didn&#8217;t have to worry about killing active sessions here. If you do need to worry about that you will probably want to toss a time on the find command.</p>
<p>After looking a little more I found a <a href="http://www.realityforge.org/articles/2006/03/01/removing-stale-rails-sessions">post about this</a> that has a ruby way of cleaning up the sessions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/58/cleaning-up-stale-rails-sessions-removing-ruby_sess-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
