Skip to content

Instantly share code, notes, and snippets.

@Roman2K
Roman2K / ll
Last active August 29, 2015 14:10
$ ll C\ à\ vous-112328272.mp4
-rw-r--r-- 1 roman staff 124M Nov 24 18:05 C à vous-112328272.mp4
describe TestMe do
describe '#initialize' do
subject { test_me.value }
context "default value" do
let(:test_me) { TestMe.new }
it { is_expected.to be_nil }
end
context "value passed as arg" do
@Roman2K
Roman2K / screenshot.png
Last active August 29, 2015 14:23
dotfiles
screenshot.png
#!/usr/bin/env ruby
# Sort entries by content size. Usage:
# sortbysize [<directory>='.']
#
# This script is documented at:
# http://roman.flucti.com/sorting-directories-by-content-size-with-ruby
#
class Entry < Struct.new(:size, :unit, :name)
@Roman2K
Roman2K / gist:16852
Created October 15, 2008 03:49
Test helper for painless record creation
# Test helper for painless record creation. Details at:
# http://roman.flucti.com/painless-record-creation-with-activerecord
#
def insert!(model, attributes={})
attributes = attributes.stringify_keys
begin
record = model.new(attributes)
def record.callback(*args)
# inhibit all callbacks
end
# Untested
module WithLogger
attr_writer :logger
def logger
@logger ||= Rails.logger
end
end
SomeClass.extend WithLogger
def nil_blank_count(object)
object.attributes.values.select(&:present?).size
end
class Post < ActiveRecord::Base
validates_length_of :title, :minimum => 4
def custom_method
title.scan(/./).join(' ').upcase
end
end
def insert!(model, attributes={})
attributes = attributes.stringify_keys
begin
record = model.new {|r| r.send(:attributes=, attributes, false) }
def record.callback(*args)
# inhibit all callbacks
end
record.save(false)
rescue ActiveRecord::StatementInvalid
if $!.message =~ /Column '(.+?)' cannot be null/
From 3014a599a158c7ef1332bf3dbc6ca25c015c618e Mon Sep 17 00:00:00 2001
From: Roman Le Negrate <roman.lenegrate@gmail.com>
Date: Mon, 22 Dec 2008 22:30:20 +0100
Subject: [PATCH] only include acts-like-git specific modules when versioning gets configured
---
lib/acts_like_git.rb | 7 +------
lib/acts_like_git/active_record_ext/base.rb | 4 ++++
2 files changed, 5 insertions(+), 6 deletions(-)