commands 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -2
- data/commands-0.2.0.gem +0 -0
- data/commands.gemspec +2 -2
- data/lib/rails/commands/console_delegation.rb +10 -1
- data/lib/rails/commands/test_environment.rb +12 -25
- data/lib/rails/commands/tester.rb +10 -0
- metadata +5 -6
- data/commands-0.0.1.gem +0 -0
- data/commands-0.1.0.gem +0 -0
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Commands
|
2
2
|
========
|
3
3
|
|
4
|
-
Run Rake and Rails commands during a console session. This side-steps the need to load the entire environment over and over again when you run these commands from the shell. This constant reloading of the environment is what causes slow boot time on big applications. Think of this like a baby Zeus or the Turbolinks of commands.
|
4
|
+
Run Rake and Rails commands during a development console session and run tests during a test console session. This side-steps the need to load the entire environment over and over again when you run these commands from the shell. This constant reloading of the environment is what causes slow boot time on big applications. Think of this like a baby Zeus or the Turbolinks of commands.
|
5
5
|
|
6
6
|
|
7
7
|
Installation
|
@@ -18,10 +18,15 @@ And then execute:
|
|
18
18
|
Usage
|
19
19
|
-----
|
20
20
|
|
21
|
-
When your console boots, it'll automatically have a `commander` object instantiated. The following methods are delegated to this object: rake,
|
21
|
+
When your console boots, it'll automatically have a `commander` object instantiated. The following methods are delegated to this object: rake, generate, destroy, update. It's used like this:
|
22
22
|
|
23
23
|
> generate "scaffold post title:string"
|
24
24
|
> rake "db:migrate"
|
25
|
+
|
26
|
+
To use a persistent console for testing, be sure to first start it in the test environment, like so `./script/rails console test`. Then you can run tests like this:
|
27
|
+
|
28
|
+
> test "models"
|
29
|
+
> test "controllers"
|
25
30
|
> test "models/person"
|
26
31
|
|
27
32
|
You can see the options available for all the commands by running them with no parameters.
|
data/commands-0.2.0.gem
ADDED
Binary file
|
data/commands.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'commands'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.1'
|
4
4
|
s.author = 'David Heinemeier Hansson'
|
5
5
|
s.email = 'david@37signals.com'
|
6
6
|
s.summary = 'Run Rake/Rails commands through the console'
|
7
7
|
|
8
|
-
s.add_dependency 'rails', '>= 3.
|
8
|
+
s.add_dependency 'rails', '>= 3.2.0'
|
9
9
|
|
10
10
|
s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
|
11
11
|
end
|
@@ -7,7 +7,16 @@ module Rails
|
|
7
7
|
@commander ||= Commander.new
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
def test(*args)
|
11
|
+
if Rails.env.test?
|
12
|
+
commander.test(*args)
|
13
|
+
else
|
14
|
+
puts "You can only run tests in a console started in the test environment. " +
|
15
|
+
"Use `./script/rails console test` to start such a console"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
delegate :rake, :generate, :destroy, :update, to: :commander
|
11
20
|
end
|
12
21
|
end
|
13
22
|
end
|
@@ -7,52 +7,39 @@ module Rails
|
|
7
7
|
|
8
8
|
def fork
|
9
9
|
Environment.fork do
|
10
|
-
|
10
|
+
setup_for_test
|
11
11
|
yield
|
12
12
|
end
|
13
|
+
|
14
|
+
reset_active_record
|
13
15
|
end
|
14
16
|
|
15
17
|
|
16
18
|
private
|
17
|
-
def
|
18
|
-
|
19
|
-
switch_bundler
|
20
|
-
|
21
|
-
reset_active_record
|
22
|
-
reload_classes
|
23
|
-
|
19
|
+
def setup_for_test
|
20
|
+
reload_classes
|
24
21
|
add_test_dir_to_load_path
|
25
22
|
end
|
26
23
|
|
27
|
-
def switch_rails
|
28
|
-
ENV['RAILS_ENV'] = Rails.env = "test"
|
29
|
-
|
30
|
-
Kernel.silence_warnings do
|
31
|
-
Dir[Rails.root.join('config', 'initializers', '*.rb')].map { |file| load file }
|
32
|
-
load Rails.root.join('config', 'environments', "test.rb")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def switch_bundler
|
37
|
-
Bundler.require "test"
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
24
|
def reload_classes
|
25
|
+
# Overwrite the default config.cache_classes = true,
|
26
|
+
# so we can change classes in the test session.
|
27
|
+
ActiveSupport::Dependencies.mechanism = :load
|
28
|
+
|
42
29
|
ActionDispatch::Reloader.cleanup!
|
43
30
|
ActionDispatch::Reloader.prepare!
|
44
31
|
end
|
45
|
-
|
32
|
+
|
46
33
|
def reset_active_record
|
47
34
|
if defined? ActiveRecord
|
48
35
|
ActiveRecord::Base.clear_active_connections!
|
49
36
|
ActiveRecord::Base.establish_connection
|
50
37
|
end
|
51
38
|
end
|
52
|
-
|
53
39
|
|
54
40
|
def add_test_dir_to_load_path
|
55
|
-
|
41
|
+
test_path = Rails.root.join("test")
|
42
|
+
$:.unshift(test_path) unless $:.first == test_path
|
56
43
|
end
|
57
44
|
end
|
58
45
|
end
|
@@ -27,6 +27,16 @@ module Rails
|
|
27
27
|
require File.expand_path(path)
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
trigger_runner
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def trigger_runner
|
36
|
+
if defined?(Test::Unit::TestCase) && ActiveSupport::TestCase.ancestors.include?(Test::Unit::TestCase)
|
37
|
+
MiniTest::Unit.runner.run
|
38
|
+
else
|
39
|
+
# MiniTest::Spec setups in Rails 4.0+ has autorun defined
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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: 2012-12-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: 3.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,15 +26,14 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.
|
29
|
+
version: 3.2.0
|
30
30
|
description:
|
31
31
|
email: david@37signals.com
|
32
32
|
executables: []
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- ./commands-0.0.
|
37
|
-
- ./commands-0.1.0.gem
|
36
|
+
- ./commands-0.2.0.gem
|
38
37
|
- ./commands.gemspec
|
39
38
|
- ./Gemfile
|
40
39
|
- ./Gemfile.lock
|
data/commands-0.0.1.gem
DELETED
Binary file
|
data/commands-0.1.0.gem
DELETED
Binary file
|