Skip to content

Instantly share code, notes, and snippets.

View caulfield's full-sized avatar

Sergey Kuchmistov caulfield

View GitHub Profile
@caulfield
caulfield / prepare-commit-msg
Last active August 29, 2015 14:03
git prepare commit message
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
@caulfield
caulfield / action_controller_callbacks_matchers
Last active August 29, 2015 14:15
Action controller callbacks rspec matchers
RSpec::Matchers.define :use_before_action do |expected|
# @example
# expect { get :index }.to use_before_action(:authenticate_user!)
match do |actual|
expect(controller).to receive(expected).and_call_original
instance_exec &actual
described_class._process_action_callbacks.find do |callback|
@caulfield
caulfield / factory_girl.rb
Created March 26, 2015 14:40
rspec subject with factorygirl
module FactoryGirlHelpers
# extract subject attributes and produce factory object from them
#
# @example subject_factory(:build_stubbed)
# @example subject_factory(:create, :comment_reply)
def subject_factory(method, factory_name = nil)
changed_attrbiutes = subject.changed
attributes = subject.attributes.slice changed_attrbiutes
@caulfield
caulfield / link_helpers.rb
Created April 6, 2015 11:22
rails link_to_if with options
@caulfield
caulfield / rspec.rb
Last active March 2, 2020 04:27
Stub templates in rspec helper
module HelperExamplesExtensions
# Copy of stub_template from view specs
# @see RSpec::Rails::ViewExampleGroup::ExampleMethods#stub_template
def stub_template(hash)
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
end
end
RSpec.configure do |config|
config.include HelperExamplesExtensions, type: :helper
@caulfield
caulfield / index.html
Created January 13, 2017 14:07
DOM events
<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script
src="index.js"></script>
</head>