From 5a5914f5c53742475f7935fd3a1851e14f5f8fb3 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Sun, 1 May 2016 18:21:24 -0400 Subject: [PATCH] Drop backwards-compatibility for Resource.new. Ancient versions of rest-client allowed you to do this: RestClient::Resource.new(url, username, pass) Drop support for this since it was unnecessarily confusing. Instead: RestClient::Resource.new(url, user: username, password: pass) Fixes: #467 --- history.md | 3 +++ lib/restclient/resource.rb | 8 ++------ spec/unit/resource_spec.rb | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/history.md b/history.md index df26956..26edeaf 100644 --- a/history.md +++ b/history.md @@ -77,6 +77,9 @@ This release is largely API compatible, but makes several breaking changes. - Refactor URI parsing to happen earlier, in Request initialization. - When adding URL params, handle URLs that already contain params. - Add a few more exception classes for obscure HTTP status codes. +- Drop ancient backwards compatibility for old Resource initializer. + No longer supported: `RestClient::Resource.new(url, username, pass)` + Instead use: `RestClient::Resource.new(url, user: username, password: pass)` # 2.0.0.rc1 diff --git a/lib/restclient/resource.rb b/lib/restclient/resource.rb index 955f682..08940d5 100644 --- a/lib/restclient/resource.rb +++ b/lib/restclient/resource.rb @@ -36,14 +36,10 @@ module RestClient class Resource attr_reader :url, :options, :block - def initialize(url, options={}, backwards_compatibility=nil, &block) + def initialize(url, options={}, &block) @url = url @block = block - if options.class == Hash - @options = options - else # compatibility with previous versions - @options = { :user => options, :password => backwards_compatibility } - end + @options = options end def get(additional_headers={}, &block) diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 056a8fb..ea5ec26 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -46,10 +46,10 @@ describe RestClient::Resource do @resource = RestClient::Resource.new('http://some/resource') end - it "is backwards compatible with previous constructor" do - @resource = RestClient::Resource.new('http://some/resource', 'user', 'pass') - @resource.user.should eq 'user' - @resource.password.should eq 'pass' + it "is NOT backwards compatible with previous constructor" do + lambda { + @resource = RestClient::Resource.new('http://some/resource', 'user', 'pass') + }.should raise_error(ArgumentError) end it "concatenates urls, inserting a slash when it needs one" do