rack-test-accepts 0.0.1
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 +19 -0
- data/.travis.yml +14 -0
- data/Gemfile +15 -0
- data/LICENCE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +11 -0
- data/lib/rack/test/accepts.rb +25 -0
- data/lib/rack/test/accepts/version.rb +7 -0
- data/rack-test-accepts.gemspec +20 -0
- data/spec/accepts_spec.rb +38 -0
- data/spec/spec_helper.rb +28 -0
- metadata +75 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENCE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Iain Barnett
|
2
|
+
|
3
|
+
MIT Licence
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Rack::Test::Accepts
|
2
|
+
|
3
|
+
Helpers for rack-test that mean I don't need to remember the accept header syntax, or whether to prepend HTTP to them.
|
4
|
+
|
5
|
+
## Why? ##
|
6
|
+
|
7
|
+
Just to make life a bit easier.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'rack-test-accepts'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rack-test-accepts
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
It's easy to add this in where it's needed by including it via the RSpec config:
|
26
|
+
|
27
|
+
require 'rack/test/accepts'
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.include Rack::Test::Accepts, :type => :request
|
31
|
+
|
32
|
+
then:
|
33
|
+
|
34
|
+
describe "My route", :type => :request do
|
35
|
+
let(:body) { { :key => "abcdef" }.to_json }
|
36
|
+
before do
|
37
|
+
post '/channel/create', body, env(:accepts_json)
|
38
|
+
end
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rack"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module Test
|
5
|
+
module Accepts
|
6
|
+
def env( *methods )
|
7
|
+
methods.each_with_object({}) do |meth, obj|
|
8
|
+
obj.merge! __send__(meth)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Rack::Mime::MIME_TYPES.each do |ext,mime_type|
|
13
|
+
define_method "accepts_#{ext[1..-1]}" do
|
14
|
+
{"HTTP_ACCEPT" => mime_type }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Sets the HTTP_ACCEPT header to XMLHttpRequest
|
19
|
+
def via_xhr
|
20
|
+
{"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/test/accepts/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rack-test-accepts"
|
8
|
+
gem.version = Rack::Test::Accepts::VERSION
|
9
|
+
gem.authors = ["Iain Barnett"]
|
10
|
+
gem.email = ["iainspeed@gmail.com"]
|
11
|
+
gem.description = %q{Helpers for rack-test that mean I don't need to remember the accept header syntax, or whether to prepend HTTP to them.}
|
12
|
+
gem.summary = %q{Helpers for rack-test for the HTTP_ACCEPT header.}
|
13
|
+
gem.homepage = "https://github.com/yb66/rack-test-accepts"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency("rack")
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require_relative "../lib/rack/test/accepts.rb"
|
5
|
+
|
6
|
+
describe "Accepts module" do
|
7
|
+
subject { Rack::Test::Accepts.instance_methods }
|
8
|
+
it { should include :env }
|
9
|
+
Rack::Mime::MIME_TYPES.each do |k,v|
|
10
|
+
it { should include "accepts_#{k[1..-1]}".to_sym }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Including the methods" do
|
14
|
+
let(:fake_thing) {
|
15
|
+
o = Object.new
|
16
|
+
o.extend Rack::Test::Accepts
|
17
|
+
o
|
18
|
+
}
|
19
|
+
subject{ fake_thing }
|
20
|
+
it { should respond_to :env }
|
21
|
+
describe "Using the methods" do
|
22
|
+
|
23
|
+
Rack::Mime::MIME_TYPES.each do |k,v|
|
24
|
+
method = "accepts_#{k[1..-1]}"
|
25
|
+
context "calling env(:#{method})" do
|
26
|
+
subject { fake_thing.env method.to_sym }
|
27
|
+
it { should = {"HTTP_ACCEPT" => v } }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "calling accepts_xhr" do
|
31
|
+
subject { fake_thing.env :accepts_xhr }
|
32
|
+
it { should = {"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
Spec_dir = File.expand_path( File.dirname __FILE__ )
|
5
|
+
|
6
|
+
unless Kernel.respond_to?(:require_relative)
|
7
|
+
module Kernel
|
8
|
+
def require_relative(path)
|
9
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# code coverage
|
15
|
+
require 'simplecov'
|
16
|
+
SimpleCov.start do
|
17
|
+
add_filter "/vendor/"
|
18
|
+
add_filter "/bin/"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
Dir[ File.join( Spec_dir, "/support/**/*.rb")].each do |f|
|
23
|
+
require f
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-test-accepts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Iain Barnett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Helpers for rack-test that mean I don't need to remember the accept header
|
31
|
+
syntax, or whether to prepend HTTP to them.
|
32
|
+
email:
|
33
|
+
- iainspeed@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- .travis.yml
|
40
|
+
- Gemfile
|
41
|
+
- LICENCE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/rack/test/accepts.rb
|
45
|
+
- lib/rack/test/accepts/version.rb
|
46
|
+
- rack-test-accepts.gemspec
|
47
|
+
- spec/accepts_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
homepage: https://github.com/yb66/rack-test-accepts
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.25
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Helpers for rack-test for the HTTP_ACCEPT header.
|
73
|
+
test_files:
|
74
|
+
- spec/accepts_spec.rb
|
75
|
+
- spec/spec_helper.rb
|