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
#--------------------------- | |
#profile_controller_spec.rb | |
#--------------------------- | |
describe ProfileController do | |
shared_examples_for "User" do | |
it "should show user profile" do | |
get :index | |
response.should be_success | |
end |
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
user = mock_model(User) | |
User.stub!(:find).at_least(1).and_return do |id| | |
if id == mock_user.id.to_s | |
user | |
else | |
User.find_by_id(id) | |
end | |
end |
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 stub_find_for_specific_values(model, stubs) | |
model.stub!(:find).at_least(1).and_return do |id| | |
if stubs.has_key? id | |
stubs[id] | |
else | |
model.find_by_id(id) | |
end | |
end | |
end |
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
named_scope :active_within, lambda {|time| | |
{:joins => {:workflows => :activities}, | |
:conditions => ["activities.created_at > ?", time.ago], | |
:select => "DISTINCT(users.*)"} |
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
#will wait until all dom elements are rendered | |
def wait_for_dom(timeout = Capybara.default_wait_time) | |
uuid = SecureRandom.uuid | |
page.find(:xpath, "//body") | |
page.evaluate_script <<-EOS | |
_.defer(function() { | |
$('body').append("<div id='#{uuid}'></div>"); | |
}); | |
EOS | |
wait_until(timeout) {page.find(:xpath, "//div[@id='#{uuid}']")} |
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
#before | |
def load_submissions_count | |
Enrollment.where(initiative_id: @initiative_ids).group(:initiative_id).select('initiative_id, sum(submissions_count) as sum_submissions_count').each do |data| | |
initiative = @initiatives_data[data.initiative_id] | |
initiative.cached_submissions_count = data.sum_submissions_count.to_i | |
end | |
end | |
#after | |
def load_submissions_count |
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
# Format | |
# owner email address: <email address of owner of the question> | |
# question: <text of the question> | |
# total_enrollments: <total number of enrollments for this question> | |
# primary_user_category: | |
# name: <category name>: | |
# values: | |
# <user_category_value.name>: | |
# percentage_of_total: <percentage of enrollments in this category_value> | |
# promoter_percentage: <percentage of enrollments in this category_value that are promoters> |
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
import Foundation | |
class MetawearConfig:NSObject, MBLRestorable { | |
var pulseWidthEvent:MBLEvent! | |
func encodeWithCoder(aCoder: NSCoder) { | |
aCoder.encodeObject(self.pulseWidthEvent, forKey: "pulseWidthEvent") | |
} | |
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
var page; | |
page = require('webpage').create(); | |
page.viewportSize = { width: 320, height: 780 }; | |
phantom.waitFor = function(callback) { | |
do { | |
// Clear the event queue while waiting. | |
// This can be accomplished using page.sendEvent() | |
this.page.sendEvent('mousemove'); |
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
const puppeteer = require('puppeteer'); | |
var config; | |
config = { | |
username: 'username', | |
password: 'password' | |
}; | |
(async () => { | |
const browser = await puppeteer.launch({ |
OlderNewer