grape 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grape might be problematic. Click here for more details.

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/.rubocop_todo.yml +80 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +21 -2
  6. data/Gemfile +1 -6
  7. data/Guardfile +1 -5
  8. data/README.md +110 -27
  9. data/Rakefile +1 -1
  10. data/UPGRADING.md +35 -0
  11. data/grape.gemspec +5 -2
  12. data/lib/grape.rb +20 -4
  13. data/lib/grape/api.rb +25 -467
  14. data/lib/grape/api/helpers.rb +7 -0
  15. data/lib/grape/dsl/callbacks.rb +27 -0
  16. data/lib/grape/dsl/configuration.rb +27 -0
  17. data/lib/grape/dsl/helpers.rb +86 -0
  18. data/lib/grape/dsl/inside_route.rb +227 -0
  19. data/lib/grape/dsl/middleware.rb +33 -0
  20. data/lib/grape/dsl/parameters.rb +79 -0
  21. data/lib/grape/dsl/request_response.rb +152 -0
  22. data/lib/grape/dsl/routing.rb +172 -0
  23. data/lib/grape/dsl/validations.rb +29 -0
  24. data/lib/grape/endpoint.rb +6 -226
  25. data/lib/grape/error_formatter/base.rb +28 -0
  26. data/lib/grape/error_formatter/json.rb +2 -0
  27. data/lib/grape/error_formatter/txt.rb +2 -0
  28. data/lib/grape/error_formatter/xml.rb +2 -0
  29. data/lib/grape/exceptions/base.rb +6 -0
  30. data/lib/grape/exceptions/validation.rb +3 -3
  31. data/lib/grape/exceptions/validation_errors.rb +19 -6
  32. data/lib/grape/locale/en.yml +5 -3
  33. data/lib/grape/middleware/auth/base.rb +28 -12
  34. data/lib/grape/middleware/auth/dsl.rb +35 -0
  35. data/lib/grape/middleware/auth/strategies.rb +24 -0
  36. data/lib/grape/middleware/auth/strategy_info.rb +15 -0
  37. data/lib/grape/validations.rb +3 -92
  38. data/lib/grape/validations/at_least_one_of.rb +25 -0
  39. data/lib/grape/validations/coerce.rb +2 -2
  40. data/lib/grape/validations/exactly_one_of.rb +2 -2
  41. data/lib/grape/validations/mutual_exclusion.rb +2 -2
  42. data/lib/grape/validations/presence.rb +1 -1
  43. data/lib/grape/validations/regexp.rb +1 -1
  44. data/lib/grape/validations/values.rb +1 -1
  45. data/lib/grape/version.rb +1 -1
  46. data/spec/grape/api/helpers_spec.rb +36 -0
  47. data/spec/grape/api_spec.rb +72 -19
  48. data/spec/grape/dsl/callbacks_spec.rb +44 -0
  49. data/spec/grape/dsl/configuration_spec.rb +37 -0
  50. data/spec/grape/dsl/helpers_spec.rb +54 -0
  51. data/spec/grape/dsl/inside_route_spec.rb +222 -0
  52. data/spec/grape/dsl/middleware_spec.rb +40 -0
  53. data/spec/grape/dsl/parameters_spec.rb +108 -0
  54. data/spec/grape/dsl/request_response_spec.rb +123 -0
  55. data/spec/grape/dsl/routing_spec.rb +132 -0
  56. data/spec/grape/dsl/validations_spec.rb +55 -0
  57. data/spec/grape/endpoint_spec.rb +60 -11
  58. data/spec/grape/entity_spec.rb +9 -4
  59. data/spec/grape/exceptions/validation_errors_spec.rb +31 -1
  60. data/spec/grape/middleware/auth/base_spec.rb +34 -0
  61. data/spec/grape/middleware/auth/dsl_spec.rb +53 -0
  62. data/spec/grape/middleware/auth/strategies_spec.rb +81 -0
  63. data/spec/grape/middleware/error_spec.rb +33 -1
  64. data/spec/grape/middleware/exception_spec.rb +13 -0
  65. data/spec/grape/validations/at_least_one_of_spec.rb +63 -0
  66. data/spec/grape/validations/exactly_one_of_spec.rb +1 -1
  67. data/spec/grape/validations/presence_spec.rb +159 -122
  68. data/spec/grape/validations/zh-CN.yml +1 -1
  69. data/spec/grape/validations_spec.rb +77 -15
  70. data/spec/spec_helper.rb +1 -0
  71. data/spec/support/endpoint_faker.rb +23 -0
  72. metadata +93 -15
  73. data/lib/grape/middleware/auth/basic.rb +0 -13
  74. data/lib/grape/middleware/auth/digest.rb +0 -13
  75. data/lib/grape/middleware/auth/oauth2.rb +0 -83
  76. data/spec/grape/middleware/auth/basic_spec.rb +0 -31
  77. data/spec/grape/middleware/auth/digest_spec.rb +0 -47
  78. data/spec/grape/middleware/auth/oauth2_spec.rb +0 -135
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16ab2241d8805f0449737830d3fb60b5ecf6a1e3
4
- data.tar.gz: b2d2d3cce8167bac238d0d8ac770edac583b0a81
3
+ metadata.gz: 065f62bd14d8e5f24acc6b085a2fd2f7b5cc835a
4
+ data.tar.gz: 1d95db90f66a6ddcae57416a557ac58977bae3b2
5
5
  SHA512:
6
- metadata.gz: ead66bb7118fdb6c173dcb4e9459a6385cd1ea984738e60c23754ff1c508d8562ff8d0a161ac7bebd14ec9afc22fd73170b7f15324facfc1ce79e6688d0a2d5b
7
- data.tar.gz: 10be3eceb5dcd72fcf5952d4d8bac3fa0eb9eb1a3eb5f08fa14486a2e24dcf21b578886dc314f09b6227d12214fa8ba9326f488405e2082acf1397e397d24d88
6
+ metadata.gz: 51324bbb02265b2ba09dae20e06039c1cdba09e4fd6f40979328be0bc32bd4fb03628ef90862c41016d14002b8b280906b945532d96b295ab8624dc567a57836
7
+ data.tar.gz: 93b0e47cbd02e8faad346d2e43b7f7d3bf56f05497331e87c6969dd17c65e8df651b69777e32f8aa9d68f6b17ae113e0094f6e04bf02fe25962959d71d7c7be5
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - vendor/**
4
- - bin/**
3
+ - vendor/**/*
4
+ - bin/**/*
5
5
 
6
6
  LineLength:
7
7
  Enabled: false
@@ -68,3 +68,5 @@ DoubleNegation:
68
68
 
69
69
  PredicateName:
70
70
  Enabled: false
71
+
72
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,80 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-08-12 13:16:39 +0200 using RuboCop version 0.24.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 28
9
+ # Cop supports --auto-correct.
10
+ Lint/UnusedBlockArgument:
11
+ Enabled: false
12
+
13
+ # Offense count: 30
14
+ # Cop supports --auto-correct.
15
+ Lint/UnusedMethodArgument:
16
+ Enabled: false
17
+
18
+ # Offense count: 5
19
+ # Cop supports --auto-correct.
20
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
21
+ Style/ClassCheck:
22
+ Enabled: false
23
+
24
+ # Offense count: 6
25
+ Style/EachWithObject:
26
+ Enabled: false
27
+
28
+ # Offense count: 11
29
+ # Configuration parameters: MinBodyLength.
30
+ Style/GuardClause:
31
+ Enabled: false
32
+
33
+ # Offense count: 1
34
+ # Cop supports --auto-correct.
35
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
36
+ Style/HashSyntax:
37
+ Enabled: false
38
+
39
+ # Offense count: 14
40
+ # Cop supports --auto-correct.
41
+ Style/IndentArray:
42
+ Enabled: false
43
+
44
+ # Offense count: 2
45
+ # Cop supports --auto-correct.
46
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
47
+ Style/IndentHash:
48
+ Enabled: true
49
+
50
+ # Offense count: 3
51
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
52
+ Style/Next:
53
+ Enabled: false
54
+
55
+ # Offense count: 2
56
+ # Cop supports --auto-correct.
57
+ # Configuration parameters: PreferredDelimiters.
58
+ Style/PercentLiteralDelimiters:
59
+ Enabled: false
60
+
61
+ # Offense count: 1
62
+ # Cop supports --auto-correct.
63
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
64
+ Style/SpaceBeforeBlockBraces:
65
+ Enabled: false
66
+
67
+ # Offense count: 12
68
+ # Cop supports --auto-correct.
69
+ Style/SpaceBeforeSemicolon:
70
+ Enabled: false
71
+
72
+ # Offense count: 1
73
+ # Cop supports --auto-correct.
74
+ Style/SpecialGlobalVars:
75
+ Enabled: false
76
+
77
+ # Offense count: 2
78
+ # Cop supports --auto-correct.
79
+ Style/UnneededPercentQ:
80
+ Enabled: false
@@ -3,14 +3,14 @@ language: ruby
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - ruby-head
7
6
  - 2.1.2
8
7
  - 2.1.0
9
8
  - 2.0.0
10
9
  - 1.9.3
10
+ - rbx-2.2.10
11
11
  - jruby-19mode
12
+ - ruby-head
12
13
  - jruby-head
13
- - rbx-2
14
14
 
15
15
  matrix:
16
16
  allow_failures:
@@ -1,11 +1,30 @@
1
+ 0.9.0 (8/27/2014)
2
+ =================
3
+
4
+ #### Features
5
+
6
+ * [#691](https://github.com/intridea/grape/issues/691): Added `at_least_one_of` parameter validator - [@dblock](https://github.com/dblock).
7
+ * [#698](https://github.com/intridea/grape/pull/698): `error!` sets `status` for `Endpoint` too - [@dspaeth-faber](https://github.com/dspaeth-faber).
8
+ * [#703](https://github.com/intridea/grape/pull/703): Added support for Auth-Middleware extension - [@dspaeth-faber](https://github.com/dspaeth-faber).
9
+ * [#703](https://github.com/intridea/grape/pull/703): Removed `Grape::Middleware::Auth::Basic` - [@dspaeth-faber](https://github.com/dspaeth-faber).
10
+ * [#703](https://github.com/intridea/grape/pull/703): Removed `Grape::Middleware::Auth::Digest` - [@dspaeth-faber](https://github.com/dspaeth-faber).
11
+ * [#703](https://github.com/intridea/grape/pull/703): Removed `Grape::Middleware::Auth::OAuth2` - [@dspaeth-faber](https://github.com/dspaeth-faber).
12
+ * [#719](https://github.com/intridea/grape/pull/719): Allow passing options hash to a custom validator - [@elado](https://github.com/elado).
13
+ * [#716](https://github.com/intridea/grape/pull/716): Calling `content-type` will now return the current content-type - [@dblock](https://github.com/dblock).
14
+ * [#705](https://github.com/intridea/grape/pull/705): Errors can now be presented with a `Grape::Entity` class - [@dspaeth-faber](https://github.com/dspaeth-faber).
15
+
16
+ #### Fixes
17
+
18
+ * [#687](https://github.com/intridea/grape/pull/687): Fix: `mutually_exclusive` and `exactly_one_of` validation error messages now label parameters as strings, consistently with `requires` and `optional` - [@dblock](https://github.com/dblock).
19
+
1
20
  0.8.0 (7/10/2014)
2
21
  =================
3
22
 
4
23
  #### Features
5
24
 
6
25
  * [#639](https://github.com/intridea/grape/pull/639): Added support for blocks with reusable params - [@mibon](https://github.com/mibon).
7
- * [#637](https://github.com/intridea/grape/pull/637): Added 'exactly_one_of' validation - [@Morred](https://github.com/Morred).
8
- * [#626](https://github.com/intridea/grape/pull/626): Mutually exclusive params - [@oliverbarnes](https://github.com/oliverbarnes).
26
+ * [#637](https://github.com/intridea/grape/pull/637): Added support for `exactly_one_of` parameter validation - [@Morred](https://github.com/Morred).
27
+ * [#626](https://github.com/intridea/grape/pull/626): Added support for `mutually_exclusive` parameters - [@oliverbarnes](https://github.com/oliverbarnes).
9
28
  * [#617](https://github.com/intridea/grape/pull/617): Running tests on Ruby 2.1.1, Rubinius 2.1 and 2.2, Ruby and JRuby HEAD - [@dblock](https://github.com/dblock).
10
29
  * [#397](https://github.com/intridea/grape/pull/397): Adds `Grape::Endpoint.before_each` to allow easy helper stubbing - [@mbleigh](https://github.com/mbleigh).
11
30
  * [#673](https://github.com/intridea/grape/pull/673): Avoid requiring non-existent fields when using Grape::Entity documentation - [@qqshfox](https://github.com/qqshfox).
data/Gemfile CHANGED
@@ -3,15 +3,10 @@ source 'http://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem 'rspec', '~> 2.14.1'
7
- gem 'rack-test', '~> 0.6.2', require: 'rack/test'
8
- gem 'cookiejar'
9
- gem 'rack-contrib'
10
- gem 'rubocop', '~> 0.20.1'
6
+ gem 'rubocop', '~> 0.24.1'
11
7
  gem 'guard'
12
8
  gem 'guard-rspec'
13
9
  gem 'guard-rubocop'
14
- gem 'mime-types'
15
10
  end
16
11
 
17
12
  platforms :rbx do
data/Guardfile CHANGED
@@ -1,13 +1,9 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard :rspec do
1
+ guard :rspec, all_on_start: true, cmd: 'bundle exec rspec' do
5
2
  watch(%r{^spec/.+_spec\.rb$})
6
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
4
  watch('spec/spec_helper.rb') { "spec" }
8
5
  end
9
6
 
10
-
11
7
  guard :rubocop do
12
8
  watch(%r{.+\.rb$})
13
9
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
data/README.md CHANGED
@@ -31,6 +31,7 @@
31
31
  - [Helpers](#helpers)
32
32
  - [Parameter Documentation](#parameter-documentation)
33
33
  - [Cookies](#cookies)
34
+ - [HTTP Status Code](#http-status-code)
34
35
  - [Redirecting](#redirecting)
35
36
  - [Allowed Methods](#allowed-methods)
36
37
  - [Raising Exceptions](#raising-exceptions)
@@ -76,8 +77,7 @@ content negotiation, versioning and much more.
76
77
 
77
78
  ## Stable Release
78
79
 
79
- You're reading the documentation for the stable release of Grape, 0.8.0.
80
- Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
80
+ You're reading the documentation for Grape [0.9.0](https://github.com/intridea/grape/blob/v0.9.0/README.md).
81
81
 
82
82
  ## Project Resources
83
83
 
@@ -300,6 +300,21 @@ When an invalid `Accept` header is supplied, a `406 Not Acceptable` error is ret
300
300
  option is set to `false`. Otherwise a `404 Not Found` error is returned by Rack if no other route
301
301
  matches.
302
302
 
303
+ ### HTTP Status Code
304
+
305
+ By default Grape returns a 200 status code for `GET`-Requests and 201 for `POST`-Requests.
306
+ You can use `status` to query and set the actual HTTP Status Code
307
+
308
+ ```ruby
309
+ post do
310
+ status 202
311
+
312
+ if status == 200
313
+ # do some thing
314
+ end
315
+ end
316
+ ```
317
+
303
318
  ### Accept-Version Header
304
319
 
305
320
  ```ruby
@@ -444,12 +459,12 @@ params do
444
459
  end
445
460
  ```
446
461
 
447
- The :values option can also be supplied with a `Proc` to be evalutated at runtime. For example, given a status
462
+ The `:values` option can also be supplied with a `Proc` to be evalutated at runtime. For example, given a status
448
463
  model you may want to restrict by hashtags that you have previously defined in the `HashTag` model.
449
464
 
450
465
  ```ruby
451
466
  params do
452
- required :hashtag, type: String, values: -> { Hashtag.all.map(&:tag) }
467
+ requires :hashtag, type: String, values: -> { Hashtag.all.map(&:tag) }
453
468
  end
454
469
  ```
455
470
 
@@ -509,6 +524,17 @@ params do
509
524
  end
510
525
  ```
511
526
 
527
+ Parameters can be defined as 'at_least_one_of', ensuring that at least one parameter gets selected.
528
+
529
+ ```ruby
530
+ params do
531
+ optional :beer
532
+ optional :wine
533
+ optional :juice
534
+ at_least_one :beer, :wine, :juice
535
+ end
536
+ ```
537
+
512
538
  ### Namespace Validation and Coercion
513
539
 
514
540
  Namespaces allow parameter definitions and apply to every method within the namespace.
@@ -588,21 +614,28 @@ end
588
614
 
589
615
  ### Validation Errors
590
616
 
591
- Validation and coercion errors are collected and an exception of type `Grape::Exceptions::ValidationErrors` is raised.
592
- If the exception goes uncaught it will respond with a status of 400 and an error message.
593
- You can rescue a `Grape::Exceptions::ValidationErrors` and respond with a custom response.
617
+ Validation and coercion errors are collected and an exception of type `Grape::Exceptions::ValidationErrors` is raised. If the exception goes uncaught it will respond with a status of 400 and an error message. The validation errors are grouped by parameter name and can be accessed via `Grape::Exceptions::ValidationErrors#errors`.
618
+
619
+
620
+ The default response from a `Grape::Exceptions::ValidationErrors` is a humanly readable string, such as "beer, wine are mutually exclusive", in the following example.
594
621
 
595
622
  ```ruby
596
- rescue_from Grape::Exceptions::ValidationErrors do |e|
597
- Rack::Response.new({
598
- status: e.status,
599
- message: e.message,
600
- errors: e.errors
601
- }.to_json, e.status)
623
+ params do
624
+ optional :beer
625
+ optional :wine
626
+ optional :juice
627
+ exactly_one_of :beer, :wine, :juice
602
628
  end
603
629
  ```
604
630
 
605
- The validation errors are grouped by parameter name and can be accessed via ``Grape::Exceptions::ValidationErrors#errors``.
631
+ You can rescue a `Grape::Exceptions::ValidationErrors` and respond with a custom response or turn the response into well-formatted JSON for a JSON API that separates individual parameters and the corresponding error messages. The following `rescue_from` example produces `[{"params":["beer","wine"],"messages":["are mutually exclusive"]}]`.
632
+
633
+ ```ruby
634
+ format :json
635
+ subject.rescue_from Grape::Exceptions::ValidationErrors do |e|
636
+ rack_response e.to_json, 400
637
+ end
638
+ ```
606
639
 
607
640
  ### I18n
608
641
 
@@ -909,6 +942,31 @@ instead of a message.
909
942
  error!({ error: "unexpected error", detail: "missing widget" }, 500)
910
943
  ```
911
944
 
945
+ You can present documented errors with a Grape entity using the the [grape-entity](https://github.com/intridea/grape-entity) gem.
946
+
947
+ ```ruby
948
+ module API
949
+ class Error < Grape::Entity
950
+ expose :code
951
+ expose :message
952
+ end
953
+ end
954
+ ```
955
+
956
+ The following example specifies the entity to use in the `http_codes` definition.
957
+
958
+ ```
959
+ desc 'My Route', http_codes: [[408, 'Unauthorized', API::Error]]
960
+ error!({ message: 'Unauthorized' }, 408)
961
+ ```
962
+
963
+ The following example specifies the presented entity explicitly in the error message.
964
+
965
+ ```ruby
966
+ desc 'My Route', http_codes: [[408, 'Unauthorized']]
967
+ error!({ message: 'Unauthorized', with: API::Error }, 408)
968
+ ```
969
+
912
970
  ### Default Error HTTP Status Code
913
971
 
914
972
  By default Grape returns a 500 status code from `error!`. You can change this with `default_error_status`.
@@ -1412,11 +1470,9 @@ Grape will automatically detect that there is a `Status::Entity` class and use t
1412
1470
  representative entity. This can still be overridden by using the `:with` option or an explicit
1413
1471
  `represents` call.
1414
1472
 
1415
- ### Hypermedia
1473
+ ### Hypermedia and Roar
1416
1474
 
1417
- You can use any Hypermedia representer, including [Roar](https://github.com/apotonick/roar).
1418
- Roar renders JSON and works with the built-in Grape JSON formatter. Add `Roar::Representer::JSON`
1419
- into your models or call `to_json` explicitly in your API implementation.
1475
+ You can use [Roar](https://github.com/apotonick/roar) to render HAL or Collection+JSON with the help of [grape-roar](https://github.com/dblock/grape-roar), which defines a custom JSON formatter and enables presenting entities with Grape's `present` keyword.
1420
1476
 
1421
1477
  ### Rabl
1422
1478
 
@@ -1435,7 +1491,9 @@ formatter.
1435
1491
 
1436
1492
  ### Basic and Digest Auth
1437
1493
 
1438
- Grape has built-in Basic and Digest authentication.
1494
+ Grape has built-in Basic and Digest authentication (the given `block`
1495
+ is executed in the context of the current `Endpoint`). Authentication
1496
+ applies to the current namespace and any children, but not parents.
1439
1497
 
1440
1498
  ```ruby
1441
1499
  http_basic do |username, password|
@@ -1451,6 +1509,33 @@ http_digest({ realm: 'Test Api', opaque: 'app secret' }) do |username|
1451
1509
  end
1452
1510
  ```
1453
1511
 
1512
+ ### Register custom middleware for authentication
1513
+
1514
+ Grape can use custom Middleware for authentication. How to implement these
1515
+ Middleware have a look at `Rack::Auth::Basic` or similar implementations.
1516
+
1517
+
1518
+ For registering a Middlewar you need the following options:
1519
+
1520
+ * `label` - the name for your authenticator to use it later
1521
+ * `MiddlewareClass` - the MiddlewareClass to use for authentication
1522
+ * `option_lookup_proc` - A Proc with one Argument to lookup the options at
1523
+ runtime (return value is an `Array` as Paramter for the Middleware).
1524
+
1525
+ Example:
1526
+
1527
+ ```ruby
1528
+
1529
+ Grape::Middleware::Auth::Strategies.add(:my_auth, AuthMiddleware, ->(options) { [options[:realm]] } )
1530
+
1531
+
1532
+ auth :my_auth ,{ real: 'Test Api'} do |credentials|
1533
+ # lookup the user's password here
1534
+ { 'user1' => 'password1' }[username]
1535
+ end
1536
+
1537
+ ```
1538
+
1454
1539
  Use [warden-oauth2](https://github.com/opperator/warden-oauth2) or [rack-oauth2](https://github.com/nov/rack-oauth2) for OAuth2 support.
1455
1540
 
1456
1541
  ## Describing and Inspecting an API
@@ -1640,15 +1725,15 @@ describe Twitter::API do
1640
1725
  describe "GET /api/v1/statuses" do
1641
1726
  it "returns an empty array of statuses" do
1642
1727
  get "/api/v1/statuses"
1643
- last_response.status.should == 200
1644
- JSON.parse(last_response.body).should == []
1728
+ expect(last_response.status).to eq(200)
1729
+ expect(JSON.parse(last_response.body)).to eq []
1645
1730
  end
1646
1731
  end
1647
1732
  describe "GET /api/v1/statuses/:id" do
1648
1733
  it "returns a status by id" do
1649
1734
  status = Status.create!
1650
1735
  get "/api/v1/statuses/#{status.id}"
1651
- last_response.body.should == status.to_json
1736
+ expect(last_response.body).to eq status.to_json
1652
1737
  end
1653
1738
  end
1654
1739
  end
@@ -1658,21 +1743,19 @@ end
1658
1743
  ### Writing Tests with Rails
1659
1744
 
1660
1745
  ```ruby
1661
- require 'spec_helper'
1662
-
1663
1746
  describe Twitter::API do
1664
1747
  describe "GET /api/v1/statuses" do
1665
1748
  it "returns an empty array of statuses" do
1666
1749
  get "/api/v1/statuses"
1667
- response.status.should == 200
1668
- JSON.parse(response.body).should == []
1750
+ expect(response.status).to eq(200)
1751
+ expect(JSON.parse(response.body)).to eq []
1669
1752
  end
1670
1753
  end
1671
1754
  describe "GET /api/v1/statuses/:id" do
1672
1755
  it "returns a status by id" do
1673
1756
  status = Status.create!
1674
1757
  get "/api/v1/statuses/#{status.id}"
1675
- response.body.should == status.to_json
1758
+ expect(response.body).to eq status.to_json
1676
1759
  end
1677
1760
  end
1678
1761
  end
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ task :spec
18
18
 
19
19
  require 'rainbow/ext/string' unless String.respond_to?(:color)
20
20
  require 'rubocop/rake_task'
21
- Rubocop::RakeTask.new(:rubocop)
21
+ RuboCop::RakeTask.new
22
22
 
23
23
  task default: [:rubocop, :spec]
24
24
 
@@ -1,6 +1,41 @@
1
1
  Upgrading Grape
2
2
  ===============
3
3
 
4
+ ### Upgrading to >= 0.9.0
5
+
6
+ #### Changes in Authentication
7
+
8
+ The following middleware classes have been removed:
9
+
10
+ * `Grape::Middleware::Auth::Basic`
11
+ * `Grape::Middleware::Auth::Digest`
12
+ * `Grape::Middleware::Auth::OAuth2`
13
+
14
+ When you use theses classes directly like:
15
+
16
+ ```ruby
17
+ module API
18
+ class Root < Grape::API
19
+ class Protected < Grape::API
20
+ use Grape::Middleware::Auth::OAuth2,
21
+ token_class: 'AccessToken',
22
+ parameter: %w(access_token api_key)
23
+
24
+ ```
25
+
26
+ you have to replace these classes.
27
+
28
+ As replacement can be used
29
+
30
+ * `Grape::Middleware::Auth::Basic` => [`Rack::Auth::Basic`](https://github.com/rack/rack/blob/master/lib/rack/auth/basic.rb)
31
+ * `Grape::Middleware::Auth::Digest` => [`Rack::Auth::Digest::MD5`](https://github.com/rack/rack/blob/master/lib/rack/auth/digest/md5.rb)
32
+ * `Grape::Middleware::Auth::OAuth2` => [warden-oauth2](https://github.com/opperator/warden-oauth2) or [rack-oauth2](https://github.com/nov/rack-oauth2)
33
+
34
+ If this is not possible you can extract the middleware files from [grape v0.7.0](https://github.com/intridea/grape/tree/v0.7.0/lib/grape/middleware/auth)
35
+ and host these files within your application
36
+
37
+ See [#703](https://github.com/intridea/Grape/pull/703) for more information.
38
+
4
39
  ### Upgrading to >= 0.7.0
5
40
 
6
41
  #### Changes in Exception Handling