diff --git a/.travis.yml b/.travis.yml index 59d4585..a1dfbfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ rvm: - "2.0" - "2.1" - "2.2" + - "2.3" + - "2.4" + - "2.5" env: - RAILS_VERSION="" - RAILS_VERSION="~>3.2.0" @@ -13,6 +16,9 @@ env: - RAILS_VERSION="~>4.0.0" - RAILS_VERSION="~>4.1.0" - RAILS_VERSION="~>4.2.0" + - RAILS_VERSION="~>5.0.0" + - RAILS_VERSION="~>5.1.0" + - RAILS_VERSION="~>5.2.0" - RAILS_VERSION="" MONETA_VERSION="~> 0.6.0" - RAILS_VERSION="" MONETA_VERSION="~> 0.7.0" notifications: diff --git a/lib/rocket_pants/base.rb b/lib/rocket_pants/base.rb index f64784d..f5becdc 100644 --- a/lib/rocket_pants/base.rb +++ b/lib/rocket_pants/base.rb @@ -15,11 +15,9 @@ class Base < ActionController::Metal end MODULES = [ - ActionController::HideActions, ActionController::UrlFor, ActionController::Redirecting, ActionController::ConditionalGet, - ActionController::RackDelegation, record_identifier_klass, ActionController::HttpAuthentication::Basic::ControllerMethods, ActionController::HttpAuthentication::Digest::ControllerMethods, diff --git a/lib/rocket_pants/controller/format_verification.rb b/lib/rocket_pants/controller/format_verification.rb index 84f50ea..c020d2c 100644 --- a/lib/rocket_pants/controller/format_verification.rb +++ b/lib/rocket_pants/controller/format_verification.rb @@ -3,7 +3,7 @@ module FormatVerification extend ActiveSupport::Concern included do - before_filter :ensure_has_valid_format + before_action :ensure_has_valid_format end private @@ -13,4 +13,4 @@ def ensure_has_valid_format end end -end \ No newline at end of file +end diff --git a/lib/rocket_pants/controller/jsonp.rb b/lib/rocket_pants/controller/jsonp.rb index 0459ca8..fe74cdc 100644 --- a/lib/rocket_pants/controller/jsonp.rb +++ b/lib/rocket_pants/controller/jsonp.rb @@ -43,8 +43,8 @@ def wrap_response_in_jsonp # Finally, set up the callback using the JSONP parameter. response.content_type = 'application/javascript' response.body = "#{jsonp_parameter}(#{response.body});" - headers['Content-Length'] = Rack::Utils.bytesize(response.body).to_s + headers['Content-Length'] = (response.body.bytesize).to_s end end -end \ No newline at end of file +end diff --git a/lib/rocket_pants/controller/rescuable.rb b/lib/rocket_pants/controller/rescuable.rb index 1c9d9ac..d04562e 100644 --- a/lib/rocket_pants/controller/rescuable.rb +++ b/lib/rocket_pants/controller/rescuable.rb @@ -23,7 +23,13 @@ module Rescuable end }, :bugsnag => lambda { |controller, exception, request| - controller.send(:notify_bugsnag, exception, request: request) + if controller.respond_to?(:notify_bugsnag, true) + controller.send(:notify_bugsnag, exception, request: request) + else + # Bugsnag v6 removed #notify_bugsnag controller method + # Use #notify directly + Bugsnag.notify(exception) + end } } diff --git a/lib/rocket_pants/controller/respondable.rb b/lib/rocket_pants/controller/respondable.rb index 6b6476e..c203a61 100644 --- a/lib/rocket_pants/controller/respondable.rb +++ b/lib/rocket_pants/controller/respondable.rb @@ -123,9 +123,9 @@ def render_json(json, options = {}) json = encode_to_json(json) unless json.respond_to?(:to_str) # Encode the object to json. self.status ||= :ok - self.content_type ||= Mime::JSON + self.content_type ||= Mime[:json] self.response_body = json - headers['Content-Length'] = Rack::Utils.bytesize(json).to_s + headers['Content-Length'] = (json.bytesize).to_s end # Renders a raw object, without any wrapping etc. @@ -227,4 +227,4 @@ def metadata_for(object, options, type, singular) end end -end \ No newline at end of file +end diff --git a/lib/rocket_pants/controller/versioning.rb b/lib/rocket_pants/controller/versioning.rb index 24eeff6..fa5bfb6 100644 --- a/lib/rocket_pants/controller/versioning.rb +++ b/lib/rocket_pants/controller/versioning.rb @@ -12,7 +12,7 @@ module ClassMethods def version(version) version = version..version if version.is_a?(Integer) self._version_range = version - before_filter :verify_api_version + before_action :verify_api_version end end diff --git a/lib/rocket_pants/railtie.rb b/lib/rocket_pants/railtie.rb index 9cb91fa..0fcee75 100644 --- a/lib/rocket_pants/railtie.rb +++ b/lib/rocket_pants/railtie.rb @@ -7,7 +7,7 @@ class Railtie < Rails::Railtie config.rocket_pants.pass_through_errors = nil config.rocket_pants.pass_through_errors = nil - config.i18n.railties_load_path << File.expand_path('../locale/en.yml', __FILE__) + config.i18n.load_path << File.expand_path('../locale/en.yml', __FILE__) initializer "rocket_pants.logger" do ActiveSupport.on_load(:rocket_pants) { self.logger ||= Rails.logger } @@ -39,7 +39,12 @@ class Railtie < Rails::Railtie initializer "rocket_pants.setup_caching" do |app| if RocketPants.caching_enabled? - app.middleware.insert 'Rack::Runtime', RocketPants::CacheMiddleware + run_time_middleware = if Rails::VERSION::MAJOR >= 5 + Rack::Runtime + else + "Rack::Runtime" + end + app.middleware.insert run_time_middleware, RocketPants::CacheMiddleware end end @@ -54,4 +59,4 @@ class Railtie < Rails::Railtie end end -end \ No newline at end of file +end diff --git a/lib/rocket_pants/test_helper.rb b/lib/rocket_pants/test_helper.rb index 1ecb6eb..06bf963 100644 --- a/lib/rocket_pants/test_helper.rb +++ b/lib/rocket_pants/test_helper.rb @@ -9,9 +9,6 @@ module TestHelper # Extend the response on first include. class_attribute :_default_version - unless ActionController::TestResponse < ResponseHelper - ActionController::TestResponse.send :include, ResponseHelper - end unless ActionDispatch::TestResponse < ResponseHelper ActionDispatch::TestResponse.send :include, ResponseHelper @@ -90,21 +87,30 @@ def insert_action_controller_testing_into_base # Like process, but automatically adds the api version. def process(action, *args) - insert_action_controller_testing_into_base - # Rails 4 changes the method signature. In rails 3, parameters is the first argument. - # In Rails 4, it's the second. - if args.first.is_a?(String) - parameters = (args[1] ||= {}) + if Rails::VERSION::MAJOR <= 4 + # Rails 4 changes the method signature. In rails 3, parameters is the first argument. + # In Rails 4, it's the second. + if args.first.is_a?(String) + parameters = (args[1] ||= {}) + else + parameters = (args[0] ||= {}) + end else parameters = (args[0] ||= {}) end response.recycle_cached_body! - if _default_version.present? && parameters[:version].blank? && parameters['version'].blank? - parameters[:version] = _default_version + if Rails::VERSION::MAJOR <= 4 + if _default_version.present? && parameters[:version].blank? && parameters['version'].blank? + parameters[:version] = _default_version + end + else + if _default_version.present? && parameters[:params][:version].blank? + parameters[:params][:version] = _default_version + end end super action, *args diff --git a/rocket_pants.gemspec b/rocket_pants.gemspec index 302529a..edbc764 100644 --- a/rocket_pants.gemspec +++ b/rocket_pants.gemspec @@ -13,21 +13,21 @@ Gem::Specification.new do |s| s.description = "Rocket Pants adds JSON API love to Rails and ActionController, making it simpler to build API-oriented controllers." s.required_rubygems_version = ">= 1.3.6" - s.add_dependency 'actionpack', '>= 3.0', '< 5.0' - s.add_dependency 'railties', '>= 3.0', '< 5.0' + s.add_dependency 'actionpack', '>= 3.0', '< 6.0' + s.add_dependency 'railties', '>= 3.0', '< 6.0' s.add_dependency 'will_paginate', '~> 3.0' - s.add_dependency 'hashie', '>= 1.0', '< 3' + s.add_dependency 'hashie', '>= 1.0', '< 4' s.add_dependency 'api_smith' s.add_dependency 'moneta' s.add_development_dependency 'rspec', '>= 2.4', '< 4.0' s.add_development_dependency 'rspec-rails', '>= 2.4', '< 4.0' s.add_development_dependency 'rr', '~> 1.0' s.add_development_dependency 'webmock' - s.add_development_dependency 'activerecord', '>= 3.0', '< 5.0' + s.add_development_dependency 'activerecord', '>= 3.0', '< 6.0' s.add_development_dependency 'sqlite3' s.add_development_dependency 'reversible_data', '~> 1.0' s.add_development_dependency 'kaminari' s.files = Dir.glob("{lib}/**/*") s.require_path = 'lib' -end \ No newline at end of file +end diff --git a/spec/rocket_pants/controller/error_handling_spec.rb b/spec/rocket_pants/controller/error_handling_spec.rb index 9563650..8d23c64 100644 --- a/spec/rocket_pants/controller/error_handling_spec.rb +++ b/spec/rocket_pants/controller/error_handling_spec.rb @@ -75,6 +75,9 @@ before :each do controller_class.use_named_exception_notifier :bugsnag stub.instance_of(controller_class).notify_bugsnag {} + Bugsnag = Class.new do + define_singleton_method(:notify) { |exception| } + end end it 'should send notification when it is the named exception notifier' do diff --git a/spec/rocket_pants/controller_spec.rb b/spec/rocket_pants/controller_spec.rb index b6cd677..a15a8f2 100644 --- a/spec/rocket_pants/controller_spec.rb +++ b/spec/rocket_pants/controller_spec.rb @@ -410,7 +410,7 @@ def object.serializable_hash(*); {:serialised => true}; end get :echo, :echo => "Hello World", :callback => "test" response.content_type.should include 'application/javascript' response.body.should == %|test({"response":{"echo":"Hello World"}});| - response.headers['Content-Length'].to_i.should == Rack::Utils.bytesize(response.body) + response.headers['Content-Length'].to_i.should == response.body.bytesize end end @@ -436,4 +436,4 @@ def object.serializable_hash(*); {:serialised => true}; end end -end \ No newline at end of file +end