Skip to content

Instantly share code, notes, and snippets.

View hindenbug's full-sized avatar
💻

Manoj hindenbug

💻
View GitHub Profile
@millisami
millisami / gist:721466
Created November 30, 2010 10:16
Mongoid Dirty Tracking
%w(rubygems mongoid rspec).each do |gem|
require gem
end
require 'hijacker'
Hijacker.configure do
uri 'druby://localhost:8787'
end
Mongoid.configure do |config|
name = "dirty_track_test"
@justinko
justinko / gist:743458
Created December 16, 2010 14:37
Common gem configuration implementations
class MyGem
class << self
attr_accessor :color
end
def self.configure(&block)
instance_eval(&block)
end
end
@zhasm
zhasm / sqlite3.py
Created December 19, 2010 01:36
python sqlite
import os
import re
import glob
def initdb(base=os.getcwd(), ext="*.db3"):
'''get db file list,
use current directory as base,
and db3 as extention
'''
try:
@jittuu
jittuu / gist:792715
Created January 24, 2011 02:19
Test Omniauth Facebook Callback Controllers in Devise with rspec
require 'spec_helper'
describe Users::OauthCallbacksController, "handle facebook authentication callback" do
describe "#annonymous user" do
context "when facebook email doesn't exist in the system" do
before(:each) do
stub_env_for_omniauth
get :facebook
@txus
txus / delegate_matcher.rb
Created February 2, 2011 09:19
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@sleistner
sleistner / mongoid_step_definitions.rb
Created February 7, 2011 20:16
factory_girl cucumber step definitions using mongoid
FactoryGirl.factories.values.each do |factory|
if factory.build_class.respond_to?(:fields)
factory.build_class.fields.map(&:first).each do |field|
human_field_name = field.downcase.gsub('_', ' ')
Given /^an? #{factory.human_name} exists with an? #{human_field_name} of "([^"]*)"$/i do |value|
Factory(factory.name, field => value)
end
Given /^(\d+) #{factory.human_name.pluralize} exist with an? #{human_field_name} of "([^"]*)"$/i do |count, value|
count.to_i.times { Factory(factory.name, field => value) }
@icebreaker
icebreaker / mongoid-cheatsheet.md
Created February 15, 2011 09:11
Mongoid cheat sheet
@ches
ches / rvm-prompt.sh
Created February 20, 2011 16:02
An example of a bash prompt showing RVM Ruby version and active gemset
RED="\[\033[01;31m\]"
GREEN="\[\033[01;32m\]"
COLOR_NONE="\[\033[0m\]"
function ruby_version {
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then
local system=$(~/.rvm/bin/rvm-prompt s)
local interp=$(~/.rvm/bin/rvm-prompt i)
if [[ ! -n $system ]]; then
# Don't show interpreter if it's just MRI
@javascript
Scenario: confiming when saving inactive
Given I expect to click "OK" on a confirmation box saying "Are you sure?"
When I press "Save"
Then the confirmation box should have been displayed
And I should see "TV" in the "Campaign Keywords" section
Scenario: alert when form is not valid
Given I expect to click on an alert box saying "Please complete all fields in this form"
When I press "Save"
@adomokos
adomokos / tracks_controller.rb
Created April 15, 2011 03:50
This code is to demonstrate how I use test doubles for Rails.
class TracksController < ApplicationController
def index
signed_in_user
end
def new
@track = Track.new
end
def create