3
# test-mongodb-generate.sh - Generates a rails project for testing MongoDB
5
# Copyright (C) 2011 Canonical
8
# Marc Cluet <marc.cluet@canonical.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU Affero General Public License as
12
# published by the Free Software Foundation, version 3 of the License.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
# Create a rails 3.0 project under the test_mongodb link
23
echo " * Creating new Rails project test_mongodb"
24
rails new test_mongodb --skip-active-record
27
echo " * Adding mongodb_mapper"
30
gem 'rails3-generators'
33
echo " * Building bundle"
36
echo " * Generating extra code"
37
cat >> config/initializers/mongo.rb << EOF
38
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
39
MongoMapper.database = "#myapp-#{Rails.env}"
41
if defined?(PhusionPassenger)
42
PhusionPassenger.on_event(:starting_worker_process) do |forked|
43
MongoMapper.connection.connect if forked
48
mv -f config/application.rb config/application.rb.old
49
cat config/application.rb.old | sed s'/ end/ config.generators do |g|\n g.fixture_replacement :factory_girl\n g.orm :mongo_mapper\n end\n end/' > config/application.rb
51
echo " * Generating model for basic Rails application"
52
rails generate scaffold Account user_name:string description:string active:boolean birthday:date
54
echo " * Making default homepage our newly created project"
55
mv -f config/routes.rb config/routes.rb.old
56
cat config/routes.rb.old | sed 's/# root :to => "welcome#index"/root :to => "Accounts#index"/' > config/routes.rb
57
rm -f public/index.html
59
echo " * Pushing application to CloudFoundry"