Skip to content

Instantly share code, notes, and snippets.

View mockdeep's full-sized avatar

Robert Fletcher mockdeep

View GitHub Profile
@mockdeep
mockdeep / spec_helper.rb
Last active October 7, 2019 07:19
A spec helper file for managing database cleaner configuration
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.treat_symbols_as_metadata_keys_with_true_values = true
@mockdeep
mockdeep / bulk_updateable.rb
Created October 29, 2015 17:13
module to add ActiveRecord bulk update functionality for postgres
module BulkUpdatable
def bulk_update(objects, attribute)
return unless objects.any?
query = build_query_for(objects, attribute)
connection.execute(query)
end
private
require 'active_support/all'
class JsFile
attr_accessor :path, :file_contents
def initialize(path)
@path = path
@file_contents = File.read(@path)
end
@mockdeep
mockdeep / exampes.rb
Last active January 4, 2016 20:49
List rspec example groups
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = 'test'
require_relative '../config/environment'
class Speccer
def configuration
@configuration ||= RSpec::Core::Configuration.new
end
@mockdeep
mockdeep / trashable.rb
Last active December 28, 2015 22:49
module to make accidentally deleting records really hard
module Trashable
module ClassMethods
def dependent_associations
reflect_on_all_associations.select do |association|
[:destroy, :delete_all].include?(association.options[:dependent])
end
end
@mockdeep
mockdeep / mutagen.rb
Created October 19, 2013 03:13
Script to convert spec files to mutation testing format
require 'active_support/inflector'
inflectors_path = File.expand_path('./config/initializers/inflections.rb')
load inflectors_path if File.exist?(inflectors_path)
class Mutagen
def initialize(path)
file_match_expression = File.join(File.expand_path(path), '**/*.rb')
@source_files = Dir.glob(file_match_expression).map do |file_path|
SourceFile.new(file_path, path)
end
@mockdeep
mockdeep / mutant.rake
Created October 16, 2013 20:35
mutant rake script
# encoding: utf-8
# Eager load application and dependencies
require File.expand_path('../../../config/environment', __FILE__)
Rails.application.eager_load!
# All classes to mutate
classes = ActiveSupport::Dependencies.autoloaded_constants.
map(&:constantize).grep(Class).map(&:name)
@mockdeep
mockdeep / build-lp_solve.sh
Last active December 25, 2015 03:49
build script for lp_solve
#!/bin/sh
set -e
# capture root dir
root=$(pwd)
echo "cache url: $CACHE_URL"
mv lp_solve_5.5 /tmp/
cd /tmp/lp_solve_5.5/lp_solve/
Benchmark.bm do|b|
b.report("exclusion join ") do
a = ""
10_000.times do
Element.find_by_sql(
<<-SQL
select e.* from elements e
left outer join elements leafs
on e.id = leafs.parent_id
where leafs.parent_id is null
@mockdeep
mockdeep / setup.sh
Created July 20, 2012 19:11
ruby setup
# install some dependencies
sudo apt-get install -y vim eclipse git \
curl mysql-server zlib1g-dev coreutils libtool bison libxt-dev \
sqlite3 libsqlite3-dev libxml2-dev libreadline-dev \
libmagickwand-dev libmysqlclient-dev libmemcached-dbg \
postgresql postgresql-client libpq-dev libxslt1-dev nodejs \
libqt4-dev libqtwebkit-dev
# install rvm and ruby
curl -L get.rvm.io | bash -s stable