Carson's (🚗☀☔🔑) Blog

Oct 13

Aug 27

Mocking SMTP in Unit Tests

I’m sure there are other better ways to do this, but I just wanted to try doing something real quick using MailCatcher.

Instead of just starting a process up, I added the following to the test_helper.rb

mailcatcher_process_id = Kernel.fork do
  require 'mail_catcher'!(:daemon => false)
$stderr.puts('Unable to fork mailcatcher') if mailcatcher_process_id.nil?()
Kernel.at_exit do
  unless mailcatcher_process_id.nil?()
    Process.kill('TERM', mailcatcher_process_id) rescue nil
    Process.kill('SIGTERM', mailcatcher_process_id) rescue nil

Jun 27

Jun 9

Jun 6

May 2

Liquid::Drop method with arguments

Kind of a hack, but possible using a new stack and a variable named “args” from a filter method:

@context.stack({'args' => args}) do
    #Call to drop method


Apr 30

Apr 29

ActiveModel::Serialization#serializable_hash Excluding Nested Attributes

For some reason, the documentation does not go into the options available for ActiveModel::Serialization#serializable_hash. Primarily, how nested attributes can be excluded via the :include option. Each nested attributes can provide a hash of options for that object. For example, if Person has an association of projects, person.serializable_hash({:include => {:projects => {:except => [:id]}}) will exclude the id attribute of from projects. These options apply to all the Rails methods that render via serializers (e.g. respond_with, render).

Apr 18

Page 1 of 8