A clean workaround for running capybara tests on Rails with assets pipeline enabled.
Original: teamcapybara/capybara#500 (comment)
| check process redis-server | |
| with pidfile "/var/run/redis.pid" | |
| start program = "/etc/init.d/redis-server start" | |
| stop program = "/etc/init.d/redis-server stop" | |
| if 2 restarts within 3 cycles then timeout | |
| if totalmem > 100 Mb then alert | |
| if children > 255 for 5 cycles then stop | |
| if cpu usage > 95% for 3 cycles then restart | |
| if failed host 127.0.0.1 port 6379 then restart | |
| if 5 restarts within 5 cycles then timeout |
| # 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: |
| <% flash.each do |type, message| %> | |
| <div class="alert <%= bootstrap_class_for(type) %> fade in"> | |
| <button class="close" data-dismiss="alert">×</button> | |
| <%= message %> | |
| </div> | |
| <% end %> |
| /** | |
| * | |
| * 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. |
| 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 |
| # 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 |
| module Abilities | |
| def self.ability_for(user) | |
| if user.admin? | |
| AdminAbility.new(user) | |
| else user | |
| MemberAbility.new(user) | |
| else | |
| GuestAbility.new | |
| end | |
| end |
A clean workaround for running capybara tests on Rails with assets pipeline enabled.
Original: teamcapybara/capybara#500 (comment)
| // 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; |
| require 'delegate' | |
| class Base | |
| def foo | |
| "foo" | |
| end | |
| def bar | |
| "bar" | |
| end | |
| end |