Skip to content

Instantly share code, notes, and snippets.

View JamesFerguson's full-sized avatar

James Ferguson JamesFerguson

View GitHub Profile
@JamesFerguson
JamesFerguson / params in nested traits.rb
Last active December 1, 2015 00:22
Trait calling trait with params, Factory Girl
FactoryGirl.define do
factory :currency do
name Forgery::Currency.description
sequence(:short_name) { |sn| "#{Forgery::Currency.code}#{sn}" }
symbol '$'
end
factory :price do
full_price { 6000 }
discount_price { 3000 }
@JamesFerguson
JamesFerguson / email_validator.rb
Created November 4, 2011 00:34 — forked from jcf/email_validator.rb
Rails 3 Email Validator
require 'mail'
class EmailValidator < ActiveModel::EachValidator
attr_reader :record, :attribute, :value, :email, :tree
def validate_each(record, attribute, value)
@record, @attribute, @value = record, attribute, value
@email = Mail::Address.new(value)
@tree = email.__send__(:tree)
@JamesFerguson
JamesFerguson / 56e55726c8cdc920f48c97187c7fe8b9d2baddc6.diff
Created January 31, 2011 23:06
Diff of one line patch to devise making its remember_scope_token cookie HttpOnly by default
diff --git a/test/integration/rememberable_test.rb b/test/integration/rememberable_test.rb
index 14e66fb..295fab0 100644
--- a/test/integration/rememberable_test.rb
+++ b/test/integration/rememberable_test.rb
@@ -54,6 +54,7 @@ class RememberMeTest < ActionController::IntegrationTest
test 'remember the user before sign in' do
user = create_user_and_remember
get users_path
assert_response :success
@JamesFerguson
JamesFerguson / environment.rb
Created December 21, 2010 00:26
A monkey patch to make devise's rememberable module set the remember_#{scope}_token cookie httponly to prevent xss vulnerabilities.
# config/environment.rb
# ...
Dir[Rails.root + 'lib/monkey_patches/**/*.rb'].each { |file| require file }
# ...