combustion 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .rvmrc
5
+ .rvmrc
6
+ .ruby-version
data/HISTORY CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.0 - May 1st 2013
2
+ * whitelist_attributes is now set within configure_for_combustion, as it depends on which Railties are loaded.
3
+ * Make sure Rails gems are loaded before the engine's gem (Pablo Herrero).
4
+ * Fixed Rails version comparison (Josh Adam).
5
+
1
6
  0.4.0 - March 16th 2013
2
7
  * Don't delete the SQLite test database if it doesn't exist (Michael Gee, Alexander Rozumiy).
3
8
  * Support for secret_key_base for Rails 4 apps (Philip Arndt).
@@ -1,25 +1,28 @@
1
- h1. Combustion
1
+ # Combustion
2
2
 
3
3
  Combustion is a library to help you test your Rails Engines in a simple and effective manner, instead of creating a full Rails application in your spec or test folder.
4
4
 
5
5
  It allows you to write your specs within the context of your engine, using only the parts of a Rails app you need.
6
6
 
7
- h2. Usage
7
+ ## Usage
8
8
 
9
9
  Get the gem into either your gemspec or your Gemfile, depending on how you manage your engine's dependencies:
10
10
 
11
- <pre><code># gemspec
12
- gem.add_development_dependency 'combustion', '~> 0.3.1'
13
- # Gemfile
14
- gem 'combustion', '~> 0.3.1', :group => :test</code></pre>
11
+ ```ruby
12
+ # gemspec
13
+ gem.add_development_dependency 'combustion', '~> 0.4.0'
15
14
 
16
- In your @spec_helper.rb@, get Combustion to set itself up - which has to happen before you introduce @rspec/rails@ and - if being used - @capybara/rails@. Here's an example within context:
15
+ # Gemfile
16
+ gem 'combustion', '~> 0.4.0', :group => :test
17
+ ```
17
18
 
18
- <pre><code>require 'rubygems'
19
- require 'bundler'
19
+ In your `spec_helper.rb`, get Combustion to set itself up - which has to happen before you introduce `rspec/rails` and - if being used - `capybara/rails`. Here's an example within context:
20
20
 
21
- Bundler.require :default, :test
21
+ ```ruby
22
+ require 'rubygems'
23
+ require 'bundler/setup'
22
24
 
25
+ require 'combustion'
23
26
  require 'capybara/rspec'
24
27
 
25
28
  Combustion.initialize!
@@ -29,103 +32,119 @@ require 'capybara/rails'
29
32
 
30
33
  RSpec.configure do |config|
31
34
  config.use_transactional_fixtures = true
32
- end</code></pre>
35
+ end
36
+ ```
33
37
 
34
38
  You'll also want to run the generator that creates a minimal set of files expected by Rails - run this in the directory of your engine:
35
39
 
36
- <pre><code>combust
40
+ ```shell
41
+ combust
42
+
37
43
  # or, if bundling with the git repo:
38
- bundle exec combust</code></pre>
44
+ bundle exec combust
45
+ ```
39
46
 
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
47
 
42
- If you want to use Cucumber, I recommend starting with "these notes":https://github.com/pat/combustion/issues/16 from Niklas Cathor.
48
+ 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.
43
49
 
44
- h3. Configuring a different test app directory
50
+ If you want to use Cucumber, I recommend starting with [these notes in issue #16](https://github.com/pat/combustion/issues/16) from Niklas Cathor.
45
51
 
46
- If you want your app to be located somewhere other than @spec/internal@, then make sure you configure it before you call @Combustion.initialize!@:
52
+ ### Configuring a different test app directory
53
+
54
+ If you want your app to be located somewhere other than `spec/internal`, then make sure you configure it before you call `Combustion.initialize!`:
55
+
56
+ ```ruby
57
+ Combustion.path = 'spec/dummy'
58
+ Combustion.initialize!
59
+ ```
47
60
 
48
- <pre><code>Combustion.path = 'spec/dummy'
49
- Combustion.initialize!</code></pre>
50
61
 
51
- h3. Configuring which Rails modules should be loaded.
62
+ ### Configuring which Rails modules should be loaded.
52
63
 
53
- By default, Combustion doesn't come with any of the Rails stack. You can customise this though - just pass in what you'd like loaded to the @Combustion.initialize!@ call:
64
+ By default, Combustion doesn't come with any of the Rails stack. You can customise this though - just pass in what you'd like loaded to the `Combustion.initialize!` call:
54
65
 
55
- <pre><code>
66
+ ```ruby
56
67
  Combustion.initialize! :active_record, :action_controller,
57
68
  :action_view, :sprockets
58
- </code></pre>
69
+ ```
70
+
59
71
 
60
72
  And then in your engine's Gemfile:
61
73
 
62
- <pre><code>
74
+ ```ruby
63
75
  group :test do
64
76
  gem 'activerecord'
65
77
  gem 'actionpack' # action_controller, action_view
66
78
  gem 'sprockets'
67
79
  end
68
- </code></pre>
80
+ ```
69
81
 
70
82
  Make sure to specify the appropriate version that you want to use.
71
83
 
72
- ActiveSupport is always loaded, as it's an integral part of Rails.
84
+ ActiveSupport and Railties are always loaded, as they're an integral part of Rails.
73
85
 
74
- h3. Using Models and ActiveRecord
86
+ ### Using Models and ActiveRecord
75
87
 
76
- If you're using ActiveRecord, then there are two critical files within your internal Rails app at @spec/internal@ that you'll need to modify:
88
+ If you're using ActiveRecord, then there are two critical files within your internal Rails app at `spec/internal` that you'll need to modify:
77
89
 
78
90
  * config/database.yml
79
91
  * db/schema.rb
80
92
 
81
93
  Both follow the same structure as in any normal Rails application - and the schema file lets you avoid migrations, as it gets run whenever the test suite starts. Here's a quick sample (note that tables are overwritten if they already exist - this is necessary):
82
94
 
83
- <pre><code>ActiveRecord::Schema.define do
95
+ ```ruby
96
+ ActiveRecord::Schema.define do
84
97
  create_table(:pages, :force => true) do |t|
85
98
  t.string :name
86
99
  t.text :content
87
100
  t.timestamps
88
101
  end
89
- end</code></pre>
102
+ end
103
+ ```
90
104
 
91
- h3. Configuring Combustion to initialise the test db from a .sql file instead of schema.rb
105
+ ### Configuring Combustion to initialise the test db from a .sql file instead of schema.rb
92
106
 
93
107
  Name the file structure.sql and configure Combustion to use it before initialising:
94
108
 
95
- <pre><code>Combustion.schema_format = :sql
96
- Combustion.initialize!</code></pre>
109
+ ```ruby
110
+ Combustion.schema_format = :sql
111
+ Combustion.initialize!
112
+ ```
97
113
 
98
- Any models that aren't provided by your engine should be located at @spec/internal/app/models@.
114
+ Any models that aren't provided by your engine should be located at `spec/internal/app/models`.
99
115
 
100
- h3. Using ActionController and ActionView
116
+ ### Using ActionController and ActionView
101
117
 
102
- You'll only need to add controllers and views to your internal Rails app for whatever you're testing that your engine doesn't provide - this may be nothing at all, so perhaps you don't even need @spec/internal/app/views@ or @spec/internal/app/controllers@ directories.
118
+ You'll only need to add controllers and views to your internal Rails app for whatever you're testing that your engine doesn't provide - this may be nothing at all, so perhaps you don't even need `spec/internal/app/views` or `spec/internal/app/controllers` directories.
103
119
 
104
- However, if you're doing any testing of your engine's controllers or views, then you're going to need routes set up for them - so modify @spec/internal/config/routes.rb@ accordingly:
120
+ However, if you're doing any testing of your engine's controllers or views, then you're going to need routes set up for them - so modify `spec/internal/config/routes.rb` accordingly:
105
121
 
106
- <pre><code>Rails.application.routes.draw do
122
+ ```ruby
123
+ Rails.application.routes.draw do
107
124
  resources :pages
108
- end</code></pre>
125
+ end
126
+ ```
109
127
 
110
128
  Just like in a standard Rails app, if you have a mounted engine, then its routes are accessible through whatever it has been loaded as.
111
129
 
112
- h3. Using other Rails-focused libraries
130
+ ### Using other Rails-focused libraries
113
131
 
114
- Be aware that other gems may require parts of Rails when they're loaded, and this could cause some issues with Combustion's own setup. You may need to manage the loading yourself by setting @:require@ to false in your Gemfile for the gem in question, and then requiring it manually in your spec_helper. View "this issue":https://github.com/pat/combustion/issues/33 for an example with FactoryGirl.
132
+ Be aware that other gems may require parts of Rails when they're loaded, and this could cause some issues with Combustion's own setup. You may need to manage the loading yourself by setting `:require` to false in your Gemfile for the gem in question, and then requiring it manually in your spec_helper. View [issue #33](https://github.com/pat/combustion/issues/33) for an example with FactoryGirl.
115
133
 
116
- h3. Environment and Logging
134
+ ### Environment and Logging
117
135
 
118
- Your tests will execute within the test environment for the internal Rails app - and so logs are available at @spec/internal/log/test.log@. You should probably create that log directory so Rails doesn't complain.
136
+ Your tests will execute within the test environment for the internal Rails app - and so logs are available at `spec/internal/log/test.log`. You should probably create that log directory so Rails doesn't complain.
119
137
 
120
- h3. Rack it up
138
+ ### Rack it up
121
139
 
122
- Once you've got this set up, you can fire up your test environment quite easily with Rack - a @config.ru@ file is provided by the generator. Just run @rackup@ and visit "http://localhost:9292":http://localhost:9292.
140
+ Once you've got this set up, you can fire up your test environment quite easily with Rack - a `config.ru` file is provided by the generator. Just run `rackup` and visit [http://localhost:9292](http://localhost:9292).
123
141
 
124
- h3. Get your test on!
142
+ ### Get your test on!
125
143
 
126
- Now you're good to go - you can write specs within your engine's spec directory just like you were testing a full Rails application - models in @spec/models@, controllers in @spec/controllers@. If you bring Capybara into the mix, then the standard helpers from that will be loaded as well.
144
+ Now you're good to go - you can write specs within your engine's spec directory just like you were testing a full Rails application - models in `spec/models`, controllers in `spec/controllers`. If you bring Capybara into the mix, then the standard helpers from that will be loaded as well.
127
145
 
128
- <pre><code>require 'spec_helper'
146
+ ```ruby
147
+ require 'spec_helper'
129
148
 
130
149
  describe Page do
131
150
  describe '#valid' do
@@ -133,19 +152,21 @@ describe Page do
133
152
  # This is just an example. Go write your own tests!
134
153
  end
135
154
  end
136
- end</code></pre>
155
+ end
156
+ ```
157
+
137
158
 
138
- h2. Compatibility
159
+ ## Compatibility
139
160
 
140
161
  Developed for Rails 3.1 and Ruby 1.9. It should work on any other Ruby, and possibly Rails 3.0, but will not work neatly with earlier versions of Rails.
141
162
 
142
- h2. Limitations and Known Issues
163
+ ## Limitations and Known Issues
143
164
 
144
165
  Combustion is currently written with the expectation it'll be used with RSpec. I'd love to make this more flexible - if you want to give it a shot before I get around to it, patches are very much welcome.
145
166
 
146
167
  I've not tried using this with Cucumber, but it should work in theory without too much hassle. Let me know if I'm wrong!
147
168
 
148
- h2. Contributing
169
+ ## Contributing
149
170
 
150
171
  Contributions are very much welcome - but keep in mind the following:
151
172
 
@@ -154,6 +175,6 @@ Contributions are very much welcome - but keep in mind the following:
154
175
 
155
176
  There are no tests - partly because Combustion was extracted out from the tests of HyperTiny's Dobro, and partly because there's not much code. Still, if you can find a clean way of testing this, that'd be fantastic.
156
177
 
157
- h2. Credits
178
+ ## Credits
158
179
 
159
- Copyright (c) 2011, Combustion is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to HyperTiny for encouraging its development, and "all who have contributed patches":https://github.com/pat/combustion/contributors.
180
+ Copyright (c) 2011, Combustion is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to HyperTiny for encouraging its development, and [all who have contributed patches](https://github.com/pat/combustion/contributors).
@@ -1,10 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'combustion'
4
- s.version = '0.4.0'
4
+ s.version = '0.5.0'
5
5
  s.authors = ['Pat Allan']
6
6
  s.email = ['pat@freelancing-gods.com']
7
- s.homepage = ''
7
+ s.homepage = 'https://github.com/pat/combustion'
8
8
  s.summary = 'Elegant Rails Engine Testing'
9
9
  s.description = 'Test your Rails Engines without needing a full Rails app'
10
10
 
@@ -7,7 +7,7 @@ module Combustion
7
7
  self.path = '/spec/internal'
8
8
  self.schema_format = :ruby
9
9
 
10
- if Rails.version > '3.1'
10
+ if Rails.version.to_s > '3.1'
11
11
  Modules = %w( active_record action_controller action_view action_mailer
12
12
  sprockets )
13
13
  else
@@ -18,6 +18,8 @@ module Combustion
18
18
  modules = Modules if modules == [:all]
19
19
  modules.each { |mod| require "#{mod}/railtie" }
20
20
 
21
+ Bundler.require :default, Rails.env
22
+
21
23
  Combustion::Application.configure_for_combustion
22
24
  Combustion::Application.initialize!
23
25
 
@@ -5,25 +5,27 @@ module Combustion
5
5
  class Application < Rails::Application
6
6
  # Core Settings
7
7
  config.cache_classes = true
8
- config.whiny_nils = true if Rails.version < '4.0.0'
8
+ config.whiny_nils = true if Rails.version.to_s < '4.0.0'
9
9
  config.consider_all_requests_local = true
10
10
  config.secret_token = Digest::SHA1.hexdigest Time.now.to_s
11
11
  config.eager_load = Rails.env.production?
12
- config.secret_key_base = SecureRandom.hex if Rails.version >= '4.0.0'
12
+ config.secret_key_base = SecureRandom.hex if Rails.version.to_s >= '4.0.0'
13
13
 
14
14
  # ActiveSupport Settings
15
15
  config.active_support.deprecation = :stderr
16
16
 
17
- # Turn on ActiveRecord attribute whitelisting
18
- # This way the dummy app matches new rails apps re: this setting
19
- config.active_record.whitelist_attributes = true if config.respond_to? :active_record
20
-
21
- # Some settings we're not sure if we want, so let's not load them by default.
22
- # Instead, wait for this method to be invoked (to get around load-order
23
- # complications).
17
+ # Some settings we're not sure if we want, so let's not load them by
18
+ # default. Instead, wait for this method to be invoked (to get around
19
+ # load-order complications).
24
20
  def self.configure_for_combustion
25
21
  config.root = File.expand_path File.join(Dir.pwd, Combustion.path)
26
22
 
23
+ if defined? ActiveRecord::Railtie
24
+ # Turn on ActiveRecord attribute whitelisting
25
+ # This way the dummy app matches new rails apps re: this setting
26
+ config.active_record.whitelist_attributes = true
27
+ end
28
+
27
29
  if defined? ActionController::Railtie
28
30
  config.action_dispatch.show_exceptions = false
29
31
  config.action_controller.perform_caching = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combustion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-16 00:00:00.000000000 Z
12
+ date: 2013-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -71,7 +71,7 @@ files:
71
71
  - Gemfile
72
72
  - HISTORY
73
73
  - LICENCE
74
- - README.textile
74
+ - README.md
75
75
  - Rakefile
76
76
  - bin/combust
77
77
  - combustion.gemspec
@@ -83,7 +83,7 @@ files:
83
83
  - templates/database.yml
84
84
  - templates/routes.rb
85
85
  - templates/schema.rb
86
- homepage: ''
86
+ homepage: https://github.com/pat/combustion
87
87
  licenses: []
88
88
  post_install_message:
89
89
  rdoc_options: []