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.
@@ -17,5 +17,5 @@ require 'shared_examples_for_find'
17
17
  WebMock.disable_net_connect!(allow: 'coveralls.io')
18
18
 
19
19
  def stub_get(path)
20
- stub_request(:get, "http://api.brewerydb.com/v2/" + path)
21
- end
20
+ stub_request(:get, 'http://api.brewerydb.com/v2/' + path)
21
+ end
@@ -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 = mock("request")
8
+ @request = double('request')
9
9
  end
10
10
 
11
- describe "#find" do
11
+ describe '#find' do
12
12
 
13
13
  before do
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)
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 "the find method" do
20
+ it_should_behave_like 'the find method' do
21
21
  let(:context) { beer }
22
- let(:valid_items) { ["valid1", "valid2"] }
23
- let(:valid_responses) { ["valid1_found", "valid2_found"] }
24
- let(:invalid_items) { ["invalid1", "invalid2"] }
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 "#id" do
29
+ describe '#id' do
30
30
 
31
- it "sets the options[:id] to the beer id passed in" do
32
- beer.id("port")
33
- beer_options = beer.instance_variable_get(:"@options")
34
- expect(beer_options[:id]).to eql("port")
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 "returns itself" do
38
- expect(beer.object_id).to eql(beer.id("port").object_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 "#breweries" do
42
+ describe '#breweries' do
43
43
 
44
- it "sets the options[:endpoint] to breweries" do
44
+ it 'sets the options[:endpoint] to breweries' do
45
45
  beer.breweries
46
- beer_options = beer.instance_variable_get(:"@options")
47
- expect(beer_options[:endpoint]).to eql("breweries")
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 "returns itself" do
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 "#events" do
55
+ describe '#events' do
56
56
 
57
- it "sets the options[:endpoint] to events" do
57
+ it 'sets the options[:endpoint] to events' do
58
58
  beer.events
59
- beer_options = beer.instance_variable_get(:"@options")
60
- expect(beer_options[:endpoint]).to eql("events")
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 "returns itself" do
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 "#ingredients" do
68
+ describe '#ingredients' do
69
69
 
70
- it "sets the options[:endpoint] to ingredients" do
70
+ it 'sets the options[:endpoint] to ingredients' do
71
71
  beer.ingredients
72
- beer_options = beer.instance_variable_get(:"@options")
73
- expect(beer_options[:endpoint]).to eql("ingredients")
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 "returns itself" do
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 "#social_accounts" do
81
+ describe '#social_accounts' do
82
82
 
83
- it "sets the options[:endpoint] to socialaccounts" do
83
+ it 'sets the options[:endpoint] to socialaccounts' do
84
84
  beer.social_accounts
85
- beer_options = beer.instance_variable_get(:"@options")
86
- expect(beer_options[:endpoint]).to eql("socialaccounts")
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 "returns itself" do
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 "#variations" do
94
+ describe '#variations' do
95
95
 
96
- it "sets the options[:endpoint] to variations" do
96
+ it 'sets the options[:endpoint] to variations' do
97
97
  beer.variations
98
- beer_options = beer.instance_variable_get(:"@options")
99
- expect(beer_options[:endpoint]).to eql("variations")
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 "returns itself" do
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 "#params" do
107
+ describe '#params' do
108
108
 
109
- it "sets parameters" do
110
- beer.params(withSocialAccounts: "y", withGuilds: "n")
111
- beer_options = beer.instance_variable_get(:"@options")
112
- expect(beer_options[:withSocialAccounts]).to eql("y")
113
- expect(beer_options[:withGuilds]).to eql("n")
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 "merges data when called multiple times" do
117
- beer.params(test: "n")
118
- beer.params(test: "y")
119
- beer_options = beer.instance_variable_get(:"@options")
120
- expect(beer_options[:test]).to eql("y")
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 "returns itself" do
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 "private methods" do
128
+ describe 'private methods' do
129
129
 
130
- describe "#raise_if_no_id_in_options" do
130
+ describe '#raise_if_no_id_in_options' do
131
131
 
132
- context "when an ID is not set" do
132
+ context 'when an ID is not set' do
133
133
 
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")
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 "when an ID is set" do
139
+ context 'when an ID is set' do
140
140
 
141
141
  before do
142
- beer.instance_variable_get(:"@options")[:id] = "test"
142
+ beer.instance_variable_get(:"@http_request_parameters")[:id] = 'test'
143
143
  end
144
144
 
145
- it "returns the id from options" do
146
- expect(beer.send(:raise_if_no_id_in_options)).to eql("test")
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 "removes the id from options" do
149
+ it 'removes the id from options' do
150
150
  beer.send(:raise_if_no_id_in_options)
151
- expect(beer.instance_variable_get(:"@options")[:id]).to be_nil
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 "#route" do
172
+ describe '#route' do
157
173
 
158
- it "returns the route for the api request" do
159
- expect(beer.send(:route)).to eql("beer")
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 "#http_request_uri" do
179
+ describe '#http_request_uri' do
164
180
 
165
181
  before do
166
- beer.stub!(:route).and_return("beer")
167
- beer.stub!(:raise_if_no_id_in_options).and_return("123")
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 "no endpoint is set" do
186
+ context 'no endpoint is set' do
171
187
 
172
- it "returns the route with the id" do
173
- expect(beer.send(:http_request_uri)).to eql("beer/123")
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 "endpoint is set" do
193
+ context 'endpoint is set' do
178
194
 
179
195
  before do
180
- beer.instance_variable_get(:"@options")[:endpoint] = "events"
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 "returns the route with the id and endpoint" do
184
- expect(beer.send(:http_request_uri)).to eql("beer/123/events")
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 "removes the endpoint from options" do
213
+ it 'updates the cached endpoint if the user sets a new one' do
188
214
  beer.send(:http_request_uri)
189
- expect(beer.instance_variable_get(:"@options")[:endpoint]).to be_nil
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 "#http_client" do
221
+ describe '#http_client' do
195
222
 
196
- it "returns the request variable that is passed when the class is created" do
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 "#http_request_parameters" do
228
+ describe '#http_request_parameters' do
202
229
 
203
- it "returns the options for the request" do
204
- expect(beer.send(:http_request_parameters).object_id).to eql(beer.instance_variable_get(:"@options").object_id)
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 = mock("request")
7
+ @request = double('request')
8
8
  end
9
9
 
10
- describe "#name" do
10
+ describe '#name' do
11
11
 
12
- it "sets the options[:name] of a beer" do
13
- beers.name("stone")
14
- beers_options = beers.instance_variable_get(:"@options")
15
- expect(beers_options[:name]).to eql("stone")
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 "returns self" do
19
- expect(beers.object_id).to eql(beers.name("stone").object_id)
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 "#page" do
23
+ describe '#page' do
24
24
 
25
- it "sets the options[:p] for the page number" do
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(:"@options")
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 "returns self" do
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 "#params" do
36
+ describe '#params' do
37
37
 
38
- it "sets parameters" do
39
- beers.params(withSocialAccounts: "y", withGuilds: "n")
40
- beers_options = beers.instance_variable_get(:"@options")
41
- expect(beers_options[:withSocialAccounts]).to eql("y")
42
- expect(beers_options[:withGuilds]).to eql("n")
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 "merges params when called multiple times" do
46
- beers.params(test: "n")
47
- beers.params(test: "y")
48
- beers_options = beers.instance_variable_get(:"@options")
49
- expect(beers_options[:test]).to eql("y")
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 "returns itself" do
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 "private methods" do
57
+ describe 'private methods' do
58
58
 
59
- describe "#http_request_uri" do
59
+ describe '#http_request_uri' do
60
60
 
61
- it "returns the string beers" do
62
- expect(beers.send(:http_request_uri)).to eql("beers")
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 "#http_client" do
66
+ describe '#http_client' do
67
67
 
68
- it "returns the request variable that is passed in when the class is initialized" do
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 "#http_request_parameters" do
73
+ describe '#http_request_parameters' do
74
74
 
75
- it "returns the options for the request" do
76
- expect(beers.send(:http_request_parameters).object_id).to eql(beers.instance_variable_get(:"@options").object_id)
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 = mock("request")
8
+ @request = double('request')
9
9
  end
10
10
 
11
- describe "#query" do
11
+ describe '#query' do
12
12
 
13
- it "sets options[:q] with the query the user wants to run" do
14
- search.query("test")
15
- search_options = search.instance_variable_get(:"@options")
16
- expect(search_options[:q]).to eql("test")
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 "returns itself" do
20
- expect(search.object_id).to eql(search.query("test").object_id)
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 "#params" do
25
+ describe '#params' do
26
26
 
27
- it "sets parameters" do
28
- search.params(withSocialAccounts: "y", withGuilds: "n")
29
- search_options = search.instance_variable_get(:"@options")
30
- expect(search_options[:withSocialAccounts]).to eql("y")
31
- expect(search_options[:withGuilds]).to eql("n")
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 "merges params when called multiple times" do
35
- search.params(test: "n")
36
- search.params(test: "y")
37
- search_options = search.instance_variable_get(:"@options")
38
- expect(search_options[:test]).to eql("y")
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 "returns itself" do
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 "#type" do
46
+ describe '#type' do
47
47
 
48
- it "sets options[:type] with the type to search for" do
49
- search.type("beer")
50
- search_options = search.instance_variable_get(:"@options")
51
- expect(search_options[:type]).to eql("beer")
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 "returns itself" do
55
- expect(search.object_id).to eql (search.type("test").object_id)
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 "#page" do
59
+ describe '#page' do
60
60
 
61
- it "sets options[:p] with the page number to load" do
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(:"@options")
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 "returns itself" do
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 "#upc" do
72
+ describe '#upc' do
73
73
 
74
74
  before do
75
- search.upc("123")
76
- @search_options = search.instance_variable_get(:"@options")
75
+ search.upc('123')
76
+ @search_options = search.instance_variable_get(:"@http_request_parameters")
77
77
  end
78
78
 
79
- it "sets options[:endpoint] with the search endpoint to use" do
80
- expect(@search_options[:endpoint]).to eql("upc")
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 "sets options[:code] with the upc code" do
84
- expect(@search_options[:code]).to eql("123")
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 "returns itself" do
88
- expect(search.object_id).to eql(search.upc("123").object_id)
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 "#geo_point" do
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(:"@options")
96
+ @search_options = search.instance_variable_get(:"@http_request_parameters")
97
97
  end
98
98
 
99
- it "sets options[:endpoint] with the correct search endpoint to use" do
100
- expect(@search_options[:endpoint]).to eql("geo/point")
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 "sets options[:lat] with the latitude" do
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 "sets options[:lng] with the longitude" do
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 "returns itself" do
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 "#each" do
116
+ describe '#each' do
117
117
 
118
- it "should call raise_if_required_options_not_set" do
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 "calls the super object with the block" do
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 "private methods" do
132
+ describe 'private methods' do
133
133
 
134
- describe "#raise_if_required_options_not_set" do
134
+ describe '#raise_if_required_options_not_set' do
135
135
 
136
- context "the endpoint is not set" do
136
+ context 'the endpoint is not set' do
137
137
 
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")
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 "does not raise Tankard::Error::NoSearchQuery when the query is set" do
143
- search.instance_variable_get(:"@options")[:q] = "findme"
144
- expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error(Tankard::Error::MissingParameter, "No search query set")
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 "the endpoint is set to upc" do
148
+ context 'the endpoint is set to upc' do
149
149
 
150
150
  before do
151
- search.instance_variable_get(:"@options")[:endpoint] = "upc"
151
+ search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'upc'
152
152
  end
153
153
 
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")
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 "does not raise Tankard::Error::MissingParameter when code is set" do
159
- search.instance_variable_get(:"@options")[:code] = "1234"
160
- expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error(Tankard::Error::MissingParameter)
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 "the endpoint is set to geo/point" do
164
+ context 'the endpoint is set to geo/point' do
165
165
 
166
166
  before do
167
- search.instance_variable_get(:"@options")[:endpoint] = "geo/point"
167
+ search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'geo/point'
168
168
  end
169
169
 
170
- it "raises Tankard::Error::MissingParameter when latitude is not set" do
171
- search.instance_variable_get(:"@options")[:lng] = 123
172
- expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, "missing Parameters: lat, lng")
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 "raises Tankard::Error::MissingParameter when longitude is not set" do
176
- search.instance_variable_get(:"@options")[:lat] = 123
177
- expect { search.send(:raise_if_required_options_not_set) }.to raise_error(Tankard::Error::MissingParameter, "missing Parameters: lat, lng")
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 "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")
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 "does not raise Tankard::Error::MissingParameter when latitude and longitude are set" do
185
- search.instance_variable_get(:"@options")[:lat] = 123
186
- search.instance_variable_get(:"@options")[:lng] = 123
187
- expect { search.send(:raise_if_required_options_not_set) }.not_to raise_error(Tankard::Error::MissingParameter)
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 "#http_request_uri" do
192
+ describe '#http_request_uri' do
193
193
 
194
- context "no endpoint is set" do
194
+ context 'no endpoint is set' do
195
195
 
196
- it "returns search" do
197
- expect(search.send(:http_request_uri)).to eql("search")
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 "an endpoint is set" do
201
+ context 'an endpoint is set' do
202
202
 
203
203
  before do
204
- search.instance_variable_get(:"@options")[:endpoint] = "upc"
204
+ search.instance_variable_get(:"@http_request_parameters")[:endpoint] = 'upc'
205
205
  end
206
206
 
207
- it "adds the endpoint to the uri" do
208
- expect(search.send(:http_request_uri)).to eql("search/upc")
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 "removes the endpoint from options" do
211
+ it 'removes the endpoint from http_request_parameters' do
212
212
  search.send(:http_request_uri)
213
- expect(search.instance_variable_get(:"@options")[:endpoint]).to eql(nil)
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 "#http_client" do
229
+ describe '#http_client' do
219
230
 
220
- it "returns the request variable that is passed when the class is created" do
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 "#http_request_parameters" do
236
+ describe '#http_request_parameters' do
226
237
 
227
- it "returns the options for the request" do
228
- expect(search.send(:http_request_parameters).object_id).to eql(search.instance_variable_get(:"@options").object_id)
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