Permalink
Browse files

Add 'Bundler local paths' blog post

  • Loading branch information...
1 parent 8ffd337 commit b53209b8b15e8ad2eb0bb7114a719268f6110918 @radar committed Aug 16, 2013
@@ -0,0 +1,36 @@
+---
+wordpress_id: RB-343
+layout: post
+title: Bundler local paths
+---
+
+There's a little known feature of Bundler that allows you to use a local Git
+repository while developing locally, and a remote Git repo when deploying. This
+feature means that you no longer have to *constantly* switch between local paths:
+
+ gem 'spree', :path => "~/Projects/gems/spree"
+
+And remote paths:
+
+ gem 'spree', :github => 'spree/spree', :branch => 'master'
+
+How does it work?
+
+----
+
+Well, what you can do instead is tell Bundler that you have a local copy of
+this repository by running a command like this in your terminal:
+
+ bundle config local.spree ~/Projects/gems/spree
+
+Then in your Gemfile whenever you reference a Git repo for this gem, like this...
+
+ gem 'spree', :github => 'spree/spree', :branch => 'master'
+
+Bundler will use the local copy. When you deploy this application to your server, because the server is not configured to use a local copy of the repo, it will use the proper repo from GitHub.
+
+For more information, check out the [Bundler documentation page](http://bundler.io/v1.3/git.html), under "Local Git Repos".
+
+----
+
+Thanks to Phil Arndt who first showed me this trick many moons ago.
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Blog of Ryan Bigg - Bundler local paths</title>
+ <link href="http://feeds.feedburner.com/ryanbigg" rel="alternate" title="The Life of a Radar" type="application/atom+xml" />
+ <link rel='stylesheet' href='/css/style.css' media='screen'>
+ <link rel='stylesheet' href='/css/mobile.css'>
+ <body>
+ <h1 align='center'><a href='http://ryanbigg.com'>The Life of a Radar</a></h1>
+ <div id='page'>
+ <article>
+ <a href="/2013/08/bundler-local-paths"><header>Bundler local paths</header></a>
+ <small>16 Aug 2013</small><br>
+ <p>There&#39;s a little known feature of Bundler that allows you to use a local Git
+repository while developing locally, and a remote Git repo when deploying. This
+feature means that you no longer have to <em>constantly</em> switch between local paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :path =&gt; &quot;~/Projects/gems/spree&quot;
+</code></pre></div>
+<p>And remote paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
+</code></pre></div>
+<p>How does it work?</p>
+
+<hr>
+
+<p>Well, what you can do instead is tell Bundler that you have a local copy of
+this repository by running a command like this in your terminal:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">bundle config local.spree ~/Projects/gems/spree
+</code></pre></div>
+<p>Then in your Gemfile whenever you reference a Git repo for this gem, like this...</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
+</code></pre></div>
+<p>Bundler will use the local copy. When you deploy this application to your server, because the server is not configured to use a local copy of the repo, it will use the proper repo from GitHub.</p>
+
+<p>For more information, check out the <a href="http://bundler.io/v1.3/git.html">Bundler documentation page</a>, under &quot;Local Git Repos&quot;.</p>
+
+<hr>
+
+<p>Thanks to Phil Arndt who first showed me this trick many moons ago.</p>
+
+ </article>
+ </div>
+ <div id='disqus_thread'></div>
+ <script type="text/javascript">
+ var disqus_shortname = 'ryanbigg'; // required: replace example with your forum shortname
+
+ var disqus_identifier = 'RB-343 http://ryanbigg.com/?p=RB-343'
+ var disqus_url = 'http://ryanbigg.com/2013/08/bundler-local-paths';
+ </script>
+ <script src='http://ryanbigg.disqus.com/embed.js'></script>
+
+ <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+ <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
+ <script type="text/javascript">
+ var _gauges = _gauges || [];
+ (function() {
+ var t = document.createElement('script');
+ t.type = 'text/javascript';
+ t.async = true;
+ t.id = 'gauges-tracker';
+ t.setAttribute('data-site-id', '4e30f771f5a1f547c8000001');
+ t.src = '//secure.gaug.es/track.js';
+ var s = document.getElementsByTagName('script')[0];
+ s.parentNode.insertBefore(t, s);
+ })();
+ </script>
+ </body>
+</html>
View
@@ -4,7 +4,7 @@
<title>The Life of a Radar</title>
<link href="http://ryanbigg.com/atom.xml" rel="self"/>
<link href="http://ryanbigg.com"/>
- <updated>2013-07-09T13:10:00+10:00</updated>
+ <updated>2013-08-16T15:55:35+10:00</updated>
<id>http://ryanbigg.com/</id>
<author>
<name>Ryan Bigg</name>
@@ -13,6 +13,40 @@
<entry>
+ <title>Bundler local paths</title>
+ <link href="http://ryanbigg.com/2013/08/bundler-local-paths"/>
+ <updated>2013-08-16T00:00:00+10:00</updated>
+ <id>http://ryanbigg.com/2013/08/bundler-local-paths</id>
+ <content type="html"><![CDATA[<p>There&#39;s a little known feature of Bundler that allows you to use a local Git
+repository while developing locally, and a remote Git repo when deploying. This
+feature means that you no longer have to <em>constantly</em> switch between local paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :path =&gt; &quot;~/Projects/gems/spree&quot;
+</code></pre></div>
+<p>And remote paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
+</code></pre></div>
+<p>How does it work?</p>
+
+<hr>
+
+<p>Well, what you can do instead is tell Bundler that you have a local copy of
+this repository by running a command like this in your terminal:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">bundle config local.spree ~/Projects/gems/spree
+</code></pre></div>
+<p>Then in your Gemfile whenever you reference a Git repo for this gem, like this...</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
+</code></pre></div>
+<p>Bundler will use the local copy. When you deploy this application to your server, because the server is not configured to use a local copy of the repo, it will use the proper repo from GitHub.</p>
+
+<p>For more information, check out the <a href="http://bundler.io/v1.3/git.html">Bundler documentation page</a>, under &quot;Local Git Repos&quot;.</p>
+
+<hr>
+
+<p>Thanks to Phil Arndt who first showed me this trick many moons ago.</p>
+]]></content>
+ </entry>
+
+ <entry>
<title>Waiting for AJAX in Capybara</title>
<link href="http://ryanbigg.com/2013/07/waiting-for-ajax-in-capybara"/>
<updated>2013-07-09T00:00:00+10:00</updated>
@@ -1299,22 +1333,5 @@ property.</p>
]]></content>
</entry>
- <entry>
- <title>Matt Lightner</title>
- <link href="http://ryanbigg.com/2011/12/matt-lightner"/>
- <updated>2011-12-27T00:00:00+11:00</updated>
- <id>http://ryanbigg.com/2011/12/matt-lightner</id>
- <content type="html"><![CDATA[<p>Matt Lightner -- <a href='http://www.facebook.com/mlightner'>according to posts on his Facebook</a> -- is dead. It apparently
-happened on Christmas day, which just adds supremely to the suckiness of it all.</p>
-
-<p>You may remember him from that little hosting company called <a href='http://site5.com'>Site5</a> he started when he was 15. You know
-the one that was one of the, if not <em>the</em> first, hosting company to offer Ruby on Rails support.</p>
-
-<p>I had the pleasure of working with Matt around September last year and ended up visiting him in San Francisco. We went to <a href='http://www.yelp.com/biz/antonios-nut-house-palo-alto'>Antonio&#39;s Nut House</a> where we drank and played darts (and ate way too many free peanuts). Then we went back to his apartment where I got to sleep on an air mattress. That morning we went for bagels at a place not too far away from the Nut House. Those are my favourite memories of San Francisco.</p>
-
-<p>He was such an amazing guy and will be terribly missed.</p>
-]]></content>
- </entry>
-
</feed>
@@ -29,6 +29,8 @@ <h1 align='center'>The Life of a Radar</h1>
<p>The formatting for earlier posts may be a little skewiff. If you find something like that, <a href='http://github.com/radar/ryanbigg.com'>patches are very welcome</a>.</p>
<ul>
+ <li><a href="/2013/08/bundler-local-paths">Bundler local paths</a><abbr>16 Aug 2013</abbr></li>
+
<li><a href="/2013/07/waiting-for-ajax-in-capybara">Waiting for AJAX in Capybara</a><abbr>09 Jul 2013</abbr></li>
<li><a href="/2013/06/finding-sql-queries-in-rails">Finding SQL queries in Rails</a><abbr>26 Jun 2013</abbr></li>
View
@@ -30,36 +30,34 @@ <h1 align='center'>The Life of a Radar</h1>
http://litanyagainstfear.com -->
<div id='page'>
<article>
- <a href="/2013/07/waiting-for-ajax-in-capybara"><header>Waiting for AJAX in Capybara</header></a>
- <small>09 Jul 2013</small><br>
- <p>In Spree recently, we&#39;ve been using more and more of <a href="http://guides.spreecommerce.com/api">Spree&#39;s API</a> for the Backend component. This means that we&#39;ve introduced more AJAX-powered features into the backend, which has lead to some interesting test failures.</p>
-
-<p>Some of these test failures are that the tests just aren&#39;t waiting long enough for an AJAX request to complete before checking for content on the page. Others are more ... bewildering:</p>
-<div class="highlight"><pre><code class="text language-text" data-lang="text">F
-An error occurred in an after hook
- ActiveRecord::StatementInvalid:
- SQLite3::BusyException:
- database is locked: DELETE FROM &quot;spree_activators&quot;;
- occurred at ...lib/sqlite3/statement.rb:108:in `step&#39;
+ <a href="/2013/08/bundler-local-paths"><header>Bundler local paths</header></a>
+ <small>16 Aug 2013</small><br>
+ <p>There&#39;s a little known feature of Bundler that allows you to use a local Git
+repository while developing locally, and a remote Git repo when deploying. This
+feature means that you no longer have to <em>constantly</em> switch between local paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :path =&gt; &quot;~/Projects/gems/spree&quot;
+</code></pre></div>
+<p>And remote paths:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
</code></pre></div>
-<p>This error happens when an AJAX request is still being processed by the server, but the test finishes and Database Cleaner attempts to wipe the database. The server has locked the database until it&#39;s done what it needs to do, and during that lock Database Cleaner attempts to wipe all the data and can&#39;t.</p>
+<p>How does it work?</p>
-<p>To fix this, we just needed to wait for all AJAX requests to complete. This means replacing <code>sleep</code> with magic numbers, like this:</p>
-<div class="highlight"><pre><code class="text language-text" data-lang="text">sleep(2)
+<hr>
+
+<p>Well, what you can do instead is tell Bundler that you have a local copy of
+this repository by running a command like this in your terminal:</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">bundle config local.spree ~/Projects/gems/spree
</code></pre></div>
-<p>With this method:</p>
-<div class="highlight"><pre><code class="text language-text" data-lang="text">def wait_for_ajax
- counter = 0
- while page.execute_script(&quot;return $.active&quot;).to_i &gt; 0
- counter += 1
- sleep(0.1)
- raise &quot;AJAX request took longer than 5 seconds.&quot; if counter &gt;= 50
- end
-end
+<p>Then in your Gemfile whenever you reference a Git repo for this gem, like this...</p>
+<div class="highlight"><pre><code class="text language-text" data-lang="text">gem &#39;spree&#39;, :github =&gt; &#39;spree/spree&#39;, :branch =&gt; &#39;master&#39;
</code></pre></div>
-<p>This code will call <code>$.active</code> which is jQuery-code for &quot;how many <code>$.ajax</code> requests are still active?&quot;, and if that returns more than 0, then it will sleep for a moment, and check again. This code gives AJAX requests 5 seconds to wrap up before raising an exception and moving on.</p>
+<p>Bundler will use the local copy. When you deploy this application to your server, because the server is not configured to use a local copy of the repo, it will use the proper repo from GitHub.</p>
+
+<p>For more information, check out the <a href="http://bundler.io/v1.3/git.html">Bundler documentation page</a>, under &quot;Local Git Repos&quot;.</p>
-<p>Use this <code>wait_for_ajax</code> method when you need to wait for AJAX requests to finish in your tests to prevent weird, unpredictable JavaScript errors.</p>
+<hr>
+
+<p>Thanks to Phil Arndt who first showed me this trick many moons ago.</p>
</article>
</div>
@@ -68,6 +66,8 @@ <h1 align='center'>The Life of a Radar</h1>
<h2>25 back</h2>
<ul>
+ <li><a href="/2013/07/waiting-for-ajax-in-capybara">Waiting for AJAX in Capybara</a><abbr>09 Jul 2013</abbr></li>
+
<li><a href="/2013/06/finding-sql-queries-in-rails">Finding SQL queries in Rails</a><abbr>26 Jun 2013</abbr></li>
<li><a href="/2013/02/about-spec-support">About spec/support</a><abbr>02 Feb 2013</abbr></li>
@@ -116,8 +116,6 @@ <h1 align='center'>The Life of a Radar</h1>
<li><a href="/2011/11/going-on-a-spree">Going on a Spree</a><abbr>03 Nov 2011</abbr></li>
- <li><a href="/2011/10/screencast-pilot">Screencast: Pilot</a><abbr>31 Oct 2011</abbr></li>
-
</ul>
<center><a href='/blogography.html'>The Complete Blogography</a></center>
</div>

0 comments on commit b53209b

Please sign in to comment.