mlins-godwit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +20 -0
- data/README +110 -0
- data/Rakefile +37 -0
- data/VERSION.yml +4 -0
- data/app_generators/godwit/godwit_generator.rb +91 -0
- data/app_generators/godwit/templates/Rakefile +8 -0
- data/app_generators/godwit/templates/config/database.yml +13 -0
- data/app_generators/godwit/templates/config/environment.rb +22 -0
- data/app_generators/godwit/templates/log/active_migration.log +0 -0
- data/app_generators/godwit/templates/log/active_record.log +0 -0
- data/app_generators/godwit/templates/script/console +8 -0
- data/app_generators/godwit/templates/script/lib/console.rb +3 -0
- data/app_generators/godwit/templates/script/migrate +6 -0
- data/bin/godwit +17 -0
- data/godwit_generators/active_migration/active_migration_generator.rb +55 -0
- data/godwit_generators/active_migration/templates/active_migration.rb +9 -0
- data/godwit_generators/active_model/active_model_generator.rb +53 -0
- data/godwit_generators/active_model/templates/active_model.rb +3 -0
- data/godwit_generators/legacy_model/legacy_model_generator.rb +53 -0
- data/godwit_generators/legacy_model/templates/legacy_model.rb +7 -0
- data/lib/godwit/active_migration.rb +97 -0
- data/lib/godwit/base.rb +43 -0
- data/lib/godwit/bootloader.rb +79 -0
- data/lib/godwit/buffer.rb +46 -0
- data/lib/godwit/callbacks.rb +34 -0
- data/lib/godwit/config.rb +120 -0
- data/lib/godwit/irb.rb +33 -0
- data/lib/godwit/legacy_record.rb +11 -0
- data/lib/godwit/version.rb +9 -0
- data/lib/godwit.rb +44 -0
- data/spec/active_migration_generator_spec.rb +23 -0
- data/spec/active_model_generator_spec.rb +23 -0
- data/spec/buffer_spec.rb +51 -0
- data/spec/callbacks_spec.rb +29 -0
- data/spec/config_spec.rb +54 -0
- data/spec/godwit_generator_spec.rb +34 -0
- data/spec/legacy_model_generator_spec.rb +23 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +28 -0
- metadata +131 -0
data/lib/godwit/base.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Godwit
|
2
|
+
# Godwit Base class.
|
3
|
+
#
|
4
|
+
# When this class is initialized, the Godwit environment is booted.
|
5
|
+
#
|
6
|
+
class Base
|
7
|
+
|
8
|
+
def initialize #:nodoc:
|
9
|
+
Godwit::Bootloader.boot
|
10
|
+
end
|
11
|
+
|
12
|
+
# Starts Godwit.
|
13
|
+
#
|
14
|
+
def run
|
15
|
+
Godwit::Buffer.puts "\nLoading Migrations..." unless Godwit::Config[:silence]
|
16
|
+
unless Godwit::Config[:specific_migration]
|
17
|
+
run_all
|
18
|
+
else
|
19
|
+
run_single
|
20
|
+
end
|
21
|
+
Godwit::Buffer.puts "\nDone." unless Godwit::Config[:silence]
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def run_single #:nodoc:
|
27
|
+
migration = Godwit::Config[:specific_migration].camelize.constantize
|
28
|
+
migration.new.run(Godwit::Config[:skip_dependencies])
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_all #:nodoc:
|
32
|
+
Dir.foreach(File.join(Godwit::Config[:godwit_root], 'app', 'migrations')) do |file|
|
33
|
+
next unless file.ends_with?('migration.rb')
|
34
|
+
migration = file[0..-4].camelize.constantize
|
35
|
+
unless migration.completed? || Godwit::Config[:skip_migrations].include?(migration.to_s.underscore)
|
36
|
+
migration.new.run(Godwit::Config[:skip_dependencies])
|
37
|
+
migration.is_completed
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Godwit
|
2
|
+
module Bootloader
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
attr_accessor :booted
|
7
|
+
|
8
|
+
def boot(argv=ARGV) #:nodoc:
|
9
|
+
return if booted?
|
10
|
+
load_config(argv)
|
11
|
+
display_init unless Godwit::Config[:silence]
|
12
|
+
load_rails
|
13
|
+
set_load_path
|
14
|
+
set_logger
|
15
|
+
init_db
|
16
|
+
init_am
|
17
|
+
load_plugins
|
18
|
+
@booted = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def display_init #:nodoc:
|
22
|
+
system('clear')
|
23
|
+
Godwit::Buffer.puts "Godwit " + Godwit::VERSION::STRING
|
24
|
+
Godwit::Buffer.puts "\nInitializaing..."
|
25
|
+
end
|
26
|
+
|
27
|
+
def booted? #:nodoc:
|
28
|
+
@booted ||= false
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_rails #:nodoc:
|
32
|
+
unless Godwit::Config[:rails_root].nil?
|
33
|
+
require "#{Godwit::Config[:rails_root]}/config/environment"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_config(argv=ARGV) #:nodoc:
|
38
|
+
Godwit::Config.setup
|
39
|
+
require File.join(Godwit::Config[:godwit_root], 'config', 'environment.rb')
|
40
|
+
Godwit::Config.parse_args(argv)
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_load_path #:nodoc:
|
44
|
+
$:.concat [File.join(Godwit::Config[:godwit_root], 'app', 'models'),
|
45
|
+
File.join(Godwit::Config[:godwit_root], 'app', 'migrations'),
|
46
|
+
File.join(Godwit::Config[:godwit_root], 'lib')]
|
47
|
+
Dir[File.join(Godwit::Config[:godwit_root], 'vendor', 'plugins', '*', 'lib')].each do |dir|
|
48
|
+
$:.push dir
|
49
|
+
end
|
50
|
+
ActiveSupport::Dependencies.load_paths.concat $:
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_logger #:nodoc:
|
54
|
+
ActiveRecord::Base.logger = Godwit::Config[:active_record_log]
|
55
|
+
ActiveRecord::Base.logger.level = Godwit::Config[:active_record_log_level]
|
56
|
+
ActiveMigration::Base.logger = Godwit::Config[:active_migration_log]
|
57
|
+
ActiveMigration::Base.logger.level = Godwit::Config[:active_migration_log_level]
|
58
|
+
end
|
59
|
+
|
60
|
+
def init_db #:nodoc:
|
61
|
+
db_conf = YAML::load(File.open(File.join(Godwit::Config[:godwit_root], 'config', 'database.yml')))
|
62
|
+
LegacyRecord::Base.establish_connection(db_conf['legacy'])
|
63
|
+
ActiveRecord::Base.establish_connection(db_conf['active']) if Godwit::Config[:rails_root].nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def init_am #:nodoc:
|
67
|
+
ActiveMigration::KeyMapper.storage_path = Godwit::Config[:key_mapper_path]
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_plugins #:nodoc:
|
71
|
+
Dir[File.join(Godwit::Config[:godwit_root], 'vendor', 'plugins', '*', 'init.rb')].each do |init|
|
72
|
+
require init
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Godwit
|
2
|
+
# This class is used to buffer output. It's used to help out with view
|
3
|
+
# switching in the console.
|
4
|
+
#
|
5
|
+
class Buffer
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# Returns the buffer.
|
10
|
+
#
|
11
|
+
def buffer
|
12
|
+
@buffer ||= ""
|
13
|
+
@buffer
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets the buffer
|
17
|
+
#
|
18
|
+
def buffer=(string)
|
19
|
+
@buffer ||= ""
|
20
|
+
@buffer = string
|
21
|
+
end
|
22
|
+
|
23
|
+
# Outputs text with Kernel#print and stores it in the buffer.
|
24
|
+
#
|
25
|
+
def print(string)
|
26
|
+
self.buffer += string
|
27
|
+
Kernel.print string
|
28
|
+
end
|
29
|
+
|
30
|
+
# Outputs text with Kernel#puts and stores it in the buffer.
|
31
|
+
#
|
32
|
+
def puts(string)
|
33
|
+
self.buffer += (string + "\n")
|
34
|
+
Kernel.puts string
|
35
|
+
end
|
36
|
+
|
37
|
+
# Clears the buffer.
|
38
|
+
#
|
39
|
+
def clear
|
40
|
+
self.buffer = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Godwit
|
2
|
+
# Callbacks for before and after run.
|
3
|
+
#
|
4
|
+
module Callbacks
|
5
|
+
|
6
|
+
CALLBACKS = %w(before_run after_run)
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.send :alias_method_chain, :run, :callbacks
|
10
|
+
base.send :include, ActiveSupport::Callbacks
|
11
|
+
base.define_callbacks *CALLBACKS
|
12
|
+
end
|
13
|
+
|
14
|
+
# This is called before you anything actually starts.
|
15
|
+
#
|
16
|
+
def before_run() end
|
17
|
+
# This is called after everything else finishes.
|
18
|
+
#
|
19
|
+
def after_run() end
|
20
|
+
def run_with_callbacks #:nodoc:
|
21
|
+
callback(:before_run)
|
22
|
+
run_without_callbacks
|
23
|
+
callback(:after_run)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def callback(method) #:nodoc:
|
29
|
+
run_callbacks(method)
|
30
|
+
send(method)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Godwit
|
4
|
+
|
5
|
+
# Application configuration.
|
6
|
+
#
|
7
|
+
class Config
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
# Default configuration details.
|
14
|
+
def defaults
|
15
|
+
@defaults ||= {
|
16
|
+
:godwit_root => Dir.pwd,
|
17
|
+
:active_record_log => nil,
|
18
|
+
:active_record_log_level => nil,
|
19
|
+
:active_migration_log => nil,
|
20
|
+
:active_migration_log_level => nil,
|
21
|
+
:rails_root => nil,
|
22
|
+
:key_mapper_path => File.join(Dir.pwd, 'data', 'keymaps'),
|
23
|
+
:skip_dependencies => false,
|
24
|
+
:skip_migrations => [],
|
25
|
+
:specific_migration => nil,
|
26
|
+
:silence => false,
|
27
|
+
:debug => false
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Yields the configuration.
|
32
|
+
#
|
33
|
+
# Godwit::Config.use do |config|
|
34
|
+
# config[:keymapper_path] = 'some/other/path'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
def use
|
38
|
+
@configuration ||= {}
|
39
|
+
yield @configuration
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the config value at the specified key.
|
43
|
+
#
|
44
|
+
def [](key)
|
45
|
+
(@configuration||={})[key]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Set the config value at the specified key.
|
49
|
+
#
|
50
|
+
def []=(key,val)
|
51
|
+
@configuration[key] = val
|
52
|
+
end
|
53
|
+
|
54
|
+
# Deletes the config element by key.
|
55
|
+
#
|
56
|
+
def delete(key)
|
57
|
+
@configuration.delete(key)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Sets up the configuration by storing the given settings.
|
61
|
+
#
|
62
|
+
def setup(settings = {})
|
63
|
+
@configuration ||= {}
|
64
|
+
if @configuration == {}
|
65
|
+
@configuration = defaults.merge(settings)
|
66
|
+
else
|
67
|
+
@configuration.merge!(settings)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Parses command line arguments and stores them in the config.
|
72
|
+
#
|
73
|
+
def parse_args(argv = ARGV)
|
74
|
+
options = {}
|
75
|
+
opts = OptionParser.new do |opts|
|
76
|
+
|
77
|
+
opts.program_name = "Godwit"
|
78
|
+
opts.version = Godwit::VERSION::STRING
|
79
|
+
opts.banner = "Usage: migrate [OPTIONS]\n"
|
80
|
+
opts.separator ""
|
81
|
+
|
82
|
+
opts.on("-D", "--debug", "Debug mode.") do |n|
|
83
|
+
options[:debug] = true
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on("-s", "--silent", "Silence, no output, good for scripts. Silence overrides Debug(you can't debug silently)") do |n|
|
87
|
+
options[:silence] = true
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on("-m", "--skip-migrations X,Y,Z", Array, "Use underscores. Won't skip it if it's a dependency, make sure you use -d too if you need that.") do |migrations|
|
91
|
+
options[:skip_migrations] = migrations
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on("-d", "--skip-dependencies", "Skip Dependencies") do |n|
|
95
|
+
options[:skip_dependencies] = true
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on("-S", "--specific-migration MIGRATION", "Specific Migration. Use underscores. Ex. products_migration.") do |migration|
|
99
|
+
options[:specific_migration] = migration
|
100
|
+
end
|
101
|
+
|
102
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
103
|
+
puts opts
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
opts.on_tail("-v", "--version", "Show version") do
|
108
|
+
puts 'Godwit ' + Godwit::VERSION::STRING
|
109
|
+
exit
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
opts.parse!(argv)
|
114
|
+
Godwit::Config.setup(options)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
data/lib/godwit/irb.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'irb'
|
2
|
+
|
3
|
+
module IRB #:nodoc:
|
4
|
+
module ExtendCommand #:nodoc:
|
5
|
+
class Continue # :nodoc:
|
6
|
+
def self.execute(conf) #:nodoc:
|
7
|
+
throw :IRB_EXIT, :cont
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
ExtendCommandBundle.def_extend_command "cont", :Continue
|
12
|
+
|
13
|
+
def self.start_session(binding) #:nodoc:
|
14
|
+
unless @__initialized
|
15
|
+
args = ARGV
|
16
|
+
ARGV.replace(ARGV.dup)
|
17
|
+
IRB.setup(nil)
|
18
|
+
ARGV.replace(args)
|
19
|
+
@__initialized = true
|
20
|
+
end
|
21
|
+
|
22
|
+
workspace = WorkSpace.new(binding)
|
23
|
+
|
24
|
+
irb = Irb.new(workspace)
|
25
|
+
|
26
|
+
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
27
|
+
@CONF[:MAIN_CONTEXT] = irb.context
|
28
|
+
|
29
|
+
catch(:IRB_EXIT) do
|
30
|
+
irb.eval_input
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/godwit.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Matt Lins
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
25
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'active_support'
|
29
|
+
require 'active_record'
|
30
|
+
require 'active_migration'
|
31
|
+
|
32
|
+
require 'godwit/active_migration'
|
33
|
+
require 'godwit/base'
|
34
|
+
require 'godwit/bootloader'
|
35
|
+
require 'godwit/buffer'
|
36
|
+
require 'godwit/config'
|
37
|
+
require 'godwit/legacy_record'
|
38
|
+
require 'godwit/irb'
|
39
|
+
require 'godwit/callbacks'
|
40
|
+
require 'godwit/version'
|
41
|
+
|
42
|
+
Godwit::Base.class_eval do
|
43
|
+
include Godwit::Callbacks
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'ActiveMigrationGenerator' do
|
4
|
+
|
5
|
+
include GeneratorSpecHelper
|
6
|
+
|
7
|
+
before do
|
8
|
+
source = RubiGen::PathSource.new(:component, File.join(File.dirname(__FILE__), "../godwit_generators"))
|
9
|
+
RubiGen::Base.reset_sources
|
10
|
+
RubiGen::Base.prepend_sources source
|
11
|
+
@generator = RubiGen::Scripts::Generate.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should generate a migration in the migrations directory" do
|
15
|
+
silence_generator { @generator.run(['blah', '1', '2'], :generator => 'active_migration') }
|
16
|
+
File.file?(File.join(APP_ROOT, 'app', 'migrations', 'blah_migration.rb')).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
FileUtils.rm_rf(File.join(APP_ROOT, 'app'))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'ActiveModelGenerator' do
|
4
|
+
|
5
|
+
include GeneratorSpecHelper
|
6
|
+
|
7
|
+
before do
|
8
|
+
source = RubiGen::PathSource.new(:component, File.join(File.dirname(__FILE__), "../godwit_generators"))
|
9
|
+
RubiGen::Base.reset_sources
|
10
|
+
RubiGen::Base.prepend_sources source
|
11
|
+
@generator = RubiGen::Scripts::Generate.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should generate an active model" do
|
15
|
+
silence_generator { @generator.run(['blah'], :generator => 'active_model') }
|
16
|
+
File.file?(File.join(APP_ROOT, 'app', 'models', 'blah.rb')).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
FileUtils.rm_rf(File.join(APP_ROOT, 'app'))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/buffer_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'godwit')
|
4
|
+
|
5
|
+
describe 'Godwit::Buffer' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Kernel.stub!(:print).and_return(nil)
|
9
|
+
Kernel.stub!(:puts).and_return(nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be '' at the first time it's accessed" do
|
13
|
+
Godwit::Buffer.buffer.should == ''
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow the buffer to be set with =" do
|
17
|
+
Godwit::Buffer.buffer='blah'
|
18
|
+
Godwit::Buffer.buffer.should == 'blah'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should allow the buffer to be cleared" do
|
22
|
+
Godwit::Buffer.buffer = "blah"
|
23
|
+
Godwit::Buffer.clear
|
24
|
+
Godwit::Buffer.buffer.should == ''
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should print to the screen with #print" do
|
28
|
+
Kernel.should_receive(:print).with('blah')
|
29
|
+
Godwit::Buffer.print('blah')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should store the value in the buffer when calling #print" do
|
33
|
+
Godwit::Buffer.print('blah')
|
34
|
+
Godwit::Buffer.buffer.should == 'blah'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should print to the screen with #puts" do
|
38
|
+
Kernel.should_receive(:puts).with('blah')
|
39
|
+
Godwit::Buffer.puts('blah')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should store the value in the buffer when calling #puts" do
|
43
|
+
Godwit::Buffer.puts('blah')
|
44
|
+
Godwit::Buffer.buffer.should == "blah\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
Godwit::Buffer.clear
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'godwit')
|
4
|
+
|
5
|
+
describe 'Godwit::Callbacks' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Godwit::Config.setup
|
9
|
+
Godwit::Config[:silence] = true
|
10
|
+
Godwit::Bootloader.stub!(:boot).and_return(nil)
|
11
|
+
@godwit = Godwit::Base.new
|
12
|
+
@godwit.stub!(:run_all).and_return(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call #before_run" do
|
16
|
+
@godwit.should_receive(:before_run).once
|
17
|
+
@godwit.run
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should call #after_run" do
|
21
|
+
@godwit.should_receive(:after_run).once
|
22
|
+
@godwit.run
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
Godwit::Config.configuration = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'godwit')
|
4
|
+
|
5
|
+
describe 'Godwit::Config' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Godwit::Config.configuration = nil
|
9
|
+
Godwit::Config.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to yield the configuration via #use" do
|
13
|
+
res = nil
|
14
|
+
Godwit::Config.use {|c| res = c}
|
15
|
+
res.should == Godwit::Config.defaults
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to get a configuration key" do
|
19
|
+
Godwit::Config[:bar] = "foo"
|
20
|
+
Godwit::Config[:bar].should == "foo"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be able to delete a configuration key" do
|
24
|
+
Godwit::Config[:bar] = "foo"
|
25
|
+
Godwit::Config.delete(:bar)
|
26
|
+
Godwit::Config[:bar].should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should support -d to debug" do
|
30
|
+
Godwit::Config.parse_args(["-D"])
|
31
|
+
Godwit::Config[:debug].should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should support -s to silence output" do
|
35
|
+
Godwit::Config.parse_args(["-s"])
|
36
|
+
Godwit::Config[:silence].should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should support -d to skip dependencies" do
|
40
|
+
Godwit::Config.parse_args(["-d"])
|
41
|
+
Godwit::Config[:skip_dependencies].should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should support -m to skip migrations" do
|
45
|
+
Godwit::Config.parse_args(["-m", "products_migration,manufacturer_migration"])
|
46
|
+
Godwit::Config[:skip_migrations].should == ["products_migration","manufacturer_migration"]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should support -S to run a specific migration" do
|
50
|
+
Godwit::Config.parse_args(['-S', 'products_migration'])
|
51
|
+
Godwit::Config[:specific_migration].should == 'products_migration'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'GodwitGenerator' do
|
4
|
+
|
5
|
+
include GeneratorSpecHelper
|
6
|
+
|
7
|
+
before do
|
8
|
+
source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../app_generators"))
|
9
|
+
RubiGen::Base.reset_sources
|
10
|
+
RubiGen::Base.prepend_sources source
|
11
|
+
@generator = RubiGen::Scripts::Generate.new
|
12
|
+
@test_path = File.join(File.dirname(__FILE__), '..', 'tmp', 'test')
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(tmp script log config app/models/legacy app/migrations lib vendor vendor/plugins data).each do |dir|
|
16
|
+
it "should create the '#{dir}' directory" do
|
17
|
+
silence_generator { @generator.run(['tmp/test'], :generator => 'godwit') }
|
18
|
+
File.directory?(File.join(@test_path, dir)).should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
%w(Rakefile config/database.yml config/environment.rb log/active_migration.log log/active_record.log
|
23
|
+
script/console script/migrate script/generate script/destroy script/lib/console.rb).each do |file|
|
24
|
+
it "should create the '#{file}' file" do
|
25
|
+
silence_generator { @generator.run(['tmp/test'], :generator => 'godwit') }
|
26
|
+
File.file?(File.join(@test_path, file)).should be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
FileUtils.rm_rf(@test_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'LegacyModelGenerator' do
|
4
|
+
|
5
|
+
include GeneratorSpecHelper
|
6
|
+
|
7
|
+
before do
|
8
|
+
source = RubiGen::PathSource.new(:component, File.join(File.dirname(__FILE__), "../godwit_generators"))
|
9
|
+
RubiGen::Base.reset_sources
|
10
|
+
RubiGen::Base.prepend_sources source
|
11
|
+
@generator = RubiGen::Scripts::Generate.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should generate a legacy model in the legacy models directory" do
|
15
|
+
silence_generator { @generator.run(['blah'], :generator => 'legacy_model') }
|
16
|
+
File.file?(File.join(APP_ROOT, 'app', 'models', 'legacy', 'blah.rb')).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
FileUtils.rm_rf(File.join(APP_ROOT, 'app'))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|