( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
%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" |
class MyGem | |
class << self | |
attr_accessor :color | |
end | |
def self.configure(&block) | |
instance_eval(&block) | |
end | |
end |
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: |
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 |
# 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 |
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) } |
( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
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" |
class TracksController < ApplicationController | |
def index | |
signed_in_user | |
end | |
def new | |
@track = Track.new | |
end | |
def create |