tankard 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/.travis.yml +41 -4
- data/CHANGELOG.md +8 -1
- data/Rakefile +3 -3
- data/lib/tankard.rb +18 -15
- data/lib/tankard/api/beer.rb +30 -39
- data/lib/tankard/api/beers.rb +15 -20
- data/lib/tankard/api/request/get.rb +13 -17
- data/lib/tankard/api/search.rb +32 -41
- data/lib/tankard/api/style.rb +19 -23
- data/lib/tankard/api/styles.rb +10 -12
- data/lib/tankard/api/utils/find.rb +15 -12
- data/lib/tankard/api/utils/page_finders.rb +42 -37
- data/lib/tankard/client.rb +10 -6
- data/lib/tankard/configuration.rb +18 -15
- data/lib/tankard/error.rb +4 -1
- data/lib/tankard/request.rb +23 -22
- data/lib/tankard/version.rb +4 -1
- data/spec/shared_examples_for_find.rb +22 -22
- data/spec/spec_helper.rb +2 -2
- data/spec/tankard/api/beer_spec.rb +113 -86
- data/spec/tankard/api/beers_spec.rb +34 -34
- data/spec/tankard/api/search_spec.rb +106 -95
- data/spec/tankard/api/style_spec.rb +102 -21
- data/spec/tankard/api/styles_spec.rb +6 -6
- data/spec/tankard/api/utils/find_spec.rb +10 -10
- data/spec/tankard/api/utils/page_finders_spec.rb +53 -50
- data/spec/tankard/client_spec.rb +42 -42
- data/spec/tankard/request_spec.rb +26 -24
- data/spec/tankard_spec.rb +21 -19
- data/tankard.gemspec +24 -22
- metadata +45 -58
data/spec/spec_helper.rb
CHANGED
@@ -5,204 +5,231 @@ describe Tankard::Api::Beer do
|
|
5
5
|
let(:beer) { Tankard::Api::Beer.new(@request) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
@request =
|
8
|
+
@request = double('request')
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe '#find' do
|
12
12
|
|
13
13
|
before do
|
14
|
-
@request.stub(:get).with(
|
15
|
-
@request.stub(:get).with(
|
16
|
-
@request.stub(:get).with(
|
17
|
-
@request.stub(:get).with(
|
14
|
+
@request.stub(:get).with('beer/valid1', {}).and_return('data' => 'valid1_found')
|
15
|
+
@request.stub(:get).with('beer/valid2', {}).and_return('data' => 'valid2_found')
|
16
|
+
@request.stub(:get).with('beer/invalid1', {}).and_raise(Tankard::Error::HttpError)
|
17
|
+
@request.stub(:get).with('beer/invalid2', {}).and_raise(Tankard::Error::HttpError)
|
18
18
|
end
|
19
19
|
|
20
|
-
it_should_behave_like
|
20
|
+
it_should_behave_like 'the find method' do
|
21
21
|
let(:context) { beer }
|
22
|
-
let(:valid_items) {
|
23
|
-
let(:valid_responses) {
|
24
|
-
let(:invalid_items) {
|
22
|
+
let(:valid_items) { %w(valid1 valid2) }
|
23
|
+
let(:valid_responses) { %w(valid1_found valid2_found) }
|
24
|
+
let(:invalid_items) { %w(invalid1 invalid2) }
|
25
25
|
let(:valid_invalid_items) { valid_items + invalid_items }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe '#id' do
|
30
30
|
|
31
|
-
it
|
32
|
-
beer.id(
|
33
|
-
beer_options = beer.instance_variable_get(:"@
|
34
|
-
expect(beer_options[:id]).to eql(
|
31
|
+
it 'sets the options[:id] to the beer id passed in' do
|
32
|
+
beer.id('port')
|
33
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
34
|
+
expect(beer_options[:id]).to eql('port')
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
expect(beer.object_id).to eql(beer.id(
|
37
|
+
it 'returns itself' do
|
38
|
+
expect(beer.object_id).to eql(beer.id('port').object_id)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
42
|
+
describe '#breweries' do
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'sets the options[:endpoint] to breweries' do
|
45
45
|
beer.breweries
|
46
|
-
beer_options = beer.instance_variable_get(:"@
|
47
|
-
expect(beer_options[:endpoint]).to eql(
|
46
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
47
|
+
expect(beer_options[:endpoint]).to eql('breweries')
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'returns itself' do
|
51
51
|
expect(beer.object_id).to eql(beer.breweries.object_id)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe '#events' do
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'sets the options[:endpoint] to events' do
|
58
58
|
beer.events
|
59
|
-
beer_options = beer.instance_variable_get(:"@
|
60
|
-
expect(beer_options[:endpoint]).to eql(
|
59
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
60
|
+
expect(beer_options[:endpoint]).to eql('events')
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'returns itself' do
|
64
64
|
expect(beer.object_id).to eql(beer.events.object_id)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe
|
68
|
+
describe '#ingredients' do
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'sets the options[:endpoint] to ingredients' do
|
71
71
|
beer.ingredients
|
72
|
-
beer_options = beer.instance_variable_get(:"@
|
73
|
-
expect(beer_options[:endpoint]).to eql(
|
72
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
73
|
+
expect(beer_options[:endpoint]).to eql('ingredients')
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
76
|
+
it 'returns itself' do
|
77
77
|
expect(beer.object_id).to eql(beer.ingredients.object_id)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
describe
|
81
|
+
describe '#social_accounts' do
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'sets the options[:endpoint] to socialaccounts' do
|
84
84
|
beer.social_accounts
|
85
|
-
beer_options = beer.instance_variable_get(:"@
|
86
|
-
expect(beer_options[:endpoint]).to eql(
|
85
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
86
|
+
expect(beer_options[:endpoint]).to eql('socialaccounts')
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
89
|
+
it 'returns itself' do
|
90
90
|
expect(beer.object_id).to eql(beer.social_accounts.object_id)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
94
|
+
describe '#variations' do
|
95
95
|
|
96
|
-
it
|
96
|
+
it 'sets the options[:endpoint] to variations' do
|
97
97
|
beer.variations
|
98
|
-
beer_options = beer.instance_variable_get(:"@
|
99
|
-
expect(beer_options[:endpoint]).to eql(
|
98
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
99
|
+
expect(beer_options[:endpoint]).to eql('variations')
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
102
|
+
it 'returns itself' do
|
103
103
|
expect(beer.object_id).to eql(beer.variations.object_id)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe
|
107
|
+
describe '#params' do
|
108
108
|
|
109
|
-
it
|
110
|
-
beer.params(withSocialAccounts:
|
111
|
-
beer_options = beer.instance_variable_get(:"@
|
112
|
-
expect(beer_options[:withSocialAccounts]).to eql(
|
113
|
-
expect(beer_options[:withGuilds]).to eql(
|
109
|
+
it 'sets parameters' do
|
110
|
+
beer.params(withSocialAccounts: 'y', withGuilds: 'n')
|
111
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
112
|
+
expect(beer_options[:withSocialAccounts]).to eql('y')
|
113
|
+
expect(beer_options[:withGuilds]).to eql('n')
|
114
114
|
end
|
115
115
|
|
116
|
-
it
|
117
|
-
beer.params(test:
|
118
|
-
beer.params(test:
|
119
|
-
beer_options = beer.instance_variable_get(:"@
|
120
|
-
expect(beer_options[:test]).to eql(
|
116
|
+
it 'merges data when called multiple times' do
|
117
|
+
beer.params(test: 'n')
|
118
|
+
beer.params(test: 'y')
|
119
|
+
beer_options = beer.instance_variable_get(:"@http_request_parameters")
|
120
|
+
expect(beer_options[:test]).to eql('y')
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
123
|
+
it 'returns itself' do
|
124
124
|
expect(beer.object_id).to eql(beer.params.object_id)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
describe
|
128
|
+
describe 'private methods' do
|
129
129
|
|
130
|
-
describe
|
130
|
+
describe '#raise_if_no_id_in_options' do
|
131
131
|
|
132
|
-
context
|
132
|
+
context 'when an ID is not set' do
|
133
133
|
|
134
|
-
it
|
135
|
-
expect { beer.send(:raise_if_no_id_in_options) }.to raise_error(Tankard::Error::MissingParameter,
|
134
|
+
it 'raises Tankard::Error::MissingParameter' do
|
135
|
+
expect { beer.send(:raise_if_no_id_in_options) }.to raise_error(Tankard::Error::MissingParameter, 'No Beer ID is set')
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
context
|
139
|
+
context 'when an ID is set' do
|
140
140
|
|
141
141
|
before do
|
142
|
-
beer.instance_variable_get(:"@
|
142
|
+
beer.instance_variable_get(:"@http_request_parameters")[:id] = 'test'
|
143
143
|
end
|
144
144
|
|
145
|
-
it
|
146
|
-
expect(beer.send(:raise_if_no_id_in_options)).to eql(
|
145
|
+
it 'returns the id from options' do
|
146
|
+
expect(beer.send(:raise_if_no_id_in_options)).to eql('test')
|
147
147
|
end
|
148
148
|
|
149
|
-
it
|
149
|
+
it 'removes the id from options' do
|
150
150
|
beer.send(:raise_if_no_id_in_options)
|
151
|
-
expect(beer.instance_variable_get(:"@
|
151
|
+
expect(beer.instance_variable_get(:"@http_request_parameters")[:id]).to be_nil
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'can be called multiple times and not raise error' do
|
155
|
+
beer.send(:raise_if_no_id_in_options)
|
156
|
+
expect { beer.send(:raise_if_no_id_in_options) }.not_to raise_error
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'caches the ID for future method calls' do
|
160
|
+
beer.send(:raise_if_no_id_in_options)
|
161
|
+
expect(beer.send(:raise_if_no_id_in_options)).to eql('test')
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'updates the cache value if the user sets a new ID' do
|
165
|
+
beer.send(:raise_if_no_id_in_options)
|
166
|
+
beer.instance_variable_get(:"@http_request_parameters")[:id] = 'test1'
|
167
|
+
expect(beer.send(:raise_if_no_id_in_options)).to eql('test1')
|
152
168
|
end
|
153
169
|
end
|
154
170
|
end
|
155
171
|
|
156
|
-
describe
|
172
|
+
describe '#route' do
|
157
173
|
|
158
|
-
it
|
159
|
-
expect(beer.send(:route)).to eql(
|
174
|
+
it 'returns the route for the api request' do
|
175
|
+
expect(beer.send(:route)).to eql('beer')
|
160
176
|
end
|
161
177
|
end
|
162
178
|
|
163
|
-
describe
|
179
|
+
describe '#http_request_uri' do
|
164
180
|
|
165
181
|
before do
|
166
|
-
beer.stub
|
167
|
-
beer.stub
|
182
|
+
beer.stub(:route).and_return('beer')
|
183
|
+
beer.stub(:raise_if_no_id_in_options).and_return('123')
|
168
184
|
end
|
169
185
|
|
170
|
-
context
|
186
|
+
context 'no endpoint is set' do
|
171
187
|
|
172
|
-
it
|
173
|
-
expect(beer.send(:http_request_uri)).to eql(
|
188
|
+
it 'returns the route with the id' do
|
189
|
+
expect(beer.send(:http_request_uri)).to eql('beer/123')
|
174
190
|
end
|
175
191
|
end
|
176
192
|
|
177
|
-
context
|
193
|
+
context 'endpoint is set' do
|
178
194
|
|
179
195
|
before do
|
180
|
-
beer.instance_variable_get(:"@
|
196
|
+
beer.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'events'
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'returns the route with the id and endpoint' do
|
200
|
+
expect(beer.send(:http_request_uri)).to eql('beer/123/events')
|
181
201
|
end
|
182
202
|
|
183
|
-
it
|
184
|
-
|
203
|
+
it 'removes the endpoint from options' do
|
204
|
+
beer.send(:http_request_uri)
|
205
|
+
expect(beer.instance_variable_get(:"@http_request_parameters")[:endpoint]).to be_nil
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'caches the endpoint for future method calls' do
|
209
|
+
beer.send(:http_request_uri)
|
210
|
+
expect(beer.send(:http_request_uri)).to eql('beer/123/events')
|
185
211
|
end
|
186
212
|
|
187
|
-
it
|
213
|
+
it 'updates the cached endpoint if the user sets a new one' do
|
188
214
|
beer.send(:http_request_uri)
|
189
|
-
|
215
|
+
beer.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'breweries'
|
216
|
+
expect(beer.send(:http_request_uri)).to eql('beer/123/breweries')
|
190
217
|
end
|
191
218
|
end
|
192
219
|
end
|
193
220
|
|
194
|
-
describe
|
221
|
+
describe '#http_client' do
|
195
222
|
|
196
|
-
it
|
223
|
+
it 'returns the request variable that is passed when the class is created' do
|
197
224
|
expect(beer.send(:http_client).object_id).to eql(@request.object_id)
|
198
225
|
end
|
199
226
|
end
|
200
227
|
|
201
|
-
describe
|
228
|
+
describe '#http_request_parameters' do
|
202
229
|
|
203
|
-
it
|
204
|
-
expect(beer.send(:http_request_parameters).object_id).to eql(beer.instance_variable_get(:"@
|
230
|
+
it 'returns the options for the request' do
|
231
|
+
expect(beer.send(:http_request_parameters).object_id).to eql(beer.instance_variable_get(:"@http_request_parameters").object_id)
|
205
232
|
end
|
206
233
|
end
|
207
234
|
end
|
208
|
-
end
|
235
|
+
end
|
@@ -4,77 +4,77 @@ describe Tankard::Api::Beers do
|
|
4
4
|
let(:beers) { Tankard::Api::Beers.new(@request) }
|
5
5
|
|
6
6
|
before do
|
7
|
-
@request =
|
7
|
+
@request = double('request')
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe '#name' do
|
11
11
|
|
12
|
-
it
|
13
|
-
beers.name(
|
14
|
-
beers_options = beers.instance_variable_get(:"@
|
15
|
-
expect(beers_options[:name]).to eql(
|
12
|
+
it 'sets the http_request_parameters[:name] of a beer' do
|
13
|
+
beers.name('stone')
|
14
|
+
beers_options = beers.instance_variable_get(:"@http_request_parameters")
|
15
|
+
expect(beers_options[:name]).to eql('stone')
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(beers.object_id).to eql(beers.name(
|
18
|
+
it 'returns self' do
|
19
|
+
expect(beers.object_id).to eql(beers.name('stone').object_id)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe '#page' do
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'sets the http_request_parameters[:p] for the page number' do
|
26
26
|
beers.page(1)
|
27
|
-
beers_options = beers.instance_variable_get(:"@
|
27
|
+
beers_options = beers.instance_variable_get(:"@http_request_parameters")
|
28
28
|
expect(beers_options[:p]).to eql(1)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'returns self' do
|
32
32
|
expect(beers.object_id).to eql(beers.page(1).object_id)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
36
|
+
describe '#params' do
|
37
37
|
|
38
|
-
it
|
39
|
-
beers.params(withSocialAccounts:
|
40
|
-
beers_options = beers.instance_variable_get(:"@
|
41
|
-
expect(beers_options[:withSocialAccounts]).to eql(
|
42
|
-
expect(beers_options[:withGuilds]).to eql(
|
38
|
+
it 'sets parameters' do
|
39
|
+
beers.params(withSocialAccounts: 'y', withGuilds: 'n')
|
40
|
+
beers_options = beers.instance_variable_get(:"@http_request_parameters")
|
41
|
+
expect(beers_options[:withSocialAccounts]).to eql('y')
|
42
|
+
expect(beers_options[:withGuilds]).to eql('n')
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
beers.params(test:
|
47
|
-
beers.params(test:
|
48
|
-
beers_options = beers.instance_variable_get(:"@
|
49
|
-
expect(beers_options[:test]).to eql(
|
45
|
+
it 'merges params when called multiple times' do
|
46
|
+
beers.params(test: 'n')
|
47
|
+
beers.params(test: 'y')
|
48
|
+
beers_options = beers.instance_variable_get(:"@http_request_parameters")
|
49
|
+
expect(beers_options[:test]).to eql('y')
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'returns itself' do
|
53
53
|
expect(beers.object_id).to eql(beers.params.object_id)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
57
|
+
describe 'private methods' do
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe '#http_request_uri' do
|
60
60
|
|
61
|
-
it
|
62
|
-
expect(beers.send(:http_request_uri)).to eql(
|
61
|
+
it 'returns the string beers' do
|
62
|
+
expect(beers.send(:http_request_uri)).to eql('beers')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
describe
|
66
|
+
describe '#http_client' do
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'returns the request variable that is passed in when the class is initialized' do
|
69
69
|
expect(beers.send(:http_client).object_id).to eql(@request.object_id)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe
|
73
|
+
describe '#http_request_parameters' do
|
74
74
|
|
75
|
-
it
|
76
|
-
expect(beers.send(:http_request_parameters).object_id).to eql(beers.instance_variable_get(:"@
|
75
|
+
it 'returns the http_request_parameters for the request' do
|
76
|
+
expect(beers.send(:http_request_parameters).object_id).to eql(beers.instance_variable_get(:"@http_request_parameters").object_id)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
|
-
end
|
80
|
+
end
|
@@ -5,123 +5,123 @@ describe Tankard::Api::Search do
|
|
5
5
|
let(:search) { Tankard::Api::Search.new(@request) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
@request =
|
8
|
+
@request = double('request')
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe '#query' do
|
12
12
|
|
13
|
-
it
|
14
|
-
search.query(
|
15
|
-
search_options = search.instance_variable_get(:"@
|
16
|
-
expect(search_options[:q]).to eql(
|
13
|
+
it 'sets http_request_parameters[:q] with the query the user wants to run' do
|
14
|
+
search.query('test')
|
15
|
+
search_options = search.instance_variable_get(:"@http_request_parameters")
|
16
|
+
expect(search_options[:q]).to eql('test')
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
expect(search.object_id).to eql(search.query(
|
19
|
+
it 'returns itself' do
|
20
|
+
expect(search.object_id).to eql(search.query('test').object_id)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
25
|
+
describe '#params' do
|
26
26
|
|
27
|
-
it
|
28
|
-
search.params(withSocialAccounts:
|
29
|
-
search_options = search.instance_variable_get(:"@
|
30
|
-
expect(search_options[:withSocialAccounts]).to eql(
|
31
|
-
expect(search_options[:withGuilds]).to eql(
|
27
|
+
it 'sets parameters' do
|
28
|
+
search.params(withSocialAccounts: 'y', withGuilds: 'n')
|
29
|
+
search_options = search.instance_variable_get(:"@http_request_parameters")
|
30
|
+
expect(search_options[:withSocialAccounts]).to eql('y')
|
31
|
+
expect(search_options[:withGuilds]).to eql('n')
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
search.params(test:
|
36
|
-
search.params(test:
|
37
|
-
search_options = search.instance_variable_get(:"@
|
38
|
-
expect(search_options[:test]).to eql(
|
34
|
+
it 'merges params when called multiple times' do
|
35
|
+
search.params(test: 'n')
|
36
|
+
search.params(test: 'y')
|
37
|
+
search_options = search.instance_variable_get(:"@http_request_parameters")
|
38
|
+
expect(search_options[:test]).to eql('y')
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'returns itself' do
|
42
42
|
expect(search.object_id).to eql(search.params.object_id)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe
|
46
|
+
describe '#type' do
|
47
47
|
|
48
|
-
it
|
49
|
-
search.type(
|
50
|
-
search_options = search.instance_variable_get(:"@
|
51
|
-
expect(search_options[:type]).to eql(
|
48
|
+
it 'sets http_request_parameters[:type] with the type to search for' do
|
49
|
+
search.type('beer')
|
50
|
+
search_options = search.instance_variable_get(:"@http_request_parameters")
|
51
|
+
expect(search_options[:type]).to eql('beer')
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
expect(search.object_id).to eql
|
54
|
+
it 'returns itself' do
|
55
|
+
expect(search.object_id).to eql(search.type('test').object_id)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe '#page' do
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'sets http_request_parameters[:p] with the page number to load' do
|
62
62
|
search.page(1)
|
63
|
-
search_options = search.instance_variable_get(:"@
|
63
|
+
search_options = search.instance_variable_get(:"@http_request_parameters")
|
64
64
|
expect(search_options[:p]).to eql(1)
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'returns itself' do
|
68
68
|
expect(search.object_id).to eql(search.page(1).object_id)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
72
|
+
describe '#upc' do
|
73
73
|
|
74
74
|
before do
|
75
|
-
search.upc(
|
76
|
-
@search_options = search.instance_variable_get(:"@
|
75
|
+
search.upc('123')
|
76
|
+
@search_options = search.instance_variable_get(:"@http_request_parameters")
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
expect(@search_options[:endpoint]).to eql(
|
79
|
+
it 'sets http_request_parameters[:endpoint] with the search endpoint to use' do
|
80
|
+
expect(@search_options[:endpoint]).to eql('upc')
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
84
|
-
expect(@search_options[:code]).to eql(
|
83
|
+
it 'sets http_request_parameters[:code] with the upc code' do
|
84
|
+
expect(@search_options[:code]).to eql('123')
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
expect(search.object_id).to eql(search.upc(
|
87
|
+
it 'returns itself' do
|
88
|
+
expect(search.object_id).to eql(search.upc('123').object_id)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
describe
|
92
|
+
describe '#geo_point' do
|
93
93
|
|
94
94
|
before do
|
95
95
|
search.geo_point(1.23, 4.56)
|
96
|
-
@search_options = search.instance_variable_get(:"@
|
96
|
+
@search_options = search.instance_variable_get(:"@http_request_parameters")
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
100
|
-
expect(@search_options[:endpoint]).to eql(
|
99
|
+
it 'sets http_request_parameters[:endpoint] with the correct search endpoint to use' do
|
100
|
+
expect(@search_options[:endpoint]).to eql('geo/point')
|
101
101
|
end
|
102
102
|
|
103
|
-
it
|
103
|
+
it 'sets http_request_parameters[:lat] with the latitude' do
|
104
104
|
expect(@search_options[:lat]).to eql(1.23)
|
105
105
|
end
|
106
106
|
|
107
|
-
it
|
107
|
+
it 'sets http_request_parameters[:lng] with the longitude' do
|
108
108
|
expect(@search_options[:lng]).to eql(4.56)
|
109
109
|
end
|
110
110
|
|
111
|
-
it
|
111
|
+
it 'returns itself' do
|
112
112
|
expect(search.object_id).to eql(search.geo_point(1.3, 4.5).object_id)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
describe
|
116
|
+
describe '#each' do
|
117
117
|
|
118
|
-
it
|
118
|
+
it 'should call raise_if_required_options_not_set' do
|
119
119
|
search.stub(:find_on_single_or_all_pages).and_return(nil)
|
120
120
|
search.should_receive(:raise_if_required_options_not_set)
|
121
121
|
search.each
|
122
122
|
end
|
123
123
|
|
124
|
-
it
|
124
|
+
it 'calls the super object with the block' do
|
125
125
|
block = -> x { x }
|
126
126
|
search.stub(:raise_if_required_options_not_set).and_return(nil)
|
127
127
|
search.should_receive(:find_on_single_or_all_pages)
|
@@ -129,104 +129,115 @@ describe Tankard::Api::Search do
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
describe
|
132
|
+
describe 'private methods' do
|
133
133
|
|
134
|
-
describe
|
134
|
+
describe '#raise_if_required_options_not_set' do
|
135
135
|
|
136
|
-
context
|
136
|
+
context 'the endpoint is not set' do
|
137
137
|
|
138
|
-
it
|
139
|
-
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter,
|
138
|
+
it 'raises Tankard::Error::NoSearchQuery when the query is not set' do
|
139
|
+
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, 'No search query set')
|
140
140
|
end
|
141
141
|
|
142
|
-
it
|
143
|
-
search.instance_variable_get(:"@
|
144
|
-
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
142
|
+
it 'does not raise Tankard::Error::NoSearchQuery when the query is set' do
|
143
|
+
search.instance_variable_get(:"@http_request_parameters")[:q] = 'findme'
|
144
|
+
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
context
|
148
|
+
context 'the endpoint is set to upc' do
|
149
149
|
|
150
150
|
before do
|
151
|
-
search.instance_variable_get(:"@
|
151
|
+
search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'upc'
|
152
152
|
end
|
153
153
|
|
154
|
-
it
|
155
|
-
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter,
|
154
|
+
it 'raises Tankard::Error::MissingParameter when code is not set' do
|
155
|
+
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, 'missing parameter: code')
|
156
156
|
end
|
157
157
|
|
158
|
-
it
|
159
|
-
search.instance_variable_get(:"@
|
160
|
-
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
158
|
+
it 'does not raise Tankard::Error::MissingParameter when code is set' do
|
159
|
+
search.instance_variable_get(:"@http_request_parameters")[:code] = '1234'
|
160
|
+
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
context
|
164
|
+
context 'the endpoint is set to geo/point' do
|
165
165
|
|
166
166
|
before do
|
167
|
-
search.instance_variable_get(:"@
|
167
|
+
search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'geo/point'
|
168
168
|
end
|
169
169
|
|
170
|
-
it
|
171
|
-
search.instance_variable_get(:"@
|
172
|
-
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter,
|
170
|
+
it 'raises Tankard::Error::MissingParameter when latitude is not set' do
|
171
|
+
search.instance_variable_get(:"@http_request_parameters")[:lng] = 123
|
172
|
+
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, 'missing Parameters: lat, lng')
|
173
173
|
end
|
174
174
|
|
175
|
-
it
|
176
|
-
search.instance_variable_get(:"@
|
177
|
-
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter,
|
175
|
+
it 'raises Tankard::Error::MissingParameter when longitude is not set' do
|
176
|
+
search.instance_variable_get(:"@http_request_parameters")[:lat] = 123
|
177
|
+
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, 'missing Parameters: lat, lng')
|
178
178
|
end
|
179
179
|
|
180
|
-
it
|
181
|
-
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter,
|
180
|
+
it 'raises Tankard::Error::MissingParameter when latitude and longitude are not set' do
|
181
|
+
expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, 'missing Parameters: lat, lng')
|
182
182
|
end
|
183
183
|
|
184
|
-
it
|
185
|
-
search.instance_variable_get(:"@
|
186
|
-
search.instance_variable_get(:"@
|
187
|
-
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
184
|
+
it 'does not raise Tankard::Error::MissingParameter when latitude and longitude are set' do
|
185
|
+
search.instance_variable_get(:"@http_request_parameters")[:lat] = 123
|
186
|
+
search.instance_variable_get(:"@http_request_parameters")[:lng] = 123
|
187
|
+
expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
describe
|
192
|
+
describe '#http_request_uri' do
|
193
193
|
|
194
|
-
context
|
194
|
+
context 'no endpoint is set' do
|
195
195
|
|
196
|
-
it
|
197
|
-
expect(search.send(:http_request_uri)).to eql(
|
196
|
+
it 'returns search' do
|
197
|
+
expect(search.send(:http_request_uri)).to eql('search')
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
context
|
201
|
+
context 'an endpoint is set' do
|
202
202
|
|
203
203
|
before do
|
204
|
-
search.instance_variable_get(:"@
|
204
|
+
search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'upc'
|
205
205
|
end
|
206
206
|
|
207
|
-
it
|
208
|
-
expect(search.send(:http_request_uri)).to eql(
|
207
|
+
it 'adds the endpoint to the uri' do
|
208
|
+
expect(search.send(:http_request_uri)).to eql('search/upc')
|
209
209
|
end
|
210
210
|
|
211
|
-
it
|
211
|
+
it 'removes the endpoint from http_request_parameters' do
|
212
212
|
search.send(:http_request_uri)
|
213
|
-
expect(search.instance_variable_get(:"@
|
213
|
+
expect(search.instance_variable_get(:"@http_request_parameters")[:endpoint]).to eql(nil)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'caches the endpoint for future method calls' do
|
217
|
+
search.send(:http_request_uri)
|
218
|
+
expect(search.send(:http_request_uri)).to eql('search/upc')
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'updates the cached endpoint if the user sets a new one' do
|
222
|
+
search.send(:http_request_uri)
|
223
|
+
search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'geo/point'
|
224
|
+
expect(search.send(:http_request_uri)).to eql('search/geo/point')
|
214
225
|
end
|
215
226
|
end
|
216
227
|
end
|
217
228
|
|
218
|
-
describe
|
229
|
+
describe '#http_client' do
|
219
230
|
|
220
|
-
it
|
231
|
+
it 'returns the request variable that is passed when the class is created' do
|
221
232
|
expect(search.send(:http_client).object_id).to eql(@request.object_id)
|
222
233
|
end
|
223
234
|
end
|
224
235
|
|
225
|
-
describe
|
236
|
+
describe '#http_request_parameters' do
|
226
237
|
|
227
|
-
it
|
228
|
-
expect(search.send(:http_request_parameters).object_id).to eql(search.instance_variable_get(:"@
|
238
|
+
it 'returns the http_request_parameters for the request' do
|
239
|
+
expect(search.send(:http_request_parameters).object_id).to eql(search.instance_variable_get(:"@http_request_parameters").object_id)
|
229
240
|
end
|
230
241
|
end
|
231
242
|
end
|
232
|
-
end
|
243
|
+
end
|