versioncake 2.5.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +6 -14
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/Appraisals +12 -0
  5. data/CHANGELOG.md +18 -1
  6. data/CONTRIBUTING.md +2 -2
  7. data/Gemfile.lock +96 -44
  8. data/README.md +79 -29
  9. data/RELEASE.md +1 -1
  10. data/Rakefile +3 -7
  11. data/gemfiles/rails3.2.gemfile +2 -1
  12. data/gemfiles/rails3.2.gemfile.lock +34 -10
  13. data/gemfiles/rails4.0.gemfile +2 -1
  14. data/gemfiles/rails4.0.gemfile.lock +31 -7
  15. data/gemfiles/rails4.1.gemfile +1 -1
  16. data/gemfiles/rails4.1.gemfile.lock +28 -8
  17. data/gemfiles/rails4.2.gemfile +9 -0
  18. data/gemfiles/rails4.2.gemfile.lock +133 -0
  19. data/lib/generators/templates/versioncake.rb +40 -0
  20. data/lib/generators/versioncake/install_generator.rb +12 -0
  21. data/lib/versioncake.rb +24 -3
  22. data/lib/versioncake/configuration.rb +19 -2
  23. data/lib/versioncake/controller_additions.rb +35 -23
  24. data/lib/versioncake/engine.rb +7 -0
  25. data/lib/versioncake/exceptions.rb +4 -0
  26. data/lib/versioncake/rack/middleware.rb +20 -0
  27. data/lib/versioncake/strategies/extraction_strategy.rb +8 -3
  28. data/lib/versioncake/strategies/http_accept_parameter_strategy.rb +2 -2
  29. data/lib/versioncake/strategies/http_header_strategy.rb +2 -2
  30. data/lib/versioncake/strategies/path_parameter_strategy.rb +6 -2
  31. data/lib/versioncake/strategies/query_parameter_strategy.rb +2 -2
  32. data/lib/versioncake/strategies/request_parameter_strategy.rb +2 -2
  33. data/lib/versioncake/test_helpers.rb +14 -0
  34. data/lib/versioncake/version.rb +1 -1
  35. data/lib/versioncake/version_checker.rb +28 -0
  36. data/lib/versioncake/version_context.rb +20 -0
  37. data/lib/versioncake/version_context_service.rb +47 -0
  38. data/lib/versioncake/versioned_request.rb +22 -33
  39. data/lib/versioncake/versioned_resource.rb +14 -0
  40. data/lib/versioncake/view_additions.rb +7 -7
  41. data/{test → spec}/fixtures/partials/_versioned.erb +0 -0
  42. data/{test → spec}/fixtures/partials/_versioned.v1.erb +0 -0
  43. data/{test → spec}/fixtures/partials/_versioned.v2.erb +0 -0
  44. data/{test → spec}/fixtures/partials/_versioned.v3.erb +0 -0
  45. data/{test → spec}/fixtures/partials/another_versioned_partial.erb +0 -0
  46. data/{test → spec}/fixtures/partials/another_versioned_partial.v1.erb +0 -0
  47. data/{test → spec}/fixtures/templates/unversioned.html.erb +0 -0
  48. data/{test → spec}/fixtures/templates/v1_extension_scheme.v3.html.erb +0 -0
  49. data/{test → spec}/fixtures/templates/v1_extension_scheme.v6.json +0 -0
  50. data/{test → spec}/fixtures/templates/versioned.html.erb +0 -0
  51. data/{test → spec}/fixtures/templates/versioned.html.v1.erb +0 -0
  52. data/{test → spec}/fixtures/templates/versioned.html.v2.erb +0 -0
  53. data/{test → spec}/fixtures/templates/versioned.html.v3.erb +0 -0
  54. data/spec/fixtures/test_cases.yml +45 -0
  55. data/spec/integration/controller/renders_controller_spec.rb +73 -0
  56. data/spec/integration/controller/unversioned_controller_spec.rb +12 -0
  57. data/spec/integration/rack/middleware_regression_spec.rb +41 -0
  58. data/spec/integration/view/render_spec.rb +33 -0
  59. data/spec/integration/view/view_additions_spec.rb +51 -0
  60. data/spec/rails_helper.rb +41 -0
  61. data/spec/spec_helper.rb +25 -0
  62. data/spec/test_app/Rakefile +7 -0
  63. data/{test → spec/test_app}/app/controllers/renders_controller.rb +0 -0
  64. data/spec/test_app/app/controllers/unversioned_controller.rb +6 -0
  65. data/spec/test_app/app/views/renders/index.html.erb +1 -0
  66. data/{test → spec/test_app}/app/views/renders/index.html.v1.erb +0 -0
  67. data/{test → spec/test_app}/app/views/renders/index.html.v2.erb +0 -0
  68. data/spec/test_app/app/views/unversioned/index.html.erb +1 -0
  69. data/spec/test_app/config.ru +4 -0
  70. data/{test → spec/test_app}/config/application.rb +4 -6
  71. data/spec/test_app/config/boot.rb +5 -0
  72. data/spec/test_app/config/environment.rb +5 -0
  73. data/spec/test_app/config/initializers/versioncake.rb +45 -0
  74. data/spec/test_app/config/routes.rb +4 -0
  75. data/spec/test_app/script/rails +4 -0
  76. data/spec/unit/cli_spec.rb +36 -0
  77. data/spec/unit/configuration_spec.rb +61 -0
  78. data/spec/unit/strategies/extraction_strategy_spec.rb +71 -0
  79. data/spec/unit/strategies/http_accept_parameter_strategy_spec.rb +20 -0
  80. data/spec/unit/strategies/http_header_strategy_spec.rb +19 -0
  81. data/spec/unit/strategies/path_parameter_strategy_spec.rb +18 -0
  82. data/spec/unit/strategies/query_parameter_strategy_spec.rb +24 -0
  83. data/spec/unit/strategies/request_parameter_strategy_spec.rb +19 -0
  84. data/spec/unit/version_checker_spec.rb +60 -0
  85. data/spec/unit/version_context_service_spec.rb +84 -0
  86. data/spec/unit/version_context_spec.rb +46 -0
  87. data/spec/unit/versioned_request_spec.rb +35 -0
  88. data/spec/unit/versioned_resource_spec.rb +12 -0
  89. data/versioncake.gemspec +5 -2
  90. metadata +91 -70
  91. data/lib/versioncake/railtie.rb +0 -7
  92. data/test/app/views/renders/index.html.erb +0 -1
  93. data/test/config.ru +0 -0
  94. data/test/config/routes.rb +0 -3
  95. data/test/fixtures/test_cases.yml +0 -70
  96. data/test/functional/custom_strategy_controller_test.rb +0 -16
  97. data/test/functional/multiple_strategy_controller_test.rb +0 -24
  98. data/test/functional/renders_controller_test.rb +0 -71
  99. data/test/functional/strategy_controller_test.rb +0 -38
  100. data/test/script/rails +0 -0
  101. data/test/template/render_test.rb +0 -34
  102. data/test/test_helper.rb +0 -21
  103. data/test/unit/cli_test.rb +0 -48
  104. data/test/unit/configuration_test.rb +0 -45
  105. data/test/unit/strategies/extraction_strategy_test.rb +0 -70
  106. data/test/unit/strategies/http_accept_parameter_strategy_test.rb +0 -17
  107. data/test/unit/strategies/http_header_strategy_test.rb +0 -17
  108. data/test/unit/strategies/path_parameter_strategy_test.rb +0 -17
  109. data/test/unit/strategies/query_parameter_strategy_test.rb +0 -22
  110. data/test/unit/strategies/request_parameter_strategy_test.rb +0 -17
  111. data/test/unit/versioned_request_test.rb +0 -44
  112. data/test/unit/view_additions_test.rb +0 -35
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2VhZjA2ZWU5ODU0MWVhYTQ4Nzk1NmM1OTFjNmIzYzJjZGUwZGQ5OQ==
5
- data.tar.gz: !binary |-
6
- M2RhOTQ5YzNiODAzY2JkMzg2NjMzM2UwMDllNjdjMjBiNjVjNDgzNg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NmJiMzc5YTk5MjcwODU2MTI0M2YzOGIxYTlhM2EwOWJjZDRjYzJiOWJjMDIz
10
- MzJmOTA0NjFhMzlhM2I5ODMyMzE4YWYzNzc5ZTMzMWNkMGJjZDdjY2RjNzE4
11
- ODc4NDE0MmU1ZmY2ZjM1ZDc1ZmJiMTg4ZWVhODViMGU3MjkxOGE=
12
- data.tar.gz: !binary |-
13
- MWExYWQ1ZmI5ZThlN2Q4N2QwNTg5NDU4NzM5MzdlODQ5NzFiODczNjIxMTM1
14
- MzUzYjQ1OGRlMTVhNDM1MmRlMWRmMDY4NzYyNTRjYzIxZDFjZTM1YTkyYjhm
15
- ZTkxMWM2YTNkZmEyYTdhOTEzNzZlOTk5MjI3NDJlZjZmYjJjMmM=
2
+ SHA1:
3
+ metadata.gz: b2f2076334af038794b17f3f6cae1e2c0fb8347d
4
+ data.tar.gz: 8f6fc9bf8359ba05b5e7f0620c280aa2ead43f47
5
+ SHA512:
6
+ metadata.gz: 12c7dbe459aeb4a7caff6599905bc52f90a40a32a0220492d133a89f394a2791cce96abcfad434fd32cc3ccd477d59bd95cf8a86432e1f469769f925bea85fc6
7
+ data.tar.gz: 4394f668996b75d5b5ae627c895eeb5a0a45c0f096b51f1370acfacd4a458b5e68c529ee5643bae0c64e4f900630a68bda728a2e59a61e8cca7e329a5ccd72d1
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
@@ -4,12 +4,14 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.0
7
+ - 2.2.0
7
8
  - ruby-head
8
9
 
9
10
  gemfile:
10
11
  - gemfiles/rails3.2.gemfile
11
12
  - gemfiles/rails4.0.gemfile
12
13
  - gemfiles/rails4.1.gemfile
14
+ - gemfiles/rails4.2.gemfile
13
15
 
14
16
  matrix:
15
17
  exclude:
@@ -17,6 +19,8 @@ matrix:
17
19
  gemfile: gemfiles/rails4.0.gemfile
18
20
  - rvm: 1.9.2
19
21
  gemfile: gemfiles/rails4.1.gemfile
22
+ - rvm: 1.9.2
23
+ gemfile: gemfiles/rails4.2.gemfile
20
24
 
21
25
  allow_failures:
22
26
  - rvm: ruby-head
data/Appraisals CHANGED
@@ -2,12 +2,18 @@ appraise "rails3.2" do
2
2
  gem('actionpack', '~> 3.2.0')
3
3
  gem('activesupport', '~> 3.2.0')
4
4
  gem('railties', '~> 3.2.0')
5
+ # Rails 3.2 has test-unit as a dependency, but Ruby 2.2 removes
6
+ # it, so we need to now manually require it as a dependency
7
+ gem('test-unit', '~>3.0')
5
8
  end
6
9
 
7
10
  appraise "rails4.0" do
8
11
  gem('actionpack', '~> 4.0.0')
9
12
  gem('activesupport', '~> 4.0.0')
10
13
  gem('railties', '~> 4.0.0')
14
+ # Rails 4.0 has test-unit as a dependency, but Ruby 2.2 removes
15
+ # it, so we need to now manually require it as a dependency
16
+ gem('test-unit', '~>3.0')
11
17
  end
12
18
 
13
19
  appraise "rails4.1" do
@@ -15,3 +21,9 @@ appraise "rails4.1" do
15
21
  gem('activesupport', '~> 4.1.0')
16
22
  gem('railties', '~> 4.1.0')
17
23
  end
24
+
25
+ appraise "rails4.2" do
26
+ gem('actionpack', '~> 4.2.0')
27
+ gem('activesupport', '~> 4.2.0')
28
+ gem('railties', '~> 4.2.0')
29
+ end
@@ -1,6 +1,6 @@
1
1
  ## Unreleased Changes
2
2
 
3
- [Full Changelog](https://github.com/bwillis/versioncake/compare/v2.5...master)
3
+ [Full Changelog](https://github.com/bwillis/versioncake/compare/v3.0...master)
4
4
 
5
5
  Bug Fixes:
6
6
 
@@ -14,6 +14,23 @@ Deprecations:
14
14
 
15
15
  * None
16
16
 
17
+ ## 3.0.0 (Aug 3, 2015)
18
+
19
+ Bug Fixes:
20
+
21
+ * When an invalid version is received an unsupported exception is raised (#34)
22
+ * Remove deprecated X- from header (breaking change)
23
+ * Remove warning in Rails 5 (#40) Thanks [Michael Elfassy](https://github.com/elfassy)!
24
+
25
+ Enhancements:
26
+
27
+ * Migrate from test-unit to rspec (#37)
28
+ * Rack based versioning middleware (#36) (breaking changes)
29
+
30
+ Deprecations:
31
+
32
+ * None
33
+
17
34
  ## 2.5.0 (Apr 18, 2014)
18
35
 
19
36
  [Full Changelog](https://github.com/bwillis/versioncake/compare/v2.4...v2.5)
@@ -14,5 +14,5 @@ We really like when people not only discover something they want added/fixed/rem
14
14
 
15
15
  Version Cake supports multiple versions of Rails with Appriasals. These will be automatically tested against several ruby versions on CI. If you need to debug a problem, or want to be dilegent and run all of these do the following:
16
16
 
17
- * Install the gems for all supported Rails versions: `bundle exec rake appraisal:install`
18
- * Run all the tests for the supported Rails versions: `bundle exec rake appraisal test`
17
+ * Install the gems for all supported Rails versions: `bundle exec rake appraisal install`
18
+ * Run all the tests for the supported Rails versions: `bundle exec rake appraisal spec`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- versioncake (2.5.0)
4
+ versioncake (3.0.0)
5
5
  actionpack (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  railties (>= 3.2)
@@ -10,61 +10,110 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionpack (4.1.0)
14
- actionview (= 4.1.0)
15
- activesupport (= 4.1.0)
16
- rack (~> 1.5.2)
13
+ actionpack (4.2.3)
14
+ actionview (= 4.2.3)
15
+ activesupport (= 4.2.3)
16
+ rack (~> 1.6)
17
17
  rack-test (~> 0.6.2)
18
- actionview (4.1.0)
19
- activesupport (= 4.1.0)
18
+ rails-dom-testing (~> 1.0, >= 1.0.5)
19
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
+ actionview (4.2.3)
21
+ activesupport (= 4.2.3)
20
22
  builder (~> 3.1)
21
23
  erubis (~> 2.7.0)
22
- activesupport (4.1.0)
23
- i18n (~> 0.6, >= 0.6.9)
24
+ rails-dom-testing (~> 1.0, >= 1.0.5)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
+ activesupport (4.2.3)
27
+ i18n (~> 0.7)
24
28
  json (~> 1.7, >= 1.7.7)
25
29
  minitest (~> 5.1)
26
- thread_safe (~> 0.1)
30
+ thread_safe (~> 0.3, >= 0.3.4)
27
31
  tzinfo (~> 1.1)
28
- appraisal (0.5.2)
32
+ appraisal (2.0.2)
29
33
  bundler
30
34
  rake
35
+ thor (>= 0.14.0)
31
36
  builder (3.2.2)
32
- colorize (0.5.8)
33
- coveralls (0.6.7)
34
- colorize
35
- multi_json (~> 1.3)
36
- rest-client
37
- simplecov (>= 0.7)
38
- thor
37
+ coveralls (0.8.2)
38
+ json (~> 1.8)
39
+ rest-client (>= 1.6.8, < 2)
40
+ simplecov (~> 0.10.0)
41
+ term-ansicolor (~> 1.3)
42
+ thor (~> 0.19.1)
43
+ diff-lcs (1.2.5)
44
+ docile (1.1.5)
45
+ domain_name (0.5.24)
46
+ unf (>= 0.0.5, < 1.0.0)
39
47
  erubis (2.7.0)
40
- i18n (0.6.9)
41
- json (1.8.1)
42
- metaclass (0.0.1)
43
- mime-types (1.23)
44
- minitest (5.3.3)
45
- mocha (0.14.0)
46
- metaclass (~> 0.0.1)
47
- multi_json (1.9.2)
48
- rack (1.5.2)
49
- rack-test (0.6.2)
48
+ http-cookie (1.0.2)
49
+ domain_name (~> 0.5)
50
+ i18n (0.7.0)
51
+ json (1.8.3)
52
+ loofah (2.0.2)
53
+ nokogiri (>= 1.5.9)
54
+ mime-types (2.6.1)
55
+ mini_portile (0.6.2)
56
+ minitest (5.7.0)
57
+ netrc (0.10.3)
58
+ nokogiri (1.6.6.2)
59
+ mini_portile (~> 0.6.0)
60
+ rack (1.6.4)
61
+ rack-test (0.6.3)
50
62
  rack (>= 1.0)
51
- railties (4.1.0)
52
- actionpack (= 4.1.0)
53
- activesupport (= 4.1.0)
63
+ rails-deprecated_sanitizer (1.0.3)
64
+ activesupport (>= 4.2.0.alpha)
65
+ rails-dom-testing (1.0.6)
66
+ activesupport (>= 4.2.0.beta, < 5.0)
67
+ nokogiri (~> 1.6.0)
68
+ rails-deprecated_sanitizer (>= 1.0.1)
69
+ rails-html-sanitizer (1.0.2)
70
+ loofah (~> 2.0)
71
+ railties (4.2.3)
72
+ actionpack (= 4.2.3)
73
+ activesupport (= 4.2.3)
54
74
  rake (>= 0.8.7)
55
75
  thor (>= 0.18.1, < 2.0)
56
- rake (10.0.4)
57
- rest-client (1.6.7)
58
- mime-types (>= 1.16)
59
- simplecov (0.7.1)
60
- multi_json (~> 1.0)
61
- simplecov-html (~> 0.7.1)
62
- simplecov-html (0.7.1)
63
- test-unit (2.5.5)
64
- thor (0.18.1)
65
- thread_safe (0.3.3)
66
- tzinfo (1.1.0)
76
+ rake (10.4.2)
77
+ rest-client (1.8.0)
78
+ http-cookie (>= 1.0.2, < 2.0)
79
+ mime-types (>= 1.16, < 3.0)
80
+ netrc (~> 0.7)
81
+ rspec (3.3.0)
82
+ rspec-core (~> 3.3.0)
83
+ rspec-expectations (~> 3.3.0)
84
+ rspec-mocks (~> 3.3.0)
85
+ rspec-core (3.3.2)
86
+ rspec-support (~> 3.3.0)
87
+ rspec-expectations (3.3.1)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.3.0)
90
+ rspec-mocks (3.3.2)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.3.0)
93
+ rspec-rails (3.3.3)
94
+ actionpack (>= 3.0, < 4.3)
95
+ activesupport (>= 3.0, < 4.3)
96
+ railties (>= 3.0, < 4.3)
97
+ rspec-core (~> 3.3.0)
98
+ rspec-expectations (~> 3.3.0)
99
+ rspec-mocks (~> 3.3.0)
100
+ rspec-support (~> 3.3.0)
101
+ rspec-support (3.3.0)
102
+ simplecov (0.10.0)
103
+ docile (~> 1.1.0)
104
+ json (~> 1.8)
105
+ simplecov-html (~> 0.10.0)
106
+ simplecov-html (0.10.0)
107
+ term-ansicolor (1.3.2)
108
+ tins (~> 1.0)
109
+ thor (0.19.1)
110
+ thread_safe (0.3.5)
111
+ tins (1.5.4)
112
+ tzinfo (1.2.2)
67
113
  thread_safe (~> 0.1)
114
+ unf (0.1.4)
115
+ unf_ext
116
+ unf_ext (0.0.7.1)
68
117
 
69
118
  PLATFORMS
70
119
  ruby
@@ -72,7 +121,10 @@ PLATFORMS
72
121
  DEPENDENCIES
73
122
  appraisal
74
123
  coveralls
75
- mocha
76
124
  rake
77
- test-unit
125
+ rspec
126
+ rspec-rails
78
127
  versioncake!
128
+
129
+ BUNDLED WITH
130
+ 1.10.6
data/README.md CHANGED
@@ -29,18 +29,39 @@ Check out https://github.com/bwillis/350-rest-api-versioning for a comparison of
29
29
 
30
30
  ```
31
31
  gem install versioncake
32
+ rails g versioncake:install
32
33
  ```
33
34
 
34
35
  ### Requirements
35
36
 
36
- | Version | Rails 3.2 Support? | Rails 4 Support? | Rails 4.1 Support? | [Rails API](https://github.com/rails-api/rails-api) 0.2 Support? |
37
- | ------- |:---------:| -------:| -------:| -------:|
38
- | [1.0](CHANGELOG.md#100-march-14-2013) | Yes | No | No | No |
39
- | [1.1](CHANGELOG.md#110-may-18-2013) | Yes | No | No | No |
40
- | [1.2](CHANGELOG.md#120-may-26-2013) | Yes | Yes | No | No |
41
- | [1.3](CHANGELOG.md#130-sept-26-2013) | Yes | Yes | No | No |
42
- | [>2.0](CHANGELOG.md#200-feb-6-2014) | Yes | Yes | Yes | No |
43
- | [>2.4](CHANGELOG.md#200-feb-6-2014) | Yes | Yes | Yes | Yes |
37
+ | Version | Rails 3.2 Support? | Rails 4 Support? | Rails >4.1 Support? | Rails >5 Support? | [Rails API](https://github.com/rails-api/rails-api) 0.2 Support? |
38
+ | -------:|:---------:| -------:| -------:| -------:| -------:|
39
+ | [1.0](CHANGELOG.md#100-march-14-2013) | Yes | No | No | No | No |
40
+ | [1.1](CHANGELOG.md#110-may-18-2013) | Yes | No | No | No | No |
41
+ | [1.2](CHANGELOG.md#120-may-26-2013) | Yes | Yes | No | No | No |
42
+ | [1.3](CHANGELOG.md#130-sept-26-2013) | Yes | Yes | No | No | No |
43
+ | [>2.0](CHANGELOG.md#200-feb-6-2014) | Yes | Yes | Yes | No | No |
44
+ | [>2.4](CHANGELOG.md#200-feb-6-2014) | Yes | Yes | Yes | No | Yes |
45
+ | [>3.0](CHANGELOG.md) | Yes | Yes | Yes | Yes | Yes |
46
+
47
+ ## Upgrade v2.0 -> v3.0
48
+
49
+ ### Accept header name changes
50
+
51
+ The default accept header was changed from 'X-API-Version' to 'API-Version'. If you require the 'X-' or some other variant, you can specify a custom strategy as outlined in Extraction Strategy section below.
52
+
53
+ ### Configuration changes
54
+
55
+ Configuration is now done with an initializer-you can generate a default one with `rails g versioncake:install` and then modify the generated file to match your configuration.
56
+
57
+ ### Configuration changes
58
+
59
+ The configuration options for Version Cake have changed:
60
+
61
+ | Old Name | New Name |
62
+ | -------------------------------------------- | ---------------------- |
63
+ | config.versioncake.supported_version_numbers | config.resources |
64
+ | config.versioncake.default_version | config.missing_version |
44
65
 
45
66
  ## Upgrade v1.* -> v2.0
46
67
 
@@ -70,8 +91,13 @@ In this simple example we will outline the code that is introduced to support a
70
91
 
71
92
  ### config/application.rb
72
93
  ```ruby
73
- config.versioncake.supported_version_numbers = (1...4)
74
- config.versioncake.extraction_strategy = :query_parameter # for simplicity
94
+ VersionCake.setup do |config|
95
+ config.resources do |r|
96
+ r.resource %r{.*}, [], [], (1..4)
97
+ end
98
+ config.extraction_strategy = :query_parameter # for simplicity
99
+ config.missing_version = 4
100
+ end
75
101
  ```
76
102
 
77
103
  Often times with APIs, depending upon the version, different logic needs to be applied. With the following controller code, the initial value of @posts includes all Post entries.
@@ -87,7 +113,7 @@ class PostsController < ApplicationController
87
113
  @posts = Post.scoped
88
114
 
89
115
  # version 3 or greated supports embedding post comments
90
- if derived_version >= 3
116
+ if request_version >= 3
91
117
  @posts = @posts.includes(:comments)
92
118
  end
93
119
  end
@@ -160,7 +186,7 @@ For a given request, if we specify the version number, and that version of the v
160
186
  ```
161
187
 
162
188
 
163
- When no version is specified, the latest version of the view is rendered. In this case, views/posts/index.json.v4.jbuilder.
189
+ When no version is specified, the configured `missing_version` will be used to render a view. In this case, views/posts/index.json.v4.jbuilder.
164
190
 
165
191
  #### http://localhost:3000/posts.json
166
192
  ```javascript
@@ -195,20 +221,28 @@ When no version is specified, the latest version of the view is rendered. In th
195
221
  ## How to use
196
222
 
197
223
  ### Configuration
198
- The configuration should be placed in your Rails projects `config/application.rb`. It is also suggested to enable different settings per environment, for example development and test can have extraction strategies that make it easier to develop or write test code.
224
+ The configuration lives in `config/initializers/versioncake.rb`.
199
225
 
200
- #### Supported Versions
201
- You need to define the supported versions in your Rails application.rb file as `view_versions`. Use this config to set the range of supported API versions that can be served:
226
+ #### Versioned Resources
227
+ Each individual resource uri can be identified by a regular expression. For each one it can be customized to have obsolete, deprecated, supported versions.
202
228
 
203
229
  ```ruby
204
- config.versioncake.supported_version_numbers = [1,2,3,4,5] # or (1..5)
230
+ config.resources do |r|
231
+ # r.resource uri_regex, obsolete, deprecated, supported
232
+
233
+ # version 2 and 3 are still supported on users resource
234
+ r.resource %r{/users}, [1], [2,3], [4]
235
+
236
+ # all other resources only allow v4
237
+ r.resource %r{.*}, [1,2,3], [], [4]
238
+ end
205
239
  ```
206
240
 
207
241
  #### Extraction Strategy
208
242
 
209
- You can also define the way to extract the version. The `view_version_extraction_strategy` allows you to set one of the default strategies or provide a proc to set your own. You can also pass it a prioritized array of the strategies.
243
+ You can also define the way to extract the version. The `extraction_strategy` allows you to set one of the default strategies or provide a proc to set your own. You can also pass it a prioritized array of the strategies.
210
244
  ```ruby
211
- config.versioncake.extraction_strategy = :query_parameter # [:http_header, :http_accept_parameter]
245
+ config.extraction_strategy = :query_parameter # [:http_header, :http_accept_parameter]
212
246
  ```
213
247
  These are the available strategies:
214
248
 
@@ -216,8 +250,8 @@ Strategy | Description | Example
216
250
  --- | --- | ---
217
251
  :query_parameter | version in the url query parameter, for testing or to override for special case | `http://localhost:3000/posts.json?api_version=1` (This is the default.)
218
252
  :path_parameter | version in the url path parameter | `api/v:api_version/`
219
- request_parameter | version that is sent in the body of the request | Good for testing.
220
- :http_header | Api version HTTP header | `X-API-Version: 1`
253
+ :request_parameter | version that is sent in the body of the request | Good for testing.
254
+ :http_header | Api version HTTP header | `API-Version: 1`
221
255
  :http_accept_parameter | HTTP Accept header | `Accept: application/xml; version=1` [why do this?](http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http#i_want_my_api_to_be_versioned)
222
256
  custom | takes the request object and must return an integer | lambda {&#124;request&#124; request.headers["HTTP_X_MY_VERSION"].to_i } or class ExtractorStrategy; def execute(request);end;end
223
257
 
@@ -236,14 +270,20 @@ end
236
270
 
237
271
  When no version is supplied by a client, the version rendered will be the latest version by default. If you want to override this to another version, set the following property:
238
272
  ```ruby
239
- config.versioncake.default_version = 4
273
+ config.missing_version = 4
240
274
  ```
241
275
 
242
276
  #### Version String
243
277
 
244
278
  The extraction strategies use a default string key of `api_version`, but that can be changed:
245
279
  ```ruby
246
- config.versioncake.version_key = "special_version_parameter_name"
280
+ config.version_key = "special_version_parameter_name"
281
+ ```
282
+
283
+ #### Version String
284
+ If you do not wish to use the magic mapping of the version number to templates it can be disabled:
285
+ ```ruby
286
+ config.rails_view_versioning = false
247
287
  ```
248
288
 
249
289
  ### Version your views
@@ -273,7 +313,7 @@ def index
273
313
  @posts = Post.scoped
274
314
 
275
315
  # version 3 or greated supports embedding post comments
276
- if derived_version >= 3
316
+ if request_version >= 3
277
317
  @posts = @posts.includes(:comments)
278
318
  end
279
319
  end
@@ -282,9 +322,19 @@ end
282
322
 
283
323
  When a client makes a request it will automatically receive the latest supported version of the view. The client can also request for a specific version by one of the strategies configured by ``view_version_extraction_strategy``.
284
324
 
285
- ### Unsupported Version Requests
325
+ ### Raised exceptions
326
+
327
+ These are the types of exceptions VersionCake will raise:
328
+
329
+ |Exception type|Description|
330
+ |--------------|-----------|
331
+ |VersionCake::UnsupportedVersionError| The version is invalid, too high or too low for the resource.|
332
+ |VersionCake::ObsoleteVersionError|The version is obsolete for the resource.|
333
+ |VersionCake::MissingVersionError|If no `config.missing_version` is specified, this will be raised when no version is in the request.|
334
+
335
+ ### Handling Exceptions
286
336
 
287
- If a client requests a version that is no longer supported (is not included in the `config.versioncake.supported_version_numbers`), a `VersionCake::UnsupportedVersionError` will be raised. This can be handled using Rails `rescue_from` to return app specific messages to the client.
337
+ Handling exceptions can simply be done by using Rails `rescue_from` to return app specific messages to the client.
288
338
 
289
339
  ```ruby
290
340
  class ApplicationController < ActionController::Base
@@ -296,7 +346,7 @@ class ApplicationController < ActionController::Base
296
346
  private
297
347
 
298
348
  def render_unsupported_version
299
- headers['X-API-Version-Supported'] = 'false'
349
+ headers['API-Version-Supported'] = 'false'
300
350
  respond_to do |format|
301
351
  format.json { render json: {message: "You requested an unsupported version (#{requested_version})"}, status: :unprocessable_entity }
302
352
  end
@@ -317,7 +367,7 @@ Testing can be painful but here are some easy ways to test different versions of
317
367
  Allowing more extraction strategies during testing can be helpful when needing to override the version.
318
368
  ```ruby
319
369
  # config/environments/test.rb
320
- config.versioncake.extraction_strategy = [:query_parameter, :request_parameter, :http_header, :http_accept_parameter]
370
+ config.extraction_strategy = [:query_parameter, :request_parameter, :http_header, :http_accept_parameter]
321
371
  ```
322
372
 
323
373
  ### Testing a specific version
@@ -325,7 +375,7 @@ config.versioncake.extraction_strategy = [:query_parameter, :request_parameter,
325
375
  One way to test a specific version for would be to stub the requested version in the before block:
326
376
  ```ruby
327
377
  before do
328
- @controller.stubs(:requested_version).returns(3)
378
+ @controller.stubs(:request_version).returns(3)
329
379
  end
330
380
  ```
331
381
 
@@ -343,7 +393,7 @@ end
343
393
  You can iterate over all of the supported version numbers by accessing the ```AppName::Application.config.versioncake.supported_version_numbers```.
344
394
 
345
395
  ```ruby
346
- AppName::Application.config.versioncake.supported_version_numbers.each do |supported_version|
396
+ VersionCake.config.resources.first.supported_versions.each do |supported_version|
347
397
  before do
348
398
  @controller.stubs(:requested_version).returns(supported_version)
349
399
  end