Skip to content

Instantly share code, notes, and snippets.

@fahim
fahim / gist:1254682
Created September 30, 2011 19:07
What's the best way to test this method?
# Employee Discount model
class Discount::Employee < Discount
def compute?(order)
raise "look at MerchandiserStandard.compute?"
order.front_end? &&
order.credit_adjustments.empty? &&
order.discount_adjustments.empty? &&
order.promotion_credits.empty? &&
order.has_only_customer_products? &&
can_use?(self.user)
it "should not delete discounts" do
assert_equal 1, order.discount_adjustments.count
assert_equal 2, order.line_items.count
order.line_items.second.destroy
assert_equal 1, order.line_items.reload.count
assert_equal 1, order.discount_adjustments.reload.count # fails
end
def used_promotion_credits(order)
p = PromotionCredit.arel_table
o = Order.arel_table
if order.user.anonymous?
user_condition = o[:email].eq order.email
else
user_condition = o[:user_id].eq order.user_id
end
class Promotion::Rules::OnePerUser < PromotionRule
def eligible?(order)
used_promotion_credits(order).empty?
end
def used_promotion_credits(order)
p = PromotionCredit.arel_table
o = Order.arel_table
require 'spec_helper'
describe Promotion::Rules::OnePerUser do
let(:rule) { Promotion::Rules::OnePerUser.new }
let(:user) { mock_model(User) }
let(:order) { mock_model(Order, :user => user) }
describe "the arel expression" do
before do
PromotionCredit.stub_chain('includes.where')
require 'open-uri'
namespace :tax_rates_scraper do
namespace :california do
# Order to run the rake tasks:
# rake tax_rates_scraper:california:tax_rates
# rake tax_rates_scraper:california:zip_codes
task :zip_codes => [:environment] do
url = "http://www.melissadata.com/lookups/CountyZip.asp?State=CA06California"
@fahim
fahim / gist:1565874
Created January 5, 2012 16:04
_google_analytics.html.erb
<% if Rails.env.production? %>
<script type="text/javascript">
/*
Doc for special functions & to record custom variables
http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setCustomVar
*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24979565-1']);
_gaq.push(['_setDomainName', '.chloeandisabel.com']);
<% if current_user %>

Microsoft culture expects you to be in meetings. Calendars need to be decorated with sufficient colourful blocks, to signal over-activity.

Dig a bit deeper and you’ll realise that Microsoft meetings are a way to diffuse and evade responsibility for decisions. Yes – let’s spend weeks on weeks “reviewing with stakeholders.” It’s so much safer that taking swift decisions ourselves. The company places no trust on the individual to make the right decision on their own.

#!/bin/env ruby
# encoding: utf-8
module Normalizers
class SongDataNormalizer
# def initialize(object)
# @object = object
# @tags = {}
# end
@fahim
fahim / gist:4997373
Created February 20, 2013 17:36
new obj-c syntax fail (or maybe im just using it wrong)
NSDictionary *songDict = @{@"artists": [item valueForProperty: MPMediaItemPropertyArtist],
@"title": [item valueForProperty: MPMediaItemPropertyTitle]};
// ----------- vs ---------- //
// the new syntax above caused a memory error. i ended up just using the old syntax below and the code worked fine
// ----------- vs ---------- //
NSDictionary *songDict = [[NSDictionary alloc] initWithObjectsAndKeys:
[item valueForProperty: MPMediaItemPropertyTitle], @"title",
[item valueForProperty: MPMediaItemPropertyArtist], @"artists",