<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>rails upgrade on random thoughts</title><link>https://awesomeprogrammer.com/categories/rails-upgrade/</link><description>Recent content in rails upgrade on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 03 Sep 2014 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/rails-upgrade/index.xml" rel="self" type="application/rss+xml"/><item><title>Rails 3.2 to Rails 4.1 upgrade</title><link>https://awesomeprogrammer.com/blog/2014/09/03/rails-3-dot-2-to-rails-4-dot-1-upgrade/</link><pubDate>Wed, 03 Sep 2014 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2014/09/03/rails-3-dot-2-to-rails-4-dot-1-upgrade/</guid><description><![CDATA[<p>Let&rsquo;s talk about pretty tedious task - upgrading rails, of course it can be interesting experience, but if you have relatively large application to upgrade it can be cumbersome, here are my thoughts after doing through process of switching Rails 3.2 to Rails 4.1.</p>
<ul>
<li>
<p>the basic thing - test suite. Few integration specs are better than none, obviously. Make sure it&rsquo;s nice &amp; green before even starting the process</p>
</li>
<li>
<p><a href="http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html">rails upgrade guide</a> will give you some tips &amp; hints about what changes, what may brake etc. Must read.</p>
</li>
<li>
<p>if you&rsquo;re using observers you will need to include <code>rails-observers</code> gem and if you&rsquo;re not ready to implement strong attributes - go with <code>protected_attributes</code></p>
</li>
<li>
<p>Dependencies. I&rsquo;m guessing you are not running vanilla rails application, but you rather packed your Gemfile with some open source goodies. That&rsquo;s cool, but keep in mind that most of the gems will probably need upgrading as well. <code>bundle outdated</code> command will help you track down what gems needs upgrading. I recommend checking out Changelog/History in gem&rsquo;s repository (if provided) - sometimes you will need to take some additional steps during the upgrade process, but fortunately most of the popular gems are pretty well documented.</p>
</li>
<li>
<p>if you are using rspec, there is a big chance that your test suite still uses old <code>should</code> syntax. There is a really cool tool called <a href="https://github.com/yujinakayama/transpec">Transpec</a> that will help you automatically upgrade your whole test suite (even from rspec2 to rspec3)</p>
</li>
<li>
<p>some more complex SQL queries (joins with custom select etc.) won&rsquo;t allow you to do <code>count</code> - to reproduce old (Rails 3) behavior you have to call it with <code>:all</code> argument - <code>count(:all)</code></p>
</li>
<li>
<p>watch our if you&rsquo;re using <code>EXIST</code> query - I noticed that rails 4 returns boolean, where in 3.2 you got &rsquo;t&rsquo; / &lsquo;f&rsquo; string (postgresql)</p>
</li>
<li>
<p>using cancan? Cool - but check out it&rsquo;s successor called <a href="https://github.com/CanCanCommunity/cancancan">cancancan</a> - it&rsquo;s very actively maintained by open source community</p>
</li>
<li>
<p>Rails 4 comes with <a href="http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html">default headers</a> that will block running your app from iframe - if you would like to disable this behavior put this in your application config:</p>
</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>config<span style="color:#f92672">.</span>action_dispatch<span style="color:#f92672">.</span>default_headers <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># documentation specifies ALLOWALL, but empty string</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># should work across all common browsers</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;X-Frame-Options&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;&#39;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The list goes on, but every app is different, so I will stop here and wish you best luck with your upgrade process ;-). Let the 200 response status be with you, always.</p>]]></description><content:encoded><![CDATA[<p>Let&rsquo;s talk about pretty tedious task - upgrading rails, of course it can be interesting experience, but if you have relatively large application to upgrade it can be cumbersome, here are my thoughts after doing through process of switching Rails 3.2 to Rails 4.1.</p>
<ul>
<li>
<p>the basic thing - test suite. Few integration specs are better than none, obviously. Make sure it&rsquo;s nice &amp; green before even starting the process</p>
</li>
<li>
<p><a href="http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html">rails upgrade guide</a> will give you some tips &amp; hints about what changes, what may brake etc. Must read.</p>
</li>
<li>
<p>if you&rsquo;re using observers you will need to include <code>rails-observers</code> gem and if you&rsquo;re not ready to implement strong attributes - go with <code>protected_attributes</code></p>
</li>
<li>
<p>Dependencies. I&rsquo;m guessing you are not running vanilla rails application, but you rather packed your Gemfile with some open source goodies. That&rsquo;s cool, but keep in mind that most of the gems will probably need upgrading as well. <code>bundle outdated</code> command will help you track down what gems needs upgrading. I recommend checking out Changelog/History in gem&rsquo;s repository (if provided) - sometimes you will need to take some additional steps during the upgrade process, but fortunately most of the popular gems are pretty well documented.</p>
</li>
<li>
<p>if you are using rspec, there is a big chance that your test suite still uses old <code>should</code> syntax. There is a really cool tool called <a href="https://github.com/yujinakayama/transpec">Transpec</a> that will help you automatically upgrade your whole test suite (even from rspec2 to rspec3)</p>
</li>
<li>
<p>some more complex SQL queries (joins with custom select etc.) won&rsquo;t allow you to do <code>count</code> - to reproduce old (Rails 3) behavior you have to call it with <code>:all</code> argument - <code>count(:all)</code></p>
</li>
<li>
<p>watch our if you&rsquo;re using <code>EXIST</code> query - I noticed that rails 4 returns boolean, where in 3.2 you got &rsquo;t&rsquo; / &lsquo;f&rsquo; string (postgresql)</p>
</li>
<li>
<p>using cancan? Cool - but check out it&rsquo;s successor called <a href="https://github.com/CanCanCommunity/cancancan">cancancan</a> - it&rsquo;s very actively maintained by open source community</p>
</li>
<li>
<p>Rails 4 comes with <a href="http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html">default headers</a> that will block running your app from iframe - if you would like to disable this behavior put this in your application config:</p>
</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>config<span style="color:#f92672">.</span>action_dispatch<span style="color:#f92672">.</span>default_headers <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># documentation specifies ALLOWALL, but empty string</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># should work across all common browsers</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#39;X-Frame-Options&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;&#39;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The list goes on, but every app is different, so I will stop here and wish you best luck with your upgrade process ;-). Let the 200 response status be with you, always.</p>]]></content:encoded></item></channel></rss>