jnunemaker / httparty

:tada: Makes http fun again!
MIT License
5.81k stars 964 forks source link

Setting `basic_auth` on `Base` doesn't get inherited #276

Closed coreyward closed 9 years ago

coreyward commented 10 years ago

Similar to #83. Setting basic_auth in a Base class and inheriting from it in subclasses does not work. Issue exists in Closeio library:

# as expected:
Closeio::Base.default_options
 => {:base_uri=>"https://app.close.io/api/v1", :basic_auth=>{:username=>"foo", :password=>""}, :headers=>{"Content-Type"=>"application/json"}, :parser=>HTTParty::Parser, :format=>:json} 

# unexpected, as described above:
Closeio::Lead.default_options
 => {:base_uri=>"https://app.close.io/api/v1", :basic_auth=>{:username=>nil, :password=>""}, :headers=>{"Content-Type"=>"application/json"}, :parser=>HTTParty::Parser, :format=>:json} 

Using v0.13.0.

rusikf commented 9 years ago

@coreyward , can you give full steps for reproduce it ? ( Write here full example, which doesn't work )

coreyward commented 9 years ago
  1. Set basic_auth on Base, e.g. Base.default_options.merge! basic_auth: { ... }.
  2. Subclass it, e.g. class Lead < Base
  3. Inspect default_options on subclass, e.g. Lead.default_options.

The default options should follow, but do not.

rusikf commented 9 years ago

@coreyward , I test it, but it works:

require './lib/httparty'
# first example
class Yandex
  include HTTParty
  basic_auth 'rusik', '123'
end

class YandexMoney < Yandex

end  
p Yandex.default_options
p YandexMoney.default_options
p Yandex.default_options == YandexMoney.default_options
# second example
class Google
  include HTTParty
end
Google.default_options.merge! basic_auth: {username: 'john', password: '123'}
class GoogleWallet < Google
end

p Google.default_options
p GoogleWallet.default_options  
p Google.default_options == GoogleWallet.default_options

Output:

/httparty$ pry fun.rb 
{:basic_auth=>{:username=>"rusik", :password=>"123"}}
{:basic_auth=>{:username=>"rusik", :password=>"123"}}
true
{:basic_auth=>{:username=>"john", :password=>"123"}}
{:basic_auth=>{:username=>"john", :password=>"123"}}
true
ruslan@rs3:~/Work/httparty-fun/httparty$ pry fun.rb 
{:basic_auth=>{:username=>"rusik", :password=>"123"}}
{:basic_auth=>{:username=>"rusik", :password=>"123"}}
true
{:basic_auth=>{:username=>"john", :password=>"123"}}
{:basic_auth=>{:username=>"john", :password=>"123"}}
true

@jnunemaker, what you think about it ?

jnunemaker commented 9 years ago

I guess closing until we get something repeatable to prove there is an issue.

coreyward commented 9 years ago

Hmm, I wonder if it isn't a version issue, or perhaps because CloseIO inherits from OpenStruct.