<?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>Transcending Frontiers &#187; Sending Apple Push notifications in rails with Redis and apn_sender</title>
	<atom:link href="http://blog.thefrontiergroup.com.au/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thefrontiergroup.com.au</link>
	<description>Your peek inside the collective mind of The Frontier Group</description>
	<lastBuildDate>Tue, 03 Jan 2012 06:53:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Sending Apple Push notifications in rails with Redis and apn_sender</title>
		<link>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/#comments</comments>
		<pubDate>Wed, 11 May 2011 05:39:58 +0000</pubDate>
		<dc:creator>Mario Visic</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1363</guid>
		<description><![CDATA[Sending iOS push notifications from a Rails application is very easy to do these days, thankfully there are many great Ruby gems that can be used to handle most of the magic for you. Recently I ran into the apn_sender gem which handles sending push notifications in a really neat way. Sending push notifications directly [...]]]></description>
			<content:encoded><![CDATA[<p>Sending iOS push notifications from a Rails application is very easy to do these days, thankfully there are many great Ruby gems that can be used to handle most of the magic for you. Recently I ran into the <a href="https://github.com/kdonovan/apn_sender">apn_sender</a> gem which handles sending push notifications in a really neat way.</p>
<p>Sending push notifications directly from a Rails application can be slow and we probably don&#8217;t want to have the user waiting until the notification is sent, instead apn_sender can be setup to run a worker which is constantly connected to the apple push notification service. When there are new notifications to send, the notifications are queued up and sent through the always open connection that is maintained by the worker.</p>
<p>apn_sender uses <a href="http://redis.io/">redis</a> as a message queue to keep track of the notifications waiting to be sent, you&#8217;ll need to install it before using the gem.</p>
<p>To add apn_sender in your Rails 3 application, just add the gem to your Gemfile. We&#8217;re going to need the daemons gem too so we&#8217;ll include that as well.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="Gemfile" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Now we can create our daemon which we will be using for sending push notifications, this can be placed anywhere, I&#8217;ve put mine in script/apn_sender. Make sure to add execute permission to the file after creating so we can run it.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="apn_sender.rb" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Before the daemon can start running we&#8217;ll need to put our iOS push certificate into the application. Instructions for generating the certificates are available at the <a href="http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ProvisioningDevelopment/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW1">Apple Developer site</a>. The certificates need to be placed inside of /config/certs and should be named <i>apn_development.pem</i> or <i>apn_production.pem</i> for production.</p>
<p>Once the certificates are in their correct locations, we can start up the daemon. The daemon does not know about the Rails environment so we need to specify this when starting it up. The daemon supports <i>start</i>, <i>stop</i> and <i>restart</i> commands. There is a verbose flag available to output more information (which can be helpful when debugging).</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="start_command.bash" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Our application is now set up to send push notifications, this can now easily be performed by adding a new notification to the queue. The notify method on the APN class will take a push notification token and then our parameters, we can specify the alert message to show the user, whether or not we want sound as well as the number to display on the badge icon. Anything else we pass to notify will be sent as metadata in the push notification. Here&#8217;s an example of creating a notification.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="notify.rb" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>The worker should pick up the notification within a few seconds and send it off. The apn_sender has many other features that I haven&#8217;t covered, you can view the full documentation over at <a href="https://github.com/kdonovan/apn_sender">https://github.com/kdonovan/apn_sender</a>.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Composing Scopes On Multiple Models with Rails 3</title>
		<link>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 11:30:25 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[AREL]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1239</guid>
		<description><![CDATA[Today I had some knowledge delivered straight to the top of my dome, by Darcy. The issue was I had two models that I wanted to join and then apply scopes to. I wanted to retrieve Story objects that were joined to HourEntry objects, that were from this week. However when I tried to use [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had some knowledge delivered straight to the top of my dome, by Darcy. The issue was I had two models that I wanted to join and then apply scopes to. I wanted to retrieve Story objects that were joined to HourEntry objects, that were from this week. However when I tried to use the Time scope on the query it was attempting to call those methods on Story.</p>
<pre>ree-1.8.7-2011.02 :132 &gt; Story.joins(:hour_entries).this_week
NoMethodError: undefined method `this_week' for #</pre>
<p>The problem was that the .this_week call was being sent to Story rather than to HourEntry. Here&#8217;s where Darcy chimed in with the scoped.merge call. It went a little something like this :</p>
<pre>Story.scoped.merge HourEntry.this_week</pre>
<p>This successfully merged the scope defined by Story with the scope defined by the HourEntry.this_week call and I get all the stories that have HourEntry objects that are returned by the .this_week scope.</p>
<p>The final stage for this call was :</p>
<pre>Story.scoped.merge HourEntry.worked_on_by(user).this_week</pre>
<p>This then returns all the stories you&#8217;ve worked on this week. Add a bit of grouping/distinct and it&#8217;s done and done. The additional nice part about this is composing these scopes will allow me to do a lot more in the future, very quickly.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Get All Associations for an Activerecord Model</title>
		<link>http://blog.thefrontiergroup.com.au/2011/01/how-to-get-all-associations-for-an-activerecord-model/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/01/how-to-get-all-associations-for-an-activerecord-model/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 02:54:16 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/2011/01/how-to-get-all-associations-for-an-activerecord-model/</guid>
		<description><![CDATA[There was a question that was asked on our IRC channel today about how to get all the associations for an Activerecord model. I&#8217;m assuming it was to do some debugging or something, in any case I did a bit of digging around in the Rails docs and it turns out the answer isn&#8217;t that [...]]]></description>
			<content:encoded><![CDATA[<p>There was a question that was asked on our IRC channel today about how to get all the associations for an Activerecord model. I&#8217;m assuming it was to do some debugging or something, in any case I did a bit of digging around in the Rails docs and it turns out the answer isn&#8217;t that hard. </p>
<p>Doing something like : </p>
<pre>
    Model.reflect_on_all_associations
</pre>
<p>Will give you all the associations for that model, it&#8217;s pretty dirty though and so an easy way to tidy it up is : </p>
<pre>
    Model.reflect_on_all_associations.collect{ |association|
        association.name.to_s.classify
    }
</pre>
<p>So, as usual with Rails it was easy as pie, I just am putting this here for future use :) </p>
<p>Edit : Thanks to Darcy for tidying up my previous mess :P</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/01/how-to-get-all-associations-for-an-activerecord-model/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/01/how-to-get-all-associations-for-an-activerecord-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get Firebug, Capybara and Selenium Working Together</title>
		<link>http://blog.thefrontiergroup.com.au/2010/11/how-to-get-firebug-capybara-and-selenium-working-together/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/11/how-to-get-firebug-capybara-and-selenium-working-together/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 06:07:26 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=1058</guid>
		<description><![CDATA[I had an issue whereby a label I thought was fine wasn&#8217;t being picked up on my Cucumber tests. It turned out that the test environment was of course running our compiled javascript and I hadn&#8217;t compiled it since my change. The labels didn&#8217;t have the &#8216;for&#8217; attribute specified so Selenium was whinging it couldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I had an issue whereby a label I thought was fine wasn&#8217;t being picked up on my Cucumber tests. It turned out that the test environment was of course running our compiled javascript and I hadn&#8217;t compiled it since my change. The labels didn&#8217;t have the &#8216;for&#8217; attribute specified so Selenium was whinging it couldn&#8217;t find the element I wanted to find. </p>
<p>In any case I couldn&#8217;t find an explanation of how to get Firebug working with Selenium and Capybara but after some doc reading I got my solution working so I thought I&#8217;d post it here. </p>
<p>In my env.rb file I have : </p>
<pre>
Capybara.register_driver :selenium do |app|
  Capybara::Driver::Selenium
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile.add_extension(File.expand_path("features/support/firebug.xpi"))

  Capybara::Driver::Selenium.new(app, { :browser => :firefox, :profile => profile })
end
</pre>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/11/how-to-get-firebug-capybara-and-selenium-working-together/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/11/how-to-get-firebug-capybara-and-selenium-working-together/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Named Scopes with Joins and Default Block Arguments</title>
		<link>http://blog.thefrontiergroup.com.au/2010/05/named-scopes-with-joins-and-default-block-arguments/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/05/named-scopes-with-joins-and-default-block-arguments/#comments</comments>
		<pubDate>Tue, 04 May 2010 06:19:56 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Named Scopes]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=723</guid>
		<description><![CDATA[Today I was fiddling with some code to get particular types of payments that are due on particular days and I ran across a couple of things I don&#8217;t want to solve again. Firstly, the problem of being able to have default arguments to a block in ruby. It&#8217;s solved nicely in Ruby 1.9 but [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was fiddling with some code to get particular types of payments that are due on particular days and I ran across a couple of things I don&#8217;t want to solve again.</p>
<p>Firstly, the problem of being able to have default arguments to a block in ruby. It&#8217;s solved nicely in Ruby 1.9 but we&#8217;re using 1.8.x on our boxes at the moment. The work around is incredibly simple though and goes something like this :</p>
<p><code class="ruby"><br />
lambda { |*args|<br />
date = (args[0] || Date.today)<br />
.. remaining code ..<br />
}<br />
</code></p>
<p>That&#8217;s all there is to it really. You could go the whole hog with hashed attributes and so on but I think it starts to get a bit smelly if your anonymous functions are taking more than one argument.</p>
<p>The other issue I had was whether a named scope can include a join, and it can.</p>
<p><code class="ruby"><br />
named_scope :credit_card, { :joins =&gt; :subscription, :conditions =&gt; "subscriptions.method = 'credit_card'" }<br />
</code></p>
<p>You can hash it all out if you want to, though if it&#8217;s all about readability I find the above to be more suitable. However this will also work :</p>
<p><code class="ruby"><br />
... :conditions { :payment_plans =&gt; { :payment_method =&gt; "credit_card" } }<br />
</code></p>
<p>The coolest thing about all of this though (and I feel I&#8217;m very late to the party here) is that I now get to do things like :</p>
<p><code class="ruby"><br />
Payment.credit_card.due_on(Date.today)<br />
# or<br />
Payment.credit_card.due_on<br />
# or<br />
Payment.due_on(Date.today + 1.month)<br />
</code></p>
<p>In the above I had just used the default argument to the due_on named scope to be today&#8217;s date.</p>
<p>I mean, I&#8217;d seen a bunch of tutorials on named scopes and how they worked but hadn&#8217;t found a use case in my work. I think it&#8217;s finally twigged for me though and will be making use of them a bit more in the future. </p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/05/named-scopes-with-joins-and-default-block-arguments/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/05/named-scopes-with-joins-and-default-block-arguments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running RSpec in Distributed and Parallel using Specjour</title>
		<link>http://blog.thefrontiergroup.com.au/2010/04/running-rspec-in-distributed-and-parallel-using-specjour/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/04/running-rspec-in-distributed-and-parallel-using-specjour/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 09:27:20 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Specjour]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=715</guid>
		<description><![CDATA[Just to cut to the chase, Specjour will easily allow you to run your tests in parallel on your local machine, or in a distributed way on your network. It cut our test suite from over 11 minutes to under 2.5 minutes. We went from one Macbook Pro to a Macbook Pro plus an iMac. [...]]]></description>
			<content:encoded><![CDATA[<p>Just to cut to the chase, Specjour will easily allow you to run your tests in parallel on your local machine, or in a distributed way on your network. It cut our test suite from over 11 minutes to under 2.5 minutes. We went from one Macbook Pro to a Macbook Pro plus an iMac. Specjour is gooood, but continuing &#8230;</p>
<p>We were running into issues with our testing suite running past 15 minutes to run. It caused a number of issues, firstly it disuaded people from running the suite for small changes they thought would be okay, secondly people tended to slow down or not work at all when the suite was running. Given we were building tests into an existing code base and coverage was running generally under 30% this was already <strong>really</strong> worrying. </p>
<p>We&#8217;ve been concentrating primarily on functional testing with RSpec so I went looking for solutions for trying to parallelise RSpec specifically. I tried parallel-tests but I couldn&#8217;t get it to work. Then I heard about Specjour on a Hashrocket video so I decided to give that a try. It worked pretty well out of the box, I just had to plug up a wayward plugin, update the rsync config file for the project and change one of the files in the gem to call a different rake task. </p>
<p><a href="http://github.com/sandro/specjour">Specjour</a> essentially uses Bonjour to find workers on the network and dispatch tests to them and it uses rsync to synchronise the project you&#8217;re testing to the remote server. Once the sync has happened then runs the rake task to setup the databases, loads the environment and starts accepting the tests that are dispatched to it. </p>
<p>The instructions will work for the majority of people, I only had some hiccups due to our project. Essentially I gem installed specjour which gave me a specjour executable which I ran to create a dRb server that communicates via Bonjour. Then in my project I added specjour to my Gemfile (all managed via Bundler!) and ran <code>rake specjour</code>. </p>
<p>For me, I ended up having a few hundred failing tests, all to do with the Ruby version of a stack overflow (stack level too deep). It turned out it was caused by a plugin calling alias method chain twice so that the original method ended up being aliased to the replacement method and so there was an infinite loop. Once I applied a fix then we were only down to a few failing tests to do with seed data. </p>
<p>I changed the db_scrub.rb file to perform a different rake task for us as we do require some seed data and then we were on our way. </p>
<p>Previously on my Macbook Pro the suite ran in just over 11 minutes, after turning on a four core iMac and my Macbook Pro I had six workers ready to go and it took about 2.5 minutes to run our tests. I&#8217;d really like to crank up the other few iMacs and the 10 or so Macbooks and see what happens then. </p>
<p>I think the only changes we&#8217;ll require is to be able to specify which task is run to create the databases, other than that it works perfectly. </p>
<p>In closing I&#8217;d say I tried a number of distributed and parallel methods for running our tests and I like Specjour the best. Apparently it will run Cucumber tests as well, I&#8217;m hoping to move on to that soon enough. </p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/04/running-rspec-in-distributed-and-parallel-using-specjour/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/04/running-rspec-in-distributed-and-parallel-using-specjour/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting Up an iMac Pairing Station for Rails Development</title>
		<link>http://blog.thefrontiergroup.com.au/2010/04/setting-up-an-imac-pairing-station-for-rails-development/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/04/setting-up-an-imac-pairing-station-for-rails-development/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 09:08:33 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iMac]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=599</guid>
		<description><![CDATA[I used this post today as a guide on how to get another iMac up and running so I thought it was probably a good point to chuck this up here, if only for our own reference. We are starting with a 27&#8243; iMac and a base Snow Leopard install. The first step was to [...]]]></description>
			<content:encoded><![CDATA[<p>I used this post today as a guide on how to get another iMac up and running so I thought it was probably a good point to chuck this up here, if only for our own reference. </p>
<p>We are starting with a 27&#8243; iMac and a base Snow Leopard install. </p>
<p>The first step was to install Xcode from the Snow Leopard disc, you&#8217;ll find it in the Optional Installs part of the disc. </p>
<p>Ruby and RubyGems comes with Snow Leopard by default so we&#8217;ll use them. You&#8217;ll likely need to update the RubyGems system :</p>
<pre class="console">
    sudo gem update --system
</pre>
<p>Now we can install Rails :</p>
<pre>
  sudo gem install rails
</pre>
<p>This will install the latest stable version of Rails. We need a specific version for some of our applications (until we&#8217;ve tested it under the newer version) and you can do this by adding the -v switch : </p>
<pre>
  sudo gem install rails -v=2.3.4
</pre>
<p>After this we can switch on Apache and install passenger, the module that runs Rails on Apache. So turn on Web Sharing in the Sharing panel of your System Preferences. </p>
<pre>
  sudo gem install passenger
  sudo passenger-install-apache2-module
</pre>
<p>This will compile the Apache module and give you some text to paste into your apache conf file to load it. I keep this in a separate config file in /etc/apache2/other/passenger.conf. It should look something like : </p>
<pre>
  LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
  PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.8
  PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
</pre>
<p>Next download the Passenger Preference Pane so you can control your Rails sites from the OS X Preferences area. You can get it from <a href="http://www.fngtps.com/passenger-preference-pane">http://www.fngtps.com/passenger-preference-pane</a>. You should now be able to run Rails websites on your local machine very easily.</p>
<p>We use Git for our source control and Git X is the best GUI for this on OS X at the moment. You can download Git for OS X from <a href="http://code.google.com/p/git-osx-installer/">http://code.google.com/p/git-osx-installer/</a> and you can get GitX from <a href="http://gitx.frim.nl/">http://gitx.frim.nl/</a>.</p>
<p>I like to use a Pomodoro timer when pairing and the one I like the best for OS X is just called Pomodoro Desktop. It will keep people focussed and also can serve to keep the control swapping in a fairly regular way. You can find out about how Pomodoro works <a href="http://www.pomodorotechnique.com/">here</a>.</p>
<p>We use Github for our repository and exchange is done via SSH, so you&#8217;ll need to generate an SSH key and put that into your Github account. </p>
<pre>
  ssh-keygen
  cat ~/.ssh/id_rsa.pub
</pre>
<p>Copy the output and put that into your public SSH keys in Git Hub. </p>
<p>When pairing with Git the ability to have both parties responsible for the work they&#8217;re doing is appreciated sometimes. Especially twelve months from now when you can&#8217;t remember why you did something. Not that you don&#8217;t comment your code, or always write beautifully understandable code. There is a nice gem called <a href="http://github.com/therubymug/hitch">hitch</a>. It comes out of Hashrocket and handles the &#8216;hitching&#8217; and &#8216;unhitching&#8217; of partners on a machine. We have a pairing station so generally we just want to change the pair that&#8217;s in operation, so it works well. You&#8217;ll need to be inside a git repository to do the initial setup. I cloned one of our projects and then you issue : </p>
<pre>
  hitch -m
</pre>
<p>Which will prompt you for your main email address, this is the email address that all devs in your team receive, or a group email of some sort. </p>
<p>Now to hitch two devs you&#8217;d do : </p>
<pre>
  hitch dev1 dev2
</pre>
<p>This will prompt you for names of the dev1 and dev2 users so that they&#8217;ll be displayed in your commit. It&#8217;ll also associate your commits to the email address devs+dev1+dev2@company.com if you setup devs@company.com as the email address when you issued the hitch -m command. If you setup gravatars for all your devs+user1+user2@company.com email addresses then you&#8217;ll get a nice picture in Github too. </p>
<p>I think that&#8217;s about it really. We obviously just install gems as required and make customisations on a per developer need. We generally use Textmate for editing so this means installing a theme (we use the Railscast theme) and the relevant bundles for Rspec, Haml and Sass. </p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/04/setting-up-an-imac-pairing-station-for-rails-development/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/04/setting-up-an-imac-pairing-station-for-rails-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Problems with DateTime, TimeZone, Bundler and Rails 2.3.5</title>
		<link>http://blog.thefrontiergroup.com.au/2010/04/problems-with-datetime-timezone-bundler-and-rails-2-3-5/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/04/problems-with-datetime-timezone-bundler-and-rails-2-3-5/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 04:18:11 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Bundler]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=708</guid>
		<description><![CDATA[I&#8217;ve been converting a Rails 2.3.5 project to using Bundler and ran into a bit of a snag this week. I was getting a over 300 failing tests with errors such as : uninitialized constant ActiveSupport::TimeWithZone and no such file to load -- tzinfo I couldn&#8217;t find anything that I&#8217;d missed, I&#8217;d moved all my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been converting a Rails 2.3.5 project to using Bundler and ran into a bit of a snag this week. I was getting a over 300 failing tests with errors such as : </p>
<pre class="ruby">uninitialized constant ActiveSupport::TimeWithZone</pre>
<p> and
<pre class="ruby">no such file to load -- tzinfo</pre>
<p>I couldn&#8217;t find anything that I&#8217;d missed, I&#8217;d moved all my gem declarations from the various environment files into my Gemfile and hadn&#8217;t had many issues (many) but this was a really odd problem. It was as if part of Rails wasn&#8217;t being loaded correctly.</p>
<p>It turns out that you need to include a tzinfo gem for some reason. Don&#8217;t ask me how I ran across the solution for this issue, I really can&#8217;t remember. It works though. </p>
<p>So if you&#8217;re having issues with your app, or tests not passing due to time zone issues in Rails 2.3.x using Bundler then just include : </p>
<pre class="ruby">
gem "tzinfo"
</pre>
<p>In your Gemfile, run another bundle install and away you go. It worked for me, I hope it works for you!</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/04/problems-with-datetime-timezone-bundler-and-rails-2-3-5/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/04/problems-with-datetime-timezone-bundler-and-rails-2-3-5/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using RSpec Example Groups for Common Functionality</title>
		<link>http://blog.thefrontiergroup.com.au/2010/01/using-rspec-example-groups-for-common-functionality/</link>
		<comments>http://blog.thefrontiergroup.com.au/2010/01/using-rspec-example-groups-for-common-functionality/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 00:58:53 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=624</guid>
		<description><![CDATA[I&#8217;m currently getting into using RSpec for testing our controllers on what is turning into a large project. It&#8217;s been more than handy because we have a lot of complex scoping to take into account whenever retrieving data. People don&#8217;t like to see other peoples&#8217; financial data, mostly because it implies that someone is probably [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently getting into using RSpec for testing our controllers on what is turning into a large project. It&#8217;s been more than handy because we have a lot of complex scoping to take into account whenever retrieving data. People don&#8217;t like to see other peoples&#8217; financial data, mostly because it implies that someone is probably looking at theirs. With this in mind it&#8217;s more than important that we know the right data is going to the right places and hence the need for controller testing. </p>
<p>Now most of our controllers require the user to be logged in so writing tests to check this for every controller is annoying and time consuming, more than that it feels dirty. I think this is what some people call a <em>code smell</em> though I&#8217;m not up to speed on buzz words. There are also other tasks that are done quite often such as setting up the various types of users we&#8217;d like to test as, it would be nice if this were easily put in one place and could be easily pulled in. I guess I was looking for a template of tests that I could share. </p>
<p>It seems that the solution to it is found in Shared Example Groups which I hadn&#8217;t heard very much discussion about and it kind of leaves working out how they work to you rather than documenting it too much. </p>
<p>So far I&#8217;ve used it simply to make sure that controllers that require are redirecting users appropriately and also for setting up a specific type of user for our system before testing. </p>
<p>I created a directory under /spec/support called example_groups and in there I have a file called login_groups.rb. In that file I have something like the following : </p>
<pre class="ruby">
shared_examples_for "customer is logged in" do
  before(:all) do
    @user = Factory(:customer_user)
    @user.customers.push Factory(:customer)
  end

  before(:each) do
    activate_authlogic
    OperatorSession.create(@operator)
  end
end
</pre>
<p>Now in my spec files when I have a bunch of tests requiring a logged in customer I will include this little snippet : </p>
<pre class="ruby">
  it_should_behave_like "customer is logged in"
</pre>
<p>I get a logged in customer to start playing around with. I have the spec/support/example_groups directory in my include paths for Rspec and so it just all works. </p>
<p>My tests can then start to look like : </p>
<pre class="ruby">
describe MerchantsController do
  it_should_behave_like "areas requiring login"

  context "customer logged in" do
    it_should_behave_like "customer is logged in"

    ... insert other tests here ...
  end
end
</pre>
<p>It means I can swap in another authentication gem/plugin pretty easily and also encapsulates the logic about creating customers, or whatever type of item you want to use, so that if that changes you can swap things in and out with a minimum of fuss. </p>
<p>Just to be clear, example groups aren&#8217;t limited to setup tasks or connecting to before/after hooks, you can also include a bunch of tests as well. This allows me to have a bunch of tests to run to make sure that a user does have to be logged in for various controllers and include these tests in on line. </p>
<p>I hope this helps someone, it took a bit of searching and trial and error myself this morning to get it working and find the uses for it that I&#8217;ve found. I&#8217;m definitely open to better solutions to this sort of issue though. </p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2010/01/using-rspec-example-groups-for-common-functionality/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2010/01/using-rspec-example-groups-for-common-functionality/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Database Transactions in Cucumber Breaking Selenium</title>
		<link>http://blog.thefrontiergroup.com.au/2009/10/database-transactions-in-cucumber-breaking-selenium/</link>
		<comments>http://blog.thefrontiergroup.com.au/2009/10/database-transactions-in-cucumber-breaking-selenium/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 06:00:06 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=441</guid>
		<description><![CDATA[We&#8217;ve been using Selenium, Webrat, Cucumber and any number of other gems together for quite a while with very few problems. Just recently our Selenium tests just stopped working on the login step, and given our application requires users to login to do anything, it meant out test suite was basically broken from step one. [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been using Selenium, Webrat, Cucumber and any number of other gems together for quite a while with very few problems. Just recently our Selenium tests just stopped working on the login step, and given our application requires users to login to do anything, it meant out test suite was basically broken from step one.</p>
<p>Given that we thought very little of any consequence had changed it was annoying trying to troubleshoot the problem. Typically you start off thinking it&#8217;s something you did, then maybe it&#8217;s something someone you know did, then you start to branch out and think that maybe, just maybe, it was a bug elsewhere!</p>
<p>I initially started to check the logs and they seemed perfect, but it wasn&#8217;t finding the user record in the database. So I loaded the database in sqlite and lo-and-behold there were no user records to be found. I started a debug session and it reported that the user had in fact been created. I thought it had to be something to do with transactions being used. Trying to insert a record into the database and being told the database was locked confirmed this.</p>
<p>I turned out that the Cucumber gem writer determined that there should be no more global setting for turning on or off transaction support when running tests. Previously transactions were turned off by default in Cucumber, and you&#8217;d generally turn them back on if you needed them. This change is annoying because a good chunk of our suite uses Selnium for testing and it requires transactions to be turned off. It&#8217;s also a bit odd to reverse a default option and have no way to enable it at all.</p>
<p>Apparently the work around is to tag all the features and scenarios that rely on non-transactional database operations with this new tag of @no-txn. After implementing this, we&#8217;ve found it does work and so our tests are back to usual condition.</p>
<p>So if you&#8217;re running into problems with your Selenium tests using Cucumber with Rails and your database isn&#8217;t updating within a test then check out the &#8216;@no-txn&#8217; tag and see what happens after you use that.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2009/10/database-transactions-in-cucumber-breaking-selenium/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2009/10/database-transactions-in-cucumber-breaking-selenium/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

