padrino-gen 0.9.25 → 0.9.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/lib/padrino-gen/generators/actions.rb +1 -0
  2. data/lib/padrino-gen/generators/app/app.rb.tt +1 -1
  3. data/lib/padrino-gen/generators/app.rb +1 -0
  4. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +4 -4
  5. data/lib/padrino-gen/generators/components/tests/bacon.rb +19 -10
  6. data/lib/padrino-gen/generators/components/tests/riot.rb +16 -7
  7. data/lib/padrino-gen/generators/components/tests/rspec.rb +15 -6
  8. data/lib/padrino-gen/generators/components/tests/shoulda.rb +17 -8
  9. data/lib/padrino-gen/generators/components/tests/testspec.rb +17 -8
  10. data/lib/padrino-gen/generators/project/.gitignore +7 -0
  11. data/lib/padrino-gen/generators/project.rb +3 -1
  12. data/lib/padrino-gen/padrino-tasks/mongoid.rb +6 -6
  13. data/padrino-gen.gemspec +8 -5
  14. data/test/test_app_generator.rb +10 -0
  15. data/test/test_controller_generator.rb +34 -17
  16. data/test/test_model_generator.rb +43 -28
  17. data/test/test_project_generator.rb +21 -2
  18. metadata +32 -33
  19. data/lib/padrino-gen/generators/templates/static/README.rdoc +0 -16
  20. data/lib/padrino-gen/generators/templates/static/js/dojo.js +0 -1
  21. data/lib/padrino-gen/generators/templates/static/js/ext.js +0 -1
  22. data/lib/padrino-gen/generators/templates/static/js/jquery.js +0 -16
  23. data/lib/padrino-gen/generators/templates/static/js/lowpro.js +0 -1
  24. data/lib/padrino-gen/generators/templates/static/js/mootools.js +0 -468
  25. data/lib/padrino-gen/generators/templates/static/js/protopak.js +0 -1
  26. data/lib/padrino-gen/generators/templates/static/js/right.js +0 -1
  27. data/lib/padrino-gen/generators/templates/static/ujs/dojo.js +0 -24
  28. data/lib/padrino-gen/generators/templates/static/ujs/ext.js +0 -24
  29. data/lib/padrino-gen/generators/templates/static/ujs/jquery.js +0 -91
  30. data/lib/padrino-gen/generators/templates/static/ujs/mootools.js +0 -104
  31. data/lib/padrino-gen/generators/templates/static/ujs/prototype.js +0 -106
  32. data/lib/padrino-gen/generators/templates/static/ujs/right.js +0 -95
@@ -51,6 +51,7 @@ module Padrino
51
51
  config = retrieve_component_config(path)
52
52
  config[key] = value
53
53
  create_file(path, :force => true) { config.to_yaml }
54
+ value
54
55
  end
55
56
 
56
57
  # Loads the component config back into a hash
@@ -2,7 +2,7 @@ class <%= @app_name %> < Padrino::Application
2
2
  register Padrino::Mailer
3
3
  register Padrino::Helpers
4
4
 
5
- set :session_secret, "<%= '%x' % rand(2**255) %>"
5
+ set :session_secret, "<%= @session_secret %>"
6
6
  set :sessions, true
7
7
 
8
8
  ##
@@ -31,6 +31,7 @@ module Padrino
31
31
  @app_name = name.gsub(/\W/, "_").underscore.camelize
32
32
  if in_app_root?
33
33
  self.behavior = :revoke if options[:destroy]
34
+ @session_secret = fetch_component_choice(:session_secret)
34
35
  app_skeleton(@app_name.downcase, options[:tiny])
35
36
  empty_directory destination_root("public/#{@app_name.downcase}")
36
37
  append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"#{@app_name}\").to(\"/#{@app_name.downcase}\")"
@@ -49,9 +49,9 @@ class !NAME! < Mongomatic::Base
49
49
  # end
50
50
 
51
51
  # def create_indexes
52
- # self.mapion.create_index('name', :unique => true)
53
- # self.mapion.create_index('email', :unique => true)
54
- # self.mapion.create_index('age')
52
+ # self.collection.create_index('name', :unique => true)
53
+ # self.collection.create_index('email', :unique => true)
54
+ # self.collection.create_index('age')
55
55
  # end
56
56
  def validate
57
57
  expectations do
@@ -82,4 +82,4 @@ end
82
82
 
83
83
  def create_migration_file(migration_name, name, columns)
84
84
  # NO MIGRATION NEEDED
85
- end
85
+ end
@@ -15,7 +15,7 @@ end
15
15
  TEST
16
16
 
17
17
  BACON_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_CONTROLLER_TEST)
18
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
18
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
19
19
 
20
20
  describe "!NAME!Controller" do
21
21
  it 'returns text at root' do
@@ -28,14 +28,21 @@ TEST
28
28
  BACON_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_RAKE)
29
29
  require 'rake/testtask'
30
30
 
31
- Rake::TestTask.new(:test) do |test|
32
- test.pattern = 'test/**/*_test.rb'
33
- test.verbose = true
31
+ test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
32
+
33
+ test_tasks.each do |folder|
34
+ Rake::TestTask.new("test:\#{folder}") do |test|
35
+ test.pattern = "test/\#{folder}/**/*_test.rb"
36
+ test.verbose = true
37
+ end
34
38
  end
39
+
40
+ desc "Run application test suite"
41
+ task 'test' => test_tasks.map { |f| "test:\#{f}" }
35
42
  TEST
36
43
 
37
44
  BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_MODEL_TEST)
38
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
45
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
39
46
 
40
47
  describe "!NAME! Model" do
41
48
  it 'can be created' do
@@ -55,11 +62,13 @@ end
55
62
 
56
63
  # Generates a controller test given the controllers name
57
64
  def generate_controller_test(name)
58
- bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
59
- create_file destination_root("test/controllers/","#{name.to_s.underscore}_controller_test.rb"), bacon_contents, :skip => true
65
+ bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
66
+ controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
67
+ create_file destination_root(controller_test_path), bacon_contents, :skip => true
60
68
  end
61
69
 
62
70
  def generate_model_test(name)
63
- bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
64
- create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), bacon_contents, :skip => true
65
- end
71
+ bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
72
+ model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
73
+ create_file destination_root(model_test_path), bacon_contents, :skip => true
74
+ end
@@ -36,7 +36,7 @@ end
36
36
  TEST
37
37
 
38
38
  RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_CONTROLLER_TEST)
39
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
39
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
40
40
 
41
41
  context "!NAME!Controller" do
42
42
  context "description here" do
@@ -52,14 +52,21 @@ TEST
52
52
  RIOT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_RAKE)
53
53
  require 'rake/testtask'
54
54
 
55
- Rake::TestTask.new(:test) do |test|
56
- test.pattern = 'test/**/*_test.rb'
57
- test.verbose = true
55
+ test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
56
+
57
+ test_tasks.each do |folder|
58
+ Rake::TestTask.new("test:\#{folder}") do |test|
59
+ test.pattern = "test/\#{folder}/**/*_test.rb"
60
+ test.verbose = true
61
+ end
58
62
  end
63
+
64
+ desc "Run application test suite"
65
+ task 'test' => test_tasks.map { |f| "test:\#{f}" }
59
66
  TEST
60
67
 
61
68
  RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_MODEL_TEST)
62
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
69
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
63
70
 
64
71
  context "!NAME! Model" do
65
72
  context 'can be created' do
@@ -82,10 +89,12 @@ end
82
89
  # Generates a controller test given the controllers name
83
90
  def generate_controller_test(name)
84
91
  riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
85
- create_file destination_root("test/controllers/#{name.to_s.underscore}_controller_test.rb"), riot_contents, :skip => true
92
+ controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
93
+ create_file destination_root(controller_test_path), riot_contents, :skip => true
86
94
  end
87
95
 
88
96
  def generate_model_test(name)
89
97
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize)
90
- create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), riot_contents, :skip => true
98
+ model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
99
+ create_file destination_root(model_test_path), riot_contents, :skip => true
91
100
  end
@@ -31,10 +31,17 @@ TEST
31
31
  RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
32
32
  require 'rspec/core/rake_task'
33
33
 
34
- RSpec::Core::RakeTask.new(:spec) do |t|
35
- t.pattern = "./spec/**/*_spec.rb"
36
- t.rspec_opts = %w(-fs --color)
34
+ spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
35
+
36
+ spec_tasks.each do |folder|
37
+ RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
38
+ t.pattern = "./spec/\#{folder}/**/*_spec.rb"
39
+ t.rspec_opts = %w(-fs --color)
40
+ end
37
41
  end
42
+
43
+ desc "Run complete application spec suite"
44
+ task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
38
45
  TEST
39
46
 
40
47
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
@@ -58,10 +65,12 @@ end
58
65
  # Generates a controller test given the controllers name
59
66
  def generate_controller_test(name)
60
67
  rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
61
- create_file destination_root("spec/controllers/#{name.to_s.underscore}_controller_spec.rb"), rspec_contents, :skip => true
68
+ controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
69
+ create_file destination_root(controller_spec_path), rspec_contents, :skip => true
62
70
  end
63
71
 
64
72
  def generate_model_test(name)
65
73
  rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
66
- create_file destination_root("spec/models/#{name.to_s.underscore}_spec.rb"), rspec_contents, :skip => true
67
- end
74
+ model_spec_path = File.join('spec',options[:app],'models',"#{name.to_s.underscore}_spec.rb")
75
+ create_file destination_root(model_spec_path), rspec_contents, :skip => true
76
+ end
@@ -15,7 +15,7 @@ end
15
15
  TEST
16
16
 
17
17
  SHOULDA_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_CONTROLLER_TEST)
18
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
18
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
19
19
 
20
20
  class !NAME!ControllerTest < Test::Unit::TestCase
21
21
  context "!NAME!Controller" do
@@ -33,14 +33,21 @@ TEST
33
33
  SHOULDA_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_RAKE)
34
34
  require 'rake/testtask'
35
35
 
36
- Rake::TestTask.new(:test) do |test|
37
- test.pattern = 'test/**/*_test.rb'
38
- test.verbose = true
36
+ test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
37
+
38
+ test_tasks.each do |folder|
39
+ Rake::TestTask.new("test:\#{folder}") do |test|
40
+ test.pattern = "test/\#{folder}/**/*_test.rb"
41
+ test.verbose = true
42
+ end
39
43
  end
44
+
45
+ desc "Run application test suite"
46
+ task 'test' => test_tasks.map { |f| "test:\#{f}" }
40
47
  TEST
41
48
 
42
49
  SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_MODEL_TEST)
43
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
50
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
44
51
 
45
52
  class !NAME!Test < Test::Unit::TestCase
46
53
  context "!NAME! Model" do
@@ -65,10 +72,12 @@ end
65
72
  # Generates a controller test given the controllers name
66
73
  def generate_controller_test(name)
67
74
  shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
68
- create_file destination_root("test/controllers/#{name.to_s.underscore}_controller_test.rb"), shoulda_contents, :skip => true
75
+ controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
76
+ create_file destination_root(controller_test_path), shoulda_contents, :skip => true
69
77
  end
70
78
 
71
79
  def generate_model_test(name)
72
80
  shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
73
- create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), shoulda_contents, :skip => true
74
- end
81
+ model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
82
+ create_file destination_root(model_test_path), shoulda_contents, :skip => true
83
+ end
@@ -15,7 +15,7 @@ end
15
15
  TEST
16
16
 
17
17
  TESTSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTSPEC_CONTROLLER_TEST)
18
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
18
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
19
19
 
20
20
  context "!NAME!Controller" do
21
21
  setup { get('/') }
@@ -28,14 +28,21 @@ TEST
28
28
  TESTSPEC_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTSPEC_RAKE)
29
29
  require 'rake/testtask'
30
30
 
31
- Rake::TestTask.new(:test) do |test|
32
- test.pattern = 'test/**/*_test.rb'
33
- test.verbose = true
31
+ test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
32
+
33
+ test_tasks.each do |folder|
34
+ Rake::TestTask.new("test:\#{folder}") do |test|
35
+ test.pattern = "test/\#{folder}/**/*_test.rb"
36
+ test.verbose = true
37
+ end
34
38
  end
39
+
40
+ desc "Run application test suite"
41
+ task 'test' => test_tasks.map { |f| "test:\#{f}" }
35
42
  TEST
36
43
 
37
44
  TESTSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTSPEC_MODEL_TEST)
38
- require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
45
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
39
46
 
40
47
  context "!NAME! Model" do
41
48
  specify 'can be created' do
@@ -55,10 +62,12 @@ end
55
62
  # Generates a controller test given the controllers name
56
63
  def generate_controller_test(name)
57
64
  testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
58
- create_file destination_root("test/controllers/#{name.to_s.underscore}_controller_test.rb"), testspec_contents, :skip => true
65
+ controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
66
+ create_file destination_root(controller_test_path), testspec_contents, :skip => true
59
67
  end
60
68
 
61
69
  def generate_model_test(name)
62
70
  tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
63
- create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), tests_contents, :skip => true
64
- end
71
+ model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
72
+ create_file destination_root(model_test_path), tests_contents, :skip => true
73
+ end
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ bin/*
5
+ vendor/gems/*
6
+ !vendor/gems/cache/
7
+ .sass-cache/*
@@ -53,8 +53,9 @@ module Padrino
53
53
  empty_directory destination_root("public/javascripts")
54
54
  empty_directory destination_root("public/stylesheets")
55
55
  empty_directory destination_root("tmp")
56
- app_skeleton('app', options[:tiny])
57
56
  store_component_config('.components')
57
+ @session_secret = '%x' % rand(2**255)
58
+ app_skeleton('app', options[:tiny])
58
59
  template "templates/Gemfile.tt", destination_root("Gemfile")
59
60
  end
60
61
  end
@@ -68,6 +69,7 @@ module Padrino
68
69
  execute_component_setup(comp, choice)
69
70
  end
70
71
  store_component_config('.components')
72
+ store_component_choice(:session_secret, @session_secret)
71
73
  end
72
74
 
73
75
  # Bundle all required components using bundler and Gemfile
@@ -3,7 +3,7 @@ if defined?(Mongoid)
3
3
 
4
4
  desc 'Drops all the collections for the database for the current Padrino.env'
5
5
  task :drop => :environment do
6
- Mongoid.master.mapions.select {|c| c.name !~ /system/ }.each(&:drop)
6
+ Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
7
7
  end
8
8
 
9
9
  # Helper to retrieve a list of models.
@@ -48,7 +48,7 @@ if defined?(Mongoid)
48
48
  end
49
49
 
50
50
  def collection_names
51
- @collection_names ||= get_mongoid_models.map{ |d| d.mapion.name }.uniq
51
+ @collection_names ||= get_mongoid_models.map{ |d| d.collection.name }.uniq
52
52
  end
53
53
 
54
54
  desc "Convert string objectids in mongo database to ObjectID type"
@@ -57,7 +57,7 @@ if defined?(Mongoid)
57
57
  puts "Converting #{collection_name} to use ObjectIDs"
58
58
 
59
59
  # get old collection
60
- collection = Mongoid.master.mapion(collection_name)
60
+ collection = Mongoid.master.collection(collection_name)
61
61
 
62
62
  # get new collection (a clean one)
63
63
  collection.db["#{collection_name}_new"].drop
@@ -76,7 +76,7 @@ if defined?(Mongoid)
76
76
 
77
77
  # no errors. great! now rename _new to collection_name
78
78
  collection_names.each do |collection_name|
79
- collection = Mongoid.master.mapion(collection_name)
79
+ collection = Mongoid.master.collection(collection_name)
80
80
  new_collection = collection.db["#{collection_name}_new"]
81
81
 
82
82
  # swap collection to _old
@@ -107,9 +107,9 @@ if defined?(Mongoid)
107
107
  desc "Clean up old collections backed up by objectid_convert"
108
108
  task :cleanup_old_collections => :environment do
109
109
  collection_names.each do |collection_name|
110
- collection = Mongoid.master.mapion(collection_name)
110
+ collection = Mongoid.master.collection(collection_name)
111
111
  collection.db["#{collection.name}_old"].drop
112
112
  end
113
113
  end
114
114
  end
115
- end
115
+ end
data/padrino-gen.gemspec CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
@@ -8,15 +9,17 @@ Gem::Specification.new do |s|
8
9
  s.summary = "Generators for easily creating and building padrino applications"
9
10
  s.homepage = "http://www.padrinorb.com"
10
11
  s.description = "Generators for easily creating and building padrino applications from the console"
11
- s.default_executable = "padrino-gen"
12
- s.executables = ["padrino-gen"]
13
12
  s.required_rubygems_version = ">= 1.3.6"
14
13
  s.version = Padrino.version
15
14
  s.date = Time.now.strftime("%Y-%m-%d")
15
+
16
16
  s.extra_rdoc_files = Dir["*.rdoc"]
17
- s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-gen.gemspec) + Dir.glob("{bin,lib,test}/**/*")
18
- s.rdoc_options = ["--charset=UTF-8"]
19
- s.require_path = "lib"
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.rdoc_options = ["--charset=UTF-8"]
22
+
20
23
  s.add_dependency("padrino-core", Padrino.version)
21
24
  s.add_dependency("bundler", ">= 1.0.2")
22
25
  s.add_dependency("grit")
@@ -33,6 +33,16 @@ class TestAppGenerator < Test::Unit::TestCase
33
33
  assert_match_in_file 'set :session_secret, "', "#{@apptmp}/sample_project/demo/app.rb"
34
34
  end
35
35
 
36
+ should "store and apply session_secret" do
37
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
38
+ silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
39
+ assert_match_in_file(/session_secret:.+/, "#{@apptmp}/sample_project/.components")
40
+ session_secret = YAML.load_file("#{@apptmp}/sample_project/.components")[:session_secret]
41
+ assert_not_equal "", session_secret
42
+ assert_match_in_file(/#{session_secret}/, "#{@apptmp}/sample_project/app/app.rb")
43
+ assert_match_in_file(/#{session_secret}/, "#{@apptmp}/sample_project/demo/app.rb")
44
+ end
45
+
36
46
  should "generate tiny app skeleton" do
37
47
  assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") } }
38
48
  assert_nothing_raised { silence_logger { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") } }
@@ -5,7 +5,7 @@ class TestControllerGenerator < Test::Unit::TestCase
5
5
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
6
  `mkdir -p #{@apptmp}`
7
7
  @controller_path = "#{@apptmp}/sample_project/app/controllers/demo_items.rb"
8
- @controller_test_path = "#{@apptmp}/sample_project/test/controllers/demo_items_controller_test.rb"
8
+ @controller_test_path = "#{@apptmp}/sample_project/test/app/controllers/demo_items_controller_test.rb"
9
9
  end
10
10
 
11
11
  def teardown
@@ -25,6 +25,7 @@ class TestControllerGenerator < Test::Unit::TestCase
25
25
  assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
26
26
  assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
27
27
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
28
+ assert_file_exists(@controller_test_path)
28
29
  end
29
30
 
30
31
  should "generate controller within existing project with weird name" do
@@ -56,40 +57,46 @@ class TestControllerGenerator < Test::Unit::TestCase
56
57
 
57
58
  should "generate controller test for bacon" do
58
59
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
59
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
60
- assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path)
60
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
61
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
62
+ assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
61
63
  end
62
64
 
63
65
  should "generate controller test for riot" do
64
66
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
65
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
66
- assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
67
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
68
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
69
+ assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
67
70
  end
68
71
 
69
72
  should "generate controller test for testspec" do
70
73
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec') }
71
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
72
- assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
74
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
75
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
76
+ assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
73
77
  end
74
78
 
75
79
  should "generate controller test for rspec" do
76
80
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
77
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
78
- assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
81
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
82
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
83
+ assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
79
84
  end
80
85
 
81
86
  should "generate controller test for shoulda" do
82
87
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
83
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
88
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
89
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
84
90
  expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
85
- assert_match_in_file(expected_pattern, @controller_test_path)
86
- assert_file_exists("#{@apptmp}/sample_project/test/controllers/demo_items_controller_test.rb")
91
+ assert_match_in_file(expected_pattern, @controller_test_path.gsub('app','subby'))
92
+ assert_file_exists("#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
87
93
  end
88
94
 
89
95
  should "generate controller test for cucumber" do
90
96
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
91
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
92
- assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
97
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
98
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
99
+ assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
93
100
  assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
94
101
  end
95
102
 
@@ -99,7 +106,7 @@ class TestControllerGenerator < Test::Unit::TestCase
99
106
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
100
107
  assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
101
108
  assert_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
102
- assert_file_exists("#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
109
+ assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
103
110
  end
104
111
 
105
112
  # Controller action generation
@@ -127,7 +134,17 @@ class TestControllerGenerator < Test::Unit::TestCase
127
134
  silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
128
135
  assert_no_file_exists(@controller_path)
129
136
  assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
130
- assert_no_file_exists("#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
137
+ assert_no_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
138
+ end
139
+
140
+ should "destroy controller files in sub apps" do
141
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
142
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
143
+ silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project") }
144
+ silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project",'-d') }
145
+ assert_no_file_exists(@controller_path.gsub('app','subby'))
146
+ assert_no_file_exists(@controller_test_path.gsub('app','subby'))
147
+ assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
131
148
  end
132
149
  end
133
- end
150
+ end