forked from eval/rack-pjax
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in rack-pjax.gemspec | ||
gemspec | ||
|
||
group :test do | ||
gem "rspec", ">2" | ||
gem "rack-test" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
require 'bundler/gem_tasks' | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new do |t| | ||
t.rspec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] | ||
end | ||
|
||
desc "Run the specs" | ||
task :default => :spec | ||
|
||
desc 'Removes trailing whitespace' | ||
task :whitespace do | ||
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe Rack::Pjax do | ||
include Rack::Test::Methods # can be moved to config | ||
|
||
def app | ||
Rack::Builder.app do | ||
use Rack::Pjax | ||
run lambda { |env| | ||
body = '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>' | ||
headers = {"Content-Length" => Rack::Utils.bytesize(body).to_s} | ||
[200, headers, [body]] | ||
} | ||
end | ||
end | ||
|
||
context "when receiving a pjax-request" do | ||
it "should return title-tag and inner-html of the pjax-container" do | ||
get "/", {}, {'HTTP_X_PJAX' => true} | ||
body.should == "<title>Hello</title>World!" | ||
end | ||
|
||
it "should recalculate the Content Length" do | ||
get "/", {}, {'HTTP_X_PJAX' => true} | ||
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s | ||
end | ||
end | ||
|
||
context "when receiving a non-pjax request" do | ||
it "should not alter the body" do | ||
get "/" | ||
body.should == '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>' | ||
end | ||
|
||
it "should have the correct Content Length" do | ||
get "/" | ||
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "rubygems" | ||
require "bundler" | ||
Bundler.setup | ||
|
||
$:.unshift File.expand_path("../../lib", __FILE__) | ||
require "rack-pjax" | ||
|
||
Bundler.require(:test) | ||
|
||
# helpers ripped from wycat's Rack::Offline | ||
# (https://github.com/wycats/rack-offline/blob/master/spec/spec_helper.rb) | ||
module Rack::Test::Methods | ||
def self.included(klass) | ||
class << klass | ||
attr_accessor :app | ||
end | ||
end | ||
|
||
def body | ||
last_response.body | ||
end | ||
|
||
def status | ||
last_response.status | ||
end | ||
|
||
def headers | ||
last_response.headers | ||
end | ||
|
||
def app | ||
self.class.app | ||
end | ||
end |