<?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>amazing development &#187; Rails</title>
	<atom:link href="http://amazing-development.com/archives/category/all/work/ruby/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://amazing-development.com</link>
	<description>ruby, java and the rest</description>
	<lastBuildDate>Thu, 20 May 2010 06:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Profiling Rails Unittests</title>
		<link>http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/</link>
		<comments>http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 15:38:40 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/</guid>
		<description><![CDATA[Thanks to a hint by Chris Mear on the Ruby on Rails Mailinglist I had an idea how to add profiling my unittests. It&#8217;s a simple 3 step process and adds just 5 lines of code to your unittests: Step 1: require 'profiler' Step 2: &#160;def setup &#160;&#160;# ... &#160;&#160;# your normal setup code &#160;&#160;# [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to a hint by <a href="http://www.feedmechocolate.com/">Chris Mear</a> on the <a href="http://lists.rubyonrails.org/mailman/listinfo/rails">Ruby on Rails Mailinglist</a> I had an idea how to add profiling my unittests. It&#8217;s a simple 3 step process and adds just 5 lines of code to your unittests:</p>
<p><b>Step 1:</b><br />
<code class="ruby"><br />
require 'profiler'<br />
</code></p>
<p><b>Step 2:</b><br />
<code class="ruby"><br />
&nbsp;def setup<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;# your normal setup code<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;Profiler__::start_profile<br />
&nbsp;end<br />
</code></p>
<p><b>Step 2:</b><br />
<code class="ruby"><br />
&nbsp;def teardown<br />
&nbsp;&nbsp;Profiler__::stop_profile<br />
&nbsp;&nbsp;f=File::new("#{RAILS_ROOT}/log/profiler.#{name() + ' ' +<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.now.strftime('%Y-%m-%d %H:%M')}.log", 'w')<br />
&nbsp;&nbsp;Profiler__::print_profile(f)<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;# your normal teardown code<br />
&nbsp;&nbsp;# ...<br />
&nbsp;end<br />
</code></p>
<p>As you probably guessed from the code, this will log the profiling results into a file for each test. But beware: this is <b>VERY SLOW!</b> The tests I was profiling took 9s without profiling and 1267s with profiling&#8230; But slow profiling still beats no profiling <img src='http://amazing-development.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you are looking for memory profiling, there is a nice article by Scott Laird on <a href="http://scottstuff.net/blog/articles/2006/08/17/memory-leak-profiling-with-rails">Memory leak profiling with Rails</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails, ActiveRecord and Distributed Ruby (DRb) in a nutshell</title>
		<link>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/</link>
		<comments>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 09:52:09 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/</guid>
		<description><![CDATA[This tutorial shows how to use distributed ruby to connect a rails application with another ruby service not running inside Rails. Distributed Ruby (DRb) I won&#8217;t waste time here explaining how to use DRb. Just a short example from Rubycentral with a very simple server: require &apos;drb&apos; class TestServer def doit &#34;Hello, Distributed World&#34; end [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>This tutorial shows how to use distributed ruby to connect a rails application with another ruby service not running inside Rails.<span id="more-208"></span></p>
<h3 class="article">Distributed Ruby (DRb)</h3>
<p>I won&#8217;t waste time here explaining how to use DRb. Just a short example from <a href="http://www.rubycentral.com/articles/drb.html">Rubycentral</a> with a very simple server:</p>
<pre><textarea wrap="off" class="code" rows="11" readonly>require &apos;drb&apos;

class TestServer
  def doit
    &quot;Hello, Distributed World&quot;
  end
end

aServerObject = TestServer.new
DRb.start_service(&apos;druby&#58;//localhost&#58;9000&apos;, aServerObject)
DRb.thread.join # Don&apos;t exit just yet!</textarea></pre>
<p>and an even simpler client:</p>
<pre><textarea wrap="off" class="code" rows="5" readonly>require &apos;drb&apos;
DRb.start_service
obj = DRbObject.new(nil, &apos;druby&#58;//localhost&#58;9000&apos;)
# Now use obj
puts obj.doit</textarea></pre>
<h3 class="article">Active Record</h3>
<p>As you want to connect the DRb Server to Rails, you probably want to use your model classes, too. Just include them (I&#8217;m still looking for a simple way to automagically include all models) and configure ActiveRecord:</p>
<pre><textarea wrap="off" class="code" rows="23" readonly>require &apos;drb&apos;
require &apos;rubygems&apos;
require_gem &apos;activerecord&apos;

require &apos;app/models/user.rb&apos;

class Server
  def dump
    puts User.find(&#58;first).inspect
  end
end

ActiveRecord&#58;&#58;Base.establish_connection(
    &#58;adapter  =&gt; &quot;mysql&quot;,
    &#58;username =&gt; &quot;xxxx&quot;,
    &#58;host     =&gt; &quot;localhost&quot;,
    &#58;password =&gt; &quot;xxxx&quot;,
    &#58;database =&gt; &quot;xxxx&quot;
)

DRb.start_service(&quot;druby&#58;//localhost&#58;9000&quot;, Server.new)
puts DRb.uri
DRb.thread.join</textarea></pre>
<h3 class="article">Don&#8217;t repeat yourself!</h3>
<p>Repeating the database configuration as I did in the above example is soooo against The Ruby Way. A better way is to parse <tt>config/database.yml</tt> and use the result to configure ActiveRecord. This has the added benefit of being able to use different database setups:</p>
<pre><textarea wrap="off" class="code" rows="22" readonly>require &apos;drb&apos;
require &apos;rubygems&apos;
require &apos;yaml&apos;
require_gem &apos;activerecord&apos;

require &apos;app/models/user.rb&apos;

class Server
  def dump
    puts User.find(&#58;first).inspect
  end
end

abort &quot;usage&#58; #{__FILE__} environment&quot; unless ARGV[0]
database_yaml = YAML.load_file(&quot;config/database.yml&quot;)
abort &quot;environment &apos;#{ARGV[0]}&apos; not found&quot; unless database_config = database_yaml[ARGV[0]]

ActiveRecord&#58;&#58;Base.establish_connection(database_config)

DRb.start_service(&quot;druby&#58;//localhost&#58;9000&quot;, Server.new)
puts DRb.uri
DRb.thread.join</textarea></pre>
<h3 class="article">From Rails?</h3>
<p>Just use the simple client from above inside your model or controller without special changes for Rails. Yes, it&#8217;s that simple. Enjoy!</p>
<pre><textarea wrap="off" class="code" rows="9" readonly>require &apos;drb&apos;
...
class DrbController &lt; ApplicationController

  def get_user_via_drb
    DRb.start_service
    obj = DRbObject.new(nil, &apos;druby&#58;//localhost&#58;9000&apos;)
    @user = obj.dump
  end </textarea></pre>
<p><a href="http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/ec565ebc86f25066/0b25eac91671699c">Here</a> is a short thread about problems with DRb.</p>
<h3 class="article">DRb over unix sockets</h3>
<p><a href="http://kasparov.skife.org/blog/">Brian</a> has a <a href="http://kasparov.skife.org/blog/2006/04/22/">nice writeup how to use DRb over unix sockets</a> &#8211; it&#8217;s extremly easy, just change the URI et voila&#8230;</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/ruby" rel="tag">ruby</a>, <a href="http://technorati.com/tag/rails" rel="tag"> rails</a>, <a href="http://technorati.com/tag/drb" rel="tag"> drb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Useful test for Rails functional tests</title>
		<link>http://amazing-development.com/archives/2006/03/06/functional-testing/</link>
		<comments>http://amazing-development.com/archives/2006/03/06/functional-testing/#comments</comments>
		<pubDate>Mon, 06 Mar 2006 20:48:28 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/03/06/functional-testing/</guid>
		<description><![CDATA[Evil folks and stupid users expose webapplications to requests no sane developer usually expects. To find methods that cannot cope with unexpected input I added a simple test to my current Ruby on Rails project. The test calls all public actions via all http actions and uses some dummy parameters. There are no assertions in [...]]]></description>
			<content:encoded><![CDATA[<p>Evil folks and stupid users expose webapplications to requests no sane developer usually expects. To find methods that cannot cope with unexpected input I added a simple test to my current Ruby on Rails project. The test calls all public actions via all http actions and uses some dummy parameters. There are no assertions in this test, because I don&#8217;t know if an action should succeed or redirect. The only thing checked with this test is that the action does not fail.</p>
<pre><textarea wrap="off" class="code" rows="12" readonly>def test_dummy_calls
  ac = ApplicationController.new
  @controller.public_methods.each do |action|
    unless ac.respond_to?(action)
      [&#58;get, &#58;post, &#58;head, &#58;put, &#58;delete].each do |http_method|
        [nil, &apos;&apos;, &apos;abc&apos;*80, &apos;&#45;23&apos;, &apos;123456789012345&apos;].each do |param|
          method(http_method).call(action, &#58;id =&gt; param)
        end
      end
    end
  end
end</textarea></pre>
<p>Technorati Tags: <a href="http://technorati.com/tag/ruby" rel="tag">ruby</a>, <a href="http://technorati.com/tag/rails" rel="tag"> rails</a>, <a href="http://technorati.com/tag/tests" rel="tag"> tests</a></p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/03/06/functional-testing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
