<?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>Forem: Malki Davis</title>
    <description>The latest articles on Forem by Malki Davis (@mxdavis).</description>
    <link>https://forem.com/mxdavis</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%2F315223%2F1a4dcf44-beba-4ab9-b55f-d8893e50eeb6.png</url>
      <title>Forem: Malki Davis</title>
      <link>https://forem.com/mxdavis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mxdavis"/>
    <language>en</language>
    <item>
      <title>Passings args into Rspec Shared Examples</title>
      <dc:creator>Malki Davis</dc:creator>
      <pubDate>Tue, 20 Apr 2021 22:07:03 +0000</pubDate>
      <link>https://forem.com/mxdavis/passings-args-into-rspec-shared-examples-5dab</link>
      <guid>https://forem.com/mxdavis/passings-args-into-rspec-shared-examples-5dab</guid>
      <description>&lt;p&gt;It is convenient to have shared examples for testing to DRY up our tests and tests models or controllers that share code. An example could be an extend or include in a model or a before action in a controller.&lt;/p&gt;

&lt;p&gt;Create your shared example in the support directory (make sure it auto loads by adding &lt;code&gt;Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }&lt;/code&gt; to your spec_helper)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RSpec.shared_examples 'good stuff' do
  it 'runs some tests' do
    expect(arg).to be_valid
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then pass in args as a block in your test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  it_behaves_like "good stuff" do
    let(:arg) { create(:something) }
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you've got yourself a bunch of green tests with little effort!&lt;/p&gt;

</description>
      <category>rspec</category>
      <category>testing</category>
      <category>rails</category>
    </item>
    <item>
      <title>Make remove column a reversible migration</title>
      <dc:creator>Malki Davis</dc:creator>
      <pubDate>Tue, 20 Apr 2021 09:05:17 +0000</pubDate>
      <link>https://forem.com/mxdavis/make-remove-column-a-reversible-migration-5f1k</link>
      <guid>https://forem.com/mxdavis/make-remove-column-a-reversible-migration-5f1k</guid>
      <description>&lt;p&gt;Today I learned in order to make a &lt;code&gt;remove_column&lt;/code&gt; migration reversible (which I need often when tinkering in development with the perfect database setup) we need to add the the type which is not required for migrating the database.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;remove_column :table, :column, :type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For just a few more characters, the investment definitely pays off in case of the need to reverse the migration (even if it's not only in development).&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>ruby</category>
      <category>rails</category>
      <category>activerecord</category>
    </item>
    <item>
      <title>Redirecting to an external URL within React Router</title>
      <dc:creator>Malki Davis</dc:creator>
      <pubDate>Tue, 18 Feb 2020 06:48:30 +0000</pubDate>
      <link>https://forem.com/mxdavis/redirecting-to-an-external-url-within-react-router-3nf1</link>
      <guid>https://forem.com/mxdavis/redirecting-to-an-external-url-within-react-router-3nf1</guid>
      <description>&lt;h2&gt;
  
  
  TIL: How to redirect to an external URL within react-router-dom
&lt;/h2&gt;

&lt;p&gt;At my current development position at &lt;a href="https://astrolabediagnostics.com"&gt;Astrolabe Diagnostics&lt;/a&gt;&lt;br&gt;
 I was tasked with a route loading a React component if the user was signed in, or redirecting to an external site. I wanted to do this from the route level instead of handling the redirect from the component.&lt;/p&gt;

&lt;p&gt;We simply need to render a function assigning the &lt;code&gt;window.location&lt;/code&gt; to the new site, and the user is redirected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;exact&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;exact&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://redirectsite.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>reactrouter</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
