api-versions 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +17 -0
- data/Gemfile +17 -1
- data/README.md +4 -2
- data/api-versions.gemspec +7 -2
- data/lib/api-versions.rb +2 -2
- data/lib/api-versions/dsl.rb +7 -7
- data/lib/api-versions/simplify_format.rb +1 -1
- data/lib/api-versions/version.rb +1 -1
- data/lib/api-versions/version_check.rb +4 -2
- data/lib/generators/api_versions/bump_generator.rb +1 -1
- data/spec/controllers/simplified_format_spec.rb +47 -0
- data/spec/dummy/app/controllers/api/v1/bar_controller.rb +1 -1
- data/spec/dummy/app/controllers/api/v2/bar_controller.rb +1 -1
- data/spec/dummy/app/controllers/api/v2/foo_controller.rb +1 -1
- data/spec/dummy/app/controllers/api/v2/users_controller.rb +1 -1
- data/spec/dummy/app/controllers/api/v3/bar_controller.rb +1 -1
- data/spec/dummy/app/controllers/api/v3/foo_controller.rb +1 -1
- data/spec/dummy/config/application.rb +0 -42
- data/spec/dummy/config/environments/test.rb +0 -21
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/lib/api_versions_spec.rb +9 -0
- data/spec/routing/routing_spec.rb +62 -40
- data/spec/spec_helper.rb +0 -12
- metadata +42 -9
- data/spec/controllers/application_controller_spec.rb +0 -31
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
language: ruby
|
2
|
+
before_install: gem install bundler
|
2
3
|
|
3
4
|
rvm:
|
4
5
|
- 1.9.3
|
@@ -12,3 +13,19 @@ notifications:
|
|
12
13
|
email:
|
13
14
|
recipients:
|
14
15
|
- api-versions@erichmenge.com
|
16
|
+
env:
|
17
|
+
- RAILS_VERSION=3.0.20
|
18
|
+
- RAILS_VERSION=3.1.11
|
19
|
+
- RAILS_VERSION=3.2.12
|
20
|
+
- RAILS_VERSION=3-2-stable
|
21
|
+
- RAILS_VERSION=3-1-stable
|
22
|
+
- RAILS_VERSION=3-0-stable
|
23
|
+
- RAILS_VERSION=master
|
24
|
+
|
25
|
+
matrix:
|
26
|
+
allow_failures:
|
27
|
+
- rvm: 2.0.0
|
28
|
+
- env: RAILS_VERSION=3-2-stable
|
29
|
+
- env: RAILS_VERSION=3-1-stable
|
30
|
+
- env: RAILS_VERSION=3-0-stable
|
31
|
+
- env: RAILS_VERSION=master
|
data/Gemfile
CHANGED
@@ -2,4 +2,20 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in api-versions.gemspec
|
4
4
|
gemspec
|
5
|
-
|
5
|
+
|
6
|
+
case ENV['RAILS_VERSION']
|
7
|
+
when /master/
|
8
|
+
gem "rails", github: "rails/rails"
|
9
|
+
gem "journey", github: "rails/journey"
|
10
|
+
gem "activerecord-deprecated_finders", github: "rails/activerecord-deprecated_finders"
|
11
|
+
when /3-2-stable/
|
12
|
+
gem "rails", github: "rails/rails", branch: "3-2-stable"
|
13
|
+
when /3-1-stable/
|
14
|
+
gem "rails", github: "rails/rails", branch: "3-1-stable"
|
15
|
+
when /3-0-stable/
|
16
|
+
gem "rails", github: "rails/rails", branch: "3-0-stable"
|
17
|
+
else
|
18
|
+
gem "rails", ENV['RAILS_VERSION']
|
19
|
+
end
|
20
|
+
|
21
|
+
gem 'tzinfo'
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# api-versions [![Build Status](https://
|
1
|
+
# api-versions [![Build Status](https://travis-ci.org/erichmenge/api-versions.png?branch=master)](https://travis-ci.org/erichmenge/api-versions) #
|
2
2
|
|
3
3
|
|
4
4
|
#### api-versions is a Gem to help you manage your Rails API endpoints.
|
@@ -71,7 +71,7 @@ In your routes.rb file:
|
|
71
71
|
|
72
72
|
|
73
73
|
Then the client simply sets the Accept header `application/vnd.myvendor+json;version=1`. If no version is specified, the default version you set will be assumed.
|
74
|
-
You'll of course still need to copy all of your controllers over, even if they haven't changed from version to version. At least you'll remove a bit of the mess in your routes file.
|
74
|
+
You'll of course still need to copy all of your controllers over (or bump them automatically, see below), even if they haven't changed from version to version. At least you'll remove a bit of the mess in your routes file.
|
75
75
|
|
76
76
|
A more complicated example:
|
77
77
|
|
@@ -181,6 +181,8 @@ To get around this I suggest creating a base API controller and including ApiVer
|
|
181
181
|
``` ruby
|
182
182
|
class Api::V1::BaseController < ActionController::Base
|
183
183
|
include ApiVersions::SimplifyFormat
|
184
|
+
|
185
|
+
respond_to :json
|
184
186
|
end
|
185
187
|
```
|
186
188
|
|
data/api-versions.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Erich Menge"]
|
9
9
|
s.email = ["erich.menge@me.com"]
|
10
10
|
s.homepage = "https://github.com/erichmenge/api-versions"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "api-versions helps manage your app
|
11
|
+
s.summary = "api-versions helps manage your Rails app API endpoints."
|
12
|
+
s.description = "api-versions helps manage your Rails app API endpoints."
|
13
13
|
|
14
14
|
s.rubyforge_project = "api-versions"
|
15
15
|
|
@@ -18,6 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.required_ruby_version = '>= 1.9'
|
22
|
+
|
23
|
+
s.add_dependency('actionpack', '>= 3.0')
|
24
|
+
s.add_dependency('activesupport', '>= 3.0')
|
25
|
+
|
21
26
|
s.add_development_dependency "rspec-rails", "~> 2.0"
|
22
27
|
s.add_development_dependency 'ammeter', '0.2.5'
|
23
28
|
end
|
data/lib/api-versions.rb
CHANGED
@@ -6,11 +6,11 @@ require "api-versions/simplify_format"
|
|
6
6
|
|
7
7
|
module ApiVersions
|
8
8
|
def api(options = {}, &block)
|
9
|
+
raise "Please set a vendor_string for the api method" if options[:vendor_string].nil?
|
10
|
+
|
9
11
|
VersionCheck.default_version = options[:default_version]
|
10
12
|
VersionCheck.vendor_string = options[:vendor_string]
|
11
13
|
|
12
|
-
raise "Please set a vendor_string for the api method" if options[:vendor_string].nil?
|
13
|
-
|
14
14
|
namespace(:api) { DSL.new(self, &block) }
|
15
15
|
end
|
16
16
|
end
|
data/lib/api-versions/dsl.rb
CHANGED
@@ -4,8 +4,8 @@ module ApiVersions
|
|
4
4
|
|
5
5
|
def initialize(context, &block)
|
6
6
|
@context = context
|
7
|
-
|
8
|
-
instance_eval
|
7
|
+
singleton_class.def_delegators :@context, *(@context.public_methods - public_methods)
|
8
|
+
instance_eval(&block)
|
9
9
|
end
|
10
10
|
|
11
11
|
def version(version_number, &block)
|
@@ -16,16 +16,16 @@ module ApiVersions
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def inherit(
|
20
|
-
Array.wrap(
|
19
|
+
def inherit(options)
|
20
|
+
Array.wrap(options[:from]).each do |block|
|
21
21
|
@resource_cache[block].call
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def cache(
|
25
|
+
def cache(options, &block)
|
26
26
|
@resource_cache ||= {}
|
27
|
-
@resource_cache[
|
28
|
-
|
27
|
+
@resource_cache[options[:as]] = block
|
28
|
+
yield
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -9,7 +9,7 @@ module ApiVersions
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def simplify_format
|
12
|
-
request.headers['Accept'] && request.headers['Accept'].match(/\+\s*(
|
12
|
+
request.headers['Accept'] && request.headers['Accept'].match(/\+\s*(\w+)/) { |m| request.format = m[1] }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/api-versions/version.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module ApiVersions
|
2
2
|
class VersionCheck
|
3
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :default_version, :vendor_string
|
5
|
+
end
|
4
6
|
|
5
7
|
def initialize(args = {})
|
6
8
|
@process_version = args[:version]
|
@@ -13,7 +15,7 @@ module ApiVersions
|
|
13
15
|
private
|
14
16
|
|
15
17
|
def accepts_proper_format?(request)
|
16
|
-
request.headers['Accept'] =~ /\Aapplication\/vnd\.#{self.class.vendor_string}
|
18
|
+
request.headers['Accept'] =~ /\Aapplication\/vnd\.#{self.class.vendor_string}\s*\+\s*.+/
|
17
19
|
end
|
18
20
|
|
19
21
|
def matches_version?(request)
|
@@ -18,7 +18,7 @@ module ApiVersions
|
|
18
18
|
|
19
19
|
def generate_new_controllers
|
20
20
|
@controllers.each do |controller|
|
21
|
-
new_controller = controller.gsub
|
21
|
+
new_controller = controller.gsub(/api\/v#{@highest_version}\//, "api/v#{@highest_version.to_i + 1}/")
|
22
22
|
@current_new_controller = new_controller.chomp(File.extname(controller)).camelize
|
23
23
|
@current_old_controller = controller.chomp(File.extname(controller)).camelize
|
24
24
|
template 'controller.rb', File.join('app', 'controllers', new_controller)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SimplifiedFormat < ActionController::Base
|
4
|
+
include ApiVersions::SimplifyFormat
|
5
|
+
|
6
|
+
def index
|
7
|
+
render nothing: true, status: 200
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe SimplifiedFormat do
|
12
|
+
describe "simplify format" do
|
13
|
+
after { request.format.should == 'application/json' }
|
14
|
+
|
15
|
+
it "should set the format" do
|
16
|
+
request.env['Accept'] = 'application/vnd.myvendor+json;version=1'
|
17
|
+
get :index
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set the format when there is no version specified" do
|
21
|
+
request.env['Accept'] = 'application/vnd.myvendor+json'
|
22
|
+
get :index
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the format with spaces" do
|
26
|
+
request.env['Accept'] = 'application/vnd.myvendor + json ; version = 1'
|
27
|
+
get :index
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the format with spaces and no version" do
|
31
|
+
request.env['Accept'] = 'application/vnd.myvendor + json'
|
32
|
+
get :index
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the header is not set" do
|
37
|
+
it "should be successful" do
|
38
|
+
get :index
|
39
|
+
response.should be_success
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not change the format" do
|
43
|
+
get :index
|
44
|
+
request.format.should == "text/html"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Api::V1::BarController <
|
1
|
+
class Api::V1::BarController < ActionController::Base
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Api::V2::FooController <
|
1
|
+
class Api::V2::FooController < ActionController::Base
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Api::V2::UsersController <
|
1
|
+
class Api::V2::UsersController < ActionController::Base
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Api::V3::BarController <
|
1
|
+
class Api::V3::BarController < ActionController::Base
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Api::V3::FooController <
|
1
|
+
class Api::V3::FooController < ActionController::Base
|
2
2
|
end
|
@@ -1,54 +1,12 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
# Pick the frameworks you want:
|
4
2
|
require "action_controller/railtie"
|
5
|
-
# require "rails/test_unit/railtie"
|
6
3
|
|
7
4
|
Bundler.require
|
8
5
|
require "api-versions"
|
9
6
|
|
10
7
|
module Dummy
|
11
8
|
class Application < Rails::Application
|
12
|
-
# Settings in config/environments/* take precedence over those specified here.
|
13
|
-
# Application configuration should go into files in config/initializers
|
14
|
-
# -- all .rb files in that directory are automatically loaded.
|
15
|
-
|
16
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
17
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
18
|
-
|
19
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
20
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
21
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
22
|
-
|
23
|
-
# Activate observers that should always be running.
|
24
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
25
|
-
|
26
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
27
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
28
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
29
|
-
|
30
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
31
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
32
|
-
# config.i18n.default_locale = :de
|
33
|
-
|
34
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
35
9
|
config.encoding = "utf-8"
|
36
|
-
|
37
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
38
|
-
config.filter_parameters += [:password]
|
39
|
-
|
40
|
-
# Enable escaping HTML in JSON.
|
41
|
-
config.active_support.escape_html_entities_in_json = true
|
42
|
-
|
43
|
-
# Use SQL instead of Active Record's schema dumper when creating the database.
|
44
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
45
|
-
# like if you have constraints or database-specific column types
|
46
|
-
# config.active_record.schema_format = :sql
|
47
|
-
|
48
|
-
# Enforce whitelist mode for mass assignment.
|
49
|
-
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
50
|
-
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
51
|
-
# parameters by using an attr_accessible or attr_protected declaration.
|
52
10
|
end
|
53
11
|
end
|
54
12
|
|
@@ -1,29 +1,8 @@
|
|
1
1
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The test environment is used exclusively to run your application's
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
2
|
config.cache_classes = true
|
9
|
-
|
10
|
-
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.serve_static_assets = true
|
12
|
-
config.static_cache_control = "public, max-age=3600"
|
13
|
-
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
3
|
config.whiny_nils = true
|
16
|
-
|
17
|
-
# Show full error reports and disable caching
|
18
4
|
config.consider_all_requests_local = true
|
19
5
|
config.action_controller.perform_caching = false
|
20
|
-
|
21
|
-
# Raise exceptions instead of rendering exception templates
|
22
6
|
config.action_dispatch.show_exceptions = false
|
23
|
-
|
24
|
-
# Disable request forgery protection in test environment
|
25
|
-
config.action_controller.allow_forgery_protection = false
|
26
|
-
|
27
|
-
# Print deprecation notices to the stderr
|
28
7
|
config.active_support.deprecation = :stderr
|
29
8
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ApiVersions do
|
4
|
+
let(:testclass) { Class.new.extend ApiVersions }
|
5
|
+
|
6
|
+
it "should raise if no vendor string is provided" do
|
7
|
+
expect { testclass.api }.to raise_exception(RuntimeError, 'Please set a vendor_string for the api method')
|
8
|
+
end
|
9
|
+
end
|
@@ -7,39 +7,24 @@ describe 'API Routing' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "V1" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
it "should not route something from V2" do
|
11
|
+
merge_and_stub new_api_foo_path, 'get', 'Accept' => 'application/vnd.myvendor+json;version=1'
|
12
|
+
expect(get: new_api_foo_path).to_not be_routable
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
expect(get: '/api/bar/new').to_not be_routable
|
20
|
-
end
|
15
|
+
it "should route" do
|
16
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json;version=1'
|
17
|
+
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should route" do
|
30
|
-
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json;version=1'
|
31
|
-
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should default" do
|
35
|
-
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json'
|
36
|
-
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
37
|
-
end
|
20
|
+
it "should default" do
|
21
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json'
|
22
|
+
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
23
|
+
end
|
38
24
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
25
|
+
it "should default with nothing after the semi-colon" do
|
26
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json; '
|
27
|
+
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
43
28
|
end
|
44
29
|
end
|
45
30
|
|
@@ -76,24 +61,61 @@ describe 'API Routing' do
|
|
76
61
|
end
|
77
62
|
|
78
63
|
describe "Header syntax" do
|
79
|
-
|
80
|
-
|
81
|
-
|
64
|
+
context "when valid" do
|
65
|
+
after(:each) do
|
66
|
+
expect(get: new_api_bar_path).to route_to(controller: 'api/v1/bar', action: 'new')
|
67
|
+
end
|
82
68
|
|
83
|
-
|
84
|
-
|
85
|
-
|
69
|
+
context "the semi-colon" do
|
70
|
+
it "should allow spaces after" do
|
71
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json; version=1'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow spaces before" do
|
75
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor + xml ;version=1'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should allow spaces around" do
|
79
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor + xml ; version=1'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "the equal sign" do
|
84
|
+
it "should allow spacing before" do
|
85
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json; version =1'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should allow spacing after" do
|
89
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json; version= 1'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should allow spacing around" do
|
93
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+json; version = 1'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "the plus sign" do
|
98
|
+
it "should allow spacing before" do
|
99
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor +xml; version=1'
|
100
|
+
end
|
86
101
|
|
87
|
-
|
88
|
-
|
102
|
+
it "should allow spacing after" do
|
103
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor+ xml; version=1'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow spacing around" do
|
107
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.myvendor +xml; version=1'
|
108
|
+
end
|
109
|
+
end
|
89
110
|
end
|
90
111
|
|
91
|
-
it "should
|
92
|
-
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.
|
112
|
+
it "should not route when invalid" do
|
113
|
+
merge_and_stub new_api_bar_path, 'get', 'Accept' => 'application/vnd.garbage+xml;version=1'
|
114
|
+
expect(get: new_api_bar_path).to_not route_to(controller: 'api/v1/bar', action: 'new')
|
93
115
|
end
|
94
116
|
|
95
|
-
it "should
|
96
|
-
|
117
|
+
it "should not route when no header is specified" do
|
118
|
+
expect(get: new_api_bar_path).to_not be_routable
|
97
119
|
end
|
98
120
|
end
|
99
121
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
1
|
ENV["RAILS_ENV"] ||= 'test'
|
3
2
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
3
|
require 'rspec/rails'
|
5
4
|
require 'rspec/autorun'
|
6
5
|
require 'ammeter/init'
|
7
6
|
|
8
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
-
# in spec/support/ and its subdirectories.
|
10
7
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
11
8
|
|
12
9
|
RSpec.configure do |config|
|
13
|
-
|
14
|
-
# If true, the base class of anonymous controllers will be inferred
|
15
|
-
# automatically. This will be the default behavior in future versions of
|
16
|
-
# rspec-rails.
|
17
10
|
config.infer_base_class_for_anonymous_controllers = true
|
18
|
-
|
19
|
-
# Run specs in random order to surface order dependencies. If you find an
|
20
|
-
# order dependency and want to debug it, you can fix the order by providing
|
21
|
-
# the seed, which is printed after each run.
|
22
|
-
# --seed 1234
|
23
11
|
config.order = "random"
|
24
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.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: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
14
46
|
- !ruby/object:Gem::Dependency
|
15
47
|
name: rspec-rails
|
16
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,7 +75,7 @@ dependencies:
|
|
43
75
|
- - '='
|
44
76
|
- !ruby/object:Gem::Version
|
45
77
|
version: 0.2.5
|
46
|
-
description: api-versions helps manage your app
|
78
|
+
description: api-versions helps manage your Rails app API endpoints.
|
47
79
|
email:
|
48
80
|
- erich.menge@me.com
|
49
81
|
executables: []
|
@@ -51,6 +83,7 @@ extensions: []
|
|
51
83
|
extra_rdoc_files: []
|
52
84
|
files:
|
53
85
|
- .gitignore
|
86
|
+
- .rspec
|
54
87
|
- .travis.yml
|
55
88
|
- Gemfile
|
56
89
|
- License.txt
|
@@ -64,7 +97,7 @@ files:
|
|
64
97
|
- lib/api-versions/version_check.rb
|
65
98
|
- lib/generators/api_versions/bump_generator.rb
|
66
99
|
- lib/generators/api_versions/templates/controller.rb
|
67
|
-
- spec/controllers/
|
100
|
+
- spec/controllers/simplified_format_spec.rb
|
68
101
|
- spec/dummy/app/controllers/api/v1/bar_controller.rb
|
69
102
|
- spec/dummy/app/controllers/api/v2/bar_controller.rb
|
70
103
|
- spec/dummy/app/controllers/api/v2/foo_controller.rb
|
@@ -72,7 +105,6 @@ files:
|
|
72
105
|
- spec/dummy/app/controllers/api/v3/bar_controller.rb
|
73
106
|
- spec/dummy/app/controllers/api/v3/foo_controller.rb
|
74
107
|
- spec/dummy/app/controllers/api/v3/nests/nested_controller.rb
|
75
|
-
- spec/dummy/app/controllers/application_controller.rb
|
76
108
|
- spec/dummy/config.ru
|
77
109
|
- spec/dummy/config/application.rb
|
78
110
|
- spec/dummy/config/boot.rb
|
@@ -81,6 +113,7 @@ files:
|
|
81
113
|
- spec/dummy/config/routes.rb
|
82
114
|
- spec/dummy/log/.gitkeep
|
83
115
|
- spec/generators/bump_generator_spec.rb
|
116
|
+
- spec/lib/api_versions_spec.rb
|
84
117
|
- spec/routing/routing_spec.rb
|
85
118
|
- spec/spec_helper.rb
|
86
119
|
homepage: https://github.com/erichmenge/api-versions
|
@@ -94,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
127
|
requirements:
|
95
128
|
- - ! '>='
|
96
129
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
130
|
+
version: '1.9'
|
98
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
132
|
none: false
|
100
133
|
requirements:
|
@@ -106,9 +139,9 @@ rubyforge_project: api-versions
|
|
106
139
|
rubygems_version: 1.8.23
|
107
140
|
signing_key:
|
108
141
|
specification_version: 3
|
109
|
-
summary:
|
142
|
+
summary: api-versions helps manage your Rails app API endpoints.
|
110
143
|
test_files:
|
111
|
-
- spec/controllers/
|
144
|
+
- spec/controllers/simplified_format_spec.rb
|
112
145
|
- spec/dummy/app/controllers/api/v1/bar_controller.rb
|
113
146
|
- spec/dummy/app/controllers/api/v2/bar_controller.rb
|
114
147
|
- spec/dummy/app/controllers/api/v2/foo_controller.rb
|
@@ -116,7 +149,6 @@ test_files:
|
|
116
149
|
- spec/dummy/app/controllers/api/v3/bar_controller.rb
|
117
150
|
- spec/dummy/app/controllers/api/v3/foo_controller.rb
|
118
151
|
- spec/dummy/app/controllers/api/v3/nests/nested_controller.rb
|
119
|
-
- spec/dummy/app/controllers/application_controller.rb
|
120
152
|
- spec/dummy/config.ru
|
121
153
|
- spec/dummy/config/application.rb
|
122
154
|
- spec/dummy/config/boot.rb
|
@@ -125,5 +157,6 @@ test_files:
|
|
125
157
|
- spec/dummy/config/routes.rb
|
126
158
|
- spec/dummy/log/.gitkeep
|
127
159
|
- spec/generators/bump_generator_spec.rb
|
160
|
+
- spec/lib/api_versions_spec.rb
|
128
161
|
- spec/routing/routing_spec.rb
|
129
162
|
- spec/spec_helper.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class ApplicationController < ActionController::Base
|
4
|
-
include ApiVersions::SimplifyFormat
|
5
|
-
|
6
|
-
def index
|
7
|
-
render nothing: true, status: 200
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe ApplicationController do
|
12
|
-
describe "simplify format" do
|
13
|
-
it "should set the format" do
|
14
|
-
request.env['Accept'] = 'application/vnd.myvendor+json;version=1'
|
15
|
-
get :index
|
16
|
-
request.format.should == 'application/json'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when the header is not set" do
|
21
|
-
it "should be successful" do
|
22
|
-
get :index
|
23
|
-
response.should be_success
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not change the format" do
|
27
|
-
get :index
|
28
|
-
request.format.should == "text/html"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|