rack-pjax 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +5 -1
- data/Rakefile +13 -0
- data/lib/rack/pjax.rb +1 -5
- data/lib/rack/pjax/version.rb +1 -1
- data/rack-pjax.gemspec +1 -1
- data/spec/rack/pjax_spec.rb +40 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +34 -0
- metadata +16 -13
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1 +1,14 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new do |t|
|
5
|
+
t.rspec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Run the specs"
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
desc 'Removes trailing whitespace'
|
12
|
+
task :whitespace do
|
13
|
+
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
14
|
+
end
|
data/lib/rack/pjax.rb
CHANGED
@@ -25,11 +25,7 @@ module Rack
|
|
25
25
|
end
|
26
26
|
response = [body]
|
27
27
|
|
28
|
-
|
29
|
-
length = response.to_ary.inject(0) { |len, part| len + bytesize(part) }
|
30
|
-
headers['Content-Length'] = length.to_s
|
31
|
-
end
|
32
|
-
|
28
|
+
headers['Content-Length'] &&= bytesize(body).to_s
|
33
29
|
end
|
34
30
|
[status, headers, response]
|
35
31
|
end
|
data/lib/rack/pjax/version.rb
CHANGED
data/rack-pjax.gemspec
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Rack::Pjax do
|
4
|
+
include Rack::Test::Methods # can be moved to config
|
5
|
+
|
6
|
+
def app
|
7
|
+
Rack::Builder.app do
|
8
|
+
use Rack::Pjax
|
9
|
+
run lambda { |env|
|
10
|
+
body = '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>'
|
11
|
+
headers = {"Content-Length" => Rack::Utils.bytesize(body).to_s}
|
12
|
+
[200, headers, [body]]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when receiving a pjax-request" do
|
18
|
+
it "should return title-tag and inner-html of the pjax-container" do
|
19
|
+
get "/", {}, {'HTTP_X_PJAX' => true}
|
20
|
+
body.should == "<title>Hello</title>World!"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should recalculate the Content Length" do
|
24
|
+
get "/", {}, {'HTTP_X_PJAX' => true}
|
25
|
+
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when receiving a non-pjax request" do
|
30
|
+
it "should not alter the body" do
|
31
|
+
get "/"
|
32
|
+
body.should == '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have the correct Content Length" do
|
36
|
+
get "/"
|
37
|
+
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
6
|
+
require "rack-pjax"
|
7
|
+
|
8
|
+
Bundler.require(:test)
|
9
|
+
|
10
|
+
# helpers ripped from wycat's Rack::Offline
|
11
|
+
# (https://github.com/wycats/rack-offline/blob/master/spec/spec_helper.rb)
|
12
|
+
module Rack::Test::Methods
|
13
|
+
def self.included(klass)
|
14
|
+
class << klass
|
15
|
+
attr_accessor :app
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
last_response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def status
|
24
|
+
last_response.status
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
last_response.headers
|
29
|
+
end
|
30
|
+
|
31
|
+
def app
|
32
|
+
self.class.app
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-pjax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gert Goet
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-11-01 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rack
|
@@ -41,12 +40,12 @@ dependencies:
|
|
41
40
|
requirements:
|
42
41
|
- - ~>
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
43
|
+
hash: 3
|
45
44
|
segments:
|
46
45
|
- 1
|
47
|
-
-
|
48
|
-
-
|
49
|
-
version: 1.
|
46
|
+
- 5
|
47
|
+
- 0
|
48
|
+
version: 1.5.0
|
50
49
|
type: :runtime
|
51
50
|
version_requirements: *id002
|
52
51
|
description: Serve pjax responses through rack middleware
|
@@ -68,7 +67,9 @@ files:
|
|
68
67
|
- lib/rack/pjax.rb
|
69
68
|
- lib/rack/pjax/version.rb
|
70
69
|
- rack-pjax.gemspec
|
71
|
-
|
70
|
+
- spec/rack/pjax_spec.rb
|
71
|
+
- spec/spec.opts
|
72
|
+
- spec/spec_helper.rb
|
72
73
|
homepage: https://github.com/eval/rack-pjax
|
73
74
|
licenses: []
|
74
75
|
|
@@ -98,9 +99,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
requirements: []
|
99
100
|
|
100
101
|
rubyforge_project: rack-pjax
|
101
|
-
rubygems_version: 1.
|
102
|
+
rubygems_version: 1.8.11
|
102
103
|
signing_key:
|
103
104
|
specification_version: 3
|
104
105
|
summary: Serve pjax responses through rack middleware
|
105
|
-
test_files:
|
106
|
-
|
106
|
+
test_files:
|
107
|
+
- spec/rack/pjax_spec.rb
|
108
|
+
- spec/spec.opts
|
109
|
+
- spec/spec_helper.rb
|