padrino-gen 0.16.0.pre4 → 0.16.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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/bin/padrino-gen +4 -4
- data/lib/padrino-gen/command.rb +2 -2
- data/lib/padrino-gen/generators/actions.rb +68 -64
- data/lib/padrino-gen/generators/app/app.rb.tt +6 -6
- data/lib/padrino-gen/generators/app.rb +19 -19
- data/lib/padrino-gen/generators/cli.rb +16 -19
- data/lib/padrino-gen/generators/component.rb +18 -19
- data/lib/padrino-gen/generators/components/actions.rb +42 -42
- data/lib/padrino-gen/generators/components/mocks/mocha.rb +7 -7
- data/lib/padrino-gen/generators/components/mocks/rr.rb +7 -7
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +158 -156
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +33 -33
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +108 -103
- data/lib/padrino-gen/generators/components/orms/dynamoid.rb +40 -40
- data/lib/padrino-gen/generators/components/orms/minirecord.rb +114 -114
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +65 -65
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +20 -20
- data/lib/padrino-gen/generators/components/orms/mongomatic.rb +63 -59
- data/lib/padrino-gen/generators/components/orms/ohm.rb +49 -47
- data/lib/padrino-gen/generators/components/orms/ripple.rb +45 -45
- data/lib/padrino-gen/generators/components/orms/sequel.rb +51 -46
- data/lib/padrino-gen/generators/components/renderers/erb.rb +1 -1
- data/lib/padrino-gen/generators/components/renderers/liquid.rb +1 -1
- data/lib/padrino-gen/generators/components/scripts/dojo.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/extcore.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/jquery.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/mootools.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/prototype.rb +8 -8
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/bacon.rb +66 -66
- data/lib/padrino-gen/generators/components/tests/cucumber.rb +61 -61
- data/lib/padrino-gen/generators/components/tests/minitest.rb +70 -70
- data/lib/padrino-gen/generators/components/tests/rspec.rb +74 -74
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +72 -72
- data/lib/padrino-gen/generators/components/tests/testunit.rb +69 -69
- data/lib/padrino-gen/generators/controller.rb +16 -17
- data/lib/padrino-gen/generators/helper.rb +8 -9
- data/lib/padrino-gen/generators/mailer.rb +8 -9
- data/lib/padrino-gen/generators/migration.rb +6 -6
- data/lib/padrino-gen/generators/model.rb +20 -21
- data/lib/padrino-gen/generators/plugin.rb +9 -9
- data/lib/padrino-gen/generators/project/config/apps.rb.tt +4 -4
- data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
- data/lib/padrino-gen/generators/project/config.ru +1 -1
- data/lib/padrino-gen/generators/project.rb +49 -51
- data/lib/padrino-gen/generators/runner.rb +25 -24
- data/lib/padrino-gen/generators/task.rb +7 -8
- data/lib/padrino-gen/generators/templates/Gemfile.tt +5 -5
- data/lib/padrino-gen/generators/templates/controller.rb.tt +3 -3
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +15 -15
- data/lib/padrino-gen/generators/templates/project_bin.tt +1 -1
- data/lib/padrino-gen/generators/templates/task.rb.tt +1 -1
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +152 -160
- data/lib/padrino-gen/padrino-tasks/database.rb +2 -2
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +31 -31
- data/lib/padrino-gen/padrino-tasks/minirecord.rb +3 -3
- data/lib/padrino-gen/padrino-tasks/mongoid.rb +39 -41
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +18 -14
- data/lib/padrino-gen/padrino-tasks/sequel.rb +28 -28
- data/lib/padrino-gen/padrino-tasks/sql-helpers.rb +45 -45
- data/lib/padrino-gen.rb +4 -4
- data/padrino-gen.gemspec +19 -19
- data/test/fixtures/admin_template.rb +5 -5
- data/test/fixtures/database_template.rb +19 -22
- data/test/fixtures/example_template.rb +8 -8
- data/test/fixtures/git_template.rb +2 -2
- data/test/fixtures/plugin_template.rb +3 -3
- data/test/fixtures/rake_template.rb +5 -5
- data/test/helper.rb +23 -21
- data/test/test_app_generator.rb +13 -13
- data/test/test_cli.rb +4 -5
- data/test/test_component_generator.rb +17 -17
- data/test/test_controller_generator.rb +62 -63
- data/test/test_generator.rb +6 -6
- data/test/test_helper_generator.rb +23 -24
- data/test/test_mailer_generator.rb +7 -7
- data/test/test_migration_generator.rb +31 -31
- data/test/test_model_generator.rb +80 -80
- data/test/test_plugin_generator.rb +35 -36
- data/test/test_project_generator.rb +171 -169
- data/test/test_sql_helpers.rb +49 -50
- data/test/test_task_generator.rb +13 -13
- metadata +10 -10
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
RSPEC_SETUP =
|
|
2
|
-
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
-
|
|
4
|
-
Dir[File.expand_path(
|
|
1
|
+
RSPEC_SETUP = <<~TEST.gsub(/^ {12}/, '') unless defined?(RSPEC_SETUP)
|
|
2
|
+
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
+
require_relative '../config/boot'
|
|
4
|
+
Dir[File.expand_path("\#{__dir__}/../app/helpers/**/*.rb")].each(&method(:require))
|
|
5
5
|
|
|
6
|
-
RSpec.configure do |conf|
|
|
7
|
-
|
|
8
|
-
end
|
|
6
|
+
RSpec.configure do |conf|
|
|
7
|
+
conf.include Rack::Test::Methods
|
|
8
|
+
end
|
|
9
9
|
|
|
10
|
-
# You can use this method to custom specify a Rack app
|
|
11
|
-
# you want rack-test to invoke:
|
|
12
|
-
#
|
|
13
|
-
# app CLASS_NAME
|
|
14
|
-
# app CLASS_NAME.tap { |a| }
|
|
15
|
-
# app(CLASS_NAME) do
|
|
16
|
-
# set :foo, :bar
|
|
17
|
-
# end
|
|
18
|
-
#
|
|
19
|
-
def app(app = nil, &blk)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
10
|
+
# You can use this method to custom specify a Rack app
|
|
11
|
+
# you want rack-test to invoke:
|
|
12
|
+
#
|
|
13
|
+
# app CLASS_NAME
|
|
14
|
+
# app CLASS_NAME.tap { |a| }
|
|
15
|
+
# app(CLASS_NAME) do
|
|
16
|
+
# set :foo, :bar
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
def app(app = nil, &blk)
|
|
20
|
+
@app ||= block_given? ? app.instance_eval(&blk) : app
|
|
21
|
+
@app ||= Padrino.application
|
|
22
|
+
end
|
|
23
23
|
TEST
|
|
24
24
|
|
|
25
|
-
RSPEC_CONTROLLER_TEST =
|
|
26
|
-
require 'spec_helper'
|
|
25
|
+
RSPEC_CONTROLLER_TEST = <<~TEST.gsub(/^ {12}/, '') unless defined?(RSPEC_CONTROLLER_TEST)
|
|
26
|
+
require 'spec_helper'
|
|
27
27
|
|
|
28
|
-
RSpec.describe "!PATH!" do
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
RSpec.describe "!PATH!" do
|
|
29
|
+
pending "add some examples to \#{__FILE__}" do
|
|
30
|
+
before do
|
|
31
|
+
get "!EXPANDED_PATH!"
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
it "returns hello world" do
|
|
35
|
+
expect(last_response.body).to eq "Hello World"
|
|
36
|
+
end
|
|
36
37
|
end
|
|
37
38
|
end
|
|
38
|
-
end
|
|
39
39
|
TEST
|
|
40
40
|
|
|
41
|
-
RSPEC_RAKE =
|
|
42
|
-
begin
|
|
43
|
-
|
|
41
|
+
RSPEC_RAKE = <<~TEST.gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
|
|
42
|
+
begin
|
|
43
|
+
require 'rspec/core/rake_task'
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
spec_tasks = Dir['spec/*/'].each_with_object([]) do |d, result|
|
|
46
|
+
result << File.basename(d) unless Dir["\#{d}*"].empty?
|
|
47
|
+
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
spec_tasks.each do |folder|
|
|
50
|
+
desc "Run the spec suite in \#{folder}"
|
|
51
|
+
RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
|
|
52
|
+
t.pattern = "./spec/\#{folder}/**/*_spec.rb"
|
|
53
|
+
t.rspec_opts = "--color"
|
|
54
|
+
end
|
|
54
55
|
end
|
|
55
|
-
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
rescue LoadError
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
desc "Run complete application spec suite"
|
|
58
|
+
task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
|
|
59
|
+
rescue LoadError
|
|
60
|
+
task :spec do
|
|
61
|
+
puts "RSpec is not part of this bundle, skip specs."
|
|
62
|
+
end
|
|
62
63
|
end
|
|
63
|
-
end
|
|
64
64
|
|
|
65
|
-
task :
|
|
65
|
+
task default: :spec
|
|
66
66
|
TEST
|
|
67
67
|
|
|
68
|
-
RSPEC_MODEL_TEST =
|
|
69
|
-
require 'spec_helper'
|
|
68
|
+
RSPEC_MODEL_TEST = <<~TEST.gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
|
|
69
|
+
require 'spec_helper'
|
|
70
70
|
|
|
71
|
-
RSpec.describe !NAME! do
|
|
72
|
-
|
|
73
|
-
end
|
|
71
|
+
RSpec.describe !NAME! do
|
|
72
|
+
pending "add some examples to (or delete) \#{__FILE__}"
|
|
73
|
+
end
|
|
74
74
|
TEST
|
|
75
75
|
|
|
76
|
-
RSPEC_HELPER_TEST =
|
|
77
|
-
require 'spec_helper'
|
|
76
|
+
RSPEC_HELPER_TEST = <<~TEST unless defined?(RSPEC_HELPER_TEST)
|
|
77
|
+
require 'spec_helper'
|
|
78
78
|
|
|
79
|
-
RSpec.describe "!NAME!" do
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
RSpec.describe "!NAME!" do
|
|
80
|
+
pending "add some examples to (or delete) \#{__FILE__}" do
|
|
81
|
+
let(:helpers){ Class.new }
|
|
82
|
+
before { helpers.extend !NAME! }
|
|
83
|
+
subject { helpers }
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
it "should return nil" do
|
|
86
|
+
expect(subject.foo).to be_nil
|
|
87
|
+
end
|
|
87
88
|
end
|
|
88
89
|
end
|
|
89
|
-
end
|
|
90
90
|
TEST
|
|
91
91
|
|
|
92
92
|
def setup_test
|
|
93
|
-
require_dependencies 'rack-test', :
|
|
94
|
-
require_dependencies 'rspec', :
|
|
95
|
-
insert_test_suite_setup RSPEC_SETUP, :
|
|
96
|
-
create_file destination_root(
|
|
93
|
+
require_dependencies 'rack-test', require: 'rack/test', group: 'test'
|
|
94
|
+
require_dependencies 'rspec', group: 'test'
|
|
95
|
+
insert_test_suite_setup RSPEC_SETUP, path: 'spec/spec_helper.rb'
|
|
96
|
+
create_file destination_root('spec/spec.rake'), RSPEC_RAKE
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def generate_controller_test(name, path)
|
|
100
|
-
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/,
|
|
101
|
-
controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
|
|
102
|
-
create_file destination_root(controller_spec_path), rspec_contents, :
|
|
100
|
+
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, '1'))
|
|
101
|
+
controller_spec_path = File.join('spec', options[:app], 'controllers', "#{name.to_s.underscore}_controller_spec.rb")
|
|
102
|
+
create_file destination_root(controller_spec_path), rspec_contents, skip: true
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def generate_model_test(name)
|
|
106
106
|
rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
|
107
|
-
model_spec_path = File.join('spec',options[:app],'models',"#{name.to_s.underscore}_spec.rb")
|
|
108
|
-
create_file destination_root(model_spec_path), rspec_contents, :
|
|
107
|
+
model_spec_path = File.join('spec', options[:app], 'models', "#{name.to_s.underscore}_spec.rb")
|
|
108
|
+
create_file destination_root(model_spec_path), rspec_contents, skip: true
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
def generate_helper_test(name, project_name, app_name)
|
|
112
112
|
rspec_contents = RSPEC_HELPER_TEST.gsub(/!NAME!/, "#{project_name}::#{app_name}::#{name}")
|
|
113
113
|
helper_spec_path = File.join('spec', options[:app], 'helpers', "#{name.underscore}_spec.rb")
|
|
114
|
-
create_file destination_root(helper_spec_path), rspec_contents, :
|
|
114
|
+
create_file destination_root(helper_spec_path), rspec_contents, skip: true
|
|
115
115
|
end
|
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
SHOULDA_SETUP =
|
|
2
|
-
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
-
|
|
4
|
-
Dir[File.expand_path(
|
|
5
|
-
|
|
6
|
-
require "test/unit"
|
|
7
|
-
|
|
8
|
-
class Test::Unit::TestCase
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
SHOULDA_SETUP = <<~TEST.gsub(/^ {10}/, '') unless defined?(SHOULDA_SETUP)
|
|
2
|
+
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
+
require_relative '../config/boot'
|
|
4
|
+
Dir[File.expand_path("\#{__dir__}/../app/helpers/**/*.rb")].each(&method(:require))
|
|
5
|
+
|
|
6
|
+
require "test/unit"
|
|
7
|
+
|
|
8
|
+
class Test::Unit::TestCase
|
|
9
|
+
include Rack::Test::Methods
|
|
10
|
+
|
|
11
|
+
# You can use this method to custom specify a Rack app
|
|
12
|
+
# you want rack-test to invoke:
|
|
13
|
+
#
|
|
14
|
+
# app CLASS_NAME
|
|
15
|
+
# app CLASS_NAME.tap { |a| }
|
|
16
|
+
# app(CLASS_NAME) do
|
|
17
|
+
# set :foo, :bar
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
def app(app = nil, &blk)
|
|
21
|
+
@app ||= block_given? ? app.instance_eval(&blk) : app
|
|
22
|
+
@app ||= Padrino.application
|
|
23
|
+
end
|
|
23
24
|
end
|
|
24
|
-
end
|
|
25
25
|
TEST
|
|
26
26
|
|
|
27
|
-
SHOULDA_CONTROLLER_TEST =
|
|
28
|
-
require File.expand_path(
|
|
27
|
+
SHOULDA_CONTROLLER_TEST = <<~TEST.gsub(/^ {10}/, '') unless defined?(SHOULDA_CONTROLLER_TEST)
|
|
28
|
+
require File.expand_path("\#{__dir__}/../../test_config.rb")
|
|
29
29
|
|
|
30
|
-
class !NAME!ControllerTest < Test::Unit::TestCase
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
class !NAME!ControllerTest < Test::Unit::TestCase
|
|
31
|
+
context "!NAME!Controller" do
|
|
32
|
+
setup do
|
|
33
|
+
get '/'
|
|
34
|
+
end
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
should "return hello world text" do
|
|
37
|
+
assert_equal "Hello World", last_response.body
|
|
38
|
+
end
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
|
-
end
|
|
41
41
|
TEST
|
|
42
42
|
|
|
43
|
-
SHOULDA_RAKE =
|
|
44
|
-
require 'rake/testtask'
|
|
43
|
+
SHOULDA_RAKE = <<~TEST.gsub(/^ {10}/, '') unless defined?(SHOULDA_RAKE)
|
|
44
|
+
require 'rake/testtask'
|
|
45
45
|
|
|
46
|
-
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
|
46
|
+
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
|
47
47
|
|
|
48
|
-
test_tasks.each do |folder|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
test_tasks.each do |folder|
|
|
49
|
+
Rake::TestTask.new("test:\#{folder}") do |test|
|
|
50
|
+
test.pattern = "test/\#{folder}/**/*_test.rb"
|
|
51
|
+
test.verbose = true
|
|
52
|
+
end
|
|
52
53
|
end
|
|
53
|
-
end
|
|
54
54
|
|
|
55
|
-
desc "Run application test suite"
|
|
56
|
-
task 'test' => test_tasks.map { |f| "test:\#{f}" }
|
|
55
|
+
desc "Run application test suite"
|
|
56
|
+
task 'test' => test_tasks.map { |f| "test:\#{f}" }
|
|
57
57
|
|
|
58
|
-
task :
|
|
58
|
+
task default: :test
|
|
59
59
|
TEST
|
|
60
60
|
|
|
61
|
-
SHOULDA_MODEL_TEST =
|
|
62
|
-
require File.expand_path(
|
|
61
|
+
SHOULDA_MODEL_TEST = <<~TEST.gsub(/^ {10}/, '') unless defined?(SHOULDA_MODEL_TEST)
|
|
62
|
+
require File.expand_path("\#{__dir__}!PATH!/test_config.rb")
|
|
63
63
|
|
|
64
|
-
class !NAME!Test < Test::Unit::TestCase
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
class !NAME!Test < Test::Unit::TestCase
|
|
65
|
+
context "!NAME! Model" do
|
|
66
|
+
should 'construct new instance' do
|
|
67
|
+
@!DNAME! = !NAME!.new
|
|
68
|
+
assert_not_nil @!DNAME!
|
|
69
|
+
end
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
|
-
end
|
|
72
72
|
TEST
|
|
73
73
|
|
|
74
|
-
SHOULDA_HELPER_TEST =
|
|
75
|
-
require File.expand_path(
|
|
74
|
+
SHOULDA_HELPER_TEST = <<~TEST unless defined?(SHOULDA_HELPER_TEST)
|
|
75
|
+
require File.expand_path("\#{__dir__}!PATH!/test_config.rb")
|
|
76
76
|
|
|
77
|
-
class !NAME!Test < Test::Unit::TestCase
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
class !NAME!Test < Test::Unit::TestCase
|
|
78
|
+
context "!NAME!" do
|
|
79
|
+
setup do
|
|
80
|
+
@helpers = Class.new
|
|
81
|
+
@helpers.extend !NAME!
|
|
82
|
+
end
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
should "return nil" do
|
|
85
|
+
assert_equal nil, @helpers.foo
|
|
86
|
+
end
|
|
86
87
|
end
|
|
87
88
|
end
|
|
88
|
-
end
|
|
89
89
|
TEST
|
|
90
90
|
|
|
91
91
|
def setup_test
|
|
92
|
-
require_dependencies 'rack-test', :
|
|
93
|
-
require_dependencies 'shoulda', :
|
|
94
|
-
require_dependencies 'test-unit', :
|
|
92
|
+
require_dependencies 'rack-test', require: 'rack/test', group: 'test'
|
|
93
|
+
require_dependencies 'shoulda', group: 'test'
|
|
94
|
+
require_dependencies 'test-unit', group: 'test'
|
|
95
95
|
insert_test_suite_setup SHOULDA_SETUP
|
|
96
|
-
create_file destination_root(
|
|
96
|
+
create_file destination_root('test/test.rake'), SHOULDA_RAKE
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def generate_controller_test(name, path = nil)
|
|
100
100
|
shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
|
101
|
-
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
|
102
|
-
create_file destination_root(controller_test_path), shoulda_contents, :
|
|
101
|
+
controller_test_path = File.join('test', options[:app], 'controllers', "#{name.to_s.underscore}_controller_test.rb")
|
|
102
|
+
create_file destination_root(controller_test_path), shoulda_contents, skip: true
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def generate_model_test(name)
|
|
106
106
|
shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
|
107
107
|
shoulda_contents.gsub!(/!PATH!/, recognize_path)
|
|
108
|
-
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
|
109
|
-
create_file destination_root(model_test_path), shoulda_contents, :
|
|
108
|
+
model_test_path = File.join('test', options[:app], 'models', "#{name.to_s.underscore}_test.rb")
|
|
109
|
+
create_file destination_root(model_test_path), shoulda_contents, skip: true
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def generate_helper_test(name, project_name, app_name)
|
|
113
113
|
shoulda_contents = SHOULDA_HELPER_TEST.gsub(/!NAME!/, "#{project_name}::#{app_name}::#{name}")
|
|
114
114
|
shoulda_contents.gsub!(/!PATH!/, recognize_path)
|
|
115
115
|
helper_spec_path = File.join('test', options[:app], 'helpers', "#{name.underscore}_test.rb")
|
|
116
|
-
create_file destination_root(helper_spec_path), shoulda_contents, :
|
|
116
|
+
create_file destination_root(helper_spec_path), shoulda_contents, skip: true
|
|
117
117
|
end
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
TESTUNIT_SETUP =
|
|
2
|
-
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
-
|
|
4
|
-
Dir[File.expand_path(
|
|
5
|
-
|
|
6
|
-
class Test::Unit::TestCase
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
TESTUNIT_SETUP = <<~TEST.gsub(/^ {10}/, '') unless defined?(TESTUNIT_SETUP)
|
|
2
|
+
RACK_ENV = 'test' unless defined?(RACK_ENV)
|
|
3
|
+
require_relative '../config/boot'
|
|
4
|
+
Dir[File.expand_path("\#{__dir__}/../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
|
|
21
22
|
end
|
|
22
|
-
end
|
|
23
23
|
TEST
|
|
24
24
|
|
|
25
|
-
TESTUNIT_RAKE =
|
|
26
|
-
require 'rake/testtask'
|
|
25
|
+
TESTUNIT_RAKE = <<~TEST.gsub(/^ {10}/, '') unless defined?(TESTUNIT_RAKE)
|
|
26
|
+
require 'rake/testtask'
|
|
27
27
|
|
|
28
|
-
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
|
28
|
+
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
|
29
29
|
|
|
30
|
-
test_tasks.each do |folder|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
34
35
|
end
|
|
35
|
-
end
|
|
36
36
|
|
|
37
|
-
desc "Run application test suite"
|
|
38
|
-
task 'test' => test_tasks.map { |f| "test:\#{f}" }
|
|
37
|
+
desc "Run application test suite"
|
|
38
|
+
task 'test' => test_tasks.map { |f| "test:\#{f}" }
|
|
39
39
|
|
|
40
|
-
task :
|
|
40
|
+
task default: :test
|
|
41
41
|
TEST
|
|
42
42
|
|
|
43
|
-
TESTUNIT_CONTROLLER_TEST =
|
|
44
|
-
require File.expand_path(
|
|
43
|
+
TESTUNIT_CONTROLLER_TEST = <<~TEST.gsub(/^ {10}/, '') unless defined?(TESTUNIT_CONTROLLER_TEST)
|
|
44
|
+
require File.expand_path("\#{__dir__}/../../test_config.rb")
|
|
45
45
|
|
|
46
|
-
class !NAME!ControllerTest < Test::Unit::TestCase
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
class !NAME!ControllerTest < Test::Unit::TestCase
|
|
47
|
+
def setup
|
|
48
|
+
get "/"
|
|
49
|
+
end
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
def test_returns_hello_world_text
|
|
52
|
+
assert_equal "Hello World", last_response.body
|
|
53
|
+
end
|
|
53
54
|
end
|
|
54
|
-
end
|
|
55
55
|
TEST
|
|
56
56
|
|
|
57
|
-
TESTUNIT_MODEL_TEST =
|
|
58
|
-
require File.expand_path(
|
|
57
|
+
TESTUNIT_MODEL_TEST = <<~TEST.gsub(/^ {10}/, '') unless defined?(TESTUNIT_MODEL_TEST)
|
|
58
|
+
require File.expand_path("\#{__dir__}!PATH!/test_config.rb")
|
|
59
59
|
|
|
60
|
-
class !NAME!Test < Test::Unit::TestCase
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
class !NAME!Test < Test::Unit::TestCase
|
|
61
|
+
def test_constructs_a_new_instance
|
|
62
|
+
@!DNAME! = !NAME!.new
|
|
63
|
+
refute_nil @!DNAME!
|
|
64
|
+
end
|
|
64
65
|
end
|
|
65
|
-
end
|
|
66
66
|
TEST
|
|
67
67
|
|
|
68
|
-
TESTUNIT_HELPER_TEST =
|
|
69
|
-
require File.expand_path(
|
|
68
|
+
TESTUNIT_HELPER_TEST = <<~TEST unless defined?(TESTUNIT_HELPER_TEST)
|
|
69
|
+
require File.expand_path("\#{__dir__}!PATH!/test_config.rb")
|
|
70
70
|
|
|
71
|
-
class !NAME!Test < Test::Unit::TestCase
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
class !NAME!Test < Test::Unit::TestCase
|
|
72
|
+
def self.setup
|
|
73
|
+
@helpers = Class.new
|
|
74
|
+
@helpers.extend !CONSTANT_NAME!
|
|
75
|
+
end
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
def helpers
|
|
78
|
+
@helpers
|
|
79
|
+
end
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
def test_foo_helper
|
|
82
|
+
assert_equal nil, helpers.foo
|
|
83
|
+
end
|
|
83
84
|
end
|
|
84
|
-
end
|
|
85
85
|
TEST
|
|
86
86
|
|
|
87
87
|
def setup_test
|
|
88
|
-
require_dependencies 'rack-test', :
|
|
89
|
-
require_dependencies 'test-unit', :
|
|
88
|
+
require_dependencies 'rack-test', require: 'rack/test', group: 'test'
|
|
89
|
+
require_dependencies 'test-unit', require: 'test/unit', group: 'test'
|
|
90
90
|
insert_test_suite_setup TESTUNIT_SETUP
|
|
91
|
-
create_file destination_root(
|
|
91
|
+
create_file destination_root('test/test.rake'), TESTUNIT_RAKE
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
def generate_controller_test(name, path)
|
|
95
95
|
test_unit_contents = TESTUNIT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
|
96
|
-
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
|
97
|
-
create_file destination_root(controller_test_path), test_unit_contents, :
|
|
96
|
+
controller_test_path = File.join('test', options[:app], 'controllers', "#{name.to_s.underscore}_controller_test.rb")
|
|
97
|
+
create_file destination_root(controller_test_path), test_unit_contents, skip: true
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def generate_model_test(name)
|
|
101
101
|
test_unit_contents = TESTUNIT_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
|
102
102
|
test_unit_contents.gsub!(/!PATH!/, recognize_path)
|
|
103
|
-
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
|
104
|
-
create_file destination_root(model_test_path), test_unit_contents, :
|
|
103
|
+
model_test_path = File.join('test', options[:app], 'models', "#{name.to_s.underscore}_test.rb")
|
|
104
|
+
create_file destination_root(model_test_path), test_unit_contents, skip: true
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
def generate_helper_test(name, project_name, app_name)
|
|
108
108
|
test_unit_contents = TESTUNIT_HELPER_TEST.gsub(/!NAME!/, name).gsub(/!CONSTANT_NAME!/, "#{project_name}::#{app_name}::#{name}")
|
|
109
109
|
test_unit_contents.gsub!(/!PATH!/, recognize_path)
|
|
110
110
|
helper_spec_path = File.join('test', options[:app], 'helpers', "#{name.underscore}_test.rb")
|
|
111
|
-
create_file destination_root(helper_spec_path), test_unit_contents, :
|
|
111
|
+
create_file destination_root(helper_spec_path), test_unit_contents, skip: true
|
|
112
112
|
end
|
|
@@ -6,11 +6,10 @@ module Padrino
|
|
|
6
6
|
# Responsible for generating route controllers and associated tests within a Padrino application.
|
|
7
7
|
#
|
|
8
8
|
class Controller < Thor::Group
|
|
9
|
-
|
|
10
9
|
Padrino::Generators.add_generator(:controller, self)
|
|
11
10
|
|
|
12
|
-
def self.source_root;
|
|
13
|
-
def self.banner;
|
|
11
|
+
def self.source_root; __dir__; end
|
|
12
|
+
def self.banner; 'padrino-gen controller [name]'; end
|
|
14
13
|
|
|
15
14
|
include Thor::Actions
|
|
16
15
|
include Padrino::Generators::Actions
|
|
@@ -18,16 +17,16 @@ module Padrino
|
|
|
18
17
|
|
|
19
18
|
desc "Description:\n\n\tpadrino-gen controller generates a new Padrino controller"
|
|
20
19
|
|
|
21
|
-
argument :name,
|
|
22
|
-
argument :fields,
|
|
23
|
-
class_option :root,
|
|
24
|
-
class_option :app,
|
|
25
|
-
class_option :destroy,
|
|
26
|
-
class_option :namespace,
|
|
27
|
-
class_option :layout,
|
|
28
|
-
class_option :parent,
|
|
29
|
-
class_option :provides,
|
|
30
|
-
class_option :'no-helper'
|
|
20
|
+
argument :name, desc: 'The name of your padrino controller'
|
|
21
|
+
argument :fields, desc: 'The fields for the controller', default: [], type: :array
|
|
22
|
+
class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
|
|
23
|
+
class_option :app, desc: 'The application destination path', aliases: '-a', default: '/app', type: :string
|
|
24
|
+
class_option :destroy, aliases: '-d', default: false, type: :boolean
|
|
25
|
+
class_option :namespace, desc: 'The name space of your padrino project', aliases: '-n', default: '', type: :string
|
|
26
|
+
class_option :layout, desc: 'The layout for the controller', aliases: '-l', default: '', type: :string
|
|
27
|
+
class_option :parent, desc: 'The parent of the controller', aliases: '-p', default: '', type: :string
|
|
28
|
+
class_option :provides, desc: 'The formats provided by the controller', aliases: '-f', default: '', type: :string
|
|
29
|
+
class_option :'no-helper', desc: 'Not generate helper', default: false, type: :boolean
|
|
31
30
|
|
|
32
31
|
# Show help if no ARGV given
|
|
33
32
|
require_arguments!
|
|
@@ -49,8 +48,8 @@ module Padrino
|
|
|
49
48
|
@layout = options[:layout] if options[:layout] && !options[:layout].empty?
|
|
50
49
|
|
|
51
50
|
block_opts = []
|
|
52
|
-
block_opts << ":
|
|
53
|
-
block_opts << ":
|
|
51
|
+
block_opts << "parent: :#{options[:parent]}" if options[:parent] && !options[:parent].empty?
|
|
52
|
+
block_opts << "provides: [#{options[:provides]}]" if options[:provides] && !options[:provides].empty?
|
|
54
53
|
@block_opts_string = block_opts.join(', ') unless block_opts.empty?
|
|
55
54
|
|
|
56
55
|
self.behavior = :revoke if options[:destroy]
|
|
@@ -62,9 +61,9 @@ module Padrino
|
|
|
62
61
|
path = @controller.dup
|
|
63
62
|
|
|
64
63
|
if options[:parent] && !options[:parent].empty?
|
|
65
|
-
path = Application.process_path_for_parent_params(path, [options[:parent]]).prepend(
|
|
64
|
+
path = Application.process_path_for_parent_params(path, [options[:parent]]).prepend('/')
|
|
66
65
|
end
|
|
67
|
-
path.prepend(
|
|
66
|
+
path.prepend('/') unless path.start_with?('/')
|
|
68
67
|
generate_controller_test(name, path)
|
|
69
68
|
end
|
|
70
69
|
|