Skip to content

Instantly share code, notes, and snippets.

View cmaujean's full-sized avatar

Christopher Maujean cmaujean

  • Mostly here, but sometimes elsewhere
View GitHub Profile
@cmaujean
cmaujean / spree-extension-cap-tasks.rb
Created October 17, 2010 00:29
A set of extension management related tasks for using Capistrano on a spreecommerce install. For spree-0-11-stable.
# Spree extension capistrano tasks
# --------------------------------
# by Christopher Maujean
#
# These tasks depend on the existence of the extensions hash.
# The key is name of the directory in vendor/extensions.
# The value is the git url of the extension.
#
# set :extensions, {
# 'my_site' => "git@github.com:/username/spree-my-site.git"
@cmaujean
cmaujean / tableless.rb
Created October 25, 2010 04:17
rails 2 table-less active record model.
# class Foo < Tableless
# column :bar, :string
# column :baz, :datetime
# validates_presence_of :bar, :baz
# end
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end
@cmaujean
cmaujean / run_generator.rb
Created November 9, 2010 22:49
running a generator programatically
# Must be run in the context of your rails app
# if you put this in a rake task, you'll need to ensure the task depends on the :environment task
require 'rails/generators'
require "#{::Rails.root.to_s}/lib/generators/foo_bar/article/article_generator.rb"
# make a generator (new calls .shift on the first arg, so it must be looking for an array)
gen = FooBar::ArticleGenerator.new(["Der title of der article"])
# run your create_ methods here:
@cmaujean
cmaujean / categories-sample.yml
Created November 25, 2010 23:17
changing the ordering of taxons based on yaml
---
-
Wine & Spirits:
-
Beer: []
-
Wine:
- Red
- White
- Blush
desc "Regenerates a rails 3 app for testing"
task :test_app do
SPREE_PATH = ENV['SPREE_PATH']
raise "SPREE_PATH should be specified" unless SPREE_PATH
require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
class FlagPromotionTestAppGenerator < Spree::Generators::TestAppGenerator
def tweak_gemfile
append_file 'Gemfile' do
<<-gems
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RedirectMatch 301 ^/(.*)/$ http://www.example.com/blog/$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@cmaujean
cmaujean / example.com.conf
Created April 9, 2011 00:02
apache 2.0.54 proxy and rewrite for example of a setup for proxy to a wordpress blog so it appears to be a seamless part of the enclosing CF6.1 based shopping cart, while running on a different machine.
RewriteEngine On
Options +FollowSymLinks
<Directory /path/to/the/Blog>
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
Redirect /blog http://www.example.com/Blog
ProxyRequests Off
@cmaujean
cmaujean / capybara_select_dates_and_times.rb
Created June 7, 2011 20:03
A rollup of various Capybara date/time step definition gists, updated for Capybara 0.4.1.2 and XPath 0.1.3
require "xpath" # XPath is a separate gem now
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date (date, options = {})
date = Date.parse(date)
# lookup id prefix by label
id_prefix = id_prefix_for(options[:label])
@cmaujean
cmaujean / bar.rb
Created July 8, 2011 21:13
nested destroy problem
class Bar < ActiveRecord::Base
acts_as_nested_set :dependent => :destroy
belongs_to :foo
end
# Content Manager
# – can access overview, reports, events, faq, snippets, and pages.
class ContentAbility
include CanCan::Ability
def initialize(user)
if user.has_role?(:content)
can :manage, :all
cannot :manage, Product
cannot :manage, Configuration