combustion 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.2 - March 3rd 2011
2
+ * Tentative Rails 3.0 and migrations support.
3
+ * Allow for different internal app directory.
4
+
1
5
  0.3.1 - September 12th 2011
2
6
  * Allow for different versions of Capybara (Leo Liang).
3
7
  * Including Capybara::DSL instead of Capybara.
@@ -39,6 +39,13 @@ bundle exec combust</code></pre>
39
39
 
40
40
  What Combustion is doing is setting up a Rails application at @spec/internal@ - but you only need to add the files within that directory that you're going to use. Read on for some detail about what that involves.
41
41
 
42
+ h3. Configuring a different test app directory
43
+
44
+ If you want your app to be located somewhere other than @spec/internal@, then make sure you configure it before you call @Combustion.initialize!@:
45
+
46
+ <pre><code>Combustion.path = 'spec/dummy'
47
+ Combustion.initialize!</code></pre>
48
+
42
49
  h3. Configuring which Rails modules should be loaded.
43
50
 
44
51
  By default, Combustion assumes you want the full Rails stack. You can customise this though - just pass in what you'd like loaded to the @Combustion.initialize!@ call:
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_runtime_dependency 'rails', '>= 3.1.0'
21
+ s.add_runtime_dependency 'rails', '>= 3.0.0'
22
22
  s.add_runtime_dependency 'thor', '>= 0.14.6'
23
23
  end
@@ -12,18 +12,28 @@ module Combustion
12
12
  Combustion::Application.configure_for_combustion
13
13
  Combustion::Application.initialize!
14
14
 
15
- silence_stream(STDOUT) do
16
- load "#{Rails.root}/db/schema.rb"
15
+ if modules.include?('active_record') || modules.include?(:active_record)
16
+ Combustion::Database.setup
17
17
  end
18
18
 
19
19
  RSpec.configure do |config|
20
20
  include_capybara_into config
21
21
 
22
22
  config.include(Combustion::Application.routes.url_helpers)
23
- config.include(Combustion::Application.routes.mounted_helpers)
23
+ if Combustion::Application.routes.respond_to?(:mounted_helpers)
24
+ config.include(Combustion::Application.routes.mounted_helpers)
25
+ end
24
26
  end if defined?(RSpec) && RSpec.respond_to?(:configure)
25
27
  end
26
28
 
29
+ def self.path
30
+ @path ||= 'spec/internal'
31
+ end
32
+
33
+ def self.path=(path)
34
+ @path = path
35
+ end
36
+
27
37
  def self.include_capybara_into(config)
28
38
  return unless defined?(Capybara)
29
39
 
@@ -37,4 +47,5 @@ module Combustion
37
47
  end
38
48
 
39
49
  require 'combustion/application'
50
+ require 'combustion/database'
40
51
  require 'combustion/version'
@@ -1,8 +1,6 @@
1
1
  Rails.env = 'test'
2
2
 
3
3
  class Combustion::Application < Rails::Application
4
- config.root = File.expand_path File.join(Dir.pwd, 'spec', 'internal')
5
-
6
4
  # Core Settings
7
5
  config.cache_classes = true
8
6
  config.whiny_nils = true
@@ -16,6 +14,8 @@ class Combustion::Application < Rails::Application
16
14
  # Instead, wait for this method to be invoked (to get around load-order
17
15
  # complications).
18
16
  def self.configure_for_combustion
17
+ config.root = File.expand_path File.join(Dir.pwd, Combustion.path)
18
+
19
19
  if defined?(ActionController) && defined?(ActionController::Engine)
20
20
  config.action_dispatch.show_exceptions = false
21
21
  config.action_controller.perform_caching = false
@@ -0,0 +1,156 @@
1
+ class Combustion::Database
2
+ def self.setup
3
+ silence_stream(STDOUT) do
4
+ reset_database
5
+ load_schema
6
+ migrate
7
+ end
8
+ end
9
+
10
+ def self.reset_database
11
+ abcs = ActiveRecord::Base.configurations
12
+ case abcs['test']['adapter']
13
+ when /mysql/
14
+ ActiveRecord::Base.establish_connection(:test)
15
+ ActiveRecord::Base.connection.recreate_database(abcs['test']['database'],
16
+ mysql_creation_options(abcs['test']))
17
+ ActiveRecord::Base.establish_connection(:test)
18
+ when /postgresql/
19
+ ActiveRecord::Base.clear_active_connections!
20
+ drop_database(abcs['test'])
21
+ create_database(abcs['test'])
22
+ when /sqlite/
23
+ dbfile = abcs['test']['database'] || abcs['test']['dbfile']
24
+ File.delete(dbfile) if File.exist?(dbfile)
25
+ when 'sqlserver'
26
+ test = abcs.deep_dup['test']
27
+ test_database = test['database']
28
+ test['database'] = 'master'
29
+ ActiveRecord::Base.establish_connection(test)
30
+ ActiveRecord::Base.connection.recreate_database!(test_database)
31
+ when "oci", "oracle"
32
+ ActiveRecord::Base.establish_connection(:test)
33
+ ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
34
+ ActiveRecord::Base.connection.execute(ddl)
35
+ end
36
+ when 'firebird'
37
+ ActiveRecord::Base.establish_connection(:test)
38
+ ActiveRecord::Base.connection.recreate_database!
39
+ else
40
+ raise "Cannot reset databases for '#{abcs['test']['adapter']}'"
41
+ end
42
+ end
43
+
44
+ def self.load_schema
45
+ load "#{Rails.root}/db/schema.rb"
46
+ end
47
+
48
+ def self.migrate
49
+ migrator = ActiveRecord::Migrator
50
+ paths = 'db/migrate/'
51
+
52
+ if migrator.respond_to?(:migrations_paths)
53
+ paths = migrator.migrations_paths
54
+ end
55
+
56
+ migrator.migrate paths, nil
57
+ end
58
+
59
+ private
60
+
61
+ def self.create_database(config)
62
+ begin
63
+ if config['adapter'] =~ /sqlite/
64
+ if File.exist?(config['database'])
65
+ $stderr.puts "#{config['database']} already exists"
66
+ else
67
+ begin
68
+ # Create the SQLite database
69
+ ActiveRecord::Base.establish_connection(config)
70
+ ActiveRecord::Base.connection
71
+ rescue Exception => e
72
+ $stderr.puts e, *(e.backtrace)
73
+ $stderr.puts "Couldn't create database for #{config.inspect}"
74
+ end
75
+ end
76
+ return # Skip the else clause of begin/rescue
77
+ else
78
+ ActiveRecord::Base.establish_connection(config)
79
+ ActiveRecord::Base.connection
80
+ end
81
+ rescue
82
+ case config['adapter']
83
+ when /^(jdbc)?mysql/
84
+ if config['adapter'] =~ /jdbc/
85
+ #FIXME After Jdbcmysql gives this class
86
+ require 'active_record/railties/jdbcmysql_error'
87
+ error_class = ArJdbcMySQL::Error
88
+ else
89
+ error_class = config['adapter'] =~ /mysql2/ ? Mysql2::Error : Mysql::Error
90
+ end
91
+ access_denied_error = 1045
92
+ begin
93
+ ActiveRecord::Base.establish_connection(config.merge('database' => nil))
94
+ ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config))
95
+ ActiveRecord::Base.establish_connection(config)
96
+ rescue error_class => sqlerr
97
+ if sqlerr.errno == access_denied_error
98
+ print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
99
+ root_password = $stdin.gets.strip
100
+ grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
101
+ "TO '#{config['username']}'@'localhost' " \
102
+ "IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
103
+ ActiveRecord::Base.establish_connection(config.merge(
104
+ 'database' => nil, 'username' => 'root', 'password' => root_password))
105
+ ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config))
106
+ ActiveRecord::Base.connection.execute grant_statement
107
+ ActiveRecord::Base.establish_connection(config)
108
+ else
109
+ $stderr.puts sqlerr.error
110
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
111
+ $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
112
+ end
113
+ end
114
+ when /^(jdbc)?postgresql$/
115
+ @encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
116
+ begin
117
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
118
+ ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
119
+ ActiveRecord::Base.establish_connection(config)
120
+ rescue Exception => e
121
+ $stderr.puts e, *(e.backtrace)
122
+ $stderr.puts "Couldn't create database for #{config.inspect}"
123
+ end
124
+ end
125
+ else
126
+ $stderr.puts "#{config['database']} already exists"
127
+ end
128
+ end
129
+
130
+ def self.drop_database(config)
131
+ case config['adapter']
132
+ when /^(jdbc)?mysql/
133
+ ActiveRecord::Base.establish_connection(config)
134
+ ActiveRecord::Base.connection.drop_database config['database']
135
+ when /^(jdbc)?sqlite/
136
+ require 'pathname'
137
+ path = Pathname.new(config['database'])
138
+ file = path.absolute? ? path.to_s : File.join(Rails.root, path)
139
+
140
+ FileUtils.rm(file)
141
+ when /^(jdbc)?postgresql$/
142
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
143
+ ActiveRecord::Base.connection.drop_database config['database']
144
+ end
145
+ end
146
+
147
+ def self.mysql_creation_options(config)
148
+ @charset = ENV['CHARSET'] || 'utf8'
149
+ @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
150
+
151
+ {
152
+ :charset => (config['charset'] || @charset),
153
+ :collation => (config['collation'] || @collation)
154
+ }
155
+ end
156
+ end
@@ -1,3 +1,3 @@
1
1
  module Combustion
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,46 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: combustion
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 2
10
+ version: 0.3.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Pat Allan
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-09-12 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: &2152618140 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 3.1.0
17
+
18
+ date: 2012-03-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
22
21
  type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 7
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ version_requirements: *id001
23
34
  prerelease: false
24
- version_requirements: *2152618140
25
- - !ruby/object:Gem::Dependency
26
- name: thor
27
- requirement: &2152617480 !ruby/object:Gem::Requirement
35
+ name: rails
36
+ - !ruby/object:Gem::Dependency
37
+ type: :runtime
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 43
44
+ segments:
45
+ - 0
46
+ - 14
47
+ - 6
32
48
  version: 0.14.6
33
- type: :runtime
49
+ version_requirements: *id002
34
50
  prerelease: false
35
- version_requirements: *2152617480
51
+ name: thor
36
52
  description: Test your Rails Engines without needing a full Rails app
37
- email:
53
+ email:
38
54
  - pat@freelancing-gods.com
39
- executables:
55
+ executables:
40
56
  - combust
41
57
  extensions: []
58
+
42
59
  extra_rdoc_files: []
43
- files:
60
+
61
+ files:
44
62
  - .gitignore
45
63
  - Gemfile
46
64
  - HISTORY
@@ -51,34 +69,45 @@ files:
51
69
  - combustion.gemspec
52
70
  - lib/combustion.rb
53
71
  - lib/combustion/application.rb
72
+ - lib/combustion/database.rb
54
73
  - lib/combustion/generator.rb
55
74
  - lib/combustion/version.rb
56
75
  - templates/config.ru
57
76
  - templates/database.yml
58
77
  - templates/routes.rb
59
78
  - templates/schema.rb
60
- homepage: ''
79
+ homepage: ""
61
80
  licenses: []
81
+
62
82
  post_install_message:
63
83
  rdoc_options: []
64
- require_paths:
84
+
85
+ require_paths:
65
86
  - lib
66
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
67
88
  none: false
68
- requirements:
69
- - - ! '>='
70
- - !ruby/object:Gem::Version
71
- version: '0'
72
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
97
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
78
105
  requirements: []
106
+
79
107
  rubyforge_project: combustion
80
- rubygems_version: 1.8.6
108
+ rubygems_version: 1.8.16
81
109
  signing_key:
82
110
  specification_version: 3
83
111
  summary: Elegant Rails Engine Testing
84
112
  test_files: []
113
+