A clean workaround for running capybara tests on Rails with assets pipeline enabled.
Original: teamcapybara/capybara#500 (comment)
// How to use this: | |
// 1. Go to the desired profile page on coderwall, like http://coderwall.com/marcinbunsch | |
// 2. Paste this gist in the JS console | |
// | |
// You can also probably use this in greasemonkey and dot.js | |
// | |
// Also, it was tested in Chrome, Firefox and Safari, it probably will | |
// not work in IE, but I just don't care about it ;) | |
// | |
// UPDATE: Coderwall made changes to the site and I cannot retrieve the achievements, so they are hardcoded, taken from a cached version of the achievements page |
require 'delegate' | |
class Base | |
def foo | |
"foo" | |
end | |
def bar | |
"bar" | |
end | |
end |
// Slick little method to create a bitmask from an array of boolean values. (for Javascript) | |
function bitMask(a, b) { | |
var m = 0, i; | |
if (b !== undefined) { a = Array.prototype.slice.apply(arguments); } | |
for (i = 0; i < a.length; i += 1) { | |
if (a[i] !== false) { m += Math.pow(2, i) }; | |
} | |
return m; |
A clean workaround for running capybara tests on Rails with assets pipeline enabled.
Original: teamcapybara/capybara#500 (comment)
module Abilities | |
def self.ability_for(user) | |
if user.admin? | |
AdminAbility.new(user) | |
else user | |
MemberAbility.new(user) | |
else | |
GuestAbility.new | |
end | |
end |
# Parses YouTube URLs directly or from iframe code. Handles: | |
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI) | |
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI) | |
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">) | |
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...) | |
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/ | |
$5 #=> the video ID | |
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo |
namespace :spec do | |
# largely lifted from http://www.pervasivecode.com/blog/2007/06/28/hacking-rakestats-to-get-gross-loc/ | |
task :stats_setup do | |
require 'code_statistics' | |
class CodeStatistics | |
alias calculate_statistics_orig calculate_statistics | |
def calculate_statistics | |
@pairs.inject({}) do |stats, pair| | |
if 3 == pair.size |
/** | |
* | |
* Here's a thing that will look through all the text nodes of a document, and | |
* upon encountering an emoji codepoint, will replace it with an image. | |
* For now, those images are pulled from GitHub, which isn't very nice, so I | |
* need to find a more suitable host. | |
* | |
* Much of this code was gleaned from staring at the minified GitHub JS. | |
* | |
* Copyright (c) 2013 Mark Wunsch. Licensed under the MIT License. |
<% flash.each do |type, message| %> | |
<div class="alert <%= bootstrap_class_for(type) %> fade in"> | |
<button class="close" data-dismiss="alert">×</button> | |
<%= message %> | |
</div> | |
<% end %> |
# Rails datetime_select and similar use multiparameter attributes which are | |
# these dawful things from the bowels of activerecord and actionpack. This | |
# module extends virtus models to coerce multiparameter attributes back together | |
# before assigning attributes. | |
# | |
# Here's the implementation for ActiveRecord: | |
# | |
# https://github.com/rails/rails/blob/11fd052aa815ae0255ea5b2463e88138fb3fec61/activerecord/lib/active_record/attribute_assignment.rb#L113-L218 | |
# | |
# and DataMapper: |