padrino-gen 0.9.14 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +17 -2
- data/Rakefile +1 -2
- data/bin/padrino-gen +2 -3
- data/lib/padrino-gen.rb +2 -2
- data/lib/padrino-gen/generators/actions.rb +62 -8
- data/lib/padrino-gen/generators/app.rb +2 -1
- data/lib/padrino-gen/generators/cli.rb +3 -3
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +10 -9
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +11 -9
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/mongomatic.rb +85 -0
- data/lib/padrino-gen/generators/components/orms/ohm.rb +72 -0
- data/lib/padrino-gen/generators/components/orms/sequel.rb +12 -11
- data/lib/padrino-gen/generators/components/renderers/erubis.rb +3 -0
- data/lib/padrino-gen/generators/components/renderers/liquid.rb +4 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +3 -3
- data/lib/padrino-gen/generators/components/stylesheets/compass/application.scss +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +12 -23
- data/lib/padrino-gen/generators/components/stylesheets/sass.rb +6 -16
- data/lib/padrino-gen/generators/components/stylesheets/scss.rb +16 -0
- data/lib/padrino-gen/generators/components/tests/riot.rb +5 -23
- data/lib/padrino-gen/generators/controller.rb +1 -1
- data/lib/padrino-gen/generators/mailer.rb +3 -1
- data/lib/padrino-gen/generators/migration.rb +1 -1
- data/lib/padrino-gen/generators/model.rb +1 -1
- data/lib/padrino-gen/generators/plugin.rb +47 -0
- data/lib/padrino-gen/generators/project.rb +39 -22
- data/lib/padrino-gen/generators/project/config/boot.rb +12 -0
- data/lib/padrino-gen/generators/runner.rb +90 -0
- data/lib/padrino-gen/generators/templates/initializer.rb.tt +5 -0
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +10 -0
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +8 -7
- data/padrino-gen.gemspec +11 -12
- data/test/fixtures/admin_template.rb +7 -0
- data/test/fixtures/example_template.rb +14 -0
- data/test/fixtures/git_template.rb +4 -0
- data/test/fixtures/plugin_template.rb +13 -0
- data/test/fixtures/rake_template.rb +9 -0
- data/test/helper.rb +64 -2
- data/test/test_app_generator.rb +16 -1
- data/test/test_controller_generator.rb +1 -1
- data/test/test_generator.rb +1 -1
- data/test/test_mailer_generator.rb +11 -1
- data/test/test_model_generator.rb +64 -20
- data/test/test_plugin_generator.rb +123 -0
- data/test/test_project_generator.rb +134 -77
- metadata +37 -103
@@ -15,4 +15,16 @@ end
|
|
15
15
|
Bundler.require(:default, PADRINO_ENV.to_sym)
|
16
16
|
puts "=> Located #{Padrino.bundle} Gemfile for #{Padrino.env}"
|
17
17
|
|
18
|
+
##
|
19
|
+
# Add here your before load hooks
|
20
|
+
#
|
21
|
+
Padrino.before_load do
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Add here your after load hooks
|
26
|
+
#
|
27
|
+
Padrino.after_load do
|
28
|
+
end
|
29
|
+
|
18
30
|
Padrino.load!
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Generators
|
5
|
+
module Runner
|
6
|
+
|
7
|
+
# Generates project scaffold based on a given template file
|
8
|
+
# project :test => :shoulda, :orm => :activerecord, :renderer => "haml"
|
9
|
+
def project(options={})
|
10
|
+
components = options.map { |component, value| "--#{component}=#{value}" }
|
11
|
+
params = [name, *components].push("-r=#{destination_root("../")}")
|
12
|
+
say "=> Executing: padrino-gen #{name} #{params.join(" ")}", :magenta
|
13
|
+
Padrino.bin_gen(*params.unshift("project"))
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes generator command for specified type with given arguments
|
17
|
+
# generate :model, "post title:string body:text"
|
18
|
+
# generate :controller, "posts get:index get:new post:new"
|
19
|
+
# generate :migration, "AddEmailToUser email:string"
|
20
|
+
def generate(type, arguments="")
|
21
|
+
params = arguments.split(" ").push("-r=#{destination_root}")
|
22
|
+
params.push("--app=#{@_app_name}") if @_app_name
|
23
|
+
say "=> Executing: padrino-gen #{type} #{params.join(" ")}", :magenta
|
24
|
+
Padrino.bin_gen(*params.unshift(type))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Executes rake command with given arguments
|
28
|
+
# rake "custom task1 task2"
|
29
|
+
def rake(command)
|
30
|
+
Padrino.bin("rake", command, "-c=#{destination_root}")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Executes App generator. Accepts an optional block allowing generation inside subapp.
|
34
|
+
# app :name
|
35
|
+
# app :name do
|
36
|
+
# generate :model, "posts title:string"
|
37
|
+
# end
|
38
|
+
def app(name, &block)
|
39
|
+
say "=> Executing: padrino-gen app #{name} -r=#{destination_root}", :magenta
|
40
|
+
Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
|
41
|
+
if block_given?
|
42
|
+
@_app_name = name
|
43
|
+
block.call
|
44
|
+
@_app_name = nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Executes git commmands in project using Grit
|
49
|
+
# git :init
|
50
|
+
# git :add, "."
|
51
|
+
# git :commit, "hello world"
|
52
|
+
def git(action, arguments=nil)
|
53
|
+
FileUtils.cd(destination_root) do
|
54
|
+
require 'git' unless defined?(::Git)
|
55
|
+
if action.to_s == 'init'
|
56
|
+
::Git.init(arguments || destination_root)
|
57
|
+
say "Git repo has been initialized", :green
|
58
|
+
else
|
59
|
+
@_git ||= ::Git.open(destination_root)
|
60
|
+
@_git.method(action).call(arguments)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
# Resolves the path to the plugin template
|
67
|
+
# given the project_name and the template_file
|
68
|
+
# execute_runner(:plugin, 'path/to/local/file')
|
69
|
+
# execute_runner(:plugin, 'hoptoad')
|
70
|
+
# execute_runner(:template, 'sampleblog')
|
71
|
+
# execute_runner(:template, 'http://gist.github.com/357045')
|
72
|
+
def execute_runner(kind, template_file)
|
73
|
+
# Determine resolved template path
|
74
|
+
template_file = template_file.to_s
|
75
|
+
template_path = case
|
76
|
+
when template_file =~ %r{^http://} && template_file !~ /gist/
|
77
|
+
template_file
|
78
|
+
when template_file =~ /gist/ && template_file !~ /raw/
|
79
|
+
raw_link, _ = *open(template_file).read.scan(/<a\s+href\s?\=\"(.*?)\"\>raw/)
|
80
|
+
raw_link ? "http://gist.github.com#{raw_link[0]}" : template_file
|
81
|
+
when File.extname(template_file).blank? # referencing official plugin (i.e hoptoad)
|
82
|
+
"http://github.com/padrino/padrino-recipes/raw/master/#{kind.to_s.pluralize}/#{template_file}_#{kind}.rb"
|
83
|
+
else # local file on system
|
84
|
+
File.expand_path(template_file)
|
85
|
+
end
|
86
|
+
self.apply(template_path)
|
87
|
+
end
|
88
|
+
end # Runner
|
89
|
+
end # Generators
|
90
|
+
end # Padrino
|
@@ -34,5 +34,15 @@
|
|
34
34
|
#
|
35
35
|
|
36
36
|
<%= @app_name %>.mailer :<%= @short_name %> do
|
37
|
+
<%- if @actions.nil? || @actions.empty? -%>
|
37
38
|
# Message definitions here...
|
39
|
+
<%- else -%>
|
40
|
+
<%- @actions.each do |action| -%>
|
41
|
+
|
42
|
+
email <%=action.inspect%> do
|
43
|
+
# Your mailer goes here
|
44
|
+
end
|
45
|
+
|
46
|
+
<%- end -%>
|
47
|
+
<%- end -%>
|
38
48
|
end
|
@@ -43,7 +43,7 @@ if defined?(DataMapper)
|
|
43
43
|
desc "Create the database"
|
44
44
|
task :create => :environment do
|
45
45
|
config = DataMapper.repository.adapter.options.symbolize_keys
|
46
|
-
user, password = config[:user], config[:password]
|
46
|
+
user, password, host = config[:user], config[:password], config[:host]
|
47
47
|
database = config[:database] || config[:path].sub(/\//, "")
|
48
48
|
charset = config[:charset] || ENV['CHARSET'] || 'utf8'
|
49
49
|
collation = config[:collation] || ENV['COLLATION'] || 'utf8_unicode_ci'
|
@@ -53,10 +53,11 @@ if defined?(DataMapper)
|
|
53
53
|
system("createdb", "-E", charset, "-U", user, database)
|
54
54
|
puts "<= dm:create executed"
|
55
55
|
when 'mysql'
|
56
|
-
|
57
|
-
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), "-e",
|
58
|
-
"CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}"
|
59
|
-
|
56
|
+
query = [
|
57
|
+
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
|
58
|
+
"CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}".inspect
|
59
|
+
]
|
60
|
+
system(query.compact.join(" "))
|
60
61
|
puts "<= dm:create executed"
|
61
62
|
when 'sqlite3'
|
62
63
|
DataMapper.setup(DataMapper.repository.name, config)
|
@@ -68,7 +69,7 @@ if defined?(DataMapper)
|
|
68
69
|
desc "Drop the database (postgres and mysql only)"
|
69
70
|
task :drop => :environment do
|
70
71
|
config = DataMapper.repository.adapter.options.symbolize_keys
|
71
|
-
user, password = config[:user], config[:password]
|
72
|
+
user, password, host = config[:user], config[:password], config[:host]
|
72
73
|
database = config[:database] || config[:path].sub(/\//, "")
|
73
74
|
puts "=> Dropping database '#{database}'"
|
74
75
|
case config[:adapter]
|
@@ -77,7 +78,7 @@ if defined?(DataMapper)
|
|
77
78
|
puts "<= dm:drop executed"
|
78
79
|
when 'mysql'
|
79
80
|
query = [
|
80
|
-
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), "-e",
|
81
|
+
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
|
81
82
|
"DROP DATABASE IF EXISTS #{database}".inspect
|
82
83
|
]
|
83
84
|
system(query.compact.join(" "))
|
data/padrino-gen.gemspec
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler'
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
-
s.rubyforge_project =
|
4
|
+
s.name = "padrino-gen"
|
5
|
+
s.rubyforge_project = "padrino-gen"
|
8
6
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
9
|
-
s.email =
|
10
|
-
s.summary =
|
11
|
-
s.homepage =
|
12
|
-
s.description =
|
13
|
-
s.default_executable =
|
7
|
+
s.email = "padrinorb@gmail.com"
|
8
|
+
s.summary = "Generators for easily creating and building padrino applications"
|
9
|
+
s.homepage = "http://www.padrinorb.com"
|
10
|
+
s.description = "Generators for easily creating and building padrino applications from the console"
|
11
|
+
s.default_executable = "padrino-gen"
|
14
12
|
s.executables = ["padrino-gen"]
|
15
13
|
s.required_rubygems_version = ">= 1.3.6"
|
16
14
|
s.version = Padrino.version
|
@@ -18,7 +16,8 @@ Gem::Specification.new do |s|
|
|
18
16
|
s.extra_rdoc_files = Dir["*.rdoc"]
|
19
17
|
s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-gen.gemspec) + Dir.glob("{bin,lib,test}/**/*")
|
20
18
|
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
-
s.require_path =
|
22
|
-
s.
|
23
|
-
s.
|
19
|
+
s.require_path = "lib"
|
20
|
+
s.add_dependency("padrino-core", Padrino.version)
|
21
|
+
s.add_dependency("bundler", ">= 1.0.0.rc.2")
|
22
|
+
s.add_dependency("git")
|
24
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
project :test => :shoulda, :orm => :activerecord, :dev => true
|
2
|
+
|
3
|
+
generate :model, "post title:string body:text"
|
4
|
+
generate :controller, "posts get:index get:new post:new"
|
5
|
+
generate :migration, "AddEmailToUser email:string"
|
6
|
+
generate :fake, "foo bar"
|
7
|
+
|
8
|
+
require_dependencies 'nokogiri'
|
9
|
+
|
10
|
+
initializer :test, "# Example"
|
11
|
+
|
12
|
+
app :testapp do
|
13
|
+
generate :controller, "users get:index"
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Template to get Hoptoad on Padrino
|
2
|
+
# prereqs:
|
3
|
+
# sudo gem install rack_hoptoad
|
4
|
+
# http://github.com/atmos/rack_hoptoad
|
5
|
+
HOPTOAD = <<-HOPTOAD
|
6
|
+
app.use Rack::Hoptoad, 'API_KEY_HERE' do |notifier|
|
7
|
+
#notifier.report_under << 'custom'
|
8
|
+
#notifier.environment_filters << %w(MY_SECRET_KEY MY_SECRET_TOKEN)
|
9
|
+
end
|
10
|
+
HOPTOAD
|
11
|
+
require_dependencies 'rack_hoptoad', :require => 'rack/hoptoad'
|
12
|
+
initializer :hoptoad,HOPTOAD
|
13
|
+
inject_into_file destination_root('/app/app.rb')," enable :raise_errors\n", :after => "configure do\n"
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require File.expand_path('../../../load_paths', __FILE__)
|
2
2
|
require 'test/unit'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'rack'
|
3
5
|
require 'shoulda'
|
4
6
|
require 'mocha'
|
5
|
-
require 'rack/test'
|
6
7
|
require 'webrat'
|
8
|
+
require 'git'
|
7
9
|
require 'thor/group'
|
10
|
+
require 'fakeweb'
|
8
11
|
require 'padrino-gen'
|
9
12
|
require 'padrino-core/support_lite' unless defined?(SupportLite)
|
10
13
|
|
@@ -67,8 +70,67 @@ class Test::Unit::TestCase
|
|
67
70
|
end
|
68
71
|
|
69
72
|
def assert_no_match_in_file(pattern, file)
|
70
|
-
File.exists?(file) ?
|
73
|
+
File.exists?(file) ? assert_no_match(pattern, File.read(file)) : assert_file_exists(file)
|
74
|
+
end
|
75
|
+
|
76
|
+
# expects_generated :model, "post title:string body:text"
|
77
|
+
def expects_generated(generator, params="")
|
78
|
+
Padrino.expects(:bin_gen).with(generator, *params.split(' ')).returns(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
# expects_generated_project :test => :shoulda, :orm => :activerecord, :dev => true
|
82
|
+
def expects_generated_project(options={})
|
83
|
+
settings = options.slice!(:name, :root)
|
84
|
+
options.reverse_merge!(:name => 'sample_project', :root => '/tmp')
|
85
|
+
components = settings.map { |component, value| "--#{component}=#{value}" }
|
86
|
+
params = [options[:name], *components].push("-r=#{options[:root]}")
|
87
|
+
Padrino.expects(:bin_gen).with(*params.unshift('project')).returns(true)
|
88
|
+
end
|
89
|
+
|
90
|
+
# expects_dependencies 'nokogiri'
|
91
|
+
def expects_dependencies(name)
|
92
|
+
instance = mock
|
93
|
+
instance.expects(:invoke!).once
|
94
|
+
include_text = "gem '#{name}'\n"
|
95
|
+
Thor::Actions::InjectIntoFile.expects(:new).with(anything,'Gemfile', include_text, anything).returns(instance)
|
96
|
+
end
|
97
|
+
|
98
|
+
# expects_initializer :test, "# Example"
|
99
|
+
def expects_initializer(name, body,options={})
|
100
|
+
options.reverse_merge!(:root => "/tmp/sample_project")
|
101
|
+
path = File.join(options[:root],'lib',"#{name}_init.rb")
|
102
|
+
instance = mock
|
103
|
+
instance.expects(:invoke!).at_least_once
|
104
|
+
include_text = " register #{name.to_s.camelize}Initializer\n"
|
105
|
+
Thor::Actions::InjectIntoFile.expects(:new).with(anything,anything, include_text, anything).returns(instance)
|
106
|
+
Thor::Actions::CreateFile.expects(:new).with(anything, path, kind_of(Proc), anything).returns(instance)
|
71
107
|
end
|
108
|
+
|
109
|
+
def expects
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# expects_rake "custom"
|
114
|
+
def expects_rake(command,options={})
|
115
|
+
options.reverse_merge!(:root => '/tmp')
|
116
|
+
Padrino.expects(:bin).with("rake", command, "-c=#{options[:root]}").returns(true)
|
117
|
+
end
|
118
|
+
|
119
|
+
# expects_git :commit, "hello world"
|
120
|
+
def expects_git(command,options={})
|
121
|
+
options.reverse_merge!(:root => '/tmp')
|
122
|
+
FileUtils.mkdir_p(options[:root])
|
123
|
+
if command.to_s == 'init'
|
124
|
+
args = options[:arguments] || options[:root]
|
125
|
+
::Git.expects(:init).with(args).returns(true)
|
126
|
+
else
|
127
|
+
base = ::Git::Base.new
|
128
|
+
# base.expects(command.to_sym).with(options[:arguments]).returns(true)
|
129
|
+
::Git.stubs(:open).with(options[:root]).returns(base)
|
130
|
+
::Git::Base.any_instance.expects(command.to_sym).with(options[:arguments]).returns(true)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
72
134
|
end
|
73
135
|
|
74
136
|
class Object
|
data/test/test_app_generator.rb
CHANGED
@@ -58,5 +58,20 @@ class TestAppGenerator < Test::Unit::TestCase
|
|
58
58
|
assert_match_in_file(/DemoApp.mailer :demo/m, '/tmp/sample_project/demo_app/mailers/demo.rb')
|
59
59
|
assert_dir_exists('/tmp/sample_project/demo_app/views/mailers/demo')
|
60
60
|
end
|
61
|
+
|
62
|
+
# only destroys what it generated.
|
63
|
+
# hence, the folder will still exists if other changes were made to it.
|
64
|
+
should "destroys itself" do
|
65
|
+
silence_logger { generate(:project, 'sample_project','--root=/tmp') }
|
66
|
+
silence_logger { generate(:app, 'demo', '--root=/tmp/sample_project') }
|
67
|
+
output = silence_logger { generate(:app, 'demo', '--root=/tmp/sample_project', '-d') }
|
68
|
+
assert_no_match(/has been mounted/, output)
|
69
|
+
assert_no_dir_exists('/tmp/sample_project/public/demo')
|
70
|
+
assert_no_file_exists('/tmp/sample_project/demo/app.rb')
|
71
|
+
assert_no_dir_exists('/tmp/sample_project/demo/controllers')
|
72
|
+
assert_no_dir_exists('/tmp/sample_project/demo/helpers')
|
73
|
+
assert_no_dir_exists('/tmp/sample_project/demo/views')
|
74
|
+
assert_no_match_in_file(/Padrino\.mount\("Demo"\).to\("\/demo"\)/,'/tmp/sample_project/config/apps.rb')
|
75
|
+
end
|
61
76
|
end
|
62
|
-
end
|
77
|
+
end
|
data/test/test_generator.rb
CHANGED
@@ -4,7 +4,7 @@ class TestGenerator < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
context "the generator" do
|
6
6
|
should "have default generators" do
|
7
|
-
%w{controller mailer migration model app}.each do |gen|
|
7
|
+
%w{controller mailer migration model app plugin}.each do |gen|
|
8
8
|
assert Padrino::Generators.mappings.has_key?(gen.to_sym)
|
9
9
|
assert_equal "Padrino::Generators::#{gen.camelize}", Padrino::Generators.mappings[gen.to_sym].name
|
10
10
|
assert Padrino::Generators.mappings[gen.to_sym].respond_to?(:start)
|
@@ -20,6 +20,16 @@ class TestMailerGenerator < Test::Unit::TestCase
|
|
20
20
|
assert_dir_exists('/tmp/sample_project/subby/views/mailers/demo')
|
21
21
|
end
|
22
22
|
|
23
|
+
should "generate mailer in specified app with actions" do
|
24
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
25
|
+
silence_logger { generate(:app, 'subby', '-r=/tmp/sample_project') }
|
26
|
+
silence_logger { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby', '-r=/tmp/sample_project') }
|
27
|
+
assert_match_in_file(/Subby.mailer :demo/m, '/tmp/sample_project/subby/mailers/demo.rb')
|
28
|
+
assert_match_in_file(/email :action1 do.*?end/m, '/tmp/sample_project/subby/mailers/demo.rb')
|
29
|
+
assert_match_in_file(/email :action2 do.*?end/m, '/tmp/sample_project/subby/mailers/demo.rb')
|
30
|
+
assert_dir_exists('/tmp/sample_project/subby/views/mailers/demo')
|
31
|
+
end
|
32
|
+
|
23
33
|
should "support generating a new mailer extended from base" do
|
24
34
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
25
35
|
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project') }
|
@@ -51,4 +61,4 @@ class TestMailerGenerator < Test::Unit::TestCase
|
|
51
61
|
assert_no_file_exists('/tmp/sample_project/app/mailers/demo.rb')
|
52
62
|
end
|
53
63
|
end
|
54
|
-
end
|
64
|
+
end
|
@@ -50,6 +50,7 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
50
50
|
assert_match_in_file(/property :body, String/m, '/tmp/sample_project/subby/models/post.rb')
|
51
51
|
assert_match_in_file(/migration 1, :create_posts do/m, "/tmp/sample_project/db/migrate/001_create_posts.rb")
|
52
52
|
assert_match_in_file(/gem 'data_mapper'/m,'/tmp/sample_project/Gemfile')
|
53
|
+
assert_match_in_file(/DataMapper.finalize/m,'/tmp/sample_project/config/boot.rb')
|
53
54
|
end
|
54
55
|
|
55
56
|
should "generate only generate model once" do
|
@@ -171,7 +172,30 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
174
|
-
#
|
175
|
+
# SEQUEL
|
176
|
+
context "model generator using sequel" do
|
177
|
+
should "generate model file with given properties" do
|
178
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=sequel') }
|
179
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project') }
|
180
|
+
assert_match_in_file(/class User < Sequel::Model/m, '/tmp/sample_project/app/models/user.rb')
|
181
|
+
end
|
182
|
+
|
183
|
+
should "generate migration file with given properties" do
|
184
|
+
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
185
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=sequel') }
|
186
|
+
silence_logger { generate(:model, 'person', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project') }
|
187
|
+
migration_file_path = "/tmp/sample_project/db/migrate/001_create_people.rb"
|
188
|
+
assert_match_in_file(/class Person < Sequel::Model/m, '/tmp/sample_project/app/models/person.rb')
|
189
|
+
assert_match_in_file(/class CreatePeople < Sequel::Migration/m, migration_file_path)
|
190
|
+
assert_match_in_file(/create_table :people/m, migration_file_path)
|
191
|
+
assert_match_in_file(/String :name/m, migration_file_path)
|
192
|
+
assert_match_in_file(/Integer :age/m, migration_file_path)
|
193
|
+
assert_match_in_file(/DateTime :created/m, migration_file_path)
|
194
|
+
assert_match_in_file(/drop_table :people/m, migration_file_path)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# MONGODB
|
175
199
|
context "model generator using mongomapper" do
|
176
200
|
should "generate model file with no properties" do
|
177
201
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongomapper') }
|
@@ -210,26 +234,46 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
210
234
|
end
|
211
235
|
end
|
212
236
|
|
213
|
-
#
|
214
|
-
context "model generator using
|
215
|
-
should "generate model file with
|
216
|
-
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=
|
217
|
-
silence_logger { generate(:model, '
|
218
|
-
assert_match_in_file(/class
|
237
|
+
# REDIS
|
238
|
+
context "model generator using ohm" do
|
239
|
+
should "generate model file with no properties" do
|
240
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=ohm') }
|
241
|
+
silence_logger { generate(:model, 'person', '-r=/tmp/sample_project') }
|
242
|
+
assert_match_in_file(/class Person < Ohm::Model/, '/tmp/sample_project/app/models/person.rb')
|
243
|
+
assert_match_in_file(/include Ohm::Timestamping/, '/tmp/sample_project/app/models/person.rb')
|
244
|
+
assert_match_in_file(/include Ohm::Typecast/, '/tmp/sample_project/app/models/person.rb')
|
245
|
+
assert_match_in_file(/# attribute :name/m, '/tmp/sample_project/app/models/person.rb')
|
246
|
+
assert_match_in_file(/# reference :venue, Venue/m, '/tmp/sample_project/app/models/person.rb')
|
219
247
|
end
|
220
248
|
|
221
|
-
should "generate
|
222
|
-
|
223
|
-
silence_logger { generate(:
|
224
|
-
|
225
|
-
|
226
|
-
assert_match_in_file(/
|
227
|
-
assert_match_in_file(/
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
249
|
+
should "generate model file with given fields" do
|
250
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=ohm') }
|
251
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project') }
|
252
|
+
assert_match_in_file(/class User < Ohm::Model/, '/tmp/sample_project/app/models/user.rb')
|
253
|
+
assert_match_in_file(/attribute :name, String/m, '/tmp/sample_project/app/models/user.rb')
|
254
|
+
assert_match_in_file(/attribute :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
|
255
|
+
assert_match_in_file(/attribute :email, String/m, '/tmp/sample_project/app/models/user.rb')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# MONGOMATIC
|
260
|
+
context "model generator using mongomatic" do
|
261
|
+
should "generate model file with no properties" do
|
262
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongomatic') }
|
263
|
+
silence_logger { generate(:model, 'person', '-r=/tmp/sample_project') }
|
264
|
+
assert_match_in_file(/class Person < Mongomatic::Base/, '/tmp/sample_project/app/models/person.rb')
|
265
|
+
assert_match_in_file(/include Mongomatic::Expectations::Helper/m, '/tmp/sample_project/app/models/person.rb')
|
266
|
+
end
|
267
|
+
|
268
|
+
should "generate model file with given fields" do
|
269
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongomatic') }
|
270
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project') }
|
271
|
+
assert_match_in_file(/class User < Mongomatic::Base/, '/tmp/sample_project/app/models/user.rb')
|
272
|
+
assert_match_in_file(/include Mongomatic::Expectations::Helper/, '/tmp/sample_project/app/models/user.rb')
|
273
|
+
assert_match_in_file(/be_present self\['name'\]/m, '/tmp/sample_project/app/models/user.rb')
|
274
|
+
assert_match_in_file(/be_present self\['age'\]/m, '/tmp/sample_project/app/models/user.rb')
|
275
|
+
assert_match_in_file(/be_present self\['email'\]/m, '/tmp/sample_project/app/models/user.rb')
|
276
|
+
assert_match_in_file(/be_a_number self\['age'\]/m, '/tmp/sample_project/app/models/user.rb')
|
233
277
|
end
|
234
278
|
end
|
235
279
|
|
@@ -307,4 +351,4 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
307
351
|
assert_no_file_exists('/tmp/sample_project/db/migrate/002_create_users.rb')
|
308
352
|
end
|
309
353
|
end
|
310
|
-
end
|
354
|
+
end
|