padrino-gen 0.9.15 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,6 +58,18 @@ MYSQL = (<<-MYSQL)
58
58
  :socket => '/tmp/mysql.sock'
59
59
  MYSQL
60
60
 
61
+ MYSQL2 = (<<-MYSQL2)
62
+ :adapter => 'mysql2',
63
+ :encoding => 'utf8',
64
+ :reconnect => false,
65
+ :database => !DB_NAME!,
66
+ :pool => 5,
67
+ :username => 'root',
68
+ :password => '',
69
+ :host => 'localhost',
70
+ :socket => '/tmp/mysql.sock'
71
+ MYSQL2
72
+
61
73
  POSTGRES = (<<-POSTGRES)
62
74
  :adapter => 'postgresql',
63
75
  :database => !DB_NAME!,
@@ -82,6 +94,11 @@ def setup_orm
82
94
  ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"\"#{db}_production\"")
83
95
  ar.gsub! /!DB_TEST/, MYSQL.gsub(/!DB_NAME!/,"\"#{db}_test\"")
84
96
  require_dependencies 'mysql'
97
+ when 'mysql2'
98
+ ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"\"#{db}_development\"")
99
+ ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"\"#{db}_production\"")
100
+ ar.gsub! /!DB_TEST/, MYSQL2.gsub(/!DB_NAME!/,"\"#{db}_test\"")
101
+ require_dependencies 'mysql2'
85
102
  when 'postgres'
86
103
  ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"\"#{db}_development\"")
87
104
  ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"\"#{db}_production\"")
@@ -152,4 +169,4 @@ def create_migration_file(migration_name, name, columns)
152
169
  :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
153
170
  :remove => Proc.new { |field, kind| "t.remove :#{field}" }
154
171
  )
155
- end
172
+ end
@@ -12,8 +12,10 @@ class Riot::Situation
12
12
  ##
13
13
  # You can handle all padrino applications using instead:
14
14
  # Padrino.application
15
- CLASS_NAME.tap { |app| }
16
-
15
+
16
+ def app
17
+ CLASS_NAME.tap { |app| }
18
+ end
17
19
  end
18
20
 
19
21
  class Riot::Context
@@ -41,9 +41,9 @@ RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST
41
41
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
42
42
 
43
43
  describe "!NAME! Model" do
44
+ let(:!DNAME!) { !NAME!.new }
44
45
  it 'can be created' do
45
- @!DNAME! = !NAME!.new
46
- @!DNAME!.should_not be_nil
46
+ !DNAME!.should_not be_nil
47
47
  end
48
48
  end
49
49
  TEST
@@ -64,4 +64,4 @@ end
64
64
  def generate_model_test(name)
65
65
  rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
66
66
  create_file destination_root("spec/models/#{name.to_s.underscore}_spec.rb"), rspec_contents, :skip => true
67
- end
67
+ end
@@ -87,4 +87,4 @@ module Padrino
87
87
  end
88
88
  end # Runner
89
89
  end # Generators
90
- end # Padrino
90
+ end # Padrino
@@ -54,7 +54,7 @@ if defined?(ActiveRecord)
54
54
  end
55
55
  rescue
56
56
  case config[:adapter]
57
- when 'mysql'
57
+ when 'mysql', 'mysql2'
58
58
  @charset = ENV['CHARSET'] || 'utf8'
59
59
  @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
60
60
  creation_options = {:charset => (config[:charset] || @charset), :collation => (config[:collation] || @collation)}
@@ -190,7 +190,7 @@ if defined?(ActiveRecord)
190
190
  task :charset => :environment do
191
191
  config = ActiveRecord::Base.configurations[Padrino.env || :development]
192
192
  case config[:adapter]
193
- when 'mysql'
193
+ when 'mysql', 'mysql2'
194
194
  ActiveRecord::Base.establish_connection(config)
195
195
  puts ActiveRecord::Base.connection.charset
196
196
  when 'postgresql'
@@ -205,7 +205,7 @@ if defined?(ActiveRecord)
205
205
  task :collation => :environment do
206
206
  config = ActiveRecord::Base.configurations[Padrino.env || :development]
207
207
  case config[:adapter]
208
- when 'mysql'
208
+ when 'mysql', 'mysql2'
209
209
  ActiveRecord::Base.establish_connection(config)
210
210
  puts ActiveRecord::Base.connection.collation
211
211
  else
@@ -272,7 +272,7 @@ if defined?(ActiveRecord)
272
272
  task :dump => :environment do
273
273
  abcs = ActiveRecord::Base.configurations
274
274
  case abcs[Padrino.env][:adapter]
275
- when "mysql", "oci", "oracle"
275
+ when "mysql", "mysql2", "oci", "oracle"
276
276
  ActiveRecord::Base.establish_connection(abcs[Padrino.env])
277
277
  File.open("#{Padrino.root}/db/#{Padrino.env}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
278
278
  when "postgresql"
@@ -357,7 +357,7 @@ if defined?(ActiveRecord)
357
357
 
358
358
  def drop_database(config)
359
359
  case config[:adapter]
360
- when 'mysql'
360
+ when 'mysql', 'mysql2'
361
361
  ActiveRecord::Base.establish_connection(config)
362
362
  ActiveRecord::Base.connection.drop_database config[:database]
363
363
  when /^sqlite/
@@ -567,4 +567,4 @@ if defined?(ActiveRecord)
567
567
  end
568
568
 
569
569
  ActiveRecord::Migration.send :include, AutoMigrations
570
- end
570
+ end
@@ -11,4 +11,4 @@ initializer :test, "# Example"
11
11
 
12
12
  app :testapp do
13
13
  generate :controller, "users get:index"
14
- end
14
+ end
data/test/helper.rb CHANGED
@@ -2,6 +2,7 @@ require File.expand_path('../../../load_paths', __FILE__)
2
2
  require 'test/unit'
3
3
  require 'rack/test'
4
4
  require 'rack'
5
+ require 'uuid'
5
6
  require 'shoulda'
6
7
  require 'mocha'
7
8
  require 'webrat'
@@ -80,10 +81,11 @@ class Test::Unit::TestCase
80
81
 
81
82
  # expects_generated_project :test => :shoulda, :orm => :activerecord, :dev => true
82
83
  def expects_generated_project(options={})
84
+ project_root = options[:root]
85
+ project_name = options[:name]
83
86
  settings = options.slice!(:name, :root)
84
- options.reverse_merge!(:name => 'sample_project', :root => '/tmp')
85
87
  components = settings.map { |component, value| "--#{component}=#{value}" }
86
- params = [options[:name], *components].push("-r=#{options[:root]}")
88
+ params = [project_name, *components].push("-r=#{project_root}")
87
89
  Padrino.expects(:bin_gen).with(*params.unshift('project')).returns(true)
88
90
  end
89
91
 
@@ -97,7 +99,7 @@ class Test::Unit::TestCase
97
99
 
98
100
  # expects_initializer :test, "# Example"
99
101
  def expects_initializer(name, body,options={})
100
- options.reverse_merge!(:root => "/tmp/sample_project")
102
+ #options.reverse_merge!(:root => "/tmp/sample_project")
101
103
  path = File.join(options[:root],'lib',"#{name}_init.rb")
102
104
  instance = mock
103
105
  instance.expects(:invoke!).at_least_once
@@ -112,13 +114,13 @@ class Test::Unit::TestCase
112
114
 
113
115
  # expects_rake "custom"
114
116
  def expects_rake(command,options={})
115
- options.reverse_merge!(:root => '/tmp')
117
+ #options.reverse_merge!(:root => '/tmp')
116
118
  Padrino.expects(:bin).with("rake", command, "-c=#{options[:root]}").returns(true)
117
119
  end
118
120
 
119
121
  # expects_git :commit, "hello world"
120
122
  def expects_git(command,options={})
121
- options.reverse_merge!(:root => '/tmp')
123
+ #options.reverse_merge!(:root => '/tmp')
122
124
  FileUtils.mkdir_p(options[:root])
123
125
  if command.to_s == 'init'
124
126
  args = options[:arguments] || options[:root]
@@ -151,4 +153,4 @@ module Webrat
151
153
  @logger = nil
152
154
  end
153
155
  end
154
- end
156
+ end
@@ -2,76 +2,81 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestAppGenerator < Test::Unit::TestCase
4
4
  def setup
5
- `rm -rf /tmp/sample_project`
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
+ `mkdir -p #{@apptmp}`
7
+ end
8
+
9
+ def teardown
10
+ `rm -rf #{@apptmp}`
6
11
  end
7
12
 
8
13
  context 'the app generator' do
9
14
  should "fail outside app root" do
10
- output = silence_logger { generate(:app, 'demo_root', '-r=/tmp') }
15
+ output = silence_logger { generate(:app, 'demo_root', "-r=#{@apptmp}") }
11
16
  assert_match(/not at the root/, output)
12
- assert_no_file_exists('/tmp/demo_root')
17
+ assert_no_file_exists("#{@apptmp}/demo_root")
13
18
  end
14
19
 
15
20
  should "create correctly a new padrino application" do
16
- assert_nothing_raised { silence_logger { generate(:project, 'sample_project', '--root=/tmp') } }
17
- assert_nothing_raised { silence_logger { generate(:app, 'demo', '--root=/tmp/sample_project') } }
18
- assert_file_exists('/tmp/sample_project')
19
- assert_file_exists('/tmp/sample_project/demo')
20
- assert_file_exists('/tmp/sample_project/demo/app.rb')
21
- assert_file_exists('/tmp/sample_project/demo/controllers')
22
- assert_file_exists('/tmp/sample_project/demo/helpers')
23
- assert_file_exists('/tmp/sample_project/demo/views')
24
- assert_file_exists('/tmp/sample_project/demo/views/layouts')
25
- assert_dir_exists('/tmp/sample_project/public/demo')
26
- assert_match_in_file 'Padrino.mount("Demo").to("/demo")', '/tmp/sample_project/config/apps.rb'
27
- assert_match_in_file 'class Demo < Padrino::Application', '/tmp/sample_project/demo/app.rb'
21
+ assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") } }
22
+ assert_nothing_raised { silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") } }
23
+ assert_file_exists("#{@apptmp}/sample_project")
24
+ assert_file_exists("#{@apptmp}/sample_project/demo")
25
+ assert_file_exists("#{@apptmp}/sample_project/demo/app.rb")
26
+ assert_file_exists("#{@apptmp}/sample_project/demo/controllers")
27
+ assert_file_exists("#{@apptmp}/sample_project/demo/helpers")
28
+ assert_file_exists("#{@apptmp}/sample_project/demo/views")
29
+ assert_file_exists("#{@apptmp}/sample_project/demo/views/layouts")
30
+ assert_dir_exists("#{@apptmp}/sample_project/public/demo")
31
+ assert_match_in_file 'Padrino.mount("Demo").to("/demo")', "#{@apptmp}/sample_project/config/apps.rb"
32
+ assert_match_in_file 'class Demo < Padrino::Application', "#{@apptmp}/sample_project/demo/app.rb"
28
33
  end
29
34
 
30
35
  should "generate tiny app skeleton" do
31
- assert_nothing_raised { silence_logger { generate(:project, 'sample_project', '--root=/tmp') } }
32
- assert_nothing_raised { silence_logger { generate(:app,'demo','--tiny','--root=/tmp/sample_project') } }
33
- assert_file_exists('/tmp/sample_project')
34
- assert_file_exists('/tmp/sample_project/demo')
35
- assert_file_exists('/tmp/sample_project/demo/helpers.rb')
36
- assert_file_exists('/tmp/sample_project/demo/controllers.rb')
37
- assert_file_exists('/tmp/sample_project/demo/mailers.rb')
38
- assert_dir_exists('/tmp/sample_project/demo/views/mailers')
39
- assert_dir_exists('/tmp/sample_project/public/demo')
40
- assert_match_in_file(/:notifier/,'/tmp/sample_project/demo/mailers.rb')
41
- assert_no_file_exists('/tmp/sample_project/demo/helpers')
42
- assert_no_file_exists('/tmp/sample_project/demo/controllers')
36
+ assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") } }
37
+ assert_nothing_raised { silence_logger { generate(:app,'demo','--tiny',"--root=#{@apptmp}/sample_project") } }
38
+ assert_file_exists("#{@apptmp}/sample_project")
39
+ assert_file_exists("#{@apptmp}/sample_project/demo")
40
+ assert_file_exists("#{@apptmp}/sample_project/demo/helpers.rb")
41
+ assert_file_exists("#{@apptmp}/sample_project/demo/controllers.rb")
42
+ assert_file_exists("#{@apptmp}/sample_project/demo/mailers.rb")
43
+ assert_dir_exists("#{@apptmp}/sample_project/demo/views/mailers")
44
+ assert_dir_exists("#{@apptmp}/sample_project/public/demo")
45
+ assert_match_in_file(/:notifier/,"#{@apptmp}/sample_project/demo/mailers.rb")
46
+ assert_no_file_exists("#{@apptmp}/sample_project/demo/helpers")
47
+ assert_no_file_exists("#{@apptmp}/sample_project/demo/controllers")
43
48
  end
44
49
 
45
50
  should "correctly create a new controller inside a padrino application" do
46
- silence_logger { generate(:project, 'sample_project', '--root=/tmp') }
47
- silence_logger { generate(:app, 'demo', '--root=/tmp/sample_project') }
48
- silence_logger { generate(:controller, 'demo_items', '-r=/tmp/sample_project', '-a=demo') }
49
- assert_match_in_file(/Demo.controllers :demo_items do/m, '/tmp/sample_project/demo/controllers/demo_items.rb')
50
- assert_match_in_file(/Demo.helpers do/m, '/tmp/sample_project/demo/helpers/demo_items_helper.rb')
51
- assert_file_exists('/tmp/sample_project/demo/views/demo_items')
51
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
52
+ silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
53
+ silence_logger { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
54
+ assert_match_in_file(/Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
55
+ assert_match_in_file(/Demo.helpers do/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
56
+ assert_file_exists("#{@apptmp}/sample_project/demo/views/demo_items")
52
57
  end
53
58
 
54
59
  should "correctly create a new mailer inside a padrino application" do
55
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
56
- silence_logger { generate(:app, 'demo_app', '--root=/tmp/sample_project') }
57
- silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project', '-a=demo_app') }
58
- assert_match_in_file(/DemoApp.mailer :demo/m, '/tmp/sample_project/demo_app/mailers/demo.rb')
59
- assert_dir_exists('/tmp/sample_project/demo_app/views/mailers/demo')
60
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
61
+ silence_logger { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
62
+ silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demo_app') }
63
+ assert_match_in_file(/DemoApp.mailer :demo/m, "#{@apptmp}/sample_project/demo_app/mailers/demo.rb")
64
+ assert_dir_exists("#{@apptmp}/sample_project/demo_app/views/mailers/demo")
60
65
  end
61
66
 
62
67
  # only destroys what it generated.
63
68
  # hence, the folder will still exists if other changes were made to it.
64
69
  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') }
70
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
71
+ silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
72
+ output = silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project", '-d') }
68
73
  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')
74
+ assert_no_dir_exists("#{@apptmp}/sample_project/public/demo")
75
+ assert_no_file_exists("#{@apptmp}/sample_project/demo/app.rb")
76
+ assert_no_dir_exists("#{@apptmp}/sample_project/demo/controllers")
77
+ assert_no_dir_exists("#{@apptmp}/sample_project/demo/helpers")
78
+ assert_no_dir_exists("#{@apptmp}/sample_project/demo/views")
79
+ assert_no_match_in_file(/Padrino\.mount\("Demo"\).to\("\/demo"\)/,"#{@apptmp}/sample_project/config/apps.rb")
75
80
  end
76
81
  end
77
- end
82
+ end
data/test/test_cli.rb CHANGED
@@ -3,7 +3,12 @@ require 'padrino-gen/generators/cli'
3
3
 
4
4
  class TestCli < Test::Unit::TestCase
5
5
  def setup
6
- `rm -rf /tmp/sample_project`
6
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
7
+ `mkdir -p #{@apptmp}`
8
+ end
9
+
10
+ def teardown
11
+ `rm -rf #{@apptmp}`
7
12
  end
8
13
 
9
14
  context 'the cli' do
@@ -14,8 +19,8 @@ class TestCli < Test::Unit::TestCase
14
19
  end
15
20
 
16
21
  should "work correctly if we have a project" do
17
- silence_logger { generate(:project, 'sample_project', '--root=/tmp') }
18
- assert_nothing_raised { silence_logger { generate(:cli, '--root=/tmp/sample_project') } }
22
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
23
+ assert_nothing_raised { silence_logger { generate(:cli, "--root=#{@apptmp}/sample_project") } }
19
24
  end
20
25
  end
21
- end
26
+ end
@@ -2,106 +2,110 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestControllerGenerator < Test::Unit::TestCase
4
4
  def setup
5
- @controller_path = '/tmp/sample_project/app/controllers/demo_items.rb'
6
- @controller_test_path = '/tmp/sample_project/test/controllers/demo_items_controller_test.rb'
7
- `rm -rf /tmp/sample_project`
8
- `rm -rf /tmp/warepedia`
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
+ `mkdir -p #{@apptmp}`
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"
9
+ end
10
+
11
+ def teardown
12
+ `rm -rf #{@apptmp}`
9
13
  end
10
14
 
11
15
  context 'the controller generator' do
12
16
  should "fail outside app root" do
13
- output = silence_logger { generate(:controller, 'demo', '-r=/tmp') }
17
+ output = silence_logger { generate(:controller, 'demo', "-r=#{@apptmp}") }
14
18
  assert_match(/not at the root/, output)
15
- assert_no_file_exists('/tmp/app/controllers/demo.rb')
19
+ assert_no_file_exists("#{@apptmp}/app/controllers/demo.rb")
16
20
  end
17
21
 
18
22
  should "generate controller within existing project" do
19
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
20
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
23
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
24
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
21
25
  assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
22
- assert_match_in_file(/SampleProject.helpers do/m, '/tmp/sample_project/app/helpers/demo_items_helper.rb')
23
- assert_file_exists('/tmp/sample_project/app/views/demo_items')
26
+ assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
27
+ assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
24
28
  end
25
29
 
26
30
  should "generate controller within existing project with weird name" do
27
- silence_logger { generate(:project, 'warepedia', '--root=/tmp', '--script=none', '-t=bacon') }
28
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/warepedia') }
29
- assert_match_in_file(/Warepedia.controllers :demo_items do/m, "/tmp/warepedia/app/controllers/demo_items.rb")
30
- assert_match_in_file(/Warepedia.helpers do/m, '/tmp/warepedia/app/helpers/demo_items_helper.rb')
31
- assert_file_exists('/tmp/warepedia/app/views/demo_items')
31
+ silence_logger { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
32
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
33
+ assert_match_in_file(/Warepedia.controllers :demo_items do/m, "#{@apptmp}/warepedia/app/controllers/demo_items.rb")
34
+ assert_match_in_file(/Warepedia.helpers do/m, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
35
+ assert_file_exists("#{@apptmp}/warepedia/app/views/demo_items")
32
36
  end
33
37
 
34
38
  should "generate controller in specified app" do
35
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
36
- silence_logger { generate(:app, 'subby', '-r=/tmp/sample_project') }
37
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', '-r=/tmp/sample_project') }
39
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
40
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
41
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
38
42
  assert_match_in_file(/Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
39
- assert_match_in_file(/Subby.helpers do/m, '/tmp/sample_project/subby/helpers/demo_items_helper.rb')
40
- assert_file_exists('/tmp/sample_project/subby/views/demo_items')
43
+ assert_match_in_file(/Subby.helpers do/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
44
+ assert_file_exists("#{@apptmp}/sample_project/subby/views/demo_items")
41
45
  assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
42
46
  end
43
47
 
44
48
  should 'not fail if we don\'t have test component' do
45
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--test=none') }
46
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
49
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
50
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
47
51
  assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
48
- assert_match_in_file(/SampleProject.helpers do/m, '/tmp/sample_project/app/helpers/demo_items_helper.rb')
49
- assert_file_exists('/tmp/sample_project/app/views/demo_items')
50
- assert_no_file_exists("/tmp/sample_project/test")
52
+ assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
53
+ assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
54
+ assert_no_file_exists("#{@apptmp}/sample_project/test")
51
55
  end
52
56
 
53
57
  should "generate controller test for bacon" do
54
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
55
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
58
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
59
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
56
60
  assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path)
57
61
  end
58
62
 
59
63
  should "generate controller test for riot" do
60
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=riot') }
61
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
64
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
65
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
62
66
  assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
63
67
  end
64
68
 
65
69
  should "generate controller test for testspec" do
66
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=testspec') }
67
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
70
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec') }
71
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
68
72
  assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
69
73
  end
70
74
 
71
75
  should "generate controller test for rspec" do
72
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec') }
73
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
74
- assert_match_in_file(/describe "DemoItemsController" do/m, '/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
76
+ 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")
75
79
  end
76
80
 
77
81
  should "generate controller test for shoulda" do
78
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=shoulda') }
79
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
82
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
83
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
80
84
  expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
81
85
  assert_match_in_file(expected_pattern, @controller_test_path)
82
- assert_file_exists('/tmp/sample_project/test/controllers/demo_items_controller_test.rb')
86
+ assert_file_exists("#{@apptmp}/sample_project/test/controllers/demo_items_controller_test.rb")
83
87
  end
84
88
 
85
89
  should "generate controller test for cucumber" do
86
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=cucumber') }
87
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
88
- assert_match_in_file(/describe "DemoItemsController" do/m, '/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
89
- assert_match_in_file(/Capybara.app = /, '/tmp/sample_project/features/support/env.rb')
90
+ 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")
93
+ assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
90
94
  end
91
95
 
92
96
  should "correctly generate file names" do
93
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec') }
94
- silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
95
- assert_file_exists('/tmp/sample_project/app/views/demo_items')
96
- assert_file_exists('/tmp/sample_project/app/controllers/demo_items.rb')
97
- assert_file_exists('/tmp/sample_project/app/helpers/demo_items_helper.rb')
98
- assert_file_exists('/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
97
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
98
+ silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
99
+ assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
100
+ assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
101
+ 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")
99
103
  end
100
104
 
101
105
  # Controller action generation
102
106
  should "generate actions for get:test post:yada" do
103
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=shoulda') }
104
- silence_logger { generate(:controller, 'demo_items', "get:test", "post:yada",'-r=/tmp/sample_project') }
107
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
108
+ silence_logger { generate(:controller, 'demo_items', "get:test", "post:yada","-r=#{@apptmp}/sample_project") }
105
109
  assert_match_in_file(/get :test do\n end\n/m, @controller_path)
106
110
  assert_match_in_file(/post :yada do\n end\n/m, @controller_path)
107
111
  end
@@ -109,21 +113,21 @@ class TestControllerGenerator < Test::Unit::TestCase
109
113
 
110
114
  context "the controller destroy option" do
111
115
  should "destroy controller files" do
112
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
113
- silence_logger { generate(:controller, 'demo_items','-r=/tmp/sample_project') }
114
- silence_logger { generate(:controller, 'demo_items','-r=/tmp/sample_project','-d') }
116
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
117
+ silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
118
+ silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
115
119
  assert_no_file_exists(@controller_path)
116
120
  assert_no_file_exists(@controller_test_path)
117
- assert_no_file_exists('/tmp/sample_project/app/helpers/demo_items_helper.rb')
121
+ assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
118
122
  end
119
123
 
120
124
  should "destroy controller files with rspec" do
121
- silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec') }
122
- silence_logger { generate(:controller, 'demo_items','-r=/tmp/sample_project') }
123
- silence_logger { generate(:controller, 'demo_items','-r=/tmp/sample_project','-d') }
125
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
126
+ silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
127
+ silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
124
128
  assert_no_file_exists(@controller_path)
125
- assert_no_file_exists('/tmp/sample_project/app/helpers/demo_items_helper.rb')
126
- assert_no_file_exists('/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
129
+ 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")
127
131
  end
128
132
  end
129
- end
133
+ end