Skip to content

Instantly share code, notes, and snippets.

@JoshTGreenwood
JoshTGreenwood / gist:443253f42fb80455792f
Created December 1, 2015 22:20
Automatically add magit cloned repos to the projectile project list
(defun add-project-to-projectile-known-projects (_ directory)
(projectile-add-known-project directory))
(advice-add 'magit-clone :after 'add-project-to-projectile-known-projects)
@JoshTGreenwood
JoshTGreenwood / ar_merge.md
Created March 24, 2016 15:26
Active Record Merge

TIL #merge is a thing on AR models.

Useful for joining + using a named scoped on the joined table:

class Post; end
class Comment; scope :approved, -> {approved: true}; end
Post.joins(:comments).merge(Comment.approved)
@JoshTGreenwood
JoshTGreenwood / testdouble.rb
Created October 18, 2016 15:46
the beginning of what testdouble.rb might look like
class TestDouble
attr_accessor :instance, :when_stack
def initialize(instance)
@instance = instance
@when_stack = []
end
def when(&block)
fake_method_call = FakeMethodCall.new(block)