public
Fork of lazyatom/engines
Description: The Rails Engines plugin
Homepage: http://rails-engines.org
Clone URL: git://github.com/tekkub/engines.git
We should be able to generate the test application from the plugin itself.
lazyatom (author)
Fri Apr 18 16:04:03 -0700 2008
commit  bdd08cc5f13fb6a7e3d4f118de8ffb99e40ac795
tree    3f3cb9e797385622f9e3f68ed1f1141dc775e355
parent  8aaef7e81bf96a15e5e4f624eeb7b14601887c89
...
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
0
@@ -29,4 +29,82 @@ task :cruise do
0
   ['db:migrate', 'test', 'test:plugins'].each do |t|
0
     Rake::Task[t].invoke
0
   end
0
+end
0
+
0
+namespace :test do
0
+
0
+ def test_app_dir
0
+ File.join(File.dirname(__FILE__), 'test_app')
0
+ end
0
+
0
+ def mirror_test_files(src, dest=nil)
0
+ destination_dir = File.join(*([test_app_dir, dest].compact))
0
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', src), destination_dir)
0
+ end
0
+
0
+ def append_engines_test_helper
0
+ File.open(File.join(test_app_dir, *%w[test test_helper.rb]), 'a') do |f|
0
+ f.puts # a blank line
0
+ f.puts "require 'engines_test_helper'"
0
+ end
0
+ end
0
+
0
+ def link_engines_plugin
0
+ system "ln -s #{File.expand_path(File.dirname(__FILE__))} #{test_app_dir}/vendor/plugins/engines"
0
+ end
0
+
0
+ def insert_engines_boot_loader_line
0
+ environment_rb_file = File.join(test_app_dir, 'config', 'environment.rb')
0
+ environment_rb_lines = File.readlines(environment_rb_file)
0
+ first_initializer_line = environment_rb_lines.find { |line| line =~ /\ARails::Initializer/ }
0
+ index = environment_rb_lines.index(first_initializer_line)
0
+ environment_rb_lines.insert(index, "require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')\n")
0
+ File.open(environment_rb_file, 'w') { |f| f.write environment_rb_lines.join("\n") }
0
+ end
0
+
0
+ def create_database_yml
0
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
+ f.write <<-YML
0
+development:
0
+ adapter: sqlite3
0
+ database: engines_development.sqlite3
0
+test:
0
+ adapter: sqlite3
0
+ database: engines_test.sqlite3
0
+ YML
0
+ end
0
+ end
0
+
0
+ task :clean do
0
+ FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
0
+ end
0
+
0
+ task :generate_app do
0
+ if ENV['edge']
0
+ vendor_dir = File.join(test_app_dir, 'vendor')
0
+ FileUtils.mkdir_p vendor_dir
0
+ system "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
0
+ system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ else
0
+ system "rails #{test_app_dir}"
0
+ end
0
+ end
0
+
0
+ task :prepare_app do
0
+ mirror_test_files('app')
0
+ mirror_test_files('lib')
0
+ mirror_test_files('plugins', 'vendor')
0
+ mirror_test_files('unit', 'test')
0
+ mirror_test_files('functional', 'test')
0
+ append_engines_test_helper
0
+ link_engines_plugin
0
+ insert_engines_boot_loader_line
0
+ create_database_yml
0
+ FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
+ File.join(test_app_dir, 'db'))
0
+ system "cd #{test_app_dir} && rake db:schema:load"
0
+ end
0
+
0
+ desc 'Prepare the engines test environment'
0
+ task :prepare => [:clean, :generate_app, :prepare_app]
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.