Skip to content

Instantly share code, notes, and snippets.

View aaron's full-sized avatar

Aaron Baldwin aaron

  • Brightways Learning
  • Missoula, MT
View GitHub Profile
@aaron
aaron / test_helper.rb
Created October 8, 2014 18:34
Example functional test for a Rails 2.3 application
class ActiveSupport::TestCase
def login_as(user)
@request.session[:user_id] = user ? users(user).id : nil
end
def current_user
@current_user ||= User.find(@request.session[:user_id])
end
end
@aaron
aaron / gist:7455558
Created November 13, 2013 20:11
Document ready Rails 4 with turbolinks example
ready = function() {
$('a#toggle_all_standards_search_form').click(function() {
$('div#course_standards').html('');
$('div#all_standards').show();
return false;
});
};
$(document).ready(ready);
$(document).on('page:load', ready);
@aaron
aaron / gist:4040018
Created November 8, 2012 16:51
List duplicate rails helper methods
h = Hash.new(0)
Dir.glob(Rails.root.join('app','helpers','*.rb')).each do |file|
File.read(file).lines.each do |line|
if line[/^[ ]+def ([a-zA-Z0-9!_]+)/]
h[$1] += 1
end
end
end
h.each {|key, value| puts key if value > 1}