Cleaning up unmanaged files in boxen / puppet

Nginx and env files .. maybe others … get a mess after a while of trying different branch, since they are never auto-cleaned up. Already made this into a PR, but nobody seems to care … so fix it via overwrites.

Add an empty directory as modules/ours/files/emptydir + .gitkeep (pick whatever you want for ‘ours’).

  # remove any unmanaged configs
  # https://github.com/boxen/puppet-nginx/pull/34
  File <| title == $nginx::config::configdir |> {
    purge => true,
    force => true,
    source => "puppet:///modules/ours/emptydir",
    recurse => "true",
  }

  File <| title == $nginx::config::sitesdir |> {
    purge => true,
    force => true,
    source => "puppet:///modules/ours/emptydir",
    recurse => "true",
  }

  File <| title == $boxen::config::envdir |> {
    purge => true,
    force => true,
    source => "puppet:///modules/ours/emptydir",
    recurse => "true",
  }

Stop rails from swallowing after_commit exceptions

Problem
By default rails just swallows any exception raised in after_commit blocks.

Solution
Send these exceptions to and exception service to get notified (Airbrake / Rollbar etc).

Gem
https://github.com/grosser/after_commit_exception_notification

Copy-paste

module Foo
  module CommittedWithExceptions
    def committed!
      super
    rescue Exception => e # same as active_record/connection_adapters/abstract/database_statements.rb:370
      ExceptionService.report("after_commit exception", e)
      raise
    end
  end
end

ActiveRecord::Base.include Foo::CommittedWithExceptions

Testing multiple Gemfiles and Rubies with WWTD (no Appraisal)

Problem
Testing against many gemfiles/rubies is painful, Appraisal offers a somewhat working solution but adds new steps/problems.

Solution
Use WWTD by using the gemspec for dependencies (optional for git: or a gemfiles/common.rb)
(Also no longer runs gemfiles that are excluded in travis.yml)

Example PR

Usage

  • Run tests on all gemfiles: rake
  • Run tests on all gemfiles and all rubies: rake wwtd
  • Run tests on Gemfile: rake test

Code

# Gemfile
source &amp;quot;https://rubygems.org&amp;quot;
gemspec
gem &amp;quot;rails&amp;quot; # newest

# Rakefile
require 'wwtd/tasks'
task default: &amp;quot;wwtd:local&amp;quot;

# gemfiles/rails32.gemfile
source &amp;quot;https://rubygems.org&amp;quot;
gemspec path: &amp;quot;../&amp;quot;
gem &amp;quot;rails&amp;quot;, &amp;quot;~&amp;gt; 3.2.18&amp;quot;

# gemfiles/rails40.gemfile
source &amp;quot;https://rubygems.org&amp;quot;
gemspec path: &amp;quot;../&amp;quot;
gem &amp;quot;rails&amp;quot;, &amp;quot;~&amp;gt; 4.0.6&amp;quot;

# foo.gemspec
...
s.add_runtime_dependency &amp;quot;rails&amp;quot;, &amp;quot;&amp;gt;= 3.2.18&amp;quot;

# .travis.yml
rvm:
  - 1.9.3
  - 2.0.0
  - 2.1.2
gemfile:
  - gemfiles/rails32.gemfile
  - gemfiles/rails40.gemfile
script: &amp;quot;rake test&amp;quot;

Git dependencies
Cannot be specified in gemspec, so we put them in a loadable file.

# all gemfiles
eval(File.read('gemfiles/common.rb'))

# gemfiles/common.rb
gem &amp;quot;foo&amp;quot;, git: &amp;quot;https://github.com/bar/foo&amp;quot;