# spec/support/custom_forms_helper.rb
module CustomFormsHelper
def foundation_select(option, opts={})
# Zurb Foundation adds custom markup after (and then hides)
# the originating select. Here we simulate the user's interaction
# with the custom form instead of just setting the hidden originating select's value
originating_select_name = opts[:from]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Resource do | |
let(:resource) { create :resource } | |
#-------------------------------------# | |
# ActiveRecord Relationship Behaviors # | |
#-------------------------------------# | |
context "with/when some context/event" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def select2_select(option, opts={}) | |
# same as foundation_select, but for select2 | |
# boxes used throughout the staff app. | |
originating_select_name = opts[:from] | |
originating_select_id = find("select[name='#{originating_select_name}']")['id'] | |
custom_select = find(".select2-container[id$='#{originating_select_id}']") | |
# click dropdown | |
custom_select.find("a.select2-choice").click | |
# click option with correct text |
function ImageUpload($el) {
var self = this;
self.$el = $el
self.$image = $(this.$el.attr('data-image-selector'));
self.$uploadForm = this.$el.find('.s3-uploader')
self.$uploadTriggers = this.$el.find('.js-upload-image-trigger');
self.$imageUploader = this.$el.find('#file');
$ rake pg:query_time
total time (min) ▾ | average execution (ms) | query
--------------------+------------------------+------------------------------
2.0379 | 1153.5163 | SELECT COUNT(*) FROM "users" WHERE ("users"."username" ILIKE ?)
1.3497 | 809.8202 | INSERT INTO users (email, username, auth_token) VALUES (?, ?, ?), ...
0.0056 | 111.416 | SELECT COUNT(*) FROM "users" WHERE ("users"."avatar_file_name" ILIKE ?)
(3 rows)
With pg installed, you can run the pg:psql
Heroku command to connect to your database and execute commands using the psql interactive terminal:
$ heroku pg:psql
psql (9.3.5, server 9.3.3)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
database-name=> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Benchmark | |
def memory_usage | |
`ps -o rss= -p #{Process.pid}`.to_i | |
end | |
def memory | |
m0 = memory_usage | |
yield | |
memory_usage - m0 | |
end | |
def kb |
Enumerators yield for each value in the enumeration
e = Enumerator.new do |yielder|
a = 1
yielder.yield a
end
e.next
=> 1
class TestQuery < SimpleDelegator
def initialize
super(Bomb.all.extending(Scopes))
end
module Scopes
def processed
where(Bomb.arel_table[:asset_remote_url].eq(nil))
end
end