e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksarequire 'spec_helper'
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksadescribe Hets::HetsOptions do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:options) { {key1: 'value1', key2: 'value2'} }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'initialize' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'sets options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(Hets::HetsOptions.new(options).options).to eq(options)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'removes nil valued options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa options_new = {**options, key3: nil}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(Hets::HetsOptions.new(options_new).options).to eq(options)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'from_hash' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'sets options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa hash = {'options' => options}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(Hets::HetsOptions.from_hash(hash).options).to eq(options)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'removes nil valued options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa options_new = {**options, key3: nil}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa hash = {'options' => options_new}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(Hets::HetsOptions.from_hash(hash).options).to eq(options)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'add' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:hets_options) { Hets::HetsOptions.new(options) }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:additional_options) { {key3: 'value3', key4: 'value4'} }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'adds options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa hets_options.add(additional_options)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(hets_options.options).to eq(options.merge(additional_options))
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it 'removes nil valued options' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa additional_options_new = {**additional_options, key5: nil}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa hets_options.add(additional_options_new)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(hets_options.options).to eq(options.merge(additional_options))
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa context 'access token' do
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa context 'access token is nil' do
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa let(:access_token_options) { {**options, :'access-token' => nil} }
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa let(:hets_options) { Hets::HetsOptions.new(access_token_options) }
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa it 'has no access token key' do
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa expect(hets_options.options.has_key?(:'access-token')).to be(false)
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa context 'access token exists' do
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa let(:access_token) { create :access_token }
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa let(:access_token_options) { {**options, :'access-token' => access_token} }
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa let(:hets_options) { Hets::HetsOptions.new(access_token_options) }
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa it 'has the correct access token' do
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa expect(hets_options.options[:'access-token']).to eq(access_token.to_s)
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'url-catalog' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'empty' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:catalog_options) { {**options, :'url-catalog' => %w()} }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:hets_options) { Hets::HetsOptions.new(catalog_options) }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it "removes the key :'url-catalog'" do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(hets_options.options.has_key?(:'url-catalog')).to be(false)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'only with nil values' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:catalog_options) { {**options, :'url-catalog' => [nil, nil]} }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:hets_options) { Hets::HetsOptions.new(catalog_options) }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it "removes the key :'url-catalog'" do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa expect(hets_options.options.has_key?(:'url-catalog')).to be(false)
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'with a nil value' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:catalog_options) do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa {**options, :'url-catalog' => ['a=b', nil, 'c=d']}
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:hets_options) { Hets::HetsOptions.new(catalog_options) }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it "removes the nil value from :'url-catalog'" do
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa expect(hets_options.options[:'url-catalog']).to eq('a=b,c=d')
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa context 'without nil values' do
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:catalog_options) { {**options, :'url-catalog' => %w(a=b c=d)} }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa let(:hets_options) { Hets::HetsOptions.new(catalog_options) }
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa it "has the same :'url-catalog'" do
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa expect(hets_options.options[:'url-catalog']).to eq('a=b,c=d')
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksa end
e3aacba5227cf71454ef8b00910650c3dbb9927dEugen Kuksaend