<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Antonio J.</title>
    <description>The latest articles on DEV Community by Antonio J. (@anjosebar).</description>
    <link>https://dev.to/anjosebar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F217883%2Fa282371a-c87d-4073-a2f3-1cad793ffa1f.jpg</url>
      <title>DEV Community: Antonio J.</title>
      <link>https://dev.to/anjosebar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anjosebar"/>
    <language>en</language>
    <item>
      <title>Started with Unity 2D Game Dev</title>
      <dc:creator>Antonio J.</dc:creator>
      <pubDate>Sun, 12 Apr 2020 18:44:02 +0000</pubDate>
      <link>https://dev.to/anjosebar/started-with-unity-2d-game-dev-9lp</link>
      <guid>https://dev.to/anjosebar/started-with-unity-2d-game-dev-9lp</guid>
      <description>&lt;p&gt;This week I started learning the basics for Unity 2D Game Development. When I was in college I learned with a few Unity courses and created a &lt;a href="https://learn.unity.com/tutorial/extending-space-shooter#"&gt;3D Space shooter&lt;/a&gt;.🚀&lt;/p&gt;

&lt;p&gt;I studied Java in college so C# wasn't that hard to use. I love videogames since childhood, I'm a Nintendo fan and I was completely amazed by how physics and programming have control over characters, enemies, animations and many more. Due to this worldwide crisis &lt;a href="https://learn.unity.com/"&gt;Unity Learn Premium&lt;/a&gt; is free for three months, the perfect moment to brush up the Unity3D knowledge. &lt;br&gt;
I'm following different Unity Learn courses and projects, also I'm doing the &lt;a href="https://www.domestika.org/es/courses/716-introduccion-a-unity-para-videojuegos-2d"&gt;Domestika's course&lt;/a&gt; for 2D Games.👾&lt;/p&gt;

&lt;p&gt;If you have any content recommendations to learn more about unity and games, I'm looking forward to completing these courses and keep posting my learnings. 💭&lt;/p&gt;

&lt;p&gt;Links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.unity.com/tutorial/extending-space-shooter#"&gt;3D Space shooter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.unity.com/"&gt;Unity Learn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.domestika.org/es/courses/716-introduccion-a-unity-para-videojuegos-2d"&gt;Domestika - Introducción a Unity para videojuegos 2D&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>unity3d</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>GatsbyJS with Netlify CMS</title>
      <dc:creator>Antonio J.</dc:creator>
      <pubDate>Sun, 12 Apr 2020 18:43:40 +0000</pubDate>
      <link>https://dev.to/anjosebar/gatsbyjs-with-netlify-cms-2eei</link>
      <guid>https://dev.to/anjosebar/gatsbyjs-with-netlify-cms-2eei</guid>
      <description>&lt;p&gt;GatsbyJS is a powerful framework based on React; combined with Netlify CMS and Bulma CSS you can create fast apps with zero server configuration. 🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  Personal Web
&lt;/h3&gt;

&lt;p&gt;About two weeks ago I created a personal website for my girlfriend &lt;a href="https://sarahstand.me/"&gt;Sarah Stand&lt;/a&gt;, just for fun and practice. It was easy to get the app up and running with the &lt;a href="https://github.com/netlify-templates/gatsby-starter-netlify-cms"&gt;Netlify CMS Starter&lt;/a&gt;, cloned to my GitHub account and deployed with Netlify in less than a minute. Building the UI was easy with Bulma CSS because it comes with many common components like sidebar, hero, sections, bottom navigation bar. At this moment she's able to edit the content (text and images) all within Netlify CMS's page editor, that'll trigger a commit and push into the GitHub repository updating the markdown files required to load the react components. Where the magic happens ✨ &lt;/p&gt;

&lt;h3&gt;
  
  
  Landing page
&lt;/h3&gt;

&lt;p&gt;Another day I worked on a &lt;a href="https://tender-stonebraker-6d8b69.netlify.com/"&gt;landing page&lt;/a&gt; for my &lt;a href="https://merkabahbs.com"&gt;startup&lt;/a&gt;. The CTA was to have the user submit the form, so I decided to give it a try to Gatsby with the previous starter template. The Netlify's built-in form handling is an awesome feature, it detected the &lt;code&gt;form&lt;/code&gt; tag in the website and you can start receiving submissions in no time, zero server configurations. Additionally, I could configure an email and slack message notifications with a few clicks! 👌&lt;/p&gt;

&lt;p&gt;It was an enjoyable experience to develop with all of these tools. I'm thinking about new features to work on it, probably I'll test out the blog that cames with NetlifyCMS. Let me know any suggestion you have and I'll take it into account for upcoming websites 💭&lt;/p&gt;

&lt;p&gt;Links&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.org"&gt;GatsbyJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bulma.io/"&gt;Bulma CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.netlify.com"&gt;Netlify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.netlifycms.org/"&gt;Netlify CMS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sarahstand.me/"&gt;Sarah Stand&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tender-stonebraker-6d8b69.netlify.com/"&gt;Merkabah Workshop&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>gatsby</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Rails active jobs &amp; Tests</title>
      <dc:creator>Antonio J.</dc:creator>
      <pubDate>Sun, 12 Apr 2020 18:43:15 +0000</pubDate>
      <link>https://dev.to/anjosebar/rails-active-jobs-tests-1ch3</link>
      <guid>https://dev.to/anjosebar/rails-active-jobs-tests-1ch3</guid>
      <description>&lt;p&gt;This week I worked with background jobs for Rails. It is useful to use &lt;a href="https://edgeguides.rubyonrails.org/active_job_basics.html"&gt;Active Job&lt;/a&gt; when you're working with API Rest because your app needs to respond ASAP to your client's devices, i.e. web browsers, mobile apps or CLI apps in order to get a better UX. 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  Active Job
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Active Job is a framework for declaring jobs and making them run on a variety of queuing backends. These jobs can be everything from regularly scheduled clean-ups, to billing charges, to mailings. Anything that can be chopped up into small units of work and run in parallel, really.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's suppose you have to update your user's information with some information from another service.&lt;/p&gt;

&lt;p&gt;To create a job run the command&lt;br&gt;
&lt;code&gt;rails g job update_user&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Rails will create a file called &lt;code&gt;update_user_job.rb&lt;/code&gt; in your &lt;code&gt;app/jobs&lt;/code&gt; folder. You can edit the file and run your needed application logic inside the &lt;code&gt;perform&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app/jobs/update_user_job.rb&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UpdateUserJob&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationJob&lt;/span&gt;
  &lt;span class="n"&gt;queue_as&lt;/span&gt; &lt;span class="ss"&gt;:default&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;perform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# let's imagine you're getting external information for your user&lt;/span&gt;
    &lt;span class="n"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_some_external_metadata&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;metadata: &lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you need to call your job's &lt;code&gt;perform_later&lt;/code&gt; method whenever you want to execute your job&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app/models/user.rb&lt;/span&gt;
  &lt;span class="n"&gt;after_create&lt;/span&gt; &lt;span class="ss"&gt;:update_metadata&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update_metadata&lt;/span&gt;
    &lt;span class="no"&gt;UpdateUserJob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perform_later&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Let's take a look at how to test this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test your background job
&lt;/h3&gt;

&lt;p&gt;It gets more complicated to test your background jobs because your tests will call the methods but your user fields won't be updated. Your user is being updated in the background! Thanks to &lt;a href="https://edgeapi.rubyonrails.org/classes/ActiveJob/TestHelper.html"&gt;Active Job Test Helper&lt;/a&gt; we can use some methods to test whether our jobs are being enqueued and updating our users, i.e:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;assert_enqueued_with&lt;/code&gt; &lt;em&gt;Asserts that the job has been enqueued with the given arguments.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assert_performed_jobs&lt;/code&gt; &lt;em&gt;Asserts that the number of performed jobs matches the given number.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;perform_enqueued_jobs&lt;/code&gt; &lt;em&gt;Performs all enqueued jobs.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt; &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="s2"&gt;"update user metadata when created"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:one&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;assert_enqueued_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;job: &lt;/span&gt;&lt;span class="no"&gt;UpdateUserJob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;args: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;perform_enqueued_jobs&lt;/span&gt;
    &lt;span class="n"&gt;assert_performed_jobs&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Rspec
&lt;/h4&gt;

&lt;p&gt;If you're using &lt;code&gt;rspec-rails&lt;/code&gt; gem, you have &lt;a href="https://relishapp.com/rspec/rspec-rails/v/3-5/docs/job-specs/job-spec"&gt;helpers&lt;/a&gt; as an alternative to help you test your background jobs. Your tests must set the queue adapter as :test &lt;code&gt;ActiveJob::Base.queue_adapter = :test&lt;/code&gt; and you'll be able to use methods like &lt;code&gt;enqueue_job&lt;/code&gt; and &lt;code&gt;have_been_enqueued&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://edgeguides.rubyonrails.org/active_job_basics.html"&gt;Active Job&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://relishapp.com/rspec/rspec-rails/v/3-5/docs/job-specs/job-spec"&gt;Rspec Jobs Helper&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://edgeapi.rubyonrails.org/classes/ActiveJob/TestHelper.html"&gt;Test Helper&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>webdev</category>
      <category>testing</category>
    </item>
    <item>
      <title>This week in Rails</title>
      <dc:creator>Antonio J.</dc:creator>
      <pubDate>Sun, 29 Mar 2020 00:58:38 +0000</pubDate>
      <link>https://dev.to/anjosebar/this-week-in-rails-2ln2</link>
      <guid>https://dev.to/anjosebar/this-week-in-rails-2ln2</guid>
      <description>&lt;p&gt;This week I've made use of different ruby tools that help me make my tests, controllers and business application clean and DRY. I will show you a bit of what you can do with custom contexts for active record validations, service objects and custom exceptions to reduce your controller's methods &lt;a href="https://www.rubydoc.info/gems/rubocop/0.27.0/RuboCop/Cop/Metrics/AbcSize"&gt;AbcSize&lt;/a&gt; and use RSpec shared example groups to keep your tests code DRY.&lt;/p&gt;

&lt;h2&gt;
  
  
  Active Record Validations
&lt;/h2&gt;

&lt;p&gt;We can specify when the validation should happen with the &lt;code&gt;:on&lt;/code&gt; option. With custom context those validations are triggered explicitly by passing the contexts name to &lt;code&gt;valid?&lt;/code&gt; or &lt;code&gt;save&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;#app/models/person.rb&lt;/span&gt;
&lt;span class="n"&gt;validates&lt;/span&gt; &lt;span class="ss"&gt;:age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;presence: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;on: :submit&lt;/span&gt;

&lt;span class="c1"&gt;#app/somewhere_else.rb&lt;/span&gt;
&lt;span class="no"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valid?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:submit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="no"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;context: :submit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://guides.rubyonrails.org/active_record_validations.html#on"&gt;More info.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Service Objects
&lt;/h2&gt;

&lt;p&gt;Service objects are helpful to extract your business logic from your controllers. They must perform one action, e.g under &lt;code&gt;app/services/app_manager&lt;/code&gt; folder you can group your needed actions per file as &lt;code&gt;app_creator.rb&lt;/code&gt; or &lt;code&gt;app_submitter.rb&lt;/code&gt;. Then, you can use those classes in your controllers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;AppManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;AppCreator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;AppManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;AppSubmitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'submit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I recommend reading this ebook &lt;a href="https://rails-refactoring.com/"&gt;Fearless Refactoring.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;shared_example_group&lt;/code&gt; RSpec feature lets you group specifics behaviors that are repeated in your tests. This was useful to test API's responses with &lt;code&gt;it_behaves_like 'a success response'&lt;/code&gt; within many API controllers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://relishapp.com/rspec/rspec-core/v/2-0/docs/example-groups/shared-example-group"&gt;More info.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Exceptions
&lt;/h2&gt;

&lt;p&gt;You can create and raise your custom exceptions to reduce if's and else's cases in your app business logic. Instead of dealing with &lt;code&gt;nil&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; values returned from your methods, you can raise your custom exceptions to keep your code clean and maintainable.&lt;br&gt;
So you can transform your code from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;can_book_from?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;trip_reservations_page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;notice: &lt;/span&gt;&lt;span class="s2"&gt;"You're not allowed to book from this agency."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;trip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has_free_tickets?&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;trip_reservations_page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;notice: &lt;/span&gt;&lt;span class="s2"&gt;"No free tickets available"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;reservation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;
  &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt; &lt;span class="s2"&gt;"Failed to save reservation: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;reservation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inspect&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;trip_reservations_page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;notice: &lt;/span&gt;&lt;span class="s2"&gt;"Reservation error."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
  &lt;span class="no"&gt;TripReservationService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:trip_reservation&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="no"&gt;TripReservationService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;NotAllowedToBook&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;trip_reservations_page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;notice: &lt;/span&gt;&lt;span class="s2"&gt;"You're not allowed to book from this agency."&lt;/span&gt;
&lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="no"&gt;TripReservationService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;NoTicketsAvailable&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;trip_reservations_page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;notice: &lt;/span&gt;&lt;span class="s2"&gt;"No free tickets available."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I recommend reading this ebook &lt;a href="https://honeybadger.leadpages.co/exceptions/"&gt;Mastering Ruby Exceptions by Honey Badger&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.rubydoc.info/gems/rubocop/0.27.0/RuboCop/Cop/Metrics/AbcSize"&gt;Rubocop AbcSize Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guides.rubyonrails.org/active_record_validations.html#on"&gt;Active Record Validations Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rails-refactoring.com/"&gt;Fearless Refactoring Ebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://relishapp.com/rspec/rspec-core/v/2-0/docs/example-groups/shared-example-group"&gt;Rspec Docs shared example groups&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://honeybadger.leadpages.co/exceptions/"&gt;Mastering Ruby Exceptions by Honey Badger&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ruby</category>
      <category>testing</category>
      <category>exceptions</category>
      <category>rails</category>
    </item>
  </channel>
</rss>
