engine-assets 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +18 -17
- data/RAILS_VERSIONS +5 -0
- data/README.md +55 -0
- data/Rakefile +253 -26
- data/VERSION +1 -1
- data/app/controllers/engine_assets/assets_controller.rb +7 -1
- data/config/routes.rb +12 -1
- data/engine-assets.gemspec +53 -20
- data/features/rails.feature +127 -0
- data/features/step_definitions/rails_steps.rb +112 -0
- data/features/support/env.rb +15 -0
- data/features/support/rails.rb +125 -0
- data/features/support/terminal.rb +83 -0
- data/init.rb +1 -0
- data/lib/engine-assets.rb +8 -2
- data/lib/engine_assets/engine.rb +3 -0
- data/lib/engine_assets/extensions/rails/assets.rb +6 -0
- data/lib/engine_assets/public_locator.rb +20 -5
- data/spec/{controllers → app/controllers/engine_assets}/javascripts_controller_spec.rb +2 -2
- data/spec/{controllers → app/controllers/engine_assets}/stylesheets_controller_spec.rb +2 -2
- data/spec/lib/engine-assets_spec.rb +7 -0
- data/spec/lib/engine_assets/public_locator_spec.rb +28 -4
- data/spec/shared/assets_controller_spec.rb +39 -0
- data/spec/shared/assets_routing_spec.rb +59 -0
- data/spec/spec.opts +2 -2
- data/spec/spec_helper.rb +61 -22
- data/spec/support/Gemfile-2.3.5 +7 -0
- data/spec/support/Gemfile-2.3.5.lock +38 -0
- data/spec/support/Gemfile-2.3.9 +7 -0
- data/spec/support/Gemfile-2.3.9.lock +38 -0
- data/spec/support/Gemfile-3.0.0 +16 -0
- data/spec/support/Gemfile-3.0.0.lock +90 -0
- data/spec/support/rails.rb +32 -0
- data/spec/support/terminal.rb +54 -0
- metadata +123 -25
- data/README.rdoc +0 -18
- data/TODO.md +0 -4
- data/rails/init.rb +0 -7
- data/spec/spec_suite.rb +0 -26
- data/spec/support/shared/assets_controller_spec.rb +0 -34
- data/spec/support/shared/assets_routing_spec.rb +0 -55
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class EngineAssets::AssetsController <
|
1
|
+
class EngineAssets::AssetsController < ApplicationController
|
2
2
|
layout nil
|
3
3
|
before_filter :expire, :set_headers
|
4
4
|
after_filter :cache
|
@@ -6,9 +6,15 @@ class EngineAssets::AssetsController < ActionController::Base
|
|
6
6
|
def show
|
7
7
|
flat_file = EngineAssets::PublicLocator.locate(File.join(controller_name, [params[:path], params[:format]].join('.')))
|
8
8
|
if(flat_file)
|
9
|
+
# TODO: consider sending IO, rather than rendering
|
9
10
|
render(:file => flat_file)
|
10
11
|
else
|
11
12
|
begin
|
13
|
+
# TODO:
|
14
|
+
# * consider removing the engine_assets dir to get:
|
15
|
+
# /javascripts/path/file.js.erb
|
16
|
+
# * consider (resourceful):
|
17
|
+
# /path/file.js.erb
|
12
18
|
render(:template => File.join('engine_assets', controller_name, params[:path]), :layout => false)
|
13
19
|
rescue ActionView::MissingTemplate
|
14
20
|
head :not_found
|
data/config/routes.rb
CHANGED
@@ -3,7 +3,18 @@ ActionController::Routing::Routes.draw do |map|
|
|
3
3
|
map.send(type, "#{type}/:path.:format", {
|
4
4
|
:controller => "engine_assets/#{type}",
|
5
5
|
:action => :show,
|
6
|
-
:path => /[A-Za-z0-9\/._-]+?/
|
6
|
+
:path => /[A-Za-z0-9\/._-]+?/ # e.g., javascripts/path/file.js
|
7
7
|
})
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
# TODO: consider the following for Rails 3 (the abover works for now):
|
12
|
+
# Rails.application.routes.draw do |map|
|
13
|
+
# [:javascripts, :stylesheets].each do |type|
|
14
|
+
# match "#{type}/:path" => "engine_assets/#{type}#show",
|
15
|
+
# :as => type,
|
16
|
+
# :constraints => {
|
17
|
+
# :path => /[A-Za-z0-9\/._-]+\.(css|js)$/
|
18
|
+
# }
|
19
|
+
# end
|
20
|
+
# end
|
data/engine-assets.gemspec
CHANGED
@@ -1,46 +1,62 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{engine-assets}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Innis"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.description = %q{A Rails Engine, which enables Rails Engines to provide assets (javascript, css and images)}
|
14
14
|
s.email = %q{support@coolerator.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
22
24
|
"LICENSE",
|
23
|
-
"
|
25
|
+
"RAILS_VERSIONS",
|
26
|
+
"README.md",
|
24
27
|
"Rakefile",
|
25
|
-
"TODO.md",
|
26
28
|
"VERSION",
|
27
29
|
"app/controllers/engine_assets/assets_controller.rb",
|
28
30
|
"app/controllers/engine_assets/javascripts_controller.rb",
|
29
31
|
"app/controllers/engine_assets/stylesheets_controller.rb",
|
30
32
|
"config/routes.rb",
|
31
33
|
"engine-assets.gemspec",
|
34
|
+
"features/rails.feature",
|
35
|
+
"features/step_definitions/rails_steps.rb",
|
36
|
+
"features/support/env.rb",
|
37
|
+
"features/support/rails.rb",
|
38
|
+
"features/support/terminal.rb",
|
39
|
+
"init.rb",
|
32
40
|
"lib/engine-assets.rb",
|
41
|
+
"lib/engine_assets/engine.rb",
|
33
42
|
"lib/engine_assets/extensions/rails/assets.rb",
|
34
43
|
"lib/engine_assets/public_locator.rb",
|
35
|
-
"
|
36
|
-
"spec/controllers/
|
37
|
-
"spec/
|
44
|
+
"spec/app/controllers/engine_assets/javascripts_controller_spec.rb",
|
45
|
+
"spec/app/controllers/engine_assets/stylesheets_controller_spec.rb",
|
46
|
+
"spec/lib/engine-assets_spec.rb",
|
38
47
|
"spec/lib/engine_assets/public_locator_spec.rb",
|
39
48
|
"spec/routing/javascripts_routing_spec.rb",
|
40
49
|
"spec/routing/stylesheets_routing_spec.rb",
|
50
|
+
"spec/shared/assets_controller_spec.rb",
|
51
|
+
"spec/shared/assets_routing_spec.rb",
|
41
52
|
"spec/spec.opts",
|
42
53
|
"spec/spec_helper.rb",
|
43
|
-
"spec/
|
54
|
+
"spec/support/Gemfile-2.3.5",
|
55
|
+
"spec/support/Gemfile-2.3.5.lock",
|
56
|
+
"spec/support/Gemfile-2.3.9",
|
57
|
+
"spec/support/Gemfile-2.3.9.lock",
|
58
|
+
"spec/support/Gemfile-3.0.0",
|
59
|
+
"spec/support/Gemfile-3.0.0.lock",
|
44
60
|
"spec/support/fixtures/app/views/engine_assets/javascripts/dual.js.erb",
|
45
61
|
"spec/support/fixtures/app/views/engine_assets/javascripts/solo.js.erb",
|
46
62
|
"spec/support/fixtures/app/views/engine_assets/stylesheets/dual.css.erb",
|
@@ -49,8 +65,8 @@ Gem::Specification.new do |s|
|
|
49
65
|
"spec/support/fixtures/public/stylesheets/dual.css",
|
50
66
|
"spec/support/helpers/fixture_helper.rb",
|
51
67
|
"spec/support/helpers/textmate_helper.rb",
|
52
|
-
"spec/support/
|
53
|
-
"spec/support/
|
68
|
+
"spec/support/rails.rb",
|
69
|
+
"spec/support/terminal.rb"
|
54
70
|
]
|
55
71
|
s.homepage = %q{http://github.com/coreyti/engine-assets}
|
56
72
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -58,17 +74,19 @@ Gem::Specification.new do |s|
|
|
58
74
|
s.rubygems_version = %q{1.3.7}
|
59
75
|
s.summary = %q{Rails Engines with assets.}
|
60
76
|
s.test_files = [
|
61
|
-
"spec/controllers/javascripts_controller_spec.rb",
|
62
|
-
"spec/controllers/stylesheets_controller_spec.rb",
|
77
|
+
"spec/app/controllers/engine_assets/javascripts_controller_spec.rb",
|
78
|
+
"spec/app/controllers/engine_assets/stylesheets_controller_spec.rb",
|
79
|
+
"spec/lib/engine-assets_spec.rb",
|
63
80
|
"spec/lib/engine_assets/public_locator_spec.rb",
|
64
81
|
"spec/routing/javascripts_routing_spec.rb",
|
65
82
|
"spec/routing/stylesheets_routing_spec.rb",
|
83
|
+
"spec/shared/assets_controller_spec.rb",
|
84
|
+
"spec/shared/assets_routing_spec.rb",
|
66
85
|
"spec/spec_helper.rb",
|
67
|
-
"spec/spec_suite.rb",
|
68
86
|
"spec/support/helpers/fixture_helper.rb",
|
69
87
|
"spec/support/helpers/textmate_helper.rb",
|
70
|
-
"spec/support/
|
71
|
-
"spec/support/
|
88
|
+
"spec/support/rails.rb",
|
89
|
+
"spec/support/terminal.rb"
|
72
90
|
]
|
73
91
|
|
74
92
|
if s.respond_to? :specification_version then
|
@@ -76,12 +94,27 @@ Gem::Specification.new do |s|
|
|
76
94
|
s.specification_version = 3
|
77
95
|
|
78
96
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
79
|
-
s.add_development_dependency(%q<
|
97
|
+
s.add_development_dependency(%q<cucumber>, ["~> 0.8.5"])
|
98
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
99
|
+
s.add_development_dependency(%q<rr>, ["~> 1.0.0"])
|
100
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
101
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
102
|
+
s.add_development_dependency(%q<term-ansicolor>, ["~> 1.0.5"])
|
80
103
|
else
|
81
|
-
s.add_dependency(%q<
|
104
|
+
s.add_dependency(%q<cucumber>, ["~> 0.8.5"])
|
105
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
106
|
+
s.add_dependency(%q<rr>, ["~> 1.0.0"])
|
107
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
108
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
109
|
+
s.add_dependency(%q<term-ansicolor>, ["~> 1.0.5"])
|
82
110
|
end
|
83
111
|
else
|
84
|
-
s.add_dependency(%q<
|
112
|
+
s.add_dependency(%q<cucumber>, ["~> 0.8.5"])
|
113
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
114
|
+
s.add_dependency(%q<rr>, ["~> 1.0.0"])
|
115
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
116
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
117
|
+
s.add_dependency(%q<term-ansicolor>, ["~> 1.0.5"])
|
85
118
|
end
|
86
119
|
end
|
87
120
|
|
@@ -0,0 +1,127 @@
|
|
1
|
+
Feature: Install this Gem in a Rails application
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I have built and installed the "engine-assets" gem
|
5
|
+
|
6
|
+
Scenario: Use the gem un-vendored in a Rails application
|
7
|
+
When I generate a new Rails application
|
8
|
+
And I configure my application to require the "engine-assets" gem
|
9
|
+
And I check the configured gem version
|
10
|
+
Then I should see "Current version: 0.5.0"
|
11
|
+
|
12
|
+
Scenario: Send a request for an application-host dynamic asset
|
13
|
+
When I generate a new Rails application
|
14
|
+
And I configure my application to require the "engine-assets" gem
|
15
|
+
And I save the following as "app/views/engine_assets/javascripts/example.js.erb"
|
16
|
+
"""
|
17
|
+
// example.js (application - <%= "dynamic" -%>)
|
18
|
+
"""
|
19
|
+
And I perform a request to "http://example.com:1234/javascripts/example.js"
|
20
|
+
Then I should receive a response matching the following:
|
21
|
+
| 200 | // example.js (application - dynamic) |
|
22
|
+
|
23
|
+
Scenario: Send a request for an engine-hosted static asset
|
24
|
+
When I generate a new Rails application
|
25
|
+
And I configure my application to require the "engine-assets" gem
|
26
|
+
And I generate a new "example_plugin" plugin
|
27
|
+
And I save the following as "vendor/plugins/example_plugin/init.rb"
|
28
|
+
"""
|
29
|
+
require 'engine-assets'
|
30
|
+
EngineAssets::PublicLocator.register(File.join(File.dirname(__FILE__)))
|
31
|
+
"""
|
32
|
+
And I save the following as "vendor/plugins/example_plugin/public/javascripts/example.js"
|
33
|
+
"""
|
34
|
+
// example.js (plugin - static)
|
35
|
+
"""
|
36
|
+
And I perform a request to "http://example.com:1234/javascripts/example.js"
|
37
|
+
Then I should receive a response matching the following:
|
38
|
+
| 200 | // example.js (plugin - static) |
|
39
|
+
|
40
|
+
Scenario: Send a request for an engine-hosted dynamic asset
|
41
|
+
When I generate a new Rails application
|
42
|
+
And I configure my application to require the "engine-assets" gem
|
43
|
+
And I generate a new "example_plugin" plugin
|
44
|
+
And I save the following as "vendor/plugins/example_plugin/init.rb"
|
45
|
+
"""
|
46
|
+
require 'engine-assets'
|
47
|
+
EngineAssets::PublicLocator.register(File.join(File.dirname(__FILE__)))
|
48
|
+
"""
|
49
|
+
And I save the following as "vendor/plugins/example_plugin/app/views/engine_assets/javascripts/example.js.erb"
|
50
|
+
"""
|
51
|
+
// example.js (plugin - dynamic)
|
52
|
+
"""
|
53
|
+
And I perform a request to "http://example.com:1234/javascripts/example.js"
|
54
|
+
Then I should receive a response matching the following:
|
55
|
+
| 200 | // example.js (plugin - dynamic) |
|
56
|
+
|
57
|
+
Scenario: Send a development request for an application webpage which references an engine-hosted asset
|
58
|
+
When I generate a new Rails application
|
59
|
+
And I configure my application to require the "engine-assets" gem
|
60
|
+
And I configure my application to run in the "development" environment
|
61
|
+
And I save the following as "config/initializers/assets.rb"
|
62
|
+
"""
|
63
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :defaults => [
|
64
|
+
'example.js'
|
65
|
+
]
|
66
|
+
"""
|
67
|
+
And I generate a new "example" scaffold
|
68
|
+
And I save the following as "app/views/layouts/examples.html.erb"
|
69
|
+
"""
|
70
|
+
<html>
|
71
|
+
<head>
|
72
|
+
<%= javascript_include_tag :all, :cache => true, :recursive => true -%>
|
73
|
+
</head>
|
74
|
+
<body></body>
|
75
|
+
</html>
|
76
|
+
"""
|
77
|
+
And I generate a new "example_plugin" plugin
|
78
|
+
And I save the following as "vendor/plugins/example_plugin/init.rb"
|
79
|
+
"""
|
80
|
+
require 'engine-assets'
|
81
|
+
EngineAssets::PublicLocator.register(File.join(File.dirname(__FILE__)))
|
82
|
+
"""
|
83
|
+
And I save the following as "vendor/plugins/example_plugin/public/javascripts/example.js"
|
84
|
+
"""
|
85
|
+
// example.js content
|
86
|
+
"""
|
87
|
+
And I perform a request to "http://example.com:1234/examples"
|
88
|
+
Then I should receive a response matching the following:
|
89
|
+
| 200 | /javascripts/example.js |
|
90
|
+
|
91
|
+
Scenario: Send a production request for an application webpage which references an engine-hosted asset
|
92
|
+
When I generate a new Rails application
|
93
|
+
And I configure my application to require the "engine-assets" gem
|
94
|
+
And I configure my application to run in the "production" environment
|
95
|
+
And I save the following as "config/initializers/assets.rb"
|
96
|
+
"""
|
97
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :defaults => [
|
98
|
+
'example.js'
|
99
|
+
]
|
100
|
+
"""
|
101
|
+
And I generate a new "example" scaffold
|
102
|
+
And I save the following as "app/views/layouts/examples.html.erb"
|
103
|
+
"""
|
104
|
+
<html>
|
105
|
+
<head>
|
106
|
+
<%= javascript_include_tag :all, :cache => true, :recursive => true -%>
|
107
|
+
</head>
|
108
|
+
<body></body>
|
109
|
+
</html>
|
110
|
+
"""
|
111
|
+
And I generate a new "example_plugin" plugin
|
112
|
+
And I save the following as "vendor/plugins/example_plugin/init.rb"
|
113
|
+
"""
|
114
|
+
require 'engine-assets'
|
115
|
+
EngineAssets::PublicLocator.register(File.join(File.dirname(__FILE__)))
|
116
|
+
"""
|
117
|
+
And I save the following as "vendor/plugins/example_plugin/public/javascripts/example.js"
|
118
|
+
"""
|
119
|
+
// example.js content
|
120
|
+
"""
|
121
|
+
And I perform a request to "http://example.com:1234/examples"
|
122
|
+
Then I should receive a response matching the following:
|
123
|
+
| 200 | /javascripts/all.js |
|
124
|
+
And The first line of the "public/javascripts/all.js" file should be
|
125
|
+
"""
|
126
|
+
// example.js content
|
127
|
+
"""
|
@@ -0,0 +1,112 @@
|
|
1
|
+
Given /^I have built and installed the "([^"]*)" gem$/ do |gem_name|
|
2
|
+
@terminal.build_and_install(File.join(PROJECT_ROOT, "#{gem_name}.gemspec"))
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I generate a new Rails application$/ do
|
6
|
+
@terminal.cd(TEMP_DIR)
|
7
|
+
|
8
|
+
version = ENV['RAILS_VERSION']
|
9
|
+
rails3 = version =~ /^3/
|
10
|
+
|
11
|
+
if rails3
|
12
|
+
rails_create_command = 'new'
|
13
|
+
else
|
14
|
+
rails_create_command = ''
|
15
|
+
end
|
16
|
+
|
17
|
+
load_rails = <<-RUBY
|
18
|
+
gem 'rails', '#{version}'; \
|
19
|
+
load Gem.bin_path('rails', 'rails', '#{version}')
|
20
|
+
RUBY
|
21
|
+
|
22
|
+
@terminal.run(%{ruby -rubygems -e "#{load_rails.strip!}" #{rails_create_command} rails_root})
|
23
|
+
|
24
|
+
if rails_root_exists?
|
25
|
+
@terminal.echo("Generated a Rails #{version} application")
|
26
|
+
else
|
27
|
+
raise "Unable to generate a Rails application:\n#{@terminal.output}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
When /^I configure my application to require the "([^"]*)" gem$/ do |gem_name|
|
32
|
+
if rails_manages_gems?
|
33
|
+
config_gem(gem_name)
|
34
|
+
elsif bundler_manages_gems?
|
35
|
+
bundle_gem(gem_name)
|
36
|
+
else
|
37
|
+
File.open(environment_path, 'a') do |file|
|
38
|
+
file.puts
|
39
|
+
file.puts("require 'example-engine'")
|
40
|
+
file.puts("require 'example-engine/rails'") # ???
|
41
|
+
end
|
42
|
+
|
43
|
+
# unless rails_finds_generators_in_gems?
|
44
|
+
# FileUtils.cp_r(File.join(PROJECT_ROOT, 'generators'), File.join(RAILS_ROOT, 'lib'))
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
When /^I configure my application to run in the "([^"]*)" environment$/ do |environment|
|
50
|
+
@rails_environment = environment
|
51
|
+
end
|
52
|
+
|
53
|
+
When /^I check the configured gem version$/ do
|
54
|
+
version = ENV['RAILS_VERSION']
|
55
|
+
rails3 = version =~ /^3/
|
56
|
+
|
57
|
+
if rails3
|
58
|
+
command = 'rails runner'
|
59
|
+
else
|
60
|
+
command = 'script/runner'
|
61
|
+
end
|
62
|
+
|
63
|
+
@terminal.cd(RAILS_ROOT)
|
64
|
+
@terminal.run(%Q{#{command} 'puts "Current version: #\{EngineAssets.version\}"'})
|
65
|
+
end
|
66
|
+
|
67
|
+
When /^I generate a new "([^"]*)" ([^\s]*)$/ do |name, generator|
|
68
|
+
rails_generate("#{generator} #{name}")
|
69
|
+
end
|
70
|
+
|
71
|
+
When /^I save the following as "([^\"]*)"$/ do |path, string|
|
72
|
+
FileUtils.mkdir_p(File.join(RAILS_ROOT, File.dirname(path)))
|
73
|
+
File.open(File.join(RAILS_ROOT, path), 'w') { |file| file.write(string) }
|
74
|
+
end
|
75
|
+
|
76
|
+
When /^I perform a request to "([^\"]*)"$/ do |uri|
|
77
|
+
perform_request(uri)
|
78
|
+
end
|
79
|
+
|
80
|
+
Then /^I should receive a response matching the following:$/ do |table|
|
81
|
+
hash = table.transpose.hashes.first
|
82
|
+
result = JSON.parse(@terminal.result)
|
83
|
+
|
84
|
+
if hash['200']
|
85
|
+
result['status'].should == 200
|
86
|
+
|
87
|
+
if (header = result['headers']['X-Sendfile'])
|
88
|
+
# Rack middleware (likely Rails 3)
|
89
|
+
content = File.readlines(header).join
|
90
|
+
content.should include(hash['200'])
|
91
|
+
else
|
92
|
+
result['body'].should include(hash['200'])
|
93
|
+
end
|
94
|
+
else
|
95
|
+
raise "Don't know how to handle #{hash.inspect}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Then /^The first line of the "([^"]*)" file should be$/ do |path, string|
|
100
|
+
lines = File.readlines(File.join(RAILS_ROOT, path))
|
101
|
+
lines[0].strip.should == string
|
102
|
+
end
|
103
|
+
|
104
|
+
Then /^I should see "([^\"]*)"$/ do |expected_text|
|
105
|
+
unless @terminal.output.include?(expected_text)
|
106
|
+
raise("Got terminal output:\n#{@terminal.output}\n\nExpected output:\n#{expected_text}")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Then /^the command should have run successfully$/ do
|
111
|
+
@terminal.status.exitstatus.should == 0
|
112
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
5
|
+
TEMP_DIR = File.join(PROJECT_ROOT, 'tmp').freeze
|
6
|
+
RAILS_ROOT = File.join(TEMP_DIR, 'rails_root').freeze
|
7
|
+
BUILT_GEM_ROOT = File.join(TEMP_DIR, 'built_gems').freeze
|
8
|
+
LOCAL_GEM_ROOT = File.join(TEMP_DIR, 'local_gems').freeze
|
9
|
+
|
10
|
+
Before do
|
11
|
+
FileUtils.mkdir_p TEMP_DIR
|
12
|
+
FileUtils.rm_rf BUILT_GEM_ROOT
|
13
|
+
FileUtils.rm_rf RAILS_ROOT
|
14
|
+
FileUtils.mkdir_p BUILT_GEM_ROOT
|
15
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module RailsHelpers
|
4
|
+
def rails_root_exists?
|
5
|
+
File.exists?(environment_path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def rails3?
|
9
|
+
rails_version =~ /^3/
|
10
|
+
end
|
11
|
+
|
12
|
+
def rails_uses_rack?
|
13
|
+
rails3? || rails_version =~ /^2\.3/
|
14
|
+
end
|
15
|
+
|
16
|
+
def rails_version
|
17
|
+
@rails_version ||= begin
|
18
|
+
if bundler_manages_gems?
|
19
|
+
rails_version = open(gemfile_path).read.match(/gem.*rails["'].*["'](.+)["']/)[1]
|
20
|
+
else
|
21
|
+
environment_file = File.join(RAILS_ROOT, 'config', 'environment.rb')
|
22
|
+
rails_version = `grep RAILS_GEM_VERSION #{environment_file}`.match(/[\d.]+/)[0]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def rails_environment
|
28
|
+
@rails_environment ||= 'production'
|
29
|
+
end
|
30
|
+
|
31
|
+
def bundler_manages_gems?
|
32
|
+
File.exists?(gemfile_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def gemfile_path
|
36
|
+
gemfile = File.join(RAILS_ROOT, 'Gemfile')
|
37
|
+
end
|
38
|
+
|
39
|
+
def rails_manages_gems?
|
40
|
+
rails_version =~ /^2\.[123]/
|
41
|
+
end
|
42
|
+
|
43
|
+
def environment_path
|
44
|
+
File.join(RAILS_ROOT, 'config', 'environment.rb')
|
45
|
+
end
|
46
|
+
|
47
|
+
def rails_generate(arguments)
|
48
|
+
command = rails3? ? 'rails generate' : 'script/generate'
|
49
|
+
|
50
|
+
@terminal.cd(RAILS_ROOT)
|
51
|
+
@terminal.run("#{command} #{arguments}")
|
52
|
+
@terminal.run("RAILS_ENV=#{rails_environment} rake db:migrate")
|
53
|
+
end
|
54
|
+
|
55
|
+
def bundle_gem(gem_name)
|
56
|
+
File.open(gemfile_path, 'a') do |file|
|
57
|
+
file.puts("gem '#{gem_name}'")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def config_gem(gem_name)
|
62
|
+
run = "Rails::Initializer.run do |config|"
|
63
|
+
insert = " config.gem '#{gem_name}'"
|
64
|
+
content = File.read(environment_path)
|
65
|
+
if content.sub!(run, "#{run}\n#{insert}")
|
66
|
+
File.open(environment_path, 'wb') { |file| file.write(content) }
|
67
|
+
else
|
68
|
+
raise "Couldn't find #{run.inspect} in #{environment_path}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def perform_request(uri)
|
73
|
+
# NOTE (CTI):
|
74
|
+
# modified from thoughtbot's original to return headers and status.
|
75
|
+
if rails3?
|
76
|
+
request_script = <<-SCRIPT
|
77
|
+
require 'config/environment'
|
78
|
+
|
79
|
+
env = Rack::MockRequest.env_for(#{uri.inspect})
|
80
|
+
status, headers, body = RailsRoot::Application.call(env)
|
81
|
+
|
82
|
+
response = {
|
83
|
+
:body => body.is_a?(Array) ? body.join : body.body,
|
84
|
+
:headers => headers,
|
85
|
+
:status => status
|
86
|
+
}
|
87
|
+
|
88
|
+
puts response.to_json
|
89
|
+
SCRIPT
|
90
|
+
File.open(File.join(RAILS_ROOT, 'request.rb'), 'w') { |file| file.write(request_script) }
|
91
|
+
@terminal.cd(RAILS_ROOT)
|
92
|
+
@terminal.run("./script/rails runner -e #{rails_environment} request.rb")
|
93
|
+
elsif rails_uses_rack?
|
94
|
+
request_script = <<-SCRIPT
|
95
|
+
require 'config/environment'
|
96
|
+
|
97
|
+
env = Rack::MockRequest.env_for(#{uri.inspect})
|
98
|
+
app = Rack::Lint.new(ActionController::Dispatcher.new)
|
99
|
+
|
100
|
+
status, headers, body = app.call(env)
|
101
|
+
|
102
|
+
response = {
|
103
|
+
:body => "",
|
104
|
+
:headers => headers,
|
105
|
+
:status => status
|
106
|
+
}
|
107
|
+
|
108
|
+
if body.respond_to?(:to_str)
|
109
|
+
response[:body] << body
|
110
|
+
else
|
111
|
+
body.each { |part| response[:body] << part }
|
112
|
+
end
|
113
|
+
|
114
|
+
puts response.to_json
|
115
|
+
SCRIPT
|
116
|
+
File.open(File.join(RAILS_ROOT, 'request.rb'), 'w') { |file| file.write(request_script) }
|
117
|
+
@terminal.cd(RAILS_ROOT)
|
118
|
+
@terminal.run("./script/runner -e #{rails_environment} request.rb")
|
119
|
+
else
|
120
|
+
raise "Rails versions earlier than 2.3 are not supported"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
World(RailsHelpers)
|