public
Fork of lazyatom/engines
Description: The Rails Engines plugin
Homepage: http://rails-engines.org
Clone URL: git://github.com/tekkub/engines.git
Refactored the test rake tasks - seems to be working now
lazyatom (author)
Sun Apr 20 03:52:46 -0700 2008
commit  2f1d168a10ea77a0cdfa4b1db72e8293760858da
tree    7d39df48c75c1cc4be360db823af0b1ccaf1e1d6
parent  bdd08cc5f13fb6a7e3d4f118de8ffb99e40ac795
...
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
 
 
 
 
 
 
...
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
 
 
 
 
 
 
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
129
130
131
132
133
134
135
136
137
138
 
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
 
 
 
 
 
 
 
156
157
158
 
 
159
160
161
162
163
164
165
0
@@ -36,75 +36,129 @@ namespace :test do
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
+
0
+ task :clean do
0
+ FileUtils.rm_r(test_app_dir) if File.exist?(test_app_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
+ 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
+
0
+ # offline fix for getting rails
0
+ vendor_dir = File.join(test_app_dir, 'vendor')
0
+ FileUtils.mkdir_p vendor_dir
0
+ system "cd #{vendor_dir} && ln -s /Users/james/Code/rails/git/rails rails"
0
+ system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+
0
+ # get the database config and schema in place
0
+ require 'yaml'
0
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
+ f.write({
0
+ "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
+ "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
+ }.to_yaml)
0
     end
0
+ FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
+ File.join(test_app_dir, 'db'))
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
+ # We can't link the plugin, as it needs to be present for script/generate to find
0
+ # the plugin generator.
0
+ # TODO: find and +1/create issue for loading generators from symlinked plugins
0
+ desc 'Mirror the engines plugin into the test application'
0
+ task :copy_engines_plugin do
0
+ engines_plugin = File.join(test_app_dir, "vendor", "plugins", "engines")
0
+ FileUtils.rm_r(engines_plugin) if File.exist?(engines_plugin)
0
+ FileUtils.mkdir_p(engines_plugin)
0
+ FileList["*"].exclude("test_app").each do |file|
0
+ FileUtils.cp_r(file, engines_plugin)
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
+ # desc 'Ensure helper methods used by the engines plugin test suite are available'
0
+ # task :append_engines_test_helper do
0
+ # engines_test_helper_line = "require 'engines_test_helper'"
0
+ #
0
+ # test_helper_rb = File.join(test_app_dir, "test", "test_helper.rb")
0
+ # test_helper_lines = File.readlines(test_helper_rb)
0
+ #
0
+ # return if test_helper_lines.include?(engines_test_helper_line)
0
+ #
0
+ # test_helper_lines << engines_test_helper_line
0
+ # File.open(test_helper_rb, 'w') { |f| f.write test_helper_lines }
0
+ # end
0
+ #
0
+ # desc 'Add the engines bootstrap line to the environment.rb file if it is missing'
0
+ # task :insert_engines_boot_loader_line do
0
+ # engines_boot_line = "require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')"
0
+ #
0
+ # environment_rb_file = File.join(test_app_dir, 'config', 'environment.rb')
0
+ # environment_rb_lines = File.readlines(environment_rb_file)
0
+ # return if environment_rb_lines.include?(engines_boot_line)
0
+ #
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, engines_boot_line + "\n\n")
0
+ # File.open(environment_rb_file, 'w') { |f| f.write environment_rb_lines }
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
+ def insert_line(line, options)
0
+ line = line + "\n"
0
+ target_file = File.join(test_app_dir, options[:into])
0
+ lines = File.readlines(target_file)
0
+ return if lines.include?(line)
0
+
0
+ if options[:after]
0
+ if options[:after].is_a?(String)
0
+ after_line = options[:after] + "\n"
0
+ else
0
+ after_line = lines.find { |l| l =~ options[:after] }
0
+ raise "couldn't find a line matching #{options[:after].inspect} in #{target_file}" unless after_line
0
+ end
0
+ index = lines.index(after_line)
0
+ raise "couldn't find line '#{after_line}' in #{target_file}" unless index
0
+ lines.insert(index + 1, line)
0
     else
0
- system "rails #{test_app_dir}"
0
+ lines << line
0
     end
0
+ File.open(target_file, 'w') { |f| f.write lines.join }
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
- task :prepare_app do
0
+ desc 'Update the plugin and tests files in the test application from the plugin'
0
+ task :mirror_engine_files => [:copy_engines_plugin] do
0
+
0
+ insert_line("require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')",
0
+ :into => 'config/environment.rb',
0
+ :after => "require File.join(File.dirname(__FILE__), 'boot')")
0
+
0
+ insert_line('map.from_plugin :test_routing', :into => 'config/routes.rb',
0
+ :after => /\AActionController::Routing::Routes/)
0
+
0
+ insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')
0
+
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
0
+ task :prepare => [:clean, :generate_app, :mirror_engine_files]
0
+end
0
+
0
+task :test => "test:prepare" do
0
+ exec("cd #{test_app_dir} && rake db:schema:load && rake")
0
+end

Comments

    No one has commented yet.