Skip to content

Instantly share code, notes, and snippets.

@sbeam
sbeam / test_helper.rb
Created September 30, 2011 01:19
Access Paperclip matchers in your Shoulda tests
# In test_helper.rb add (inside Spork.prefork block)
require "paperclip/matchers"
# ...
class Test::Unit::TestCase
extend Paperclip::Shoulda::Matchers
end
@sbeam
sbeam / gist:1200891
Created September 7, 2011 15:34
create postgres DBs for Rails proj, OSX
sbeam@pris ~/Sites/parallaxp]$ psql -U postgres -c "CREATE DATABASE parallaxp_dev"
Password for user postgres:
CREATE DATABASE
sbeam@pris ~/Sites/parallaxp]$ psql -U postgres -c "CREATE USER parallaxp WITH PASSWORD 'xxxxxxxxxx'"
Password for user postgres:
CREATE ROLE
sbeam@pris ~/Sites/parallaxp]$ psql -U postgres -c "CREATE DATABASE parallaxp_test OWNER parallaxp"
Password for user postgres:
CREATE DATABASE
sbeam@pris ~/Sites/parallaxp]$ psql -U postgres -c "ALTER USER parallaxp CREATEDB"
@sbeam
sbeam / gist:1189411
Created September 2, 2011 18:32
cyclethrough() jquery plugin
/**
* loops through the collection given by 'selector' within the called node, and
* when the elem is moused-over (is that a word?) adjusts * the z-index at the
* given interval for each. Like an animated GIF for any set of DOM nodes!
* Meant to work with a set of images, like thumbnails, YMMV
*
* $('#video-thumbnails').cyclethrough('img', 800);
*
* author sbeam
* license MIT
@sbeam
sbeam / gist:1171906
Created August 25, 2011 20:55
functional testing against authentication - example
class AbstractControllerTest < ActionController::TestCase
context "handle :index" do
context "logged as user"
setup do
logged_as(:user)
get :index
end
should_redirect_to("Root page"){root_path()}
end
context "logged as admin"
[2011-05-16 15:31:00] ERROR ArgumentError: wrong number of arguments (0 for 1)
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/railties-3.0.7/lib/rails/application.rb:77:in `call'
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
(eval):3:in `send'
(eval):3:in `method_missing'
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/railties-3.0.7/lib/rails/rack/log_tailer.rb:14:in `call'
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/rack-1.2.2/lib/rack/content_length.rb:13:in `call'
/home/sbeam/.rvm/gems/ree-1.8.7-2010.02@chp99/gems/rack-1.2.2/lib/rack/handler/webrick.rb:52:in `service'
/home/sbeam/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
commit 1a448022d42dd91021b042ecb7d31f60170352e5
Author: Sam Beam <sbeam@onsetcorps.net>
Date: Mon Dec 6 21:08:43 2010 -0500
return a nil from Calculator::ActiveShipping::compute when the method is not found in the API response, and pass it through so the customer is not presented with a free shipping option
diff --git a/app/controllers/checkouts_controller.rb b/app/controllers/checkouts_controller.rb
index 1b94dc2..7c56f8d 100644
--- a/app/controllers/checkouts_controller.rb
+++ b/app/controllers/checkouts_controller.rb
Processing CheckoutsController#update (for 71.168.112.22 at 2010-11-24 04:59:59) [PUT]
Parameters: {"step"=>"address", "order_id"=>"R257486814", "action"=>"update", "_method"=>"put", "authenticity_token"=>"dX4pj58PjCHGKMvQFasLjFurQeeaGgdt/P5cfUtyVCM=", "controller"=>"checkouts", "checkout"=>{"bill_address_attributes"=>{"address1"=>"123 Test Rd", "city"=>"Newark", "address2"=>"Suite G-1", "zipcode"=>"NY\#@", "country_id"=>"214", "lastname"=>"Customero", "id"=>"67", "firstname"=>"Test", "phone"=>"", "state_id"=>"769938586"}, "ship_address_attributes"=>{"id"=>"68", "state_id"=>"721598219"}, "use_billing"=>"1"}}
Cache hit: Spree::Config ({})
.....
Cache hit: Spree::ActiveShipping::Config ({})
***** Debugger requested, but was not available: Start server with --debugger to enable *****
Cache write: UPS-R257486814-US-IN-Newark-NY#@-266_1
<%- collection ||= @menu_pages
# In order to match items that aren't shown in menu and highlight their associations.
# This can be supplied if the logic different in your case.
unless defined?(selected_item)
selected_item = collection.detect{|page| selected_page?(page)}
selected_item = @page if selected_item.nil?
end
if defined?(selected_item) %>
require_dependency 'application_controller'
class MailChimpExtension < Spree::Extension
version "1.0"
description "Mail Chimp API integration with your Spree Store, using the hominid gem"
url "http://github.com/sbeam/spree-mail-chimp.git"
def self.require_gems(config)
config.gem 'hominid', '>= 2.2.0'
sbeam@pris ~/Sites/risepoker]$ ./script/console
Loading development environment (Rails 2.3.8)
ruby-1.8.7-p302 > user = User.find_by_email('admin@risepoker.com')
=> #<User id: 1, email: "admin@risepoker.com", crypted_password: "1f0777c516b7443484cdc4f0b11928e346ec31031fcb83b0712...", salt: "PreTkwuZsGGfCr7pXprw", remember_token: nil, remember_token_expires_at: nil, created_at: "2010-09-23 19:59:47", updated_at: "2010-09-27 20:48:27", persistence_token: "d0a60168b42533b95ae97935badca4a9626e9be500be5e283df...", single_access_token: "MCFb894ZaLlAsl3RPALZ", perishable_token: "hDp6RM24MI9YDPYbJY8K", login_count: 5, failed_login_count: 0, last_request_at: "2010-09-27 20:48:27", current_login_at: "2010-09-27 20:48:09", last_login_at: "2010-09-27 20:44:03", current_login_ip: "76.118.157.124", last_login_ip: "76.118.157.124", login: "admin@risepoker.com", ship_address_id: nil, bill_address_id: nil, openid_identifier: nil, api_key: nil>
ruby-1.8.7-p302 > user.password = user.password_confirmation = 'risepoker'
=> "r