wagons 0.0.1 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.rdoc +135 -9
  3. data/Rakefile +13 -5
  4. data/lib/generators/wagon/templates/%singular_name%.gemspec.tt +0 -2
  5. data/lib/generators/wagon/templates/.gitignore +5 -0
  6. data/lib/generators/wagon/templates/Gemfile.tt +5 -9
  7. data/lib/generators/wagon/templates/app/assets/images/.empty_directory +0 -0
  8. data/lib/generators/wagon/templates/app/controllers/.empty_directory +0 -0
  9. data/lib/generators/wagon/templates/app/models/.empty_directory +0 -0
  10. data/lib/generators/wagon/templates/app/views/.empty_directory +0 -0
  11. data/lib/generators/wagon/templates/db/fixtures/development/.empty_directory +0 -0
  12. data/lib/generators/wagon/templates/db/migrate/.empty_directory +0 -0
  13. data/lib/generators/wagon/templates/lib/%singular_name%/wagon.rb.tt +7 -4
  14. data/lib/generators/wagon/templates/test/fixtures/.empty_directory +0 -0
  15. data/lib/generators/wagon/wagon_generator.rb +23 -4
  16. data/lib/tasks/wagons.rake +119 -20
  17. data/lib/wagons/extensions/application.rb +14 -0
  18. data/lib/wagons/extensions/require_optional.rb +9 -0
  19. data/lib/wagons/{test_case.rb → extensions/test_case.rb} +4 -1
  20. data/lib/wagons/installer.rb +313 -0
  21. data/lib/wagons/railtie.rb +1 -1
  22. data/lib/wagons/version.rb +1 -1
  23. data/lib/wagons/view_helper.rb +58 -0
  24. data/lib/wagons/wagon.rb +125 -109
  25. data/lib/wagons/wagon_tasks.rake +9 -7
  26. data/lib/wagons.rb +44 -7
  27. data/test/dummy/Gemfile +8 -2
  28. data/test/dummy/Gemfile.lock +51 -48
  29. data/test/dummy/app/assets/javascripts/application.js +0 -2
  30. data/test/dummy/app/controllers/people_controller.rb +6 -0
  31. data/test/dummy/app/views/people/index.html.erb +6 -0
  32. data/test/dummy/app/views/shared/_sidebar.html.erb +3 -0
  33. data/test/dummy/config/initializers/wagon_app_version.rb +7 -0
  34. data/test/dummy/config/routes.rb +3 -0
  35. data/test/dummy/db/development.sqlite3 +0 -0
  36. data/test/dummy/db/schema.rb +1 -1
  37. data/test/dummy/db/test.sqlite3 +0 -0
  38. data/test/dummy/log/development.log +1230 -1586
  39. data/test/dummy/log/test.log +6458 -1772
  40. data/test/dummy/test/unit/person_test.rb +6 -0
  41. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  42. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  43. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  44. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  45. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  46. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  47. data/test/dummy/tmp/pids/server.pid +1 -0
  48. data/test/dummy/vendor/wagons/superliner/Gemfile +1 -5
  49. data/test/dummy/vendor/wagons/superliner/Gemfile.lock +46 -48
  50. data/test/dummy/vendor/wagons/superliner/app/controllers/cities_controller.rb +6 -0
  51. data/test/dummy/vendor/wagons/superliner/app/views/cities/index.html.erb +7 -0
  52. data/test/dummy/vendor/wagons/superliner/app/views/people/_list_superliner.html.erb +3 -0
  53. data/test/dummy/vendor/wagons/superliner/app/views/shared/_sidebar_superliner.html.erb +1 -0
  54. data/test/dummy/vendor/wagons/superliner/config/routes.rb +1 -1
  55. data/test/dummy/vendor/wagons/superliner/db/migrate/{20120606125258_create_cities.rb → 20120606125058_create_cities.rb} +0 -0
  56. data/test/dummy/vendor/wagons/superliner/dummy_superliner.gemspec +0 -2
  57. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/wagon.rb +3 -1
  58. data/test/dummy/vendor/wagons/superliner/test/functionals/cities_controller_test.rb +12 -0
  59. data/test/dummy/vendor/wagons/superliner/test/functionals/people_controller_test.rb +14 -0
  60. data/test/dummy/vendor/wagons/superliner/test/unit/city_test.rb +4 -1
  61. data/test/dummy/vendor/wagons/superliner/test/wagon_test.rb +7 -5
  62. data/test/wagons_installer_test.rb +225 -0
  63. metadata +241 -169
  64. data/test/dummy/dummy.gemspec +0 -17
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 YOURNAME
1
+ Copyright 2012 Pascal Zumkehr
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,21 +1,147 @@
1
- = Here be Wagons!
1
+ = Here Be Wagons
2
2
 
3
- Wagons are extensions to your application train running on Rails. You can see them as plugins that extend the behavior of your specific Rails application. This framework makes it easy to create and manage them.
3
+ Wagons are extensions to your application train running on Rails. You can see them as plugins that
4
+ extend the behavior of your specific Rails application. This framework makes it easy to create and
5
+ manage them.
6
+
7
+ First of all, wagons are basically {Rails Engines}[http://api.rubyonrails.org/classes/Rails/Engine.html],
8
+ so make sure you are familiar with them. Wagons provide a handful of additions so your wagon
9
+ engines actually know your application.
10
+
11
+ Wagons differ from engines in a few points:
12
+
13
+ * Wagons extend your application, engines extend Rails.
14
+ * Wagon migrations are kept separately from your application's migrations to enable easy addition and removal of wagons.
15
+ * When developing and testing, wagons use the main application instead of a dummy application.
4
16
 
5
17
  == Setup
6
18
 
7
- As always, add this declaration to your application's Gemfile
19
+ As always, add this declaration to your application's Gemfile:
8
20
 
9
21
  gem 'wagons'
10
-
11
- If you do not have one yet, create a .gemspec file for your application. This allows Rubygems to see your application as a (virtual) gem, so your wagons can define a dependency on it. As with all gems, move your (production) dependencies to this gemspec (+add_dependency+) and simply call +gemspec+ inside your Gemfile.
12
22
 
13
23
  Now you are ready for your first wagon. Generate it with
14
24
 
15
25
  rails generate wagon [name]
16
26
 
17
- == Under the hood
27
+ This creates the structure of your wagon in <tt>vendor/wagons/[name]</tt>. In there, you find the file <tt>lib/[name]/wagon.rb</tt>,
28
+ which defines the <tt>Rails::Engine</tt> and includes the +Wagon+ module. Here, you may also extend your application
29
+ classes in a +config.to_prepare+ block.
30
+
31
+ In order to load wagons with the application, an entry in the +Gemfile+ would be sufficient.
32
+ To keep things flexible, wagons come with an additional file +Wagonfile+. Generate one for development purposes with:
33
+
34
+ rake wagon:file
35
+
36
+ This will include all wagons found in +vendor/wagons+ in development mode.
37
+ Do not check +Wagonfile+ into source control. In your deployments, you might want to have different entries in there.
38
+
39
+ Once your wagon is ready to ship, a gem can be built with <tt>rake build</tt>. The name of a wagon gem must always start
40
+ with the application name, followed with an underscore and the actual name of the wagon. In production, you may
41
+ simply install the wagon gem and explicitly add a declaration to your +Wagonfile+.
42
+
43
+ If your wagon contains migrations and probably seed data, update your database with
44
+
45
+ rake wagon:setup WAGON=[name]
46
+
47
+ Leave off the +WAGON+ parameter to setup all wagons in your +Wagonfile+. This should not interfere with wagons that are
48
+ already set up. Migrations are only run if they are not loaded yet, as usual.
49
+
50
+
51
+ == Extending your application with a wagon
52
+
53
+ Ruby and Rails provide all the magic required to extend your application from within a wagon.
54
+
55
+ To add new models, controllers or views, simply create them in the +app+ directory of your wagon, as you would in a regular engine.
56
+
57
+ To extend existing models and controllers, you may create modules with the required functionality.
58
+ Include them into your application classes in a +config.to_prepare+ block in <tt>lib/[wagon_name]/wagon.rb</tt>.
59
+
60
+ To extend views, wagons provides a simple view helper that looks for partials in all view paths. Any template that
61
+ might be extended by a wagon can include a call like this:
62
+
63
+ <%= render_extensions :details %>
64
+
65
+ Any partials living in an equally named subfolder as the calling template and starting with the given key are rendered at this place.
66
+
67
+
68
+ == Wagon dependencies
69
+
70
+ Wagons may depend on each other and/or have certain requirements on their load order. To make sure something
71
+ is loaded before the current wagon, add a <tt>require '[app_name]_[other_wagon]'</tt> on top of the
72
+ <tt>lib/[app_name]_[current_wagon].rb</tt> file. For development dependencies, there is an extra +require_optional+
73
+ method that will not raise a +LoadError+ if the dependency is not found.
74
+
75
+ To control that the main application actually supports a certain wagon, an application version may be defined
76
+ so wagons can define a requirement. The application version can be set in an initializer. Create it with:
77
+
78
+ rake wagon:app_version
79
+
80
+ Besides setting the version, this initializer will check all loaded wagons for their application requirement
81
+ and raise an errors if one is not met. In <tt>lib/[wagon_name]/wagon.rb</tt> the requirement may be defined, e.g.:
82
+
83
+ app_requirement '>= 1.0'
84
+
85
+ The syntax follows the Ruby gem version and requirements.
86
+
87
+
88
+ == Seed Data
89
+
90
+ Wagons integrates {Seed Fu}[https://github.com/mbleigh/seed-fu] for seed data. All seed data from the application
91
+ is also available in wagon tests, as long as no fixture files overwrite the corresponding tables.
92
+
93
+ Wagons may come with their own seed data as well. Simply put it into <tt>db/fixtures[/environment]</tt>. To allow for
94
+ an automatic removal of wagons, {Seed Fu-ndo}[https://github.com/codez/seed-fu-ndo] is able to record
95
+ seed file instructions and destroy all entries that exist in the database. Just make sure that you only use
96
+ the +seed+ and +seed_once+ methods in these files, or the unseed may not work correctly.
97
+
98
+
99
+ == Beware
100
+
101
+ There are a few other things that work differently with wagons:
102
+
103
+ === Schema & Migrations
104
+
105
+ Wagons are extensions to your application that may vary between various installations. Wagon tables are added
106
+ and removed as wagons are installed or uninstalled. After you have added a wagon's gem to your production
107
+ +Wagonfile+, run <tt>rake wagon:setup</tt> to run the migrations and load the seed data. Before you remove them
108
+ from +Wagonfile+, run <tt>rake wagon:remove WAGON=to_remove</tt> to eliminate the artifacts from the database first.
109
+
110
+ In this way, the +schema.rb+ file must only contain the tables of the application, not of all wagons.
111
+ When you have migrations for your main application and wagons loaded, the schema will not be dumped on
112
+ <tt>db:migrate</tt>. You need to either remove the wagons or reset the database before the schema may be dumped.
113
+ This is (currently) the cost for having arbitrary pluggable application extensions.
114
+
115
+ === Tests
116
+
117
+ Wagons use your application for tests. This is also true for your application's test database. To get the
118
+ correct setup, <tt>app:db:test:prepare</tt> is extended to run the migration of the current wagon and all its
119
+ dependencies, as well as their seed data. Once the database is set up, single tests may be run with
120
+ the usual <tt>ruby -I test test/my_test.rb</tt> command.
121
+
122
+ The +test_helper.rb+ of the main application is included in all wagon tests. Any additions in
123
+ this file are available in wagon tests as well. The only thing wagons need to do is reseting the
124
+ fixture path to the wagon's test fixtures.
125
+
126
+ RSpec works fine with wagons as well. Simply put the heading lines found in <tt>test_helper.rb</tt> into your
127
+ <tt>spec_helper.rb</tt>.
128
+
129
+ === Gem Bundling
130
+
131
+ Bundler manages application dependencies, with a stress on application. Because wagons live
132
+ inside your application during development, the app's +Gemfile+ is included in each wagon's +Gemfile+.
133
+ However, Bundler still keeps an own <tt>Gemfile.lock</tt> for each wagon, so you have to make sure to keep
134
+ these up to date when you change your main application gems. The gem versions for the wagons should be
135
+ the same as for the application. <tt>rake wagon:bundle:update</tt> is here to help you exactly with that.
136
+ We recommend to NOT check in the Wagon's <tt>Gemfile.lock</tt> file into source control.
137
+
138
+ Unfortunately, adding wagon gems to the +Wagonfile+ in production also breaks with Bundler's approach
139
+ of locking down application gems. Because of that, the <tt>--deployment</tt> option cannot be used
140
+ with wagons. If you install your gems from <tt>vendor/cache</tt> into <tt>vendor/bundle</tt> or so,
141
+ you still get most of the benefits of using Bundler, including the guarantee for the very same gem
142
+ versions as used in development.
143
+
144
+ Contributions to this or any other issues are very welcome.
145
+
18
146
 
19
- TODO:
20
- * Wagonfile
21
- * Rake Tasks
147
+ {<img src="https://secure.travis-ci.org/codez/wagons.png" />}[http://travis-ci.org/codez/wagons]
data/Rakefile CHANGED
@@ -21,16 +21,24 @@ RDoc::Task.new(:rdoc) do |rdoc|
21
21
  end
22
22
 
23
23
 
24
-
25
-
26
24
  Bundler::GemHelper.install_tasks
27
25
 
28
26
  require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'test'
29
+ test.pattern = 'test/*_test.rb'
30
+ test.verbose = true
31
+ end
29
32
 
30
33
  task :test do
31
- puts "Testing wagons is a bit weird. So far, please run the following command directly in your shell:"
32
- puts "(cd test/dummy/vendor/wagons/superliner && rake)"
34
+ begin
35
+ Bundler.with_clean_env { sh "cd test/dummy && rails g wagon test_wagon" }
36
+ Bundler.with_clean_env { sh "cd test/dummy && bundle exec rake db:migrate test #{'-t' if Rake.application.options.trace}" }
37
+ Bundler.with_clean_env { sh "cd test/dummy && bundle exec rake wagon:test #{'-t' if Rake.application.options.trace}" }
38
+ ensure
39
+ sh "rm -rf test/dummy/vendor/wagons/test_wagon"
40
+ end
33
41
  end
34
42
 
35
-
36
43
  task :default => :test
44
+
@@ -16,6 +16,4 @@ Gem::Specification.new do |s|
16
16
  s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile"]
17
17
  s.test_files = Dir["test/**/*"]
18
18
 
19
- s.add_dependency "<%= application_name %>"
20
-
21
19
  end
@@ -0,0 +1,5 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ doc/rdoc
5
+ Gemfile.lock
@@ -7,14 +7,10 @@ source "http://rubygems.org"
7
7
  # development dependencies will be added by default to the :development group.
8
8
  gemspec
9
9
 
10
+ # Load application Gemfile for all application dependencies.
11
+ eval File.read(File.expand_path('Gemfile', ENV['APP_ROOT']))
12
+
10
13
  group :development, :test do
11
- gem '<%= application_name %>', :path => ENV['APP_ROOT']
14
+ # Explicitly define the path for dependencies on other wagons.
15
+ # gem '<%= application_name %>_other_wagon', :path => "#{ENV['APP_ROOT']}/vendor/wagons"
12
16
  end
13
-
14
- # Declare any dependencies that are still in development here instead of in
15
- # your gemspec. These might include edge Rails or gems from your path or
16
- # Git. Remember to move these dependencies to your gemspec before releasing
17
- # your gem to rubygems.org.
18
-
19
- # To use debugger
20
- # gem 'ruby-debug'
@@ -1,13 +1,16 @@
1
1
  module <%= class_name %>
2
2
  class Wagon < Rails::Engine
3
- include ::Wagon
3
+ include Wagons::Wagon
4
4
 
5
- # Add a load path for this specific Wagon
6
- #config.autoload_paths += %W( #{config.root}/lib )
5
+ # Set the required application version.
6
+ app_requirement '>= 0'
7
+
8
+ # Add a load path for this specific wagon
9
+ # config.autoload_paths += %W( #{config.root}/lib )
7
10
 
8
11
  config.to_prepare do
9
12
  # extend application classes here
10
13
  end
11
-
14
+
12
15
  end
13
16
  end
@@ -1,4 +1,4 @@
1
- class WagonGenerator < Rails::Generators::NamedBase
1
+ class WagonGenerator < Rails::Generators::NamedBase #:nodoc:
2
2
 
3
3
  attr_reader :wagon_name, :app_root_initializer
4
4
 
@@ -12,10 +12,29 @@ class WagonGenerator < Rails::Generators::NamedBase
12
12
  assign_names!("#{application_name}_#{name}")
13
13
  end
14
14
 
15
-
16
15
  def copy_templates
17
- self.destination_root = "vendor/wagons/#{wagon_name}"
18
- directory('.')
16
+ self.destination_root = "vendor/wagons/#{wagon_name}"
17
+
18
+ # do this whole manual traversal to be able to replace every single file
19
+ # individually in the application.
20
+ all_templates.each do |file|
21
+ if File.basename(file) == '.empty_directory'
22
+ file = File.dirname(file)
23
+ directory(file, File.join(destination_root, file))
24
+ else
25
+ template(file, File.join(destination_root, file.sub(/\.tt$/, '')))
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def all_templates
33
+ source_paths.collect do |path|
34
+ Dir[File.join(path, "**", "{*,.[a-z]*}")].
35
+ select {|f| File.file?(f) }.
36
+ collect {|f| f.sub(path + File::SEPARATOR, '') }
37
+ end.flatten.uniq.sort
19
38
  end
20
39
 
21
40
  end
@@ -1,3 +1,4 @@
1
+ # The tasks available to the base application using wagons.
1
2
 
2
3
  namespace :wagon do
3
4
  desc "Run wagon migrations (options: VERSION=x, WAGON=abc, VERBOSE=false)"
@@ -22,7 +23,7 @@ namespace :wagon do
22
23
  end
23
24
 
24
25
  desc "Unseed wagon data (options: WAGON=abc)"
25
- task :unseed => :abort_if_pending_migrations do
26
+ task :unseed do
26
27
  wagons.reverse.each { |wagon| wagon.unload_seed }
27
28
  end
28
29
 
@@ -30,14 +31,35 @@ namespace :wagon do
30
31
  task :setup => [:migrate, :seed]
31
32
 
32
33
  desc "Remove the specified wagon"
33
- task :remove do
34
- if wagons.size != 1
35
- puts "Please specify a WAGON to remove"
36
- elsif message = wagons.first.protect?
37
- puts message
34
+ task :remove => :environment do
35
+ if wagons.size == 0 || (wagons.size > 1 && ENV['WAGON'].blank?)
36
+ puts "Please specify a WAGON to remove, or WAGON=ALL to remove all"
38
37
  else
39
- Rake::Task['wagon:unseed'].invoke
40
- Rake::Task['wagon:revert'].invoke
38
+ messages = wagons.collect {|w| w.protect? }.compact
39
+ if messages.present?
40
+ fail messages.join("\n")
41
+ else
42
+ Rake::Task['wagon:unseed'].invoke
43
+ Rake::Task['wagon:revert'].invoke
44
+ end
45
+ end
46
+ end
47
+
48
+ desc "Generate an initializer to set the application version"
49
+ task :app_version do
50
+ file = Rails.root.join('config', 'initializers', 'wagon_app_version.rb')
51
+ unless File.exist?(file)
52
+ File.open(file, 'w') do |f|
53
+ f.puts <<FIN
54
+ Wagons.app_version = '1.0.0'
55
+
56
+ Wagons.all.each do |wagon|
57
+ unless wagon.app_requirement.satisfied_by?(Wagons.app_version)
58
+ raise "\#{wagon.gem_name} requires application version \#{wagon.app_requirement}; got \#{Wagons.app_version}"
59
+ end
60
+ end
61
+ FIN
62
+ end
41
63
  end
42
64
  end
43
65
 
@@ -72,23 +94,50 @@ eval(File.read(wagonfile)) if File.exist?(wagonfile)"
72
94
  end
73
95
  end
74
96
 
75
- desc "list the loaded wagons"
97
+ namespace :file do
98
+ desc "Create a Wagonfile for production"
99
+ task :prod => :environment do
100
+ file = Rails.root.join('Wagonfile.prod')
101
+ File.open(file, 'w') do |f|
102
+ Wagons.all.each do |w|
103
+ f.puts "gem '#{w.gem_name}', '#{w.version}'"
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ desc "List the loaded wagons"
76
110
  task :list => :environment do # depend on environment to get correct order
77
111
  wagons.each {|p| puts p.wagon_name }
78
112
  end
79
113
 
80
- namespace :test do
81
- desc "Create script to test all wagons at once"
82
- task :script => :environment do
83
- script = 'vendor/wagons/test_wagons.sh'
84
- File.open(script, 'w') do |f|
85
- wagons.each do |w|
86
- f.puts "(echo && echo '*** TESTING #{w.wagon_name.upcase} ***' && cd #{w.root.to_s[(Rails.root.to_s.size+1)..-1]} && bundle exec rake)"
87
- end
114
+ desc "Run the tests of WAGON"
115
+ task :test do
116
+ ENV['CMD'] = "bundle exec rake #{'-t' if Rake.application.options.trace}"
117
+ Rake::Task['wagon:exec'].invoke
118
+ end
119
+
120
+ desc "Execute CMD in WAGON's base directory"
121
+ task :exec do
122
+ wagons.each do |w|
123
+ puts "\n*** #{w.wagon_name.upcase} ***" if wagons.size > 1
124
+ rel_dir = w.root.to_s.sub(Rails.root.to_s + File::SEPARATOR, '')
125
+ cmd = "cd #{rel_dir} && #{ENV['CMD']}"
126
+ Bundler.with_clean_env do
127
+ verbose(false) { sh cmd }
88
128
  end
89
129
  end
90
130
  end
91
131
 
132
+ namespace :bundle do
133
+ desc "Run bundle update for all WAGONs"
134
+ task :update do
135
+ ENV['CMD'] = "bundle update --local"
136
+ Rake::Task['wagon:exec'].invoke
137
+ end
138
+ end
139
+
140
+
92
141
  # desc "Raises an error if there are pending wagon migrations"
93
142
  task :abort_if_pending_migrations => :environment do
94
143
  pending_migrations = ActiveRecord::Migrator.new(:up, wagons.collect(&:migrations_paths).flatten).pending_migrations
@@ -103,10 +152,60 @@ eval(File.read(wagonfile)) if File.exist?(wagonfile)"
103
152
  end
104
153
  end
105
154
 
155
+ namespace :test do
156
+ desc "Test wagons (option WAGON=abc)"
157
+ task :wagons => 'wagon:test'
158
+ end
159
+
160
+
161
+ namespace :db do
162
+ namespace :seed do
163
+ desc "Load core and wagon seeds into the current environment's database."
164
+ task :all => ['db:seed', 'wagon:seed']
165
+ end
166
+
167
+ namespace :setup do
168
+ desc "Create the database, load the schema, initialize with the seed data for core and wagons"
169
+ task :all => ['db:setup', 'wagon:setup']
170
+ end
171
+
172
+ namespace :reset do
173
+ desc "Recreate the database, load the schema, initialize with the seed data for core and wagons"
174
+ task :all => ['db:reset', 'wagon:setup']
175
+ end
176
+
177
+ # DB schema should not be dumped if wagon migrations are loaded
178
+ Rake::Task[:'db:_dump'].clear_actions
179
+
180
+ task :_dump do
181
+ migrator = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations_paths)
182
+ if migrator.migrated.size > migrator.migrations.size
183
+ puts "The database schema will not be dumped when there are loaded wagon migrations."
184
+ puts "To dump the application schema, please 'rake wagon:remove WAGON=ALL' wagons beforehand or reset the database."
185
+ else
186
+ Rake::Task[:'db:_dump_rails'].invoke
187
+ end
188
+
189
+ Rake::Task[:'db:_dump'].reenable
190
+ end
191
+
192
+ task :_dump_rails do
193
+ case ActiveRecord::Base.schema_format
194
+ when :ruby then Rake::Task["db:schema:dump"].invoke
195
+ when :sql then Rake::Task["db:structure:dump"].invoke
196
+ else
197
+ raise "unknown schema format #{ActiveRecord::Base.schema_format}"
198
+ end
199
+ Rake::Task[:'db:_dump_rails'].reenable
200
+ end
201
+ end
202
+
203
+
106
204
  # Load the wagons specified by WAGON or all available.
107
205
  def wagons
108
- to_load = ENV['WAGON'].blank? ? :all : ENV['WAGON'].split(",").map(&:strip)
109
- wagons = Wagon.all.select { |wagon| to_load == :all || to_load.include?(wagon.wagon_name) }
110
- puts "Please specify at least one valid WAGON" if wagons.blank?
206
+ to_load = ENV['WAGON'].blank? || ENV['WAGON'] == 'ALL' ? :all : ENV['WAGON'].split(",").map(&:strip)
207
+ wagons = Wagons.all.select { |wagon| to_load == :all || to_load.include?(wagon.wagon_name) }
208
+ puts "Please specify at least one valid WAGON" if ENV['WAGON'].present? && wagons.blank?
111
209
  wagons
112
210
  end
211
+
@@ -0,0 +1,14 @@
1
+ module Rails
2
+ class Application
3
+ protected
4
+
5
+ # Append wagons at the end of all railties, even after the application.
6
+ def ordered_railties
7
+ @ordered_railties ||= super.tap do |ordered|
8
+ Wagons.all.each do |w|
9
+ ordered.push(ordered.delete(w))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ # Requires the specified argument but silently ignores any LoadErrors.
3
+ def require_optional(*args)
4
+ require *args
5
+ rescue LoadError
6
+ # that's fine, it's an optional require
7
+ end
8
+ alias optional_require require_optional
9
+ end
@@ -1,4 +1,5 @@
1
- class ActiveSupport::TestCase
1
+ module ActiveSupport #:nodoc:
2
+ class TestCase
2
3
 
3
4
  # Resets the fixtures to the new path
4
5
  def self.reset_fixture_path(path)
@@ -7,4 +8,6 @@ class ActiveSupport::TestCase
7
8
  self.fixture_path = path
8
9
  self.fixtures :all
9
10
  end
11
+
12
+ end
10
13
  end