<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Programming Problems Solving Log Book - Medium]]></title>
        <description><![CDATA[This is a log of the recent problems I solved. It is mostly about Ruby, Rails, Javascript and other computer related stuff. - Medium]]></description>
        <link>https://medium.com/programming-problem-solving-logbook?source=rss----1a451ea31b7---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Programming Problems Solving Log Book - Medium</title>
            <link>https://medium.com/programming-problem-solving-logbook?source=rss----1a451ea31b7---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:07:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/programming-problem-solving-logbook" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Work in progress solution for RSpec and VCR]]></title>
            <link>https://medium.com/programming-problem-solving-logbook/work-in-progress-solution-for-rspec-and-vcr-ce985b7e418d?source=rss----1a451ea31b7---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce985b7e418d</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Sat, 05 Dec 2015 22:28:21 GMT</pubDate>
            <atom:updated>2015-12-05T22:34:24.089Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wasted time on trying to understand why your tests don’t pass and should (or pass and should not) only to realize that VCR is using a cassette that you should have deleted?</p><p>Don’t get me wrong, VCR is very useful. It caused me a lot of problems and I thought many times of not using it anymore. Let’s be positive and call those frustrating problems “experience”.</p><p>One thing I did today to solve one particular problem is worth sharing with the world. I am working on a wrapper for a RESTful API and using Test-Driven-Development. However, to make actual external calls with VCR to make sure that my code is actually working, I have to put in my spec file something like that:</p><pre>before do <br>  WebMock.allow_net_connect! <br>  WebMock.disable! <br>  VCR.eject_cassette <br>  VCR.turn_off!(:ignore_cassettes =&gt; true)<br>end</pre><p>I was worried I would forget to remove that snippet before commiting my code or forget to run the tests once with VCR reactivated to records the cassettes before CI would run the test suite. It’s not a big deal, but enough to bother me.</p><p>Also, since that snippet is not commited and is nowhere in the codebase, I have to find it in my Gists and copy-paste it. Another minor annoyance that adds up.</p><p>I decided to improve that by using a `wip` tag. Easy to add and easy to remove. To make sure that I would not forget to remove it, it raises a warning at the end of the test suite if one is present.</p><p>First, I created the hook in spec_helper.rb:</p><pre>wip_count = 0<br>RSpec.configure do |config|<br>  config.around(:example, :wip) do |exampe|<br>    WebMock.allow_net_connect!<br>    VCR.turned_off(:ignore_cassettes =&gt; true) { exampe.run }<br>    WebMock.disable_net_connect!<br>    wip_count += 1<br>  end<br>end</pre><p>Then, with that `wip_count`, I can raise the warning:</p><pre>wip_count = 0<br>RSpec.configure do |config|<br>  config.around(:example, :wip) do |exampe|<br>    WebMock.allow_net_connect!<br>    VCR.turned_off(:ignore_cassettes =&gt; true) { exampe.run }<br>    WebMock.disable_net_connect!<br>    wip_count += 1<br>  end</pre><pre>  config.after(:suite) do<br>    warn &quot;\n\nWarning: don&#39;t forget to remove the &#39;wip&#39; tag before commiting your work&quot;.yellow unless wip_count.zero?<br>  end<br>end</pre><p>Now, in my spec files, I can use the tag to disable VCR on demand:</p><pre>describe &quot;#perform&quot; do<br> it &quot;makes a call to the API&quot;, :wip do<br>  # the test</pre><p>And when I run my tests, I get the results I expected!</p><pre>rspec ./spec/lib/API/request_spec.rb<br>...F.F...</pre><pre>Warning: don’t forget to remove the ‘wip’ tag before commiting your work</pre><pre>Failures:</pre><p>Bonus: I can also run only the examples with the `wip` tag!!</p><pre>rspec ./spec/lib/API/request_spec.rb --tag wip<br>Run options: include {:wip=&gt;true}</pre><pre>FF</pre><pre>Warning: don’t forget to remove the ‘wip’ tag before commiting your work</pre><pre>Failures:</pre><p>I hope you’ll find that tip useful and if you have any improvement suggestion, please, share them with me in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce985b7e418d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/programming-problem-solving-logbook/work-in-progress-solution-for-rspec-and-vcr-ce985b7e418d">Work in progress solution for RSpec and VCR</a> was originally published in <a href="https://medium.com/programming-problem-solving-logbook">Programming Problems Solving Log Book</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails multiple checkboxes]]></title>
            <link>https://medium.com/programming-problem-solving-logbook/rails-multiple-checkboxes-e9c4c7fda356?source=rss----1a451ea31b7---4</link>
            <guid isPermaLink="false">https://medium.com/p/e9c4c7fda356</guid>
            <dc:creator><![CDATA[Sophie Déziel]]></dc:creator>
            <pubDate>Thu, 16 Jul 2015 05:27:55 GMT</pubDate>
            <atom:updated>2019-05-03T23:04:39.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqbrYp0L2OT0VRroRpvg9Q.png" /></figure><p>Today, I had to create a form for business hours. It seems simple, but there is a lot to think about. Once the model logic completed, I faced a funny problem about multiple checkboxes used to populate an array of weekdays.</p><p>So, lets say you want a form with a certain number of options, you want to know which one the user checked, you want an array of it to pass into another method or object and you don’t care about the unchecked ones. There is a lot of reasons you wan’t to have a clean array:</p><ol><li>You don’t want the null, false or “0” values to pollute your database</li><li>You have validations to make on each of the values</li><li>Any other good reason to require an array containing only the values</li></ol><p>My first form attempt with the multiple option:</p><pre>// app/views/week_selections/_form.html.slim</pre><pre>= form_for @week_selection do |f|<br>  - days = [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wen&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]<br>  - days.each do |day|<br>    = f.check_box :days, { multiple: true }, day<br>    label day<br>  = f.submit</pre><p>In my controller, the params was a bit wrong:</p><pre># app/controllers/week_selections_controller.rb<br># I selected Mon and Tue</pre><pre>...</pre><pre>def form_params<br>  params.require(:week_selection).permit(days:[])<br>end</pre><pre>form_params # =&gt; { week_selection: { days: [&quot;0&quot;, &quot;Mon&quot;, &quot;0&quot;, &quot;Tue&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;] }</pre><blockquote>What happened?</blockquote><p>The checkbox helper has an option “unchecked_value” (<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box">doc</a>) and its default is “0”. If you set that option to false, you can get rid of all those unwanted values in your array!!</p><pre>// app/views/week_selections/_form.html.slim</pre><pre>= form_for @week_selection do |f|<br>  - days = [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wen&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]<br>  - days.each do |day|<br>    = f.check_box :days, { multiple: true }, day, false<br>    label day<br>  = f.submit</pre><p>See the beautifully clean array:</p><pre>form_params # =&gt; { week_selection: { days: [&quot;Mon&quot;, &quot;Tue&quot;] }</pre><pre># YAY! No need to clean the values in the controller!</pre><p>That simple option costed me too much time today. I wish I knew that before. But eh, I hope that this note will help everybody on the internet!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9c4c7fda356" width="1" height="1" alt=""><hr><p><a href="https://medium.com/programming-problem-solving-logbook/rails-multiple-checkboxes-e9c4c7fda356">Rails multiple checkboxes</a> was originally published in <a href="https://medium.com/programming-problem-solving-logbook">Programming Problems Solving Log Book</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>