Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
file 'Gemfile', <<-GEMS
source 'http://gemcutter.org'
gem "rails", "3.0.0.beta3"
gem "bson_ext", '0.20.1'
gem "mongoid", "2.0.0.beta4"
gem "compass", "0.10.0.rc5"
group :test do
gem "rspec-rails", "2.0.0.beta.8"
gem "capybara"
gem 'cucumber-rails', :git => 'git://github.com/aslakhellesoy/cucumber-rails.git'
gem 'test-unit' #https://rspec.lighthouseapp.com/projects/16211/tickets/292
gem 'machinist_mongo', :require => 'machinist/mongoid'
gem 'faker'
end
GEMS
# Bundle
run 'bundle install --relock'
# Initialize HAML and Compass
run 'bundle exec haml --rails .'
run 'bundle exec compass create . --using blueprint --app rails --sass-dir app/stylesheets --css-dir public/stylesheets'
run "sass-convert --from sass2 --to scss --recursive app/stylesheets"
run 'script/rails plugin install git://github.com/koppen/hassle.git' # for heroku
# Overwrites database.yml
file 'config/database.yml', <<-CODE
test:
adapter: mongoid
CODE
file 'lib/tasks/mongo.rake', <<-RAKE
namespace :db do
namespace :test do
task :prepare do
# Stub out for MongoDB
end
end
end
RAKE
# Initialize testing suite
run 'script/rails g rspec:install'
run 'script/rails g cucumber:skeleton --rspec --capybara'
run 'script/rails g mongoid:config'
file 'features/support/blueprints.rb', <<-EOF
require 'sham'
require 'faker'
EOF
file 'features/support/hooks.rb', <<-HOOK
Before { Sham.reset }
After { Mongoid.master.collections.each(&:drop) }
HOOK
file 'features/step_definitions/model_steps.rb', <<-RB
# Usage: Given a category with name "Parent"
Given /^an? (.+) with (.+) "([^"]*)"$/ do |model,attribute,value|
model.camelize.constantize.make attribute.dasherize => value
end
# Usage:
# Given the following entries:
# | title | category name |
# | My first post | Random entries |
Given /^the following (.+):$/ do |model,table|
table.hashes.each do |hash|
model.singularize.classify.constantize.make transform_attributes(hash)
end
end
def transform_attributes(attributes)
attributes.keys.each do |key,value|
if key.match(/^(.+) ([^ ]+)$/)
attributes[$1.dasherize] = $1.classify.constantize.first(:conditions => {$2 => attributes.delete(key)})
end
end
attributes
end
RB
# Remove default javascript files and initialize jQuery in application.js
run "rm public/javascripts/*.js"
run "curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js > public/javascripts/rails.js"
# Add a haml layout with google's jQuery
file "app/views/layouts/application.haml", <<-HAML
!!! 5
%html
%head
= csrf_meta_tag
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'print.css', :media => 'print'
/[if lt IE 8]
= stylesheet_link_tag 'ie.css', :media => 'screen, projection'
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'
= javascript_include_tag 'application.js'
%body
= yield
HAML
file 'public/javascripts/application.js',
%q|jQuery(function () {
});
|
config = <<-CONFIG
config.generators do |g|
g.orm :mongoid
g.template_engine :haml
g.test_framework :rspec, :fixture => false
end
CONFIG
inject_into_file 'config/application.rb', "#{config}", :after => "# end\n", :verbose => true
gsub_file 'features/support/env.rb', "require 'cucumber/rails/active_record'", "# require 'cucumber/rails/active_record'"
gsub_file 'features/support/env.rb', "Cucumber::Rails::World.use_transactional_fixtures = true", "# Cucumber::Rails::World.use_transactional_fixtures = true"
gsub_file 'config/application.rb', 'require "active_resource/railtie"', '# require "active_resource/railtie"'
gsub_file 'config/application.rb', 'require "rails/test_unit/railtie"', '# require "rails/test_unit/railtie"'
gsub_file 'config/application.rb', 'require "active_record/railtie"', '# require "active_record/railtie"'
gsub_file 'config/application.rb', 'Bundler.require(:default, Rails.env)', 'Bundler.require(Rails.env, :default)' # To be able to load machinist/mongoid before mongoid itself
inject_into_class 'app/helpers/application_helper.rb', 'ApplicationHelper', do <<-EOF
def partial(name, object_or_collection)
if object_or_collection.present?
render :partial => name.to_s, :locals => {name => object_or_collection}
end
end
EOF
end
file 'spec/helpers/application_helper.rb', <<-SPEC
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe ApplicationHelper do
before do
@instance = Class.new { include ApplicationHelper }.new
end
describe "partial" do
describe "without object" do
it { @instance.partial(:some_partial, nil).should be_blank }
end
describe "with empty collection" do
it { @instance.partial(:some_partial, []).should be_blank }
end
describe "with some object" do
before do
@object = mock
end
after do
@instance.partial(:some_partial, @object)
end
it "should render the partial passing the object as local variable" do
@instance.should_receive(:render).with(:partial => 'some_partial', :locals => {:some_partial => @object})
end
end
describe "with a non-empty collection" do
before do
@collection = [:stuff]
end
after do
@instance.partial(:some_partial, @collection)
end
it "should render the partial passing the collection as local variable" do
@instance.should_receive(:render).with(:partial => 'some_partial', :locals => {:some_partial => @collection})
end
end
end
end
SPEC
# Remove index.html, application.html.erb and rails.png
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm app/views/layouts/application.html.erb"
# Remove test directory since we're not using test/unit
run "rm -rf test"
readme = <<-README
===============================================================================
Phew! All work done.
* Your application is configured to use Mongoid, HAML/SASS,
Compass with blueprint, rSpec, Cucumber, Capybara, Machinist and jQuery.
SCSS, not SASS stylesheets are being used.
* Gems are locked. After modifying your Gemfile, run bundle install --relock
* Define machinist blueprints for cucumber in features/support/blueprints.rb
* You can see all the included generators by 'rails generate'.
* The MongoDB databases are prefixed by your application's name.
* jQuery 1.4.2 (via google cdn) and its Rails helpers are in public/javascripts.
* ActiveRecord is not being used. If you want to use it, uncomment the following
line in application.rb:
require "active_record/railtie"
and these lines in features/support/env.rb:
require 'cucumber/rails/active_record'
Cucumber::Rails::World.use_transactional_fixtures = true
Get coding!
===============================================================================
README
puts readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.