Skip to content

Instantly share code, notes, and snippets.

View schof's full-sized avatar

Sean Schofield schof

  • Stedi
  • Washington, DC
View GitHub Profile
@schof
schof / gist:2628078
Created May 7, 2012 14:29
Restart Pow after DNS failure
#!/bin/bash
# Restarts Pow when DNS fails to resolve
lsof | grep 20560 | awk '{print $2}' | xargs kill -9
launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist
@schof
schof / tax_rate_spec.rb
Created December 16, 2011 03:34
Latest tax rate specs
require 'spec_helper'
describe Spree::TaxRate do
context 'validation' do
it { should validate_presence_of(:tax_category_id) }
end
context "match" do
let(:zone) { Factory(:zone) }
@schof
schof / devise_hack.rb
Created March 2, 2011 14:38
Monkey Patch Devise
Devise::FailureApp.class_eval do
def http_auth?
return false
end
end
before(:each) do
@user = mock_model(User).as_null_object
end
let(:inventory_unit) { mock_model(InventoryUnit).as_null_object }
describe "GET index" do
let(:collection) { mock("collection") }
before { controller.stub :collection => collection }
@schof
schof / Heroku Bundle
Created November 8, 2010 13:42
Script for bundling CSS and JS before deploy
#!/bin/bash
# Stylesheets
cat public/stylesheets/reset.css public/stylesheets/typography.css public/stylesheets/forms.css public/stylesheets/common.css public/stylesheets/sm.css public/stylesheets/home.css public/stylesheets/checkout.css > public/stylesheets/all.css
cat public/stylesheets/admin/admin-reset.css public/stylesheets/admin/grids.css public/stylesheets/admin/admin-typography.css public/stylesheets/admin/admin-forms.css public/stylesheets/admin/admin-tables.css public/stylesheets/admin/admin.css > public/stylesheets/admin-all.css
# Javascripts
cat public/javascripts/jquery-1.4.1.min.js public/javascripts/rails.js public/javascripts/jquery.progressbar.js public/javascripts/fancyzoom.js public/javascripts/common.js public/javascripts/sm.js > public/javascripts/all.js
cat public/javascripts/jquery.js public/javascripts/jquery-ui.js public/javascripts/jrails.js public/javascripts/jquery.suggest.js public/javascripts/jrails.autocomplete.js > public/javascripts/jquery-admin-plugins.js
@schof
schof / ability_decorator.rb
Created October 29, 2010 03:15
Add custom cancan abilities on top of Spree
class AbilityDecorator
include CanCan::Ability
def initialize(user)
#############################
can :destroy, LineItem do |item|
item.order.user == user
end
#############################
can :read, Artwork do |artwork|
git clone git://github.com/railsdog/spree.git
cd spree
bundle install
cd core
rake test_app
rake spec
describe LineItem do
context "#save" do
context "when track inventory is true" do
it "should adjust inventory counts" do
# set preference here
InventoryUnit.should_receive(:adjust_inventory_counts).with(order)
order.save
end
end
context "when track inventory is false" do
# Contains logic for enforcing SSL under certain conditions.
module Spree
class SslConstraint
def matches?(request)
return true if ((Rails.env.development? || Rails.env.test?) && Spree::Config[:allow_ssl_in_development_and_test])
(Rails.env.staging? || Rails.env.production?) && Spree::Config[:allow_ssl_in_production]
end
end
require "spec_helper"
describe Spree::MailSettings do
let(:mail_method) { MailMethod.create(:environment => "test") }
before { mail_method.set(:perform_delivery => false) }
after { mail_method.set(:perform_delivery => true) }
context "init" do