rack-sprockets 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +47 -0
  4. data/README.rdoc +2 -2
  5. data/Rakefile +5 -60
  6. data/demos/yui_compressed/Gemfile +5 -0
  7. data/demos/yui_compressed/Gemfile.lock +19 -0
  8. data/demos/yui_compressed/REAME.rdoc +13 -0
  9. data/demos/yui_compressed/app.rb +17 -0
  10. data/demos/yui_compressed/app/javascripts/alert_one.js +4 -0
  11. data/demos/yui_compressed/app/javascripts/alert_two.js +4 -0
  12. data/demos/yui_compressed/app/javascripts/app.js +16 -0
  13. data/demos/yui_compressed/public/javascripts/app.js +1 -0
  14. data/demos/yui_compressed/public/javascripts/uncompressed_app.js +12 -0
  15. data/lib/rack/.rb +1 -0
  16. data/lib/rack/sprockets/request.rb +42 -24
  17. data/lib/rack/sprockets/source.rb +27 -27
  18. data/lib/rack/sprockets/version.rb +4 -12
  19. data/rack-sprockets.gemspec +29 -0
  20. data/test/app_helper.rb +25 -0
  21. data/test/config_test.rb +80 -0
  22. data/test/env.rb +9 -0
  23. data/test/fixtures/mock_options.rb +9 -0
  24. data/test/fixtures/sinatra/app.rb +9 -0
  25. data/test/fixtures/sinatra/app/javascripts/alert_one.js +2 -0
  26. data/test/fixtures/sinatra/app/javascripts/alert_two.js +2 -0
  27. data/test/fixtures/sinatra/app/javascripts/app.js +10 -0
  28. data/test/fixtures/sinatra/app/javascripts/app_compiled.js +12 -0
  29. data/test/fixtures/sinatra/app/javascripts/nested/dependency.js +2 -0
  30. data/test/fixtures/sinatra/app/javascripts/nested/thing.js +11 -0
  31. data/test/fixtures/sinatra/app/javascripts/nested/thing_compiled.js +14 -0
  32. data/test/helper.rb +80 -0
  33. data/test/options_test.rb +78 -0
  34. data/test/request_test.rb +141 -0
  35. data/test/response_test.rb +41 -0
  36. data/test/sinatra_test.rb +42 -0
  37. data/test/source_test.rb +163 -0
  38. metadata +103 -40
@@ -0,0 +1,41 @@
1
+ require 'test/helper'
2
+ require 'rack/sprockets/response'
3
+
4
+ class RequestTest < Test::Unit::TestCase
5
+
6
+ context 'Rack::Sprockets::Response' do
7
+ setup do
8
+ @defaults = env_defaults
9
+ @js = File.read(file_path('test','fixtures','sinatra','app','javascripts', 'app_compiled.js'))
10
+ @response = sprockets_response(@js)
11
+ end
12
+
13
+ should "have some attributes" do
14
+ [ :options,
15
+ :status,
16
+ :headers,
17
+ :body,
18
+ :content_length,
19
+ :content_type,
20
+ :to_rack
21
+ ].each do |a|
22
+ assert_respond_to @response, a, "request does not respond to #{a.inspect}"
23
+ end
24
+ end
25
+
26
+ should "set it's status to '#{Rack::Utils::HTTP_STATUS_CODES[200]}'" do
27
+ assert_equal 200, @response.status
28
+ end
29
+
30
+ should "set it's Content-Type to '#{Rack::Sprockets::MIME_TYPE}'" do
31
+ assert_equal Rack::Sprockets::MIME_TYPE, @response.content_type, 'the content_type accessor is incorrect'
32
+ assert_equal Rack::Sprockets::MIME_TYPE, @response.headers['Content-Type'], 'the Content-Type header is incorrect'
33
+ end
34
+
35
+ should "set it's Content-Length appropriately" do
36
+ assert_equal Rack::Sprockets::Response.content_length(@js), @response.content_length, 'the content_length accessor is incorrect'
37
+ assert_equal Rack::Sprockets::Response.content_length(@js), @response.headers['Content-Length'].to_i
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,42 @@
1
+ require 'test/helper'
2
+ require "test/app_helper"
3
+ require 'test/fixtures/sinatra/app'
4
+
5
+ class SinatraTest < Test::Unit::TestCase
6
+
7
+ def app
8
+ @app ||= SinatraApp
9
+ end
10
+ def default_value(name)
11
+ Rack::Sprockets::Base.defaults["#{Rack::Sprockets::Options::RACK_ENV_NS}.#{name}"]
12
+ end
13
+
14
+ context "A Sinatra app using Rack::Sprockets" do
15
+
16
+ context "requesting valid JavaScript" do
17
+ setup do
18
+ app.use Rack::Sprockets,
19
+ :root => file_path('test','fixtures','sinatra')
20
+
21
+ @compiled = File.read(file_path('test','fixtures','sinatra','app','javascripts', 'app_compiled.js'))
22
+ @response = visit "/javascripts/app.js"
23
+ end
24
+
25
+ should_respond_with_compiled_js
26
+ end
27
+
28
+ context "requesting valid nested JavaScript" do
29
+ setup do
30
+ app.use Rack::Sprockets,
31
+ :root => file_path('test','fixtures','sinatra')
32
+
33
+ @compiled = File.read(file_path('test','fixtures','sinatra','app','javascripts', 'nested', 'thing_compiled.js'))
34
+ @response = visit "/javascripts/nested/thing.js"
35
+ end
36
+
37
+ should_respond_with_compiled_js
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,163 @@
1
+ require 'test/helper'
2
+ require 'rack/sprockets/source'
3
+
4
+ class SourceTest < Test::Unit::TestCase
5
+ context 'Rack::Sprockets::Source' do
6
+ setup do
7
+ @source_folder = file_path('test','fixtures','sinatra','app','javascripts')
8
+ @secretary = {
9
+ :root => file_path('test','fixtures','sinatra'),
10
+ :load_path => ['app/javascripts']
11
+ }
12
+ @cache = file_path('test','fixtures','sinatra','public','javascripts')
13
+ end
14
+
15
+ should "accept the .js file extension" do
16
+ assert_equal [:js], Rack::Sprockets::Source::PREFERRED_EXTENSIONS
17
+ end
18
+
19
+ context "object" do
20
+ setup do
21
+ @basic = Rack::Sprockets::Source.new('basic', {
22
+ :folder => @source_folder,
23
+ :secretary => @secretary
24
+ })
25
+ @nested1 = Rack::Sprockets::Source.new('something/nested', {
26
+ :folder => @source_folder,
27
+ :secretary => @secretary
28
+ })
29
+ @nested2 = Rack::Sprockets::Source.new('/other/nested', {
30
+ :folder => @source_folder,
31
+ :secretary => @secretary
32
+ })
33
+ @nested3 = Rack::Sprockets::Source.new('///wrong/nested', {
34
+ :folder => @source_folder,
35
+ :secretary => @secretary
36
+ })
37
+ @compressed = Rack::Sprockets::Source.new('compressed', {
38
+ :folder => @source_folder,
39
+ :secretary => @secretary,
40
+ :compress => :whitespace
41
+ })
42
+ @cached = Rack::Sprockets::Source.new('cached', {
43
+ :folder => @source_folder,
44
+ :secretary => @secretary,
45
+ :cache => @cache,
46
+ :compress => false
47
+ })
48
+ end
49
+
50
+ should "have accessors for js_resource and cache values" do
51
+ assert_respond_to @basic, :js_resource
52
+ assert_equal 'basic', @basic.js_resource
53
+ assert_respond_to @basic, :cache
54
+ end
55
+
56
+ should "handle nested js_resource" do
57
+ assert_equal 'something/nested', @nested1.js_resource
58
+ end
59
+
60
+ should "strip any leading '/' on js_resource" do
61
+ assert_equal 'other/nested', @nested2.js_resource
62
+ assert_equal 'wrong/nested', @nested3.js_resource
63
+ end
64
+
65
+ should "have an option for using compression" do
66
+ assert_equal false, @basic.compress?, 'the basic app should not compress'
67
+ assert_equal true, @compressed.compress?, 'the compressed app should compress'
68
+ end
69
+
70
+ should "have an option for caching output to files" do
71
+ assert_equal false, @basic.cache?, 'the basic app should not cache'
72
+ assert_equal true, @cached.cache?, 'the cached app should cache'
73
+ end
74
+
75
+ should "have a secretary" do
76
+ assert_respond_to @basic, :secretary, 'source does not respond to :secretary'
77
+ assert_kind_of Sprockets::Secretary, @basic.secretary, 'the source :secretary is not a Sprockets::Secretary'
78
+ end
79
+
80
+ should "have a source files list" do
81
+ assert_respond_to @basic, :files, 'source does not respond to :files'
82
+ assert_kind_of Array, @basic.files, 'the source :files is not an Array'
83
+ end
84
+
85
+ should "have compiled js" do
86
+ assert_respond_to @basic, :to_js, 'source does not respond to :to_js'
87
+ assert_respond_to @basic, :js, 'source does not respond to :js'
88
+ end
89
+ end
90
+
91
+ context "with no corresponding source" do
92
+ setup do
93
+ @none = Rack::Sprockets::Source.new('none', {
94
+ :folder => @source_folder,
95
+ :secretary => @secretary
96
+ })
97
+ end
98
+
99
+ should "have an empty file list" do
100
+ assert @none.files.empty?, 'source file list is not empty'
101
+ end
102
+
103
+ should "generate no js" do
104
+ assert @none.to_js.empty?, 'source generated js when it should not have'
105
+ end
106
+ end
107
+
108
+ should_compile_source('app', "needing to be compiled")
109
+
110
+ context "with whitespace compression" do
111
+ setup do
112
+ @compiled = File.read(File.join(@source_folder, "app_compiled.js"))
113
+ @compressed_normal = Rack::Sprockets::Source.new('app', {
114
+ :folder => @source_folder,
115
+ :secretary => @secretary,
116
+ :compress => :whitespace
117
+ })
118
+ end
119
+
120
+ should "compress the compiled js" do
121
+ assert_equal @compiled.strip.delete("\n"), @compressed_normal.to_js, "the compiled js is compressed incorrectly"
122
+ end
123
+ end
124
+
125
+ context "with yui compression" do
126
+ setup do
127
+ @compiled = File.read(File.join(@source_folder, "app_compiled.js"))
128
+ @compressed_normal = Rack::Sprockets::Source.new('app', {
129
+ :folder => @source_folder,
130
+ :secretary => @secretary,
131
+ :compress => :yui
132
+ })
133
+ end
134
+
135
+ should "compress the compiled js" do
136
+ comp = YUI::JavaScriptCompressor.new(Rack::Sprockets::Source::YUI_OPTS).compress(@compiled.strip)
137
+ assert_equal comp, @compressed_normal.to_js, "the compiled js is compressed incorrectly"
138
+ end
139
+ end
140
+
141
+ context "with caching" do
142
+ setup do
143
+ FileUtils.rm_rf(File.dirname(@cache)) if File.exists?(File.dirname(@cache))
144
+ @expected = Rack::Sprockets::Source.new('app', {
145
+ :folder => @source_folder,
146
+ :secretary => @secretary,
147
+ :cache => @cache
148
+ }).to_js
149
+ @cached_file = File.join(@cache, "app.js")
150
+ end
151
+ teardown do
152
+ FileUtils.rm_rf(File.dirname(@cache)) if File.exists?(File.dirname(@cache))
153
+ end
154
+
155
+ should "store the compiled js to a file in the cache" do
156
+ assert File.exists?(@cache), 'the cache folder does not exist'
157
+ assert File.exists?(@cached_file), 'the js was not cached to a file'
158
+ assert_equal @expected.strip, File.read(@cached_file).strip, "the compiled js is incorrect"
159
+ end
160
+ end
161
+
162
+ end
163
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 1.0.4
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,29 +15,44 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-05 00:00:00 -05:00
18
+ date: 2011-03-21 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: shoulda
22
+ name: bundler
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 39
29
+ hash: 15
30
30
  segments:
31
- - 2
32
- - 10
31
+ - 1
33
32
  - 0
34
- version: 2.10.0
33
+ version: "1.0"
35
34
  type: :development
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
38
- name: sinatra
37
+ name: test-belt
39
38
  prerelease: false
40
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 21
45
+ segments:
46
+ - 0
47
+ - 2
48
+ - 1
49
+ version: 0.2.1
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: sinatra
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
41
56
  none: false
42
57
  requirements:
43
58
  - - ">="
@@ -49,11 +64,11 @@ dependencies:
49
64
  - 4
50
65
  version: 0.9.4
51
66
  type: :development
52
- version_requirements: *id002
67
+ version_requirements: *id003
53
68
  - !ruby/object:Gem::Dependency
54
69
  name: rack-test
55
70
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
57
72
  none: false
58
73
  requirements:
59
74
  - - ">="
@@ -65,11 +80,11 @@ dependencies:
65
80
  - 3
66
81
  version: 0.5.3
67
82
  type: :development
68
- version_requirements: *id003
83
+ version_requirements: *id004
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: webrat
71
86
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ">="
@@ -81,11 +96,11 @@ dependencies:
81
96
  - 0
82
97
  version: 0.6.0
83
98
  type: :development
84
- version_requirements: *id004
99
+ version_requirements: *id005
85
100
  - !ruby/object:Gem::Dependency
86
101
  name: yui-compressor
87
102
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
91
106
  - - ">="
@@ -97,49 +112,63 @@ dependencies:
97
112
  - 1
98
113
  version: 0.9.1
99
114
  type: :development
100
- version_requirements: *id005
115
+ version_requirements: *id006
101
116
  - !ruby/object:Gem::Dependency
102
117
  name: rack
103
118
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
119
+ requirement: &id007 !ruby/object:Gem::Requirement
105
120
  none: false
106
121
  requirements:
107
- - - ">="
122
+ - - ~>
108
123
  - !ruby/object:Gem::Version
109
- hash: 3
124
+ hash: 15
110
125
  segments:
126
+ - 1
111
127
  - 0
112
- - 4
113
- version: "0.4"
128
+ version: "1.0"
114
129
  type: :runtime
115
- version_requirements: *id006
130
+ version_requirements: *id007
116
131
  - !ruby/object:Gem::Dependency
117
132
  name: sprockets
118
133
  prerelease: false
119
- requirement: &id007 !ruby/object:Gem::Requirement
134
+ requirement: &id008 !ruby/object:Gem::Requirement
120
135
  none: false
121
136
  requirements:
122
- - - ">="
137
+ - - ~>
123
138
  - !ruby/object:Gem::Version
124
- hash: 23
139
+ hash: 15
125
140
  segments:
126
141
  - 1
127
142
  - 0
128
- - 0
129
- version: 1.0.0
143
+ version: "1.0"
130
144
  type: :runtime
131
- version_requirements: *id007
132
- description:
133
- email: kelly@kelredd.com
145
+ version_requirements: *id008
146
+ description: "Use rack middleware to handle sprockets preprocessing. Processing happens on requests to sprockets resources. This allows you to develop, check in, and deploy unprocessed sprockets resources and leave the processing to the middleware. Allows for optimizing by environment: never-cache, always-reprocess in development; cache, process-once in production (for example)."
147
+ email:
148
+ - kelly@kelredd.com
134
149
  executables: []
135
150
 
136
151
  extensions: []
137
152
 
138
- extra_rdoc_files:
139
- - README.rdoc
153
+ extra_rdoc_files: []
154
+
140
155
  files:
156
+ - .gitignore
157
+ - Gemfile
158
+ - Gemfile.lock
141
159
  - README.rdoc
142
160
  - Rakefile
161
+ - demos/yui_compressed/Gemfile
162
+ - demos/yui_compressed/Gemfile.lock
163
+ - demos/yui_compressed/REAME.rdoc
164
+ - demos/yui_compressed/app.rb
165
+ - demos/yui_compressed/app/javascripts/alert_one.js
166
+ - demos/yui_compressed/app/javascripts/alert_two.js
167
+ - demos/yui_compressed/app/javascripts/app.js
168
+ - demos/yui_compressed/public/javascripts/app.js
169
+ - demos/yui_compressed/public/javascripts/uncompressed_app.js
170
+ - lib/rack/.rb
171
+ - lib/rack/sprockets.rb
143
172
  - lib/rack/sprockets/base.rb
144
173
  - lib/rack/sprockets/config.rb
145
174
  - lib/rack/sprockets/options.rb
@@ -147,15 +176,32 @@ files:
147
176
  - lib/rack/sprockets/response.rb
148
177
  - lib/rack/sprockets/source.rb
149
178
  - lib/rack/sprockets/version.rb
150
- - lib/rack/sprockets.rb
179
+ - rack-sprockets.gemspec
180
+ - test/app_helper.rb
181
+ - test/config_test.rb
182
+ - test/env.rb
183
+ - test/fixtures/mock_options.rb
184
+ - test/fixtures/sinatra/app.rb
185
+ - test/fixtures/sinatra/app/javascripts/alert_one.js
186
+ - test/fixtures/sinatra/app/javascripts/alert_two.js
187
+ - test/fixtures/sinatra/app/javascripts/app.js
188
+ - test/fixtures/sinatra/app/javascripts/app_compiled.js
189
+ - test/fixtures/sinatra/app/javascripts/nested/dependency.js
190
+ - test/fixtures/sinatra/app/javascripts/nested/thing.js
191
+ - test/fixtures/sinatra/app/javascripts/nested/thing_compiled.js
192
+ - test/helper.rb
193
+ - test/options_test.rb
194
+ - test/request_test.rb
195
+ - test/response_test.rb
196
+ - test/sinatra_test.rb
197
+ - test/source_test.rb
151
198
  has_rdoc: true
152
199
  homepage: http://github.com/kelredd/rack-sprockets
153
200
  licenses: []
154
201
 
155
202
  post_install_message:
156
- rdoc_options:
157
- - --main
158
- - README.rdoc
203
+ rdoc_options: []
204
+
159
205
  require_paths:
160
206
  - lib
161
207
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -183,5 +229,22 @@ rubygems_version: 1.3.7
183
229
  signing_key:
184
230
  specification_version: 3
185
231
  summary: Sprockets javascript preprocessing for Rack apps.
186
- test_files: []
187
-
232
+ test_files:
233
+ - test/app_helper.rb
234
+ - test/config_test.rb
235
+ - test/env.rb
236
+ - test/fixtures/mock_options.rb
237
+ - test/fixtures/sinatra/app.rb
238
+ - test/fixtures/sinatra/app/javascripts/alert_one.js
239
+ - test/fixtures/sinatra/app/javascripts/alert_two.js
240
+ - test/fixtures/sinatra/app/javascripts/app.js
241
+ - test/fixtures/sinatra/app/javascripts/app_compiled.js
242
+ - test/fixtures/sinatra/app/javascripts/nested/dependency.js
243
+ - test/fixtures/sinatra/app/javascripts/nested/thing.js
244
+ - test/fixtures/sinatra/app/javascripts/nested/thing_compiled.js
245
+ - test/helper.rb
246
+ - test/options_test.rb
247
+ - test/request_test.rb
248
+ - test/response_test.rb
249
+ - test/sinatra_test.rb
250
+ - test/source_test.rb