rack-test-accepts 0.0.2 → 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +1 -6
- data/CHANGES.md +9 -0
- data/Gemfile +1 -1
- data/README.md +10 -0
- data/lib/rack/test/accepts.rb +23 -1
- data/lib/rack/test/accepts/version.rb +2 -1
- data/spec/accepts_spec.rb +15 -4
- metadata +12 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c1c946cf2ca27de9e2d1fcc6f7f9e903e158dc2
|
4
|
+
data.tar.gz: c4c74c9df5c33a15259036faa4db6f98f0b89d12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9874d97cfb2493c14ec026d738c407c195f21d178f321bcaf16c1f82a5862be69993b014abbcf273347f4b5547b3e03128dd23a5ba7062aff00b27fdc2765d22
|
7
|
+
data.tar.gz: 4a0713c605594c6cc66380f029081db73fd088ada0087be1945f51d4e376b5031a91d64fa95ab5970f13775ea05e072f05793653324742bcf7a926e473daa12f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGES.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -50,6 +50,16 @@ It will work for any of the mime types listed in [Rack::Mime::MIME_TYPES](https:
|
|
50
50
|
|
51
51
|
or whichever crazy format your routes want to accept.
|
52
52
|
|
53
|
+
### XHR ###
|
54
|
+
|
55
|
+
It also detects XHR in either of two ways.
|
56
|
+
|
57
|
+
get "/", {}, env(:accepts_xhr)
|
58
|
+
get "/", {}, env(:via_xhr)
|
59
|
+
|
60
|
+
There's no difference.
|
61
|
+
|
62
|
+
|
53
63
|
## Contributing
|
54
64
|
|
55
65
|
1. Fork it
|
data/lib/rack/test/accepts.rb
CHANGED
@@ -1,21 +1,43 @@
|
|
1
1
|
require "rack"
|
2
2
|
|
3
|
+
# @see https://rubygems.org/gems/rack
|
3
4
|
module Rack
|
5
|
+
|
6
|
+
# @see https://rubygems.org/gems/rack-test
|
4
7
|
module Test
|
5
|
-
|
8
|
+
|
9
|
+
# Helpers for rack-test for the HTTP_ACCEPT header.
|
10
|
+
module Accepts
|
11
|
+
|
12
|
+
# @param methods [String,Symbol] The methods to accept.
|
13
|
+
# @example
|
14
|
+
# RSpec.configure do |config|
|
15
|
+
# config.include Rack::Test::Accepts, :type => :request
|
16
|
+
# # <snip!>
|
17
|
+
#
|
18
|
+
# describe "My route", :type => :request do
|
19
|
+
# let(:body) { { :key => "abcdef" }.to_json }
|
20
|
+
# before do
|
21
|
+
# post '/channel/create', body, env(:accepts_json)
|
22
|
+
# end
|
6
23
|
def env( *methods )
|
7
24
|
methods.each_with_object({}) do |meth, obj|
|
8
25
|
obj.merge! __send__(meth)
|
9
26
|
end
|
10
27
|
end
|
11
28
|
|
29
|
+
|
30
|
+
# Include all the Rack::Mime types
|
12
31
|
Rack::Mime::MIME_TYPES.each do |ext,mime_type|
|
13
32
|
define_method "accepts_#{ext[1..-1]}" do
|
14
33
|
{"HTTP_ACCEPT" => mime_type }
|
15
34
|
end
|
16
35
|
end
|
17
36
|
|
37
|
+
|
18
38
|
# Sets the HTTP_ACCEPT header to XMLHttpRequest
|
39
|
+
# @example
|
40
|
+
# get "/", {}, env(:accepts_xhr)
|
19
41
|
def via_xhr
|
20
42
|
{"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"}
|
21
43
|
end
|
data/spec/accepts_spec.rb
CHANGED
@@ -27,10 +27,21 @@ describe "Accepts module" do
|
|
27
27
|
it { should = {"HTTP_ACCEPT" => v } }
|
28
28
|
end
|
29
29
|
end
|
30
|
-
context "
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
context "xhr" do
|
31
|
+
context "calling accepts_xhr" do
|
32
|
+
subject { fake_thing.env :accepts_xhr }
|
33
|
+
it { should = {"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} }
|
34
|
+
end
|
35
|
+
context "via_xhr helper" do
|
36
|
+
subject { fake_thing.env :via_xhr }
|
37
|
+
it { should = {"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context "Failure" do
|
41
|
+
it "should fail because there is no zzz type" do
|
42
|
+
expect { fake_thing.env :via_zzz }.to raise_error NoMethodError
|
43
|
+
end
|
44
|
+
end
|
34
45
|
|
35
46
|
end
|
36
47
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test-accepts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Iain Barnett
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Helpers for rack-test that mean I don't need to remember the accept header
|
@@ -35,8 +32,9 @@ executables: []
|
|
35
32
|
extensions: []
|
36
33
|
extra_rdoc_files: []
|
37
34
|
files:
|
38
|
-
- .gitignore
|
39
|
-
- .travis.yml
|
35
|
+
- ".gitignore"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CHANGES.md
|
40
38
|
- Gemfile
|
41
39
|
- LICENCE.txt
|
42
40
|
- README.md
|
@@ -48,27 +46,26 @@ files:
|
|
48
46
|
- spec/spec_helper.rb
|
49
47
|
homepage: https://github.com/yb66/rack-test-accepts
|
50
48
|
licenses: []
|
49
|
+
metadata: {}
|
51
50
|
post_install_message:
|
52
51
|
rdoc_options: []
|
53
52
|
require_paths:
|
54
53
|
- lib
|
55
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
55
|
requirements:
|
58
|
-
- -
|
56
|
+
- - ">="
|
59
57
|
- !ruby/object:Gem::Version
|
60
58
|
version: '0'
|
61
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
60
|
requirements:
|
64
|
-
- -
|
61
|
+
- - ">="
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: '0'
|
67
64
|
requirements: []
|
68
65
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.6.13
|
70
67
|
signing_key:
|
71
|
-
specification_version:
|
68
|
+
specification_version: 4
|
72
69
|
summary: Helpers for rack-test for the HTTP_ACCEPT header.
|
73
70
|
test_files:
|
74
71
|
- spec/accepts_spec.rb
|