Skip to content

Commit 6e442b3

Browse files
authored
Merge pull request #18 from RadiusNetworks/rails5
Relax Rails version requirement to allow for 5
2 parents 3ed6b30 + d972871 commit 6e442b3

File tree

10 files changed

+42
-24
lines changed

10 files changed

+42
-24
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ cache: bundler
44
sudo: false
55
script: bin/rake
66
rvm:
7-
- 2.1
8-
- 2.2
7+
- 2.3.1

app/controllers/kracken/application_controller.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/controllers/kracken/sessions_controller.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
module Kracken
2-
class SessionsController < ApplicationController
3-
skip_before_filter :authenticate_user!, except: [:index]
4-
skip_before_filter :handle_user_cache_cookie!, except: [:index]
5-
6-
def index
7-
end
2+
class SessionsController < ActionController::Base
83

94
def create
105
@user = user_class.find_or_create_from_auth_hash(auth_hash)

kracken.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Gem::Specification.new do |s|
1515

1616
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
1717

18-
s.add_dependency 'rails', '~> 4.0'
18+
s.add_dependency 'rails', [">= 4.0", "< 6.0"]
1919
s.add_dependency 'omniauth', '~> 1.0'
2020
s.add_dependency 'faraday', '~> 0.8'
2121
s.add_dependency 'omniauth-oauth2', '~> 1.1'
2222

23-
s.add_development_dependency 'rspec-rails', '~> 3.4'
23+
s.add_development_dependency 'rspec-rails', '~> 3.5'
2424
s.add_development_dependency 'pry'
2525
s.add_development_dependency 'pry-nav'
2626
s.add_development_dependency 'webmock'

lib/kracken/controllers/json_api_compatible.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ def verify_required_params(options = {})
7474
end
7575
end
7676

77+
def self.included(base)
78+
base.instance_exec do
79+
extend Macros
80+
81+
before_action :munge_chained_param_ids!
82+
end
83+
end
84+
7785
module DataIntegrity
7886
# Scan each item in the data root and enforce it has an id set.
7987
def enforce_resource_ids!
@@ -118,7 +126,7 @@ def self.included(base)
118126
extend Macros
119127

120128
before_action :munge_chained_param_ids!
121-
skip_before_action :verify_authenticity_token
129+
skip_before_action :verify_authenticity_token, raise: false
122130

123131
if defined?(::ActiveRecord)
124132
rescue_from ::ActiveRecord::RecordNotFound do |error|

lib/kracken/controllers/token_authenticatable.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ def self.included(base)
1515

1616
# Customize the `authenticate_or_request_with_http_token` process:
1717
# http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token/ControllerMethods.html#method-i-request_http_token_authentication
18-
def request_http_token_authentication(realm = 'Application')
19-
# Modified from https://github.com/rails/rails/blob/60d0aec7/actionpack/lib/action_controller/metal/http_authentication.rb#L490-L499
20-
headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}")
21-
raise TokenUnauthorized, "Invalid Credentials"
18+
#
19+
# Modified from https://github.com/rails/rails/blob/60d0aec7/actionpack/lib/action_controller/metal/http_authentication.rb#L490-L499
20+
if Rails::VERSION::MAJOR >= 5
21+
def request_http_token_authentication(realm = 'Application', message = nil)
22+
headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}")
23+
raise TokenUnauthorized, "Invalid Credentials"
24+
end
25+
else
26+
def request_http_token_authentication(realm = 'Application')
27+
headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}")
28+
raise TokenUnauthorized, "Invalid Credentials"
29+
end
2230
end
2331

2432
private

spec/dummy/app/controllers/welcome_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class WelcomeController < ApplicationController
2-
skip_before_filter :authenticate_user!, only: [:index]
2+
skip_before_action :authenticate_user!, only: [:index]
33

44
def index
55
end

spec/dummy/config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# config.action_dispatch.rack_cache = true
2121

2222
# Disable Rails's static asset server (Apache or nginx will already do this).
23-
config.serve_static_files = false
23+
config.public_file_server.enabled = false
2424

2525
# Compress JavaScripts and CSS.
2626
config.assets.js_compressor = :uglifier

spec/dummy/config/environments/test.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
config.eager_load = false
1515

1616
# Configure static asset server for tests with Cache-Control for performance.
17-
config.serve_static_files = true
18-
config.static_cache_control = "public, max-age=3600"
17+
if config.respond_to? :public_file_server
18+
# Hot new Rails 5 Settings
19+
config.public_file_server.enabled = true
20+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
21+
else
22+
# Deprecated Rails 4 Settings
23+
config.serve_static_files = true
24+
config.static_cache_control = "public, max-age=3600"
25+
end
1926

2027
# Show full error reports and disable caching.
2128
config.consider_all_requests_local = true

spec/requests/api_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def headers_with_token(token)
1818
stub_request(:get, "https://account.radiusnetworks.com/auth/radius/user.json?oauth_token=123")
1919
.to_return(status: 200, body: json)
2020

21-
get api_index_path, nil, headers_with_token("123")
21+
# Temporary work around while we support versions of Rails before 4
22+
if Rails::VERSION::MAJOR >= 5
23+
get api_index_path, params: {}, headers: headers_with_token("123")
24+
else
25+
get api_index_path, {}, headers_with_token("123")
26+
end
2227

2328
expect(response.status).to be 200
2429
end

0 commit comments

Comments
 (0)