forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams_hash_spec.rb
More file actions
97 lines (71 loc) · 2.23 KB
/
params_hash_spec.rb
File metadata and controls
97 lines (71 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# encoding: utf-8
require 'spec_helper'
RSpec.describe Github::ParamsHash do
let(:object) { described_class }
subject(:params) { object.new(hash) }
context 'when empty' do
let(:hash) { {} }
it { expect(params.options).to eq({:raw => false}) }
it { expect(params.data).to eq({}) }
it { expect(params.accept).to eq(nil) }
end
context 'converts key to string' do
let(:hash) { {foo: 123 } }
it { expect(params['foo']).to eql(123) }
it { expect(params.data).to eql({"foo" => 123}) }
end
context 'media' do
let(:hash) { {media: "raw"} }
it 'parses media key' do
expect(params.media).to eql('application/vnd.github.v3.raw+json')
end
end
context 'with accept' do
let(:hash) { {accept: "application/json"} }
it 'overwrites media key' do
expect(params.accept).to eql('application/json')
expect(params.to_hash).to eq({'accept' => 'application/json'})
end
end
context 'without accept' do
let(:hash) { {} }
it 'overwrites media key' do
expect(params.accept).to be_nil
end
end
context 'when data' do
let(:hash) { {data: 'foobar'} }
it 'extracts data key' do
expect(params.data).to eql('foobar')
expect(params.to_hash).to eql({'data' => 'foobar'})
end
end
context 'when content_type' do
let(:hash) { {content_type: 'application/octet-stream'} }
it 'extracts content_type key' do
expect(params.options[:headers]).to eql(hash)
end
end
context 'when header' do
let(:hash) { {headers: {"X-GitHub-OTP" => "<2FA token>"}} }
it "sets headers" do
expect(params.options[:headers]).to eql({"X-GitHub-OTP" => "<2FA token>" })
end
end
context 'merges defaults' do
let(:hash) { { :homepage => "https://tty.github.io" }}
let(:defaults) {
{ "homepage" => "https://github.com",
"private" => false}
}
it 'correctly updates values' do
subject.merge_default(defaults)
expect(params['homepage']).to eql("https://tty.github.io")
expect(params['private']).to be_false
end
end
context 'strict encode' do
let(:hash) { {content: "puts 'hello ruby'"} }
it { expect(params.strict_encode64('content')).to eql('cHV0cyAnaGVsbG8gcnVieSc=') }
end
end