~lynxman/+junk/ruby-vmc-rorgenerators

« back to all changes in this revision

Viewing changes to debian/examples/ruby/rails/test-mongodb-generate.sh

  • Committer: Marc Cluet
  • Date: 2011-08-05 19:13:59 UTC
  • Revision ID: marc.cluet@ubuntu.com-20110805191359-nlpgjremf9fibv6y
* Added new Ruby on Rails generator examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#    test-mongodb-generate.sh - Generates a rails project for testing MongoDB
 
4
#
 
5
#    Copyright (C) 2011 Canonical
 
6
#
 
7
#    Authors:
 
8
#               Marc Cluet <marc.cluet@canonical.com>
 
9
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
 
 
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
 
25
 
 
26
cd test_mongodb
 
27
echo " * Adding mongodb_mapper"
 
28
cat >> Gemfile << EOF
 
29
gem 'mongo_mapper'
 
30
gem 'rails3-generators'
 
31
EOF
 
32
 
 
33
echo " * Building bundle"
 
34
bundle install
 
35
 
 
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}"
 
40
 
 
41
if defined?(PhusionPassenger)
 
42
   PhusionPassenger.on_event(:starting_worker_process) do |forked|
 
43
     MongoMapper.connection.connect if forked
 
44
   end
 
45
end
 
46
EOF
 
47
 
 
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
 
50
 
 
51
echo " * Generating model for basic Rails application"
 
52
rails generate scaffold Account user_name:string description:string active:boolean birthday:date
 
53
 
 
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
 
58
 
 
59
echo " * Pushing application to CloudFoundry"
 
60
vmc push
 
61
 
 
62
echo " * Done"
 
63
exit 0