Skip to content

Instantly share code, notes, and snippets.

require "eventmachine"
require "mailfactory"
mail = MailFactory.new
mail.to = '[email protected]'
mail.from = '[email protected]'
mail.subject = 'hi!'
mail.text = 'hello world'
mail.html = '<h1>hello world</h1>'
binding.pry()
module AfterCommitPatch
def transaction(options = {})
rolled_back = false
begin
super
rescue ActiveRecord::Rollback => e
rolled_back = true
end
invoke_commit_objects unless rolled_back
end
class User < ActiveRecord::Base
attr_accessible :name
attr_accessible :options, :name
serialize :options
def options
self[:options] ||= {}
end
end
class User < ActiveRecord::Base
attr_accessible :name
after_commit :wow, :on => :create, :unless => :no_commit
attr_accessor :no_commit
def wow
puts "Calling wow"
self.no_commit = true
self.save
puts "Done called wow"
class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
class TopicWithSaveInCallback < ActiveRecord::Base
self.table_name = :topics
after_commit :cache_topic, :on => :create
def cache_topic
puts "******************* calling this stuff again #{cached.inspect}"
unless cached
self.cached = true
self.save
#!/usr/bin/env bash
apt-add-repository -y ppa:brightbox/ruby-ng
apt-get -y update
apt-get -y install build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install ruby1.9.3 ruby-switch
ruby-switch --set ruby1.9.1
gem install chef ruby-shadow --no-ri --no-rdoc
#!/usr/bin/env bash
apt-add-repository -y ppa:brightbox/ruby-ng
apt-get -y update
apt-get -y install build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install ruby1.9.3 ruby-switch
ruby-switch --set ruby1.9.1
gem install chef ruby-shadow --no-ri --no-rdoc
class Object
def should_chain_receive(*args,&block)
current_object = self
args[0..-2].each do |argument|
temp = Object.new()
current_object.should_receive(argument).and_return(temp)
current_object = temp
end
result = yield
current_object.should_receive(args.last).and_return result
@gnufied
gnufied / chain_should_receive.rb
Created May 28, 2012 09:16
How to chain method expectations in rspec-2
class Object
def should_chain_receive(*args,&block)
if block_given?
ChainReceive.new(self,args,block)
else
ChainReceive.new(self,args)
end
end
end
#!c:\ruby\bin\rubyw.exe
require 'mpgapi4r.rb' #path to mpgapi4r.rb
p = ReqMod::Purchase.new
p.order_id = "prodtest2"
p.cust_id = "test"
p.amount = "0.00"
p.crypt_type = "7"
p.pan = "4514011602554956"