Skip to content

Instantly share code, notes, and snippets.

# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
@MikeSilvis
MikeSilvis / gist:2304582
Created April 4, 2012 18:34
visiting an admin area
it "Visit Admin Area" do
@user = FactoryGirl.create(:admin)
login_user
visit "/dashboard"
page.should have_content("Dashboard")
end
@MikeSilvis
MikeSilvis / gist:2329928
Created April 7, 2012 15:57
Cart Products before Group_by
1.9.2p318 :087 > c.products
#=>
[
[0] #<Product:0x007fbc1ded2b38> {
:id => 3,
:name => "Racecar",
:description => "VRRRRRRRRRMMMMMMM",
:price_in_cents => 2065,
:active => 1,
:inactive_date => nil,
@MikeSilvis
MikeSilvis / gist:2329945
Created April 7, 2012 15:59
Cart Products after Group_by
1.9.2p318 :088 >p = c.products.group_by { |p| p.id }
#=>
{
3 => [
[0] #<Product:0x007fbc1ded2b38> {
:id => 3,
:name => "Racecar",
:description => "VRRRRRRRRRMMMMMMM",
:price_in_cents => 2065,
:active => 1,
@MikeSilvis
MikeSilvis / gist:2330028
Created April 7, 2012 16:12
Cart Products index_by
1.9.2p318 :119 > c.products.index_by(&:id)
#=>
{
3 => #<Product:0x007fbc222615c0> {
:id => 3,
:name => "Racecar",
:description => "VRRRRRRRRRMMMMMMM",
:price_in_cents => 2065,
:active => 1,
:inactive_date => nil,
.user#info
%b Name:
%div= user.name
%b Information:
%div= user.info
@MikeSilvis
MikeSilvis / initializersredis.rb
Created April 27, 2012 18:25
new_user_mailer
class NewUserEmailer
@queue = :emailer
def self.perform(user_id)
user = User.find(user_id)
mail(:to => user.email, :subject => "Welcome #{user.name}")
end
end
def next_status
next_status = {
"pending" => :cancel,
"shipped" => :return,
"paid" => :ship
}
if next_status["#{self.status.name}"]
send(next_status["#{self.status.name}"])
end
self.save
@MikeSilvis
MikeSilvis / Billing.rb
Created May 8, 2012 03:53
Billing_Processor
class BillingProcessor
def self.charge(amount, stripe_id)
Stripe::Charge.create(
:amount => amount,
:currency => "usd",
:customer => stripe_id
)
end
def self.create_customer(user_id, token)
user = User.find(user_id)
class UsersController < ApplicationController
before_filter :current_user
before_filter :find_user, :only => [:edit, :update, :destroy, :show]
def show
end
def new
@user = User.new
end