Top Level Namespace

Defined Under Namespace

Modules: Tennpipes

Constant Summary collapse

OHM =
(<<-OHM) unless defined?(OHM)
# Ohm does not have the concept of namespaces.
# This means that you will not be able to have
# a distinct test, development, or production database.
#
# You can, however, run multiple redis servers on the same host
# and point to them based on the environment:
#
# case Tennpipes.env
#  when :development then Ohm.connect(:port => 6379)
#  when :production then Ohm.connect(:port => 6380)
#  when :test then Ohm.connect(:port => 6381)
# end

# Alternatively, you can try specifying a difference :db
# which, outside of confirmation, appears to provide distinct
# namespaces from testing:
# case Tennpipes.env
#  when :development then Ohm.connect(:db => 0)
#  when :production then Ohm.connect(:db => 1)
#  when :test then Ohm.connec
OHM_MODEL =
(<<-MODEL) unless defined?(OHM_MODEL)
class !NAME! < Ohm::Model
# Examples:
# attribute :name
# attribute :email
# reference :venue, Venue
# set :participants, Person
# counter :votes
#
# index :name
#
# def validate
#   assert_present :name
RACK_ENV =

Defines our constants

ENV['RACK_ENV'] ||= 'development'
TENNPIPES_ROOT =
File.expand_path('../..', __FILE__)
RIOT_SETUP =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

# Specify your app using the #app helper inside a context.
# Takes either an app class or a block argument.
# app { Tennpipes.application }
# app { CLASS_NAME.tap { |app| } }

class Riot::Situation
  include Rack::Test::Methods

  # You can use this method to custom specify a Rack app
  # you want rack-test to invoke:
  #
  #   app CLASS_NAME
  #   app CLASS_NAME.tap { |a| }
  #   app(CLASS_NAME) do
  #     set :foo, :bar
  #   end
  #
  def app(app = nil, &blk)
    @app ||= block_given? ? app.instance_eval(&blk) : app
    @app ||= Tennpipes.application
  end
end

c
RIOT_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

context "!PATH!" do
  context "description here" do
setup do
  get "!EXPANDED_PATH!"
end

asserts("the response body") { last_response.body
RIOT_RAKE =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
  Rake::TestTask.new("test:\#{folder}") do |test|
    test.pattern = "test/\#{folder}/**/*_test.rb"
    test.verbose = true
  end
end

desc "Run application test suite"
task 'test' => test_tasks.ma
RIOT_MODEL_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

context "!NAME! Model" do
  context 'can be created' do
setup do
  !NAME!.new
end

asserts("that record is not nil
RIOT_HELPER_TEST =
(<<-TEST) unless defined?(RIOT_HELPER_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

describe "!NAME!" do
setup do
  helpers = Class.new
  helpers.extend !NAME!
  [helpers.foo]
end

asserts("
RIPPLE_DB =
(<<-RIAK) unless defined?(RIPPLE_DB)
development:
http_port: 8098
pb_port: 8087
host: localhost

# The test environment has additional keys for configuring the
# Riak::TestServer for your test/spec suite:
#
# * bin_dir specifies the path to the "riak" script that you use to
#           start Riak (just the directory)
# * js_source_dir specifies where your custom Javascript functions for
#           MapReduce should be loaded from. Usually app/mapreduce.
test:
http_port: 9000
pb_port: 9002
host: localhost
bin_dir: /usr/local/bin   # Default for Homebrew.
js_source_dir: <%%= Tennpipes.root + "app/mapreduce" %>

production:
http_port: 8098
pb_port:
RIPPLE_CFG =
(<<RIAK) unless defined?(RIPPLE_CFG)
# encoding: utf-8

require 'ripple'

if File.exist?(Tennpipes.root + "config/riak.yml")
Ripple.load_configuration Tennpipes.root.join('config', 'riak.yml
RIPPLE_MODEL =
(<<-MODEL) unless defined?(RIPPLE_MODEL)
# encoding: utf-8

class !NAME!
include Ripple::Document

# Standart properties
# property :name, String
!FIELDS!

# Relations
# many :addresses
# many :friends, :class_name => "Perso
SEQUEL =
(<<-SEQUEL) unless defined?(SEQUEL)
Sequel::Model.plugin(:schema)
Sequel::Model.raise_on_save_failure = false # Do not throw exceptions on failure
Sequel::Model.db = case Tennpipes.env
when :development then Sequel.connect(!DB_DEVELOPMENT!, :loggers => [logger])
when :production  then Sequel.connect(!DB_PRODUCTION!,  :loggers => [logger])
when :test        then Sequel.connect(!DB_TEST!,        :loggers
SQ_MODEL =
(<<-MODEL) unless defined?(SQ_MODEL)
class !NAME!
SQ_MIGRATION =
(<<-MIGRATION) unless defined?(SQ_MIGRATION)
Sequel.migration do
up do
  !UP!
end

down do
SQ_MODEL_UP_MG =
(<<-MIGRATION).gsub(/^/, '    ') unless defined?(SQ_MODEL_UP_MG)
create_table :!TABLE! do
primary_
SQ_MODEL_DOWN_MG =
(<<-MIGRATION) unless defined?(SQ_MODEL_DOWN
SQ_CHANGE_MG =
(<<-MIGRATION).gsub(/^/, '    ') unless defined?(SQ_CHANGE_MG)
alter_table :!TABLE
BACON_SETUP =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

class Bacon::Context
include Rack::Test::Methods
end

# You can use this method to custom specify a Rack app
# you want rack-test to invoke:
#
#   app CLASS_NAME
#   app CLASS_NAME.tap { |a| }
#   app(CLASS_NAME) do
#     set :foo, :bar
#   end
#
def app(app = nil, &blk)
@app ||= block_given? ? app.instance_eval(&blk) : app
@app ||= T
BACON_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

describe "!PATH!" do
  it 'returns text at root' do
get "!EXPANDED_PATH!"
last_response.bo
BACON_RAKE =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
  Rake::TestTask.new("test:\#{folder}") do |test|
    test.pattern = "test/\#{folder}/**/*_test.rb"
    test.verbose = true
  end
end

desc "Run application test suite"
task 'test' => test_tasks.m
BACON_MODEL_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

describe "!NAME! Model" do
  it 'can be created' do
@!DNAME! = !NAME!.new
@!DNAME
BACON_HELPER_TEST =
<<-TEST unless defined?(BACON_HELPER_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

describe "!NAME!" do
  before do
@helpers = Class.new
@helpers.extend !NAME!
  end

  it "should return nil" do
@helpers.
RSPEC_SETUP =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

RSpec.configure do |conf|
conf.include Rack::Test::Methods
end

# You can use this method to custom specify a Rack app
# you want rack-test to invoke:
#
#   app CLASS_NAME
#   app CLASS_NAME.tap { |a| }
#   app(CLASS_NAME) do
#     set :foo, :bar
#   end
#
def app(app = nil, &blk)
@app ||= block_given? ? app.instance_eval(&blk) : app
@app ||= T
RSPEC_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_CONTROLLER_TEST)
require 'spec_helper'

RSpec.describe "!PATH!" do
  pending "add some examples to \#{__FILE__}" do
    before do
get "!EXPANDED_PATH!"
    end

    it "returns hello world" do
expect(last_response.body).to
RSPEC_RAKE =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
begin
require 'rspec/core/rake_task'

spec_tasks = Dir['spec/*/'].each_with_object([]) do |d, result|
  result << File.basename(d) unless Dir["\#{d}*"].empty?
end

spec_tasks.each do |folder|
  desc "Run the spec suite in \#{folder}"
  RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
    t.pattern = "./spec/\#{folder}/**/*_spec.rb"
    t.rspec_opts = "--color"
  end
end

desc "Run complete application spec suite"
task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
rescue LoadError
puts "RSpec is not part of this b
RSPEC_MODEL_TEST =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
require 'spec_helper'

RSpec.describe !NAME! do
pending "add some examples to
RSPEC_HELPER_TEST =
(<<-TEST) unless defined?(RSPEC_HELPER_TEST)
require 'spec_helper'

RSpec.describe "!NAME!" do
  pending "add some examples to (or delete) \#{__FILE__}" do
    let(:helpers){ Class.new }
    before { helpers.extend !NAME! }
    subject { helpers }

    it "should return nil" do
expect(subject.fo
STEAK_SETUP =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

RSpec.configure do |conf|
conf.include Rack::Test::Methods
conf.include Capybara
end

def app
##
# You can handle all tennpipes applications using instead:
#   Tennpipes.application
CLASS_NAME.tap { |app|  }
STEAK_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_TEST)
require 'spec_helper'

describe "!PATH!" do
  before do
get "!EXPANDED_PATH!"
  end

  it "returns hello world" do
last_response.body
STEAK_CONTROLLER_ACCEPTANCE_TEST =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_ACCEPTANCE_TEST)
require 'spec_helper'

feature "!PATH!" do
  background do
visit "!EXPANDED_PATH!"
  end

  scenario "returns hello world" do
page.s
STEAK_RAKE =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_RAKE)
require 'rspec/core/rake_task'

spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }

spec_tasks.each do |folder|
  RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
    t.pattern = "./spec/\#{folder}/**/*_spec.rb"
    t.rspec_opts = %w(-fs --color)
  end
end

desc "Run complete application spec suite"
task 'spec' => spec_tasks.m
STEAK_MODEL_TEST =
(<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_MODEL_TEST)
require 'spec_he
STEAK_HELPER_TEST =
<<-TEST unless defined?(STEAK_HELPER_TEST)
require 'spec_helper'

describe "!NAME!" do
  let(:helpers){ Class.new }
  before { helpers.extend !NAME! }
  subject { helpers }

  it "should return nil" do
expect(su
MONGOID =
(<<-MONGO) unless defined?(MONGOID)
# Connection.new takes host and port
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT

database_name = case Tennpipes.env
  when :development then '!NAME!_development'
  when :production  then '!NAME!_production'
  when :test        then '!NAME!_test'
end

Mongoid.database = Mongo::Connection.new(host, port).db(database_name)

# You can also configure Mongoid this way:
# Mongoid.configure do |config|
#   name = @settings["database"]
#   host = @settings["host"]
#   config.master = Mongo::Connection.new.db(name)
#   config.slaves = [
#     Mongo::Connection.new(host, @settings["slave_one"]["port"], :slave_ok => true).db(name),
#     Mongo::Connection.new(host, @settings["slave_two"]["port"], :slave_ok => true).db(name)
#   ]
# end
#
# More installation and setup notes are on h
MONGOID3 =
(<<-MONGO) unless defined?(MONGOID3)
# Connection.new takes host and port.

host = 'localhost'
port = 27017

database_name = case Tennpipes.env
  when :development then '!NAME!_development'
  when :production  then '!NAME!_production'
  when :test        then '!NAME!_test'
end

# Use MONGO_URI if it's set as an environmental variable.
Mongoid::Config.sessions =
  if ENV['MONGO_URI']
    {default: {uri: ENV['MONGO_URI'] }}
  else
    {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
  end

# If you want to use a YML file for config, use this instead:
#
#   Mongoid.load!(File.join(Tennpipes.root, 'config', 'database.yml'), Tennpipes.env)
#
# And add a config/database.yml file like this:
#   development:
#     sessions:
#       default:
#         database: !NAME!_development
#         hosts:
#           - localhost:27017
#   production:
#     sessions:
#       default:
#         database: !NAME!_production
#         hosts:
#           - localhost:27017
#   test:
#     sessions:
#       default:
#         database: !NAME!_test
#         hosts:
#           - localhost:27017
#
#
# More installation and setup notes are on http://mongoid.org/en/mongoid/docs/installatio
MONGOID_MODEL =
(<<-MODEL) unless defined?(MONGOID_MODEL)
class !NAME!
include Mongoid::Document
include Mongoid::Timestamps # adds created_at and updated_at fields

# field <name>, :type => <type>, :default => <value>
!FIELDS!

# You can define indexes on documents using the index macro:
# index :field <, :unique => true>

# You can create a composite key in mongoid to replace the default id using the key macro:
# key :field <, :another_f
DYNAMOID =
(<<-DYNAMOID) unless defined?(DYNAMOID)

AWS.config({
  :access_key_id => ENV['AWS_ACCESS_KEY'],
  :secret_access_key => ENV['AWS_SECRET_KEY'],
  :dynamo_db_endpoint => 'dynamodb.ap-southeast-1.amazonaws.com'
})

Dynamoid.configure do |config|
  config.adapter = 'aws_sdk' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
  config.read_capacity = 100 # Read capacity for your tables
  config.write_capacity = 20 # Write capacity for your tables
end

# If you use mock in testing [for example in case of using fake_dynamo],
# the way is as following:
#
#   - install fake_dynamo
#     gem install fake_dynamo --version 0.1.3
#   - run
#     fake_dynamo --port 4567
# 
# And then setting for AWS.config is as following:
# 
#   AWS.config({
#     :access_key_id => 'xxx', # everything is ok
#     :secret_access_key => 'xxx', # everything is ok
#     :dynamo_db_endpoint => 'localhost', # fake_dynamo runs hostname
#     :dynamo_db_port => 4567, # fake_dynamo listens port
#     :use_ssl => false # fake_dynamo don't speak ssl
#   })
#
# Additional information on https://github.com/ananthaku
DYNAMOID_MODEL =
(<<-MODEL) unless defined?(DYNAMOID_MODEL)
class !NAME!
include Dynamoid:
SHOULDA_SETUP =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

require "test/unit"

class Test::Unit::TestCase
  include Rack::Test::Methods

  # You can use this method to custom specify a Rack app
  # you want rack-test to invoke:
  #
  #   app CLASS_NAME
  #   app CLASS_NAME.tap { |a| }
  #   app(CLASS_NAME) do
  #     set :foo, :bar
  #   end
  #
  def app(app = nil, &blk)
@app ||= block_given? ? app.instance_eval(&blk) : app
@app ||= Tennp
SHOULDA_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

class !NAME!ControllerTest < Test::Unit::TestCase
  context "!NAME!Controller" do
    setup do
get '/'
    end

    should "return hello world text" do
assert_equal "Hello World",
SHOULDA_RAKE =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
  Rake::TestTask.new("test:\#{folder}") do |test|
    test.pattern = "test/\#{folder}/**/*_test.rb"
    test.verbose = true
  end
end

desc "Run application test suite"
task 'test' => test_tasks
SHOULDA_MODEL_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

class !NAME!Test < Test::Unit::TestCase
  context "!NAME! Model" do
    should 'construct new instance' do
@!DNAME! = !NAME!.new
assert_not
SHOULDA_HELPER_TEST =
(<<-TEST) unless defined?(SHOULDA_HELPER_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

class !NAME!Test < Test::Unit::TestCase
  context "!NAME!" do
    setup do
@helpers = Class.new
@helpers.extend !NAME!
    end

    should "return nil" do
assert_equal nil
COUCHREST =
(<<-COUCHREST) unless defined?(COUCHREST)
case Tennpipes.env
when :development then db_name = '!NAME!_development'
when :production  then db_name = '!NAME!_production'
when :test        then db_name = '!NAME!_test'
end

CouchRest::Model::Base.configure do |conf|
conf.model_type_key = 'type' # compatibility with CouchModel 1.1
conf.database = CouchRest.database!(db_name)
conf.environment = Tennpipes.env
# conf.connection = {
#   :protocol => 'http',
#   :host     => 'localhost',
#   :port     => '5984',
#   :prefix   => 'tennpipes',
#   :suffix   => nil,
#   :join     => '_',
#   :username => nil,
#   :password
CR_MODEL =
(<<-MODEL) unless defined?(CR_MODEL)
class !NAME! < CouchRest::Model::Base
unique_id :id
# property <
CUCUMBER_SETUP =
(<<-TEST) unless defined?(CUCUMBER_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

require 'capybara/cucumber'
require 'rspec/expectations'

##
# You can handle all tennpipes applications using instead:
#   Tennpipes.application
Capybara.app
CUCUMBER_YML =
(<<-TEST) unless defined?(CUCUMBER_YML)
default: --tags ~@wip --strict features
html_report: --tags ~@wip --strict --format html --out=feat
CUCUMBER_FEATURE =
(<<-TEST) unless defined?(CUCUMBER_FEATURE)
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scenario: Add two numbers
Given I visit the calculator page
And I fill in '50' for 'first'
And I fill in '70' for 'second'
When I press 'Add'
Th
CUCUMBER_STEP =
(<<-TEST) unless defined?(CUCUMBER_STEP)
Given /^I visit the calculator page$/ do
visit '/add'
end

Given /^I fill in '(.*)' for '(.*)'$/ do |value, field|
fill_in(field, :with => value)
end

When /^I press '(.*)'$/ do |name|
click_button(name)
end

Then /^I should see '(.*)'$/ do |text|
page.sho
CUCUMBER_URL =
(<<-TEST) unless defined?(CUCUMBER_URL)
module Cucumber
  module Web
    module URLs
      def url_for(*names)
        Capybara.app.url_for(*names)
      end
      alias_method :url, :url_for

      def absolute_url_for(*names)
        "http://www.example.com" + Capybara.app.url_for(*names)
      end
      alias_method :absolute_url, :absolute_url_for
    end
  end
end

W
MINITEST_SETUP =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_SETUP)
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))

class MiniTest::Spec
  include Rack::Test::Methods

  # You can use this method to custom specify a Rack app
  # you want rack-test to invoke:
  #
  #   app CLASS_NAME
  #   app CLASS_NAME.tap { |a| }
  #   app(CLASS_NAME) do
  #     set :foo, :bar
  #   end
  #
  def app(app = nil, &blk)
@app ||= block_given? ? app.instance_eval(&blk) : app
@app ||= Tenn
MINITEST_RAKE =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
  Rake::TestTask.new("test:\#{folder}") do |test|
    test.pattern = "test/\#{folder}/**/*_test.rb"
    test.verbose = true
  end
end

desc "Run application test suite"
task 'test' => test_task
MINITEST_CONTROLLER_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

describe "!PATH!" do
  before do
get "!EXPANDED_PATH!"
  end

  it "should return hello world text" do
assert_equal "Hello
MINITEST_MODEL_TEST =
(<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

describe "!NAME! Model" do
  it 'can construct a new instance' do
@!DNAME! = !NAME!.new
MINITEST_HELPER_TEST =
(<<-TEST) unless defined?(MINITEST_HELPER_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

describe "!NAME!" do
  before do
@helpers = Class.new
@helpers.extend !NAME!
  end

  def helpers
@helpers
  end

  it "should return nil" do
assert
DM =
(<<-DM) unless defined?(DM)
##
# A MySQL connection:
# DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name')
#
# # A Postgres connection:
# DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name')
#
# # A Sqlite3 connection
# DataMapper.setup(:default, "sqlite3://" + Tennpipes.root('db', "development.db"))
#
# # Setup DataMapper using config/database.yml
# DataMapper.setup(:default, YAML.load_file(Tennpipes.root('config/database.yml'))[RACK_ENV])
#
# config/database.yml file:
#
# ---
# development: &defaults
#   adapter: mysql
#   database: example_development
#   username: user
#   password: Pa55w0rd
#   host: 127.0.0.1
#
# test:
#   <<: *defaults
#   database: example_test
#
# production:
#   <<: *defaults
#   database: example_production
#

DataMapper.logger = logger
DataMapper::Property::String.length(255)

case Tennpipes.env
when :development then DataMapper.setup(:default, !DB_DEVELOPMENT!)
when :production  then DataMapper.setup(:default, !DB_PRODUCTION!)
when :test        then DataMapper.setup(:defaul
DM_MODEL =
(<<-MODEL) unless defined?(DM_MODEL)
class !NAME!
include DataMapper::Resource

# property <name>, <type>
property :id, S
DM_MIGRATION =
(<<-MIGRATION) unless defined?(DM_MIGRATION)
migration !VERSION!, :!FILENAME! do
up do
  !UP!
end

down do
DM_MODEL_UP_MG =
(<<-MIGRATION).gsub(/^/, '    ') unless defined?(DM_MODEL_UP_MG)
create_table :!TABLE! do
column :id, Integer, :serial
DM_MODEL_DOWN_MG =
(<<-MIGRATION) unless defined?(DM_MODEL_DOWN
DM_CHANGE_MG =
(<<-MIGRATION).gsub(/^/, '    ') unless defined?(DM_CHANGE_MG)
modify_table :!TABLE
MR =
(<<-MR) unless defined?(MR)
##
# You can use other adapters like:
#
#   ActiveRecord::Base.configurations[:development] = {
#     :adapter   => 'mysql2',
#     :encoding  => 'utf8',
#     :reconnect => true,
#     :database  => 'your_database',
#     :pool      => 5,
#     :username  => 'root',
#     :password  => '',
#     :host      => 'localhost',
#     :socket    => '/tmp/mysql.sock'
#   }
#
ActiveRecord::Base.configurations[:development] = {
!DB_DEVELOPMENT!
}

ActiveRecord::Base.configurations[:production] = {
!DB_PRODUCTION!
}

ActiveRecord::Base.configurations[:test] = {
!DB_TEST!
}

# Setup our logger.
ActiveRecord::Base.logger = logger

if ActiveRecord::VERSION::MAJOR.to_i < 4
  # Raise exception on mass assignment protection for Active Record models.
  ActiveRecord::Base.mass_assignment_sanitizer = :strict

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL).
  ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
end

# Doesn't include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = false

# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true

# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true

# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw JSON in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

# Now we can establish connection with our db.
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Tennpipes.env])

# Timestamps are in the utc by default.
ActiveRecord::Base.defaul
MYSQL =
(<<-MYSQL) unless defined?(MYSQL)
:adapter   => 'mysql',
:encoding  => 'utf8',
:reconnect => true,
:database  => !DB_NAME!,
:pool      => 5,
:username  => 'root',
:password  => '',
:host      => 'localhost',
:socket    =>
MYSQL2 =
(<<-MYSQL2) unless defined?(MYSQL2)
:adapter   => 'mysql2',
:encoding  => 'utf8',
:reconnect => true,
:database  => !DB_NAME!,
:pool      => 5,
:username  => 'root',
:password  => '',
:host      => 'localhost',
:socket    =>
POSTGRES =
(<<-POSTGRES) unless defined?(POSTGRES)
:adapter   => 'postgresql',
:database  => !DB_NAME!,
:username  => 'root',
:password  => '',
:host      => 'localhost',
:
SQLITE =
(<<-SQLITE) unless defined?(SQLITE)
:adapter => 'sqlite3',
:data
CONNECTION_POOL_MIDDLEWARE =
<<-MIDDLEWARE
class ConnectionPoolManagement
  def initialize(app)
    @app = app
  end

  def call(env)
    ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
  end
end
MIDDLEWARE
MR_MODEL =
(<<-MODEL) unless defined?(MR_MODEL)
class !NAME! < ActiveRecord::Base
# F
MONGOMATIC =
(<<-MONGO) unless defined?(MONGOMATIC)

case Tennpipes.env
when :development then Mongomatic.db = Mongo::Connection.new.db("!NAME!_development")
when :production then Mongomatic.db = Mongo::Connection.new.db("!NAME!_production")
when :test then Mongomatic.db = Mongo::Connection.new
MONGOMATIC_MODEL =
(<<-MODEL) unless defined?(MONGOMATIC_MODEL)
class !NAME! < Mongomatic::Base
  include Mongomatic::Expectations::Helper

  # Mongomatic does not have the traditional
  # model definition that AR/MM/DM et. al. have.
  # Staying true to the "ad-hoc" nature of MongoDB,
  # there are no explicit column definitions in the
  # model file.

  # However you can "fake it" by making a column
  # required using expectations
  # For the sake of tennpipes g model,
  # we'll assume that any property defined
  # on the command-line is required
  # In the case of Integer types, we'll add
  # the expectation: be_a_number
  # Future enhancement may allow a regex for
  # String datatypes


  # Examples:
  # def validate
  #   expectations do
  #     be_present self['name'], "Name cannot be blank"
  #     be_present self['email'], "Email cannot be blank"
  #     be_present self['age'], "Age cannot be blank"
  #     be_present self['password'], "Password cannot be blank"
  #     be_a_number self['age'], "Age must be a number"
  #     be_of_length self['password'], "Password must be at least 8 characters", :minimum => 8
  #   end
  # end

  # def create_indexes
  #   self.collection.create_index('name', :unique => true)
  #   self.collection.create_index('email', :unique => true)
  #   self.collection.create_index('age')
  # end
  def validate
    expectations do
!FIELDS!
!
MONGO =
(<<-MONGO) unless defined?(MONGO)
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)

case Tennpipes.env
when :development then MongoMapper.database = '!NAME!_development'
when :production  then MongoMapper.database = '!NAME!_production'
when :test        then MongoMapper.database =
MM_MODEL =
(<<-MODEL) unless defined?(MM_MODEL)
class !NAME!
include MongoMapper::Document

# key <name>, <type>
!FIELD
LESS_INIT =
<<-LESS unless defined?(LESS_INIT)
    # Enables support for Less template reloading for rack.
    # Store Less files by default within 'app/stylesheets/'.
    # See http://github.com/kelredd/rack-less for more details.
    require 'rack/less'
    # optional - use as necessary
    Rack::Less.configure do |config|
config.compress = true
# config.cache = true
# other configs ...
    end
    app.use Rack::Less,
:root      => Tennpipes.root,
:source    => 'app/stylesheets',
:public    => 'public',
:host
SASS_INIT =
<<-SASS unless defined?(SASS_INIT)
# Enables support for SASS template reloading in rack applications.
# See http://nex-3.com/posts/88-sass-supports-rack for more details.
# Store SASS files (by default) within 'app/stylesheets'.
require 'sass/plugin/rack'
Sass::Plugin.options[:template_location] = Tennpipes.root("app/stylesheets")
Sass::Plugin.options[:css_location] = Tennpipes.root("public/stylesheets")
app.
SCSS_INIT =
<<-SCSS unless defined?(SCSS_INIT)
# Enables support for SCSS template reloading in rack applications.
# See http://nex-3.com/posts/88-sass-supports-rack for more details.
# Store SCSS files (by default) within 'app/stylesheets'.
require 'sass/plugin/rack'
Sass::Plugin.options[:syntax] = :scss
Sass::Plugin.options[:template_location] = Tennpipes.root("app/stylesheets")
Sass::Plugin.options[:css_location] = Tennpipes.root("public/stylesheets")
app.
AR =
(<<-AR) unless defined?(AR)
##
# You can use other adapters like:
#
#   ActiveRecord::Base.configurations[:development] = {
#     :adapter   => 'mysql2',
#     :encoding  => 'utf8',
#     :reconnect => true,
#     :database  => 'your_database',
#     :pool      => 5,
#     :username  => 'root',
#     :password  => '',
#     :host      => 'localhost',
#     :socket    => '/tmp/mysql.sock'
#   }
#
ActiveRecord::Base.configurations[:development] = {
!DB_DEVELOPMENT!
}

ActiveRecord::Base.configurations[:production] = {
!DB_PRODUCTION!
}

ActiveRecord::Base.configurations[:test] = {
!DB_TEST!
}

# Setup our logger
ActiveRecord::Base.logger = logger

if ActiveRecord::VERSION::MAJOR.to_i < 4
  # Raise exception on mass assignment protection for Active Record models.
  ActiveRecord::Base.mass_assignment_sanitizer = :strict

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL).
  ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
end

# Doesn't include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = false

# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true

# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true

# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw JSON in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

# Now we can establish connection with our db.
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Tennpipes.env])

# Timestamps are in the utc by default.
ActiveRecord::Base.defaul
AR_MODEL =
(<<-MODEL) unless defined?(AR_MODEL)
class !NAME! < Act
AR_MIGRATION =
(<<-MIGRATION) unless defined?(AR_MIGRATION)
class !FILECLASS! < ActiveRecord::Migration
def self.up
  !UP!
end

def self.down
AR_MODEL_UP_MG =
(<<-MIGRATION).gsub(/^/,'    ') unless defined?(AR_MODEL_UP_MG)
create_table :!TABLE! do |t|
!FIEL
AR_MODEL_DOWN_MG =
(<<-MIGRATION) unless defined?(AR_MODEL_DOWN
AR_CHANGE_MG =
(<<-MIGRATION).gsub(/^/, '    ') unless defined?(AR_CHANGE_MG)
change_table :!TABLE! do
COMPASS_INIT =
<<-COMPASS unless defined?(COMPASS_INIT)
# Enables support for Compass, a stylesheet authoring framework based on SASS.
# See http://compass-style.org/ for more details.
# Store Compass/SASS files (by default) within 'app/stylesheets'.

module CompassInitializer
  def self.registered(app)
require 'sass/plugin/rack'

Compass.configuration do |config|
  config.project_path = Tennpipes.root
  config.sass_dir = "app/stylesheets"
  config.project_type = :stand_alone
  config.http_path = "/"
  config.css_dir = "public/stylesheets"
  config.images_dir = "public/images"
  config.javascripts_dir = "public/javascripts"
  config.output_style = :compressed
end

Compass.configure_sass_plugin!
Compass.handle_configuration_change!

app.use Sass::
COMPASS_REGISTER =
<<-COMPASSR unless defined?(COMPASS_REGISTER)
regi

Instance Method Summary collapse

Instance Method Details

#catch_error(type, error, config) ⇒ Object



340
341
342
343
344
345
346
347
348
349
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 340

def catch_error(type, error, config)
  $stderr.puts *(error.backtrace)
  $stderr.puts error.inspect
  case type
  when :create
    $stderr.puts "Couldn't create database for #{config.inspect}"
  when :drop
    $stderr.puts "Couldn't drop #{config[:database]}"
  end
end

#create_migration_file(migration_name, name, columns) ⇒ Object



63
64
65
# File 'lib/tennpipes-init/generators/components/orms/ohm.rb', line 63

def create_migration_file(migration_name, name, columns)
  # NO MIGRATION NEEDED
end

#create_model_file(name, options = {}) ⇒ Object

options => { :fields => [“title:string”, “body:string”], :app => ‘app’ }



50
51
52
53
54
55
56
57
# File 'lib/tennpipes-init/generators/components/orms/ohm.rb', line 50

def create_model_file(name, options={})
    model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
    field_tuples = options[:fields].map { |value| value.split(":") }
    column_declarations = field_tuples.map { |field, kind| "attribute :#{field}" }.join("\n  ")
    model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
    model_contents.gsub!(/!FIELDS!/, column_declarations)
    create_file(model_path, model_contents)
end

#create_model_migration(migration_name, name, columns) ⇒ Object



59
60
61
# File 'lib/tennpipes-init/generators/components/orms/ohm.rb', line 59

def create_model_migration(filename, name, fields)
  # NO MIGRATION NEEDED
end

#drop_database(config) ⇒ Object



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 314

def drop_database(config)
  case config[:adapter]
  when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
    ActiveRecord::Base.establish_connection(config)
    ActiveRecord::Base.connection.drop_database config[:database]
  when /^sqlite/
    require 'pathname'
    path = Pathname.new(config[:database])
    file = path.absolute? ? path.to_s : Tennpipes.root(path)

    FileUtils.rm(file)
  when 'postgresql'
    ActiveRecord::Base.establish_connection(config.merge(:database => 'postgres', :schema_search_path => 'public'))
    ActiveRecord::Base.connection.drop_database config[:database]
  end
end

#dump_schemaObject



364
365
366
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 364

def dump_schema
  Rake::Task["ar:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end

#firebird_db_string(config) ⇒ Object



336
337
338
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 336

def firebird_db_string(config)
  FireRuby::Database.db_string_for(config.symbolize_keys)
end

#generate_controller_test(name, path) ⇒ Object

Generates a controller test given the controllers name



94
95
96
97
98
# File 'lib/tennpipes-init/generators/components/tests/steak.rb', line 94

def generate_controller_test(name, path)
  riot_contents = RIOT_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
  create_file destination_root(controller_test_path), riot_contents, :skip => true
end

#generate_helper_test(name, project_name, app_name) ⇒ Object



112
113
114
115
116
117
# File 'lib/tennpipes-init/generators/components/tests/riot.rb', line 112

def generate_helper_test(name, project_name, app_name)
  riot_contents = RIOT_HELPER_TEST.gsub(/!NAME!/, "#{project_name}::#{app_name}::#{name}")
  riot_contents.gsub!(/!PATH!/, recognize_path)
  helper_spec_path = File.join('test', options[:app], 'helpers', "#{name.underscore}_test.rb")
  create_file destination_root(helper_spec_path), riot_contents, :skip => true
end

#generate_model_test(name) ⇒ Object



105
106
107
108
109
110
# File 'lib/tennpipes-init/generators/components/tests/riot.rb', line 105

def generate_model_test(name)
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
  riot_contents.gsub!(/!PATH!/, recognize_path)
  model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
  create_file destination_root(model_test_path), riot_contents, :skip => true
end

#migrate_as(type) ⇒ Object



351
352
353
354
355
356
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 351

def migrate_as(type)
  version = env_migration_version
  fail "MIGRATION_VERSION is required" unless version
  ActiveRecord::Migrator.run(type, "db/migrate/", version)
  dump_schema
end

#move_as(type) ⇒ Object



358
359
360
361
362
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 358

def move_as(type)
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
  ActiveRecord::Migrator.send(type, 'db/migrate/', step)
  dump_schema
end

#resolve_structure_sqlObject



368
369
370
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 368

def resolve_structure_sql
  "#{Tennpipes.root}/db/#{Tennpipes.env}_structure.sql"
end

#set_firebird_env(config) ⇒ Object



331
332
333
334
# File 'lib/tennpipes-init/tennpipes-tasks/activerecord.rb', line 331

def set_firebird_env(config)
  ENV["ISC_USER"]     = config[:username].to_s if config[:username]
  ENV["ISC_PASSWORD"] = config[:password].to_s if config[:password]
end

#setup_mockObject



1
2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/tennpipes-init/generators/components/mocks/rr.rb', line 1

def setup_mock
  require_dependencies 'rr', :require => false, :group => 'test'
  case options[:test].to_s
    when 'rspec'
      inject_into_file 'spec/spec_helper.rb', "require 'rr'\n", :after => "\"/../config/boot\")\n"
    when 'riot'
      inject_into_file "test/test_config.rb","require 'riot/rr'\n", :after => "\"/../config/boot\")\n"
    when 'minitest'
      insert_mocking_include "RR::Adapters::MiniTest", :path => "test/test_config.rb"
    else
      insert_mocking_include "RR::Adapters::TestUnit", :path => "test/test_config.rb"
  end
end

#setup_ormObject



25
26
27
28
# File 'lib/tennpipes-init/generators/components/orms/ohm.rb', line 25

def setup_orm
  require_dependencies 'ohm', :version => "~> 1.3.0"
  create_file("config/database.rb", OHM)
end

#setup_rendererObject



1
2
3
# File 'lib/tennpipes-init/generators/components/renderers/erb.rb', line 1

def setup_renderer
  require_dependencies 'erubis', :version => "~> 2.7.0"
end

#setup_scriptObject



1
2
3
4
5
6
7
8
9
10
# File 'lib/tennpipes-init/generators/components/scripts/dojo.rb', line 1

def setup_script
  begin
    get('https://raw.github.com/tennpipes/tennpipes-static/master/js/dojo.js',  destination_root("/public/javascripts/dojo.js"))
    get('https://raw.github.com/tennpipes/tennpipes-static/master/ujs/dojo.js', destination_root("/public/javascripts/dojo-ujs.js"))
  rescue
    copy_file('templates/static/js/dojo.js',  destination_root("/public/javascripts/dojo.js"))
    copy_file('templates/static/ujs/dojo.js', destination_root("/public/javascripts/dojo-ujs.js"))
  end
  create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
end

#setup_stylesheetObject



19
20
21
22
23
24
25
# File 'lib/tennpipes-init/generators/components/stylesheets/less.rb', line 19

def setup_stylesheet
  require_dependencies 'less'
  require_dependencies 'rack-less'
  require_dependencies 'therubyracer'
  initializer :less, LESS_INIT
  empty_directory destination_root('/app/stylesheets')
end

#setup_testObject



92
93
94
95
96
97
# File 'lib/tennpipes-init/generators/components/tests/riot.rb', line 92

def setup_test
  require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
  require_dependencies 'riot', :group => 'test'
  insert_test_suite_setup RIOT_SETUP
  create_file destination_root("test/test.rake"), RIOT_RAKE
end