muding 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  Dir["./lib/acts/*.rb"].sort.each { |ext| load ext.to_s }
2
2
 
3
- ActiveRecord::Base.establish_connection(YAML.load_file("config/database.yml")["development"])
4
3
 
5
4
  ActiveRecord::Base.send :include, Acts::Expireable
6
5
  ActiveRecord::Base.send :include, Acts::Container
@@ -24,7 +24,7 @@ module Muding
24
24
  unless default_command
25
25
  string_array = input.split(" ")
26
26
  command = string_array.shift
27
- args = string_array.to_s
27
+ args = string_array.join(" ")
28
28
  else
29
29
  command = default_command.to_s
30
30
  args = input
@@ -26,8 +26,8 @@ module Muding
26
26
  @source_root = options[:source] || File.join(spec.path, 'templates')
27
27
  if options[:destination]
28
28
  @destination_root = options[:destination]
29
- elsif defined? ::RAILS_ROOT
30
- @destination_root = ::RAILS_ROOT
29
+ elsif defined? ::MUDING_ROOT
30
+ @destination_root = ::MUDING_ROOT
31
31
  end
32
32
 
33
33
  # Silence the logger if requested.
@@ -101,7 +101,7 @@ module Muding
101
101
  # If no name is provided, the generator raises a usage error with content
102
102
  # optionally read from the USAGE file in the generator's base path.
103
103
  #
104
- # See Rails::Generator::Base for a discussion of Manifests and Commands.
104
+ # See Muding::Generator::Base for a discussion of Manifests and Commands.
105
105
  class NamedBase < Base
106
106
  attr_reader :name, :class_name, :singular_name, :plural_name, :table_name
107
107
  attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth
@@ -2,6 +2,7 @@ require 'delegate'
2
2
  require 'optparse'
3
3
  require 'fileutils'
4
4
  require 'erb'
5
+ require 'version'
5
6
 
6
7
  module Muding
7
8
  module Generator
@@ -23,14 +24,14 @@ module Muding
23
24
  end
24
25
 
25
26
 
26
- # Generator commands delegate Rails::Generator::Base and implement
27
+ # Generator commands delegate Muding::Generator::Base and implement
27
28
  # a standard set of actions. Their behavior is defined by the way
28
29
  # they respond to these actions: Create brings life; Destroy brings
29
30
  # death; List passively observes.
30
31
  #
31
32
  # Commands are invoked by replaying (or rewinding) the generator's
32
- # manifest of actions. See Rails::Generator::Manifest and
33
- # Rails::Generator::Base#manifest method that generator subclasses
33
+ # manifest of actions. See Muding::Generator::Manifest and
34
+ # Muding::Generator::Base#manifest method that generator subclasses
34
35
  # are required to override.
35
36
  #
36
37
  # Commands allows generators to "plug in" invocation behavior, which
@@ -133,7 +134,7 @@ module Muding
133
134
  class Create < Base
134
135
 
135
136
  # Check whether the given class names are already taken by
136
- # Ruby or Rails. In the future, expand to check other namespaces
137
+ # Ruby or Muding. In the future, expand to check other namespaces
137
138
  # such as the rest of the user's app.
138
139
  def class_collisions(*class_names)
139
140
  class_names.flatten.each do |class_name|
@@ -252,7 +253,7 @@ module Muding
252
253
  source == destination
253
254
  end
254
255
 
255
- # Generate a file for a Rails application using an ERuby template.
256
+ # Generate a file for a Muding application using an ERuby template.
256
257
  # Looks up and evalutes a template by name and writes the result.
257
258
  #
258
259
  # The ERB template uses explicit trim mode to best control the
@@ -321,7 +322,7 @@ module Muding
321
322
  # Thanks to Florian Gross (flgr).
322
323
  def raise_class_collision(class_name)
323
324
  message = <<end_message
324
- The name '#{class_name}' is reserved by Ruby on Rails.
325
+ The name '#{class_name}' is reserved by Muding.
325
326
  Please choose an alternative and run this generator again.
326
327
  end_message
327
328
  if suggest = find_synonyms(class_name)
@@ -43,6 +43,7 @@ class AppGenerator < Muding::Generator::Base
43
43
  #m.template "configs/routes.rb", "config/routes.rb"
44
44
  #m.template "configs/apache.conf", "public/.htaccess"
45
45
  m.file "configs/boot.rb", "config/boot.rb"
46
+ m.template "configs/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze] }
46
47
 
47
48
  # Environments
48
49
 
@@ -1,4 +1,4 @@
1
- class ControllerGenerator < Rails::Generator::NamedBase
1
+ class ControllerGenerator < Muding::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  # Check for class naming collisions.
@@ -1,4 +1,4 @@
1
- class MigrationGenerator < Rails::Generator::NamedBase
1
+ class MigrationGenerator < Muding::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  m.migration_template 'migration.rb', 'db/migrate'
@@ -1,4 +1,4 @@
1
- class ModelGenerator < Rails::Generator::NamedBase
1
+ class ModelGenerator < Muding::Generator::NamedBase
2
2
  default_options :skip_migration => false
3
3
 
4
4
  def manifest
@@ -4,7 +4,7 @@ class Object
4
4
  class << self
5
5
  # Lookup missing generators using const_missing. This allows any
6
6
  # generator to reference another without having to know its location:
7
- # RubyGems, ~/.rails/generators, and RAILS_ROOT/generators.
7
+ # RubyGems, ~/.muding/generators, and MUDING_ROOT/generators.
8
8
  def lookup_missing_generator(class_id)
9
9
  if md = /(.+)Generator$/.match(class_id.to_s)
10
10
  name = md.captures.first.demodulize.underscore
@@ -90,20 +90,20 @@ module Muding
90
90
  end
91
91
 
92
92
  # Use component generators (model, controller, etc).
93
- # 1. Rails application. If RAILS_ROOT is defined we know we're
94
- # generating in the context of a Rails application, so search
95
- # RAILS_ROOT/generators.
96
- # 2. User home directory. Search ~/.rails/generators.
93
+ # 1. muding application. If MUDING_ROOT is defined we know we're
94
+ # generating in the context of a muding application, so search
95
+ # MUDING_ROOT/generators.
96
+ # 2. User home directory. Search ~/.muding/generators.
97
97
  # 3. RubyGems. Search for gems named *_generator.
98
98
  # 4. Builtins. Model, controller, mailer, scaffold.
99
99
  def use_component_sources!
100
100
  reset_sources
101
- if defined? ::RAILS_ROOT
102
- sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators")
103
- sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
104
- sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/**/generators")
101
+ if defined? ::MUDING_ROOT
102
+ sources << PathSource.new(:lib, "#{::MUDING_ROOT}/lib/generators")
103
+ sources << PathSource.new(:vendor, "#{::MUDING_ROOT}/vendor/generators")
104
+ sources << PathSource.new(:plugins, "#{::MUDING_ROOT}/vendor/plugins/**/generators")
105
105
  end
106
- sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
106
+ sources << PathSource.new(:user, "#{Dir.user_home}/.muding/generators")
107
107
  sources << GemSource.new if Object.const_defined?(:Gem)
108
108
  sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components")
109
109
  end
@@ -51,15 +51,15 @@ module Muding
51
51
 
52
52
  usage << <<end_blurb
53
53
 
54
- More are available at http://rubyonrails.org/show/Generators
54
+ More are available at http://muding.rubyforge.org
55
55
  1. Download, for example, login_generator.zip
56
- 2. Unzip to directory #{Dir.user_home}/.rails/generators/login
57
- to use the generator with all your Rails apps
56
+ 2. Unzip to directory #{Dir.user_home}/.muding/generators/login
57
+ to use the generator with all your muding apps
58
58
  end_blurb
59
59
 
60
- if Object.const_defined?(:RAILS_ROOT)
60
+ if Object.const_defined?(:MUDING_ROOT)
61
61
  usage << <<end_blurb
62
- or to #{File.expand_path(RAILS_ROOT)}/generators/login
62
+ or to #{File.expand_path(MUDING_ROOT)}/generators/login
63
63
  to use with this app only.
64
64
  end_blurb
65
65
  end
@@ -0,0 +1,169 @@
1
+ namespace :db do
2
+ desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
3
+ task :migrate => :environment do
4
+ ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
5
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
6
+ end
7
+
8
+ namespace :fixtures do
9
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
10
+ task :load => :environment do
11
+ require 'active_record/fixtures'
12
+ ActiveRecord::Base.establish_connection(MUDING_ENV.to_sym)
13
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
14
+ Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
15
+ end
16
+ end
17
+ end
18
+
19
+ namespace :schema do
20
+ desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
21
+ task :dump => :environment do
22
+ require 'active_record/schema_dumper'
23
+ File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
24
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
25
+ end
26
+ end
27
+
28
+ desc "Load a schema.rb file into the database"
29
+ task :load => :environment do
30
+ file = ENV['SCHEMA'] || "db/schema.rb"
31
+ load(file)
32
+ end
33
+ end
34
+
35
+ namespace :structure do
36
+ desc "Dump the database structure to a SQL file"
37
+ task :dump => :environment do
38
+ abcs = ActiveRecord::Base.configurations
39
+ case abcs[MUDING_ENV]["adapter"]
40
+ when "mysql", "oci"
41
+ ActiveRecord::Base.establish_connection(abcs[MUDING_ENV])
42
+ File.open("db/#{MUDING_ENV}_structure.sql", "w+") { |f| f <<
43
+ ActiveRecord::Base.connection.structure_dump }
44
+ when "postgresql"
45
+ ENV['PGHOST'] = abcs[MUDING_ENV]["host"] if abcs[MUDING_ENV]["host"]
46
+ ENV['PGPORT'] = abcs[MUDING_ENV]["port"].to_s if abcs[MUDING_ENV]["port"]
47
+ ENV['PGPASSWORD'] = abcs[MUDING_ENV]["password"].to_s if abcs[MUDING_ENV]["password"]
48
+ search_path = abcs[MUDING_ENV]["schema_search_path"]
49
+ search_path = "--schema=#{search_path}" if search_path
50
+ `pg_dump -i -U "#{abcs[MUIDING_ENV]["username"]}" -s -x -O -f db/#{MUDING_ENV}_structure.sql
51
+ #{search_path} #{abcs[MUDING_ENV]["database"]}`
52
+ raise "Error dumping database" if $?.exitstatus == 1
53
+ when "sqlite", "sqlite3"
54
+ dbfile = abcs[MUDING_ENV]["database"] || abcs[MUDING_ENV]["dbfile"]
55
+ `#{abcs[MUDING_ENV]["adapter"]} #{dbfile} .schema > db/#{MUDING_ENV}_structure.sql`
56
+ when "sqlserver"
57
+ `scptxfr /s #{abcs[MUDING_ENV]["host"]} /d #{abcs[MUDING_ENV]["database"]} /I /f
58
+ db\\#{MUDING_ENV}_structure.sql /q /A /r`
59
+ `scptxfr /s #{abcs[MUDING_ENV]["host"]} /d #{abcs[MUDING_ENV]["database"]} /I /F db\ /q /A
60
+ /r`
61
+ else
62
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
63
+ end
64
+
65
+ if ActiveRecord::Base.connection.supports_migrations?
66
+ File.open("db/#{MUDING_ENV}_structure.sql", "a") { |f| f <<
67
+ ActiveRecord::Base.connection.dump_schema_information }
68
+ end
69
+ end
70
+ end
71
+
72
+ namespace :test do
73
+ desc "Recreate the test database from the current environment's database schema"
74
+ task :clone => "db:schema:dump" do
75
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
76
+ ActiveRecord::Schema.verbose = false
77
+ Rake::Task["db:schema:load"].invoke
78
+ end
79
+
80
+
81
+ desc "Recreate the test databases from the development structure"
82
+ task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
83
+ abcs = ActiveRecord::Base.configurations
84
+ case abcs["test"]["adapter"]
85
+ when "mysql"
86
+ ActiveRecord::Base.establish_connection(:test)
87
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
88
+ IO.readlines("db/#{MUDING_ENV}_structure.sql").join.split("\n\n").each do |table|
89
+ ActiveRecord::Base.connection.execute(table)
90
+ end
91
+ when "postgresql"
92
+ ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
93
+ ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
94
+ ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
95
+ `psql -U "#{abcs["test"]["username"]}" -f db/#{MUDING_ENV}_structure.sql
96
+ #{abcs["test"]["database"]}`
97
+ when "sqlite", "sqlite3"
98
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
99
+ `#{abcs["test"]["adapter"]} #{dbfile} < db/#{MUDING_ENV}_structure.sql`
100
+ when "sqlserver"
101
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i
102
+ db\\#{MUDING_ENV}_structure.sql`
103
+ when "oci"
104
+ ActiveRecord::Base.establish_connection(:test)
105
+ IO.readlines("db/#{MUDING_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
106
+ ActiveRecord::Base.connection.execute(ddl)
107
+ end
108
+ else
109
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
110
+ end
111
+ end
112
+
113
+ desc "Empty the test database"
114
+ task :purge => :environment do
115
+ abcs = ActiveRecord::Base.configurations
116
+ case abcs["test"]["adapter"]
117
+ when "mysql"
118
+ ActiveRecord::Base.establish_connection(:test)
119
+ ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
120
+ when "postgresql"
121
+ ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
122
+ ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
123
+ ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
124
+ enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"]
125
+ `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
126
+ `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
127
+ when "sqlite","sqlite3"
128
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
129
+ File.delete(dbfile) if File.exist?(dbfile)
130
+ when "sqlserver"
131
+ dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
132
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
133
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i
134
+ db\\#{MUDING_ENV}_structure.sql`
135
+ when "oci"
136
+ ActiveRecord::Base.establish_connection(:test)
137
+ ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
138
+ ActiveRecord::Base.connection.execute(ddl)
139
+ end
140
+ else
141
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
142
+ end
143
+ end
144
+
145
+ desc 'Prepare the test database and load the schema'
146
+ task :prepare => :environment do
147
+ Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
148
+ end
149
+ end
150
+
151
+ namespace :sessions do
152
+ desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore"
153
+ task :create => :environment do
154
+ raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
155
+ require 'rails_generator'
156
+ require 'rails_generator/scripts/generate'
157
+ Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "AddSessions"])
158
+ end
159
+
160
+ desc "Clear the sessions table"
161
+ task :clear => :environment do
162
+ ActiveRecord::Base.connection.execute "DELETE FROM sessions"
163
+ end
164
+ end
165
+ end
166
+
167
+ def session_table_name
168
+ ActiveRecord::Base.pluralize_table_names ? :sessions : :session
169
+ end
@@ -0,0 +1,55 @@
1
+ namespace :doc do
2
+ desc "Generate documentation for the application"
3
+ Rake::RDocTask.new("app") { |rdoc|
4
+ rdoc.rdoc_dir = 'doc/app'
5
+ rdoc.title = "Muding Application Documentation"
6
+ rdoc.options << '--line-numbers' << '--inline-source'
7
+ rdoc.rdoc_files.include('doc/README_FOR_APP')
8
+ rdoc.rdoc_files.include('app/**/*.rb')
9
+ }
10
+
11
+ desc "Generate documentation for the muding framework"
12
+ Rake::RDocTask.new("muding") { |rdoc|
13
+ rdoc.rdoc_dir = 'doc/api'
14
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
15
+ rdoc.title = "muding Framework Documentation"
16
+ rdoc.options << '--line-numbers' << '--inline-source'
17
+ rdoc.rdoc_files.include('README')
18
+ }
19
+
20
+ plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
21
+
22
+ desc "Generate documation for all installed plugins"
23
+ task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
24
+
25
+ desc "Remove plugin documentation"
26
+ task :clobber_plugins do
27
+ rm_rf 'doc/plugins' rescue nil
28
+ end
29
+
30
+ namespace :plugins do
31
+ # Define doc tasks for each plugin
32
+ plugins.each do |plugin|
33
+ task(plugin => :environment) do
34
+ plugin_base = "vendor/plugins/#{plugin}"
35
+ options = []
36
+ files = Rake::FileList.new
37
+ options << "-o doc/plugins/#{plugin}"
38
+ options << "--title '#{plugin.titlecase} Plugin Documentation'"
39
+ options << '--line-numbers' << '--inline-source'
40
+ options << '-T html'
41
+
42
+ files.include("#{plugin_base}/lib/**/*.rb")
43
+ if File.exists?("#{plugin_base}/README")
44
+ files.include("#{plugin_base}/README")
45
+ options << "--main '#{plugin_base}/README'"
46
+ end
47
+ files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
48
+
49
+ options << files.to_s
50
+
51
+ sh %(rdoc #{options * ' '})
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ require "rake"
2
+ # Load Muding-specific Rake tasks automatically.
3
+ Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext }
4
+
5
+ # Now, get tasks from lib/tasks
6
+ Dir["./lib/tasks/**/*.rake"].sort.each { |ext| load ext }
7
+
@@ -0,0 +1,18 @@
1
+ STATS_DIRECTORIES = [
2
+ %w(Helpers mud/helpers),
3
+ %w(Controllers mud/controllers),
4
+ %w(APIs mud/apis),
5
+ %w(Components components),
6
+ %w(Functional\ tests test/functional),
7
+ %w(Models mud/models),
8
+ %w(Unit\ tests test/unit),
9
+ %w(Libraries lib/),
10
+ %w(Integration\ tests test/integration)
11
+ ].collect { |name, dir| [ name, "#{MUDING_ROOT}/#{dir}" ] }.select {
12
+ |name, dir| File.directory?(dir) }
13
+
14
+ desc "Report code statistics (KLOCs, etc) from the application"
15
+ task :stats do
16
+ require 'code_statistics'
17
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
18
+ end
@@ -0,0 +1,102 @@
1
+ TEST_CHANGES_SINCE = Time.now - 600
2
+
3
+ # Look up tests for recently modified sources.
4
+ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
5
+ FileList[source_pattern].map do |path|
6
+ if File.mtime(path) > touched_since
7
+ test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb"
8
+ test if File.exists?(test)
9
+ end
10
+ end.compact
11
+ end
12
+
13
+
14
+ # Recreated here from ActiveSupport because :uncommitted needs it before Rails is available
15
+ module Kernel
16
+ def silence_stderr
17
+ old_stderr = STDERR.dup
18
+ STDERR.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
19
+ STDERR.sync = true
20
+ yield
21
+ ensure
22
+ STDERR.reopen(old_stderr)
23
+ end
24
+ end
25
+
26
+ desc 'Test all units and functionals'
27
+ task :test do
28
+ Rake::Task["test:units"].invoke rescue got_error = true
29
+ Rake::Task["test:functionals"].invoke rescue got_error = true
30
+
31
+ if File.exist?("test/integration")
32
+ #Rake::Task["test:integration"].invoke rescue got_error = true
33
+ end
34
+
35
+ raise "Test failures" if got_error
36
+ end
37
+
38
+ namespace :test do
39
+ desc 'Test recent changes'
40
+ Rake::TestTask.new(:recent => "db:test:prepare") do |t|
41
+ since = TEST_CHANGES_SINCE
42
+ touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
43
+ recent_tests('app/models/*.rb', 'test/unit', since) +
44
+ recent_tests('app/controllers/*.rb', 'test/functional', since)
45
+
46
+ t.libs << 'test'
47
+ t.verbose = true
48
+ t.test_files = touched.uniq
49
+ end
50
+
51
+ desc 'Test changes since last checkin (only Subversion)'
52
+ Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t|
53
+ def t.file_list
54
+ changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }
55
+
56
+ models = changed_since_checkin.select { |path| path =~ /app\/models\/.*\.rb/ }
57
+ controllers = changed_since_checkin.select { |path| path =~ /app\/controllers\/.*\.rb/ }
58
+
59
+ unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" }
60
+ functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }
61
+
62
+ unit_tests.uniq + functional_tests.uniq
63
+ end
64
+
65
+ t.libs << 'test'
66
+ t.verbose = true
67
+ end
68
+
69
+ desc "Run the unit tests in test/unit"
70
+ Rake::TestTask.new(:units => "db:test:prepare") do |t|
71
+ t.libs << "test"
72
+ t.pattern = 'test/unit/**/*_test.rb'
73
+ t.verbose = true
74
+ end
75
+
76
+ desc "Run the functional tests in test/functional"
77
+ Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
78
+ t.libs << "test"
79
+ t.pattern = 'test/functional/**/*_test.rb'
80
+ t.verbose = true
81
+ end
82
+
83
+ desc "Run the integration tests in test/integration"
84
+ Rake::TestTask.new(:integration => "db:test:prepare") do |t|
85
+ t.libs << "test"
86
+ t.pattern = 'test/integration/**/*_test.rb'
87
+ t.verbose = true
88
+ end
89
+
90
+ desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
91
+ Rake::TestTask.new(:plugins => :environment) do |t|
92
+ t.libs << "test"
93
+
94
+ if ENV['PLUGIN']
95
+ t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb"
96
+ else
97
+ t.pattern = 'vendor/plugins/**/test/**/*_test.rb'
98
+ end
99
+
100
+ t.verbose = true
101
+ end
102
+ end