Skip to content

Instantly share code, notes, and snippets.

View descentintomael's full-sized avatar

Sean Todd descentintomael

View GitHub Profile
@descentintomael
descentintomael / log_test_helpers.rb
Created June 10, 2016 16:33
Some test helpers to make sure something is or isn't logged
module LogTestHelpers
def exclude_from_logs(*hits, &block)
exclude_from_other_logs(test_log_path, *hits, &block)
end
alias :expect_logs_to_not_include :exclude_from_logs
def exclude_from_other_logs(log_path=test_log_path, *hits, &block)
lines_to_scan = scan_logs log_path, &block
regex = Regexp.union *hits
@descentintomael
descentintomael / spec_error_raiser.rb
Created June 10, 2016 16:26
Simple method for raising custom errors in tests to test error handling
def new_error(message = 'oops', klass = RuntimeError)
raise klass, message
rescue
return $!
end
@descentintomael
descentintomael / keybase.md
Created January 27, 2015 22:12
keybase.md

Keybase proof

I hereby claim:

  • I am descentintomael on github.
  • I am sean_todd (https://keybase.io/sean_todd) on keybase.
  • I have a public key whose fingerprint is B512 CAA8 B053 DFFB B789 C81F A8D9 F6D6 BA96 61D1

To claim this, I am signing this object:

class A
def a
1
end
def b
def a
3
end
@descentintomael
descentintomael / date_scopes.rb
Created March 12, 2014 22:46
This adds in a set of date related scopes for any timestamp column. Date type columns aren't yet supported.
module DateScopes
extend ActiveSupport::Concern
module ClassMethods
def include_date_scopes
include_date_scopes_for :created_at
end
def include_date_scopes_for(column, prepend_name = false)
return unless self.table_exists?
@descentintomael
descentintomael / security_helper.rb
Last active December 21, 2015 04:08
A shared example for testing blacklists in controller security.
class SecurityHelper
def self.action_names(controller, opts = {})
actions = controller.class.public_instance_methods(false).reject{|a| a.to_s.starts_with? '_'}
actions - Array(opts[:except])
end
def self.create_insecure_user(opts = {})
roles = User.available_roles - Array(opts[:allowed_roles]).map(&:to_s)
FactoryGirl.create :user, roles: roles
end
@descentintomael
descentintomael / gist:6246800
Created August 16, 2013 02:40
What to add to your environment.rb to make rails server start in another time.
days = ENV['TIMECOP_DAYS'].nil? ? 0 : ENV['TIMECOP_DAYS'].to_i
minutes = ENV['TIMECOP_MINUTES'].nil? ? 0 : ENV['TIMECOP_MINUTES'].to_i
Timecop.travel Time.now + days.days
Timecop.travel Time.now + minutes.minutes