padrino-gen 0.13.0.beta2 → 0.13.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-gen/generators/app/app.rb.tt +1 -1
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +16 -0
- data/lib/padrino-gen/generators/components/tests/testunit.rb +110 -0
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +2 -0
- data/test/test_controller_generator.rb +8 -0
- data/test/test_helper_generator.rb +8 -0
- data/test/test_model_generator.rb +6 -0
- data/test/test_project_generator.rb +15 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aceae5b873cbcba1e4b72aa2dcb1f0466be21683
|
4
|
+
data.tar.gz: 746ce83ec7367d4472913f10efccedfe53af73e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c568757fda1a7f6a05e28baf039fcf87d68b788d9d98ed7c0d4969215813eefa23002e03398119e5e392b9bfe9c298fc7d5b687cc152c685641d32f22db4ae
|
7
|
+
data.tar.gz: 5313b5922d16b4cbb587514f1b20bee6d1a5a3c7750d5ef39993fefa08426c69b5e8aba8ec9b46a1e082276551a9b4dac8437f1843053c0ebc6cd349fa5169f5
|
@@ -15,7 +15,7 @@ module <%= @project_name %>
|
|
15
15
|
#
|
16
16
|
# set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
|
17
17
|
# set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
|
18
|
-
# set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
|
18
|
+
# set :cache, Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1)
|
19
19
|
# set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
|
20
20
|
# set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
|
21
21
|
# set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
|
@@ -41,6 +41,21 @@ case Padrino.env
|
|
41
41
|
end
|
42
42
|
DM
|
43
43
|
|
44
|
+
IDENTITY_MAP_MIDDLEWARE = <<-MIDDLEWARE
|
45
|
+
class IdentityMap
|
46
|
+
def initialize(app, name = :default)
|
47
|
+
@app = app
|
48
|
+
@name = name.to_sym
|
49
|
+
end
|
50
|
+
|
51
|
+
def call(env)
|
52
|
+
::DataMapper.repository(@name) do
|
53
|
+
@app.call(env)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
MIDDLEWARE
|
58
|
+
|
44
59
|
def setup_orm
|
45
60
|
dm = DM
|
46
61
|
db = @project_name.underscore
|
@@ -73,6 +88,7 @@ def setup_orm
|
|
73
88
|
|
74
89
|
create_file("config/database.rb", dm)
|
75
90
|
insert_hook("DataMapper.finalize", :after_load)
|
91
|
+
middleware :identity_map, IDENTITY_MAP_MIDDLEWARE
|
76
92
|
end
|
77
93
|
|
78
94
|
DM_MODEL = (<<-MODEL) unless defined?(DM_MODEL)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
TESTUNIT_SETUP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_SETUP)
|
2
|
+
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
|
4
|
+
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))
|
5
|
+
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
# You can use this method to custom specify a Rack app
|
10
|
+
# you want rack-test to invoke:
|
11
|
+
#
|
12
|
+
# app CLASS_NAME
|
13
|
+
# app CLASS_NAME.tap { |a| }
|
14
|
+
# app(CLASS_NAME) do
|
15
|
+
# set :foo, :bar
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
def app(app = nil, &blk)
|
19
|
+
@app ||= block_given? ? app.instance_eval(&blk) : app
|
20
|
+
@app ||= Padrino.application
|
21
|
+
end
|
22
|
+
end
|
23
|
+
TEST
|
24
|
+
|
25
|
+
TESTUNIT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_RAKE)
|
26
|
+
require 'rake/testtask'
|
27
|
+
|
28
|
+
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
29
|
+
|
30
|
+
test_tasks.each do |folder|
|
31
|
+
Rake::TestTask.new("test:\#{folder}") do |test|
|
32
|
+
test.pattern = "test/\#{folder}/**/*_test.rb"
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Run application test suite"
|
38
|
+
task 'test' => test_tasks.map { |f| "test:\#{f}" }
|
39
|
+
TEST
|
40
|
+
|
41
|
+
TESTUNIT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_CONTROLLER_TEST)
|
42
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
|
43
|
+
|
44
|
+
class !NAME!ControllerTest < Test::Unit::TestCase
|
45
|
+
def setup
|
46
|
+
get "/"
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_returns_hello_world_text
|
50
|
+
assert_equal "Hello World", last_response.body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
TEST
|
54
|
+
|
55
|
+
TESTUNIT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_MODEL_TEST)
|
56
|
+
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')
|
57
|
+
|
58
|
+
class !NAME!Test < Test::Unit::TestCase
|
59
|
+
def test_constructs_a_new_instance
|
60
|
+
@!DNAME! = !NAME!.new
|
61
|
+
refute_nil @!DNAME!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
TEST
|
65
|
+
|
66
|
+
TESTUNIT_HELPER_TEST = (<<-TEST) unless defined?(TESTUNIT_HELPER_TEST)
|
67
|
+
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')
|
68
|
+
|
69
|
+
class !NAME!Test < Test::Unit::TestCase
|
70
|
+
def self.setup
|
71
|
+
@helpers = Class.new
|
72
|
+
@helpers.extend !CONSTANT_NAME!
|
73
|
+
end
|
74
|
+
|
75
|
+
def helpers
|
76
|
+
@helpers
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_foo_helper
|
80
|
+
assert_equal nil, helpers.foo
|
81
|
+
end
|
82
|
+
end
|
83
|
+
TEST
|
84
|
+
|
85
|
+
def setup_test
|
86
|
+
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
|
87
|
+
require_dependencies 'test-unit', :require => 'test/unit', :group => 'test'
|
88
|
+
insert_test_suite_setup TESTUNIT_SETUP
|
89
|
+
create_file destination_root("test/test.rake"), TESTUNIT_RAKE
|
90
|
+
end
|
91
|
+
|
92
|
+
def generate_controller_test(name, path)
|
93
|
+
test_unit_contents = TESTUNIT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
94
|
+
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
95
|
+
create_file destination_root(controller_test_path), test_unit_contents, :skip => true
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_model_test(name)
|
99
|
+
test_unit_contents = TESTUNIT_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
100
|
+
test_unit_contents.gsub!(/!PATH!/, recognize_path)
|
101
|
+
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
102
|
+
create_file destination_root(model_test_path), test_unit_contents, :skip => true
|
103
|
+
end
|
104
|
+
|
105
|
+
def generate_helper_test(name, project_name, app_name)
|
106
|
+
test_unit_contents = TESTUNIT_HELPER_TEST.gsub(/!NAME!/, name).gsub(/!CONSTANT_NAME!/, "#{project_name}::#{app_name}::#{name}")
|
107
|
+
test_unit_contents.gsub!(/!PATH!/, recognize_path)
|
108
|
+
helper_spec_path = File.join('test', options[:app], 'helpers', "#{name.underscore}_test.rb")
|
109
|
+
create_file destination_root(helper_spec_path), test_unit_contents, :skip => true
|
110
|
+
end
|
@@ -86,6 +86,8 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
|
|
86
86
|
task :setup => [:create, :migrate, :seed]
|
87
87
|
end
|
88
88
|
|
89
|
+
task 'db:migrate:down' => 'dm:migrate:down'
|
90
|
+
task 'db:migrate:up' => 'dm:migrate:up'
|
89
91
|
task 'db:migrate' => 'dm:migrate'
|
90
92
|
task 'db:create' => 'dm:create'
|
91
93
|
task 'db:drop' => 'dm:drop'
|
@@ -200,6 +200,14 @@ describe "ControllerGenerator" do
|
|
200
200
|
assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
|
201
201
|
end
|
202
202
|
|
203
|
+
it "should generate controller test for testunit" do
|
204
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testunit') }
|
205
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
206
|
+
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
207
|
+
assert_match_in_file(/class DemoItemsControllerTest < Test::Unit::TestCase/m, "#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
|
208
|
+
end
|
209
|
+
|
210
|
+
|
203
211
|
it 'should correctly generate file names' do
|
204
212
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
205
213
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
@@ -95,6 +95,14 @@ describe "HelperGenerator" do
|
|
95
95
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
96
96
|
end
|
97
97
|
|
98
|
+
it "should generate helper test for testunit" do
|
99
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=testunit', '--script=none') }
|
100
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
101
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
102
|
+
assert_match_in_file(/class DemoItemsHelperTest < Test::Unit::TestCase/m, "#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
103
|
+
assert_match_in_file(/@helpers\.extend SampleProject::Subby::DemoItemsHelper/m, "#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
104
|
+
end
|
105
|
+
|
98
106
|
it 'should correctly generate file names' do
|
99
107
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
100
108
|
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
@@ -214,6 +214,12 @@ describe "ModelGenerator" do
|
|
214
214
|
|
215
215
|
# DATAMAPPER
|
216
216
|
describe "model generator using datamapper" do
|
217
|
+
it 'should add activerecord middleware' do
|
218
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
|
219
|
+
assert_match_in_file(/ use IdentityMap/m, "#{@apptmp}/sample_project/app/app.rb")
|
220
|
+
assert_file_exists("#{@apptmp}/sample_project/lib/identity_map_middleware.rb")
|
221
|
+
end
|
222
|
+
|
217
223
|
it 'should generate model file with camelized name' do
|
218
224
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
|
219
225
|
capture_io { generate(:model, 'ChunkyBacon', "-r=#{@apptmp}/sample_project") }
|
@@ -753,5 +753,20 @@ describe "ProjectGenerator" do
|
|
753
753
|
assert_match_in_file(/class ControllerTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
|
754
754
|
assert_match_in_file(/class SampleProject::App::HelperTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
|
755
755
|
end
|
756
|
+
|
757
|
+
it "should properly generate for testunit" do
|
758
|
+
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=testunit', '--script=none', '--tiny') }
|
759
|
+
assert_match(/applying.*?testunit.*?test/, out)
|
760
|
+
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
|
761
|
+
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
|
762
|
+
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
|
763
|
+
assert_match_in_file(/gem 'test-unit'/, "#{@apptmp}/sample_project/Gemfile")
|
764
|
+
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/test/test_config.rb")
|
765
|
+
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
|
766
|
+
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
|
767
|
+
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/test/test_config.rb")
|
768
|
+
assert_match_in_file(/class ControllerTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
|
769
|
+
assert_match_in_file(/class SampleProject::App::HelperTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
|
770
|
+
end
|
756
771
|
end
|
757
772
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.0.
|
4
|
+
version: 0.13.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-core
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.13.0.
|
22
|
+
version: 0.13.0.beta3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.0.
|
29
|
+
version: 0.13.0.beta3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,28 +47,28 @@ dependencies:
|
|
47
47
|
requirements:
|
48
48
|
- - '='
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.13.0.
|
50
|
+
version: 0.13.0.beta3
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - '='
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.13.0.
|
57
|
+
version: 0.13.0.beta3
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: padrino-mailer
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - '='
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: 0.13.0.
|
64
|
+
version: 0.13.0.beta3
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - '='
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 0.13.0.
|
71
|
+
version: 0.13.0.beta3
|
72
72
|
description: Generators for easily creating and building padrino applications from
|
73
73
|
the console
|
74
74
|
email: padrinorb@gmail.com
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/padrino-gen/generators/components/tests/rspec.rb
|
130
130
|
- lib/padrino-gen/generators/components/tests/shoulda.rb
|
131
131
|
- lib/padrino-gen/generators/components/tests/steak.rb
|
132
|
+
- lib/padrino-gen/generators/components/tests/testunit.rb
|
132
133
|
- lib/padrino-gen/generators/controller.rb
|
133
134
|
- lib/padrino-gen/generators/helper.rb
|
134
135
|
- lib/padrino-gen/generators/mailer.rb
|