rack-test-accepts 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -17,3 +17,7 @@ test/version_tmp
17
17
  tmp
18
18
  .rspec
19
19
  .rbx/
20
+ vendor/
21
+ bin/
22
+ vendor.noindex/
23
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,14 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
6
- - ruby-head
3
+ - 2.2.0
7
4
  - jruby-19mode
8
- - rbx-19mode
9
5
 
10
6
  # whitelist
11
7
  branches:
12
8
  only:
13
9
  - master
14
- - develop
data/CHANGES.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGES #
2
+
3
+ ## v1.0.0, Wednesday the 13th of December 2017 ##
4
+
5
+ * Updated some docs.
6
+ * Added spec for non-happy path and XHR.
7
+ * Bumped to 1.0.0 as per [semver](https://semver.org/)
8
+
9
+ ----
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  gem "rake"
7
7
 
8
8
  group :development do
9
- gem "wirble"
9
+ gem "yard"
10
10
  end
11
11
 
12
12
  group :test do
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
@@ -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
- module Accepts
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
@@ -1,7 +1,8 @@
1
1
  module Rack
2
2
  module Test
3
3
  module Accepts
4
- VERSION = "0.0.2"
4
+ # Library version
5
+ VERSION = "1.0.0"
5
6
  end
6
7
  end
7
8
  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 "calling accepts_xhr" do
31
- subject { fake_thing.env :accepts_xhr }
32
- it { should = {"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} }
33
- end
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.2
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: 2013-02-27 00:00:00.000000000 Z
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: 1.8.25
66
+ rubygems_version: 2.6.13
70
67
  signing_key:
71
- specification_version: 3
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