gratitude 0.0.9 → 0.0.10

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.
@@ -3,282 +3,275 @@ require "spec_helper"
3
3
  describe Gratitude::Statistics do
4
4
 
5
5
  describe "default attributes" do
6
- it "should include httparty methods" do
7
- Gratitude::Statistics.should include(HTTParty)
6
+ it "includes httparty methods" do
7
+ expect(Gratitude::Statistics).to include(HTTParty)
8
8
  end
9
9
 
10
-
11
- it "should have the base uri set to gittip's payday api endpoint" do
12
- expect(Gratitude::Statistics.base_uri).to eq("https://www.gittip.com/about/stats.json")
10
+ it "sets the base uri equal to gittip's payday api endpoint" do
11
+ expect(Gratitude::Statistics.base_uri)
12
+ .to eq("https://www.gittip.com/about/stats.json")
13
13
  end
14
- end # default attributes
14
+ end
15
15
 
16
16
  describe "instance methods" do
17
-
18
- before do
19
- VCR.insert_cassette "statistics"
20
- end
21
-
22
- after do
23
- VCR.eject_cassette
24
- end
25
-
17
+ before { VCR.insert_cassette "statistics" }
18
+ after { VCR.eject_cassette }
26
19
  let(:stats) { Gratitude::Statistics.current }
27
20
 
28
- it "should respond to #repsonse" do
21
+ it "responds to #repsonse" do
29
22
  expect(stats).to respond_to(:response)
30
23
  end
31
24
 
32
25
  describe "#average_tip_amount" do
33
- it "should return the correct average tip amount" do
26
+ it "returns the correct average tip amount" do
34
27
  expect(stats.average_tip_amount).to eq(1.2348237280979524)
35
28
  end
36
29
 
37
- it "should return a float" do
30
+ it "returns a float" do
38
31
  expect(stats.average_tip_amount.class).to be(Float)
39
32
  end
40
33
 
41
- it "should return the same value as its alias: #average_tip" do
34
+ it "returns the same value as its alias: #average_tip" do
42
35
  expect(stats.average_tip_amount).to eq(stats.average_tip)
43
36
  end
44
37
  end
45
38
 
46
39
  describe "#average_number_of_tippees" do
47
- it "should return the correct average number of tippees" do
40
+ it "returns the correct average number of tippees" do
48
41
  expect(stats.average_number_of_tippees).to eq(3)
49
42
  end
50
43
 
51
- it "should return a fixnum" do
44
+ it "returns a fixnum" do
52
45
  expect(stats.average_number_of_tippees.class).to be(Fixnum)
53
46
  end
54
47
 
55
- it "should return the same value as its alias: #average_tippees" do
48
+ it "returns the same value as its alias: #average_tippees" do
56
49
  expect(stats.average_number_of_tippees).to eq(stats.average_tippees)
57
50
  end
58
51
  end
59
52
 
60
53
  describe "#amount_in_escrow" do
61
- it "should return the correct amount in escrow" do
54
+ it "returns the correct amount in escrow" do
62
55
  expect(stats.amount_in_escrow).to eq(50441.17)
63
56
  end
64
57
 
65
- it "should return a float" do
58
+ it "returns a float" do
66
59
  expect(stats.amount_in_escrow.class).to be(Float)
67
60
  end
68
61
 
69
- it "should return the same value as its alias: #escrow" do
62
+ it "returns the same value as its alias: #escrow" do
70
63
  expect(stats.amount_in_escrow).to eq(stats.escrow)
71
64
  end
72
65
  end
73
66
 
74
67
  describe "#last_thursday" do
75
- it "should return the correct value for last thursday" do
68
+ it "returns the correct value for last thursday" do
76
69
  expect(stats.last_thursday).to eq("last Thursday")
77
70
  end
78
71
 
79
- it "should be a string" do
72
+ it "returns a string" do
80
73
  expect(stats.last_thursday.class).to be(String)
81
74
  end
82
75
  end
83
76
 
84
77
  describe "#number_of_achs" do
85
- it "should return the correct number of ach credits" do
78
+ it "returns the correct number of ach credits" do
86
79
  expect(stats.number_of_ach_credits).to eq(299)
87
80
  end
88
81
 
89
- it "should be a fixnum" do
82
+ it "returns a fixnum" do
90
83
  expect(stats.number_of_ach_credits.class).to be(Fixnum)
91
84
  end
92
85
 
93
- it "should return the same value as its alias: #nach" do
86
+ it "returns the same value as its alias: #nach" do
94
87
  expect(stats.number_of_ach_credits).to eq(stats.nach)
95
88
  end
96
89
 
97
- it "should return the same value as its alias: #number_of_achs" do
90
+ it "returns the same value as its alias: #number_of_achs" do
98
91
  expect(stats.number_of_ach_credits).to eq(stats.number_of_achs)
99
92
  end
100
93
  end
101
94
 
102
95
  describe "#number_of_active_users" do
103
- it "should return the correct number of active users" do
96
+ it "returns the correct number of active users" do
104
97
  expect(stats.number_of_active_users).to eq(1719)
105
98
  end
106
99
 
107
- it "should be a fixnum" do
100
+ it "returns a fixnum" do
108
101
  expect(stats.number_of_active_users.class).to be(Fixnum)
109
102
  end
110
103
 
111
- it "should return the same value as its alias: #nactive" do
104
+ it "returns the same value as its alias: #nactive" do
112
105
  expect(stats.number_of_active_users).to eq(stats.nactive)
113
106
  end
114
107
  end
115
108
 
116
109
  describe "#number_of_credit_cards" do
117
- it "should return the correct number of credit cards on file" do
110
+ it "returns the correct number of credit cards on file" do
118
111
  expect(stats.number_of_credit_cards).to eq(1496)
119
112
  end
120
113
 
121
- it "should be a fixnum" do
114
+ it "returns a fixnum" do
122
115
  expect(stats.number_of_credit_cards.class).to be(Fixnum)
123
116
  end
124
117
 
125
- it "should return the same value as its alias: #ncc" do
118
+ it "returns the same value as its alias: #ncc" do
126
119
  expect(stats.number_of_credit_cards).to eq(stats.ncc)
127
120
  end
128
121
  end
129
122
 
130
123
  describe "#number_of_givers" do
131
- it "should return the correct number of givers" do
124
+ it "returns the correct number of givers" do
132
125
  expect(stats.number_of_givers).to eq(1113)
133
126
  end
134
127
 
135
- it "should be a fixnum" do
128
+ it "returns a fixnum" do
136
129
  expect(stats.number_of_givers.class).to be(Fixnum)
137
130
  end
138
131
 
139
- it "should return the same value as its alias: #ngivers" do
132
+ it "returns the same value as its alias: #ngivers" do
140
133
  expect(stats.number_of_givers).to eq(stats.ngivers)
141
134
  end
142
135
  end
143
136
 
144
137
  describe "#number_who_give_and_receive" do
145
- it "should return the correct number of users who both give and receive" do
138
+ it "returns the correct number of users who both give and receive" do
146
139
  expect(stats.number_who_give_and_receive).to eq(301)
147
140
  end
148
141
 
149
- it "should be a fixnum" do
142
+ it "returns a fixnum" do
150
143
  expect(stats.number_who_give_and_receive.class).to be(Fixnum)
151
144
  end
152
145
 
153
- it "should return the same value as its alias: #noverlap" do
146
+ it "returns the same value as its alias: #noverlap" do
154
147
  expect(stats.number_who_give_and_receive).to eq(stats.noverlap)
155
148
  end
156
149
  end
157
150
 
158
151
  describe "#number_of_receivers" do
159
- it "should return the correct number of receivers" do
152
+ it "returns the correct number of receivers" do
160
153
  expect(stats.number_of_receivers).to eq(907)
161
154
  end
162
155
 
163
- it "should be a fixnum" do
156
+ it "returns a fixnum" do
164
157
  expect(stats.number_of_receivers.class).to be(Fixnum)
165
158
  end
166
159
 
167
- it "should return the same value as its alias: #nreceivers" do
160
+ it "returns the same value as its alias: #nreceivers" do
168
161
  expect(stats.number_of_receivers).to eq(stats.nreceivers)
169
162
  end
170
163
  end
171
164
 
172
165
  describe "#other_people" do
173
- it "should return the correct value for #other_people" do
166
+ it "returns the correct value for #other_people" do
174
167
  expect(stats.other_people).to eq("three other people")
175
168
  end
176
169
 
177
- it "should be a string" do
170
+ it "returns a string" do
178
171
  expect(stats.other_people.class).to be(String)
179
172
  end
180
173
  end
181
174
 
182
175
  describe "#percentage_of_users_with_credit_cards" do
183
- it "should return the correct value for #percentage_of_users_with_credit_cards" do
176
+ it "returns the correct value for #percentage_of_users_with_credit_cards" do
184
177
  expect(stats.percentage_of_users_with_credit_cards).to eq("7.6")
185
178
  end
186
179
 
187
- it "should be a string" do
180
+ it "returns a string" do
188
181
  expect(stats.percentage_of_users_with_credit_cards.class).to be(String)
189
182
  end
190
183
 
191
- it "should return the same value as its alias: #pcc" do
184
+ it "returns the same value as its alias: #pcc" do
192
185
  expect(stats.percentage_of_users_with_credit_cards).to eq(stats.pcc)
193
186
  end
194
187
  end
195
188
 
196
189
  describe "#punctuation" do
197
- it "should return the correct value for #punctuation" do
190
+ it "returns the correct value for #punctuation" do
198
191
  expect(stats.punctuation).to eq(".")
199
192
  end
200
193
 
201
- it "should be a string" do
194
+ it "returns a string" do
202
195
  expect(stats.punctuation.class).to be(String)
203
196
  end
204
197
 
205
- it "should return the same value as its alias: #pcc" do
198
+ it "returns the same value as its alias: #pcc" do
206
199
  expect(stats.punctuation).to eq(stats.punc)
207
200
  end
208
201
  end
209
202
 
210
203
  describe "#statements" do
211
- it "should return an array" do
204
+ it "returns an array" do
212
205
  expect(stats.statements.class).to be(Array)
213
206
  end
214
207
 
215
- it "should contain 16 elements in the array" do
208
+ it "contain the currect number of elements in the array" do
216
209
  expect(stats.statements.size).to eq(16)
217
210
  end
218
211
 
219
- it "should have a hash for each element in the array" do
212
+ it "has a hash for each element in the array" do
220
213
  expect(stats.statements.first.class).to be(Hash)
221
214
  end
222
215
 
223
- it "should have statement as a key in each hash element" do
216
+ it "has statement as a key in each hash element" do
224
217
  expect(stats.statements.first.has_key?("statement")).to be(true)
225
218
  end
226
219
 
227
- it "should have username as a key in each hash element" do
220
+ it "has username as a key in each hash element" do
228
221
  expect(stats.statements.first.has_key?("username")).to be(true)
229
222
  end
230
223
  end
231
224
 
232
225
  describe "#this_thursday" do
233
- it "should return the correct value for this thursday" do
226
+ it "returns the correct value for this thursday" do
234
227
  expect(stats.this_thursday).to eq("this Thursday")
235
228
  end
236
229
 
237
- it "should be a string" do
230
+ it "returns a string" do
238
231
  expect(stats.this_thursday.class).to be(String)
239
232
  end
240
233
  end
241
234
 
242
235
  describe "#tip_distribution_json" do
243
- it "should return a hash" do
236
+ it "returns a hash" do
244
237
  expect(stats.tip_distribution_json.class).to be(Hash)
245
238
  end
246
239
  end
247
240
 
248
241
  describe "#number_of_tips" do
249
- it "should return the correct number of tips" do
242
+ it "returns the correct number of tips" do
250
243
  expect(stats.number_of_tips).to eq(4710)
251
244
  end
252
245
 
253
- it "should be a fixnum" do
246
+ it "returns a fixnum" do
254
247
  expect(stats.number_of_tips.class).to be(Fixnum)
255
248
  end
256
249
 
257
- it "should return the same value as its alias: #tip_n" do
250
+ it "returns the same value as its alias: #tip_n" do
258
251
  expect(stats.number_of_tips).to eq(stats.tip_n)
259
252
  end
260
253
  end
261
254
 
262
255
  describe "#value_of_total_backed_tips" do
263
- it "should return the correct value of total backed tips" do
256
+ it "returns the correct value of total backed tips" do
264
257
  expect(stats.value_of_total_backed_tips).to eq(5849.36)
265
258
  end
266
259
 
267
- it "should be a float" do
260
+ it "returns a float" do
268
261
  expect(stats.value_of_total_backed_tips.class).to be(Float)
269
262
  end
270
263
 
271
- it "should return the same value as its alias: #total_backed_tips" do
264
+ it "returns the same value as its alias: #total_backed_tips" do
272
265
  expect(stats.value_of_total_backed_tips).to eq(stats.total_backed_tips)
273
266
  end
274
267
  end
275
268
 
276
269
  describe "#transfer_volume" do
277
- it "should return the correct transfer volume" do
270
+ it "returns the correct transfer volume" do
278
271
  expect(stats.transfer_volume).to eq(5464.38)
279
272
  end
280
273
 
281
- it "should be a float" do
274
+ it "returns a float" do
282
275
  expect(stats.transfer_volume.class).to be(Float)
283
276
  end
284
277
  end
@@ -1,187 +1,95 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Gratitude::Client::Tips do
4
-
5
4
  let(:username) { "gratitude_test" }
6
5
  let(:api_key) { "5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2" }
7
-
8
- let(:client) { Gratitude::Client.new(:username => username, :api_key => api_key) }
9
-
10
- describe "methods that do not interact with the API" do
11
-
12
- describe "#tips_url" do
13
- it "returns the correct tips_url" do
14
- expect(client.tips_url).to eq("https://www.gittip.com/gratitude_test/tips.json")
15
- end
6
+ let(:client) do
7
+ Gratitude::Client.new(:username => username, :api_key => api_key)
8
+ end
9
+
10
+ describe "GET Requests" do
11
+ before { VCR.insert_cassette "get_tips" }
12
+ after { VCR.eject_cassette }
13
+ let(:current_tips) do
14
+ [
15
+ {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
16
+ {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
17
+ ]
16
18
  end
17
19
 
18
- describe "#authorization" do
19
- it "returns the correct authorization hash" do
20
- expect(client.authorization).to eq({ :username => api_key })
20
+ describe "#current_tips" do
21
+ it "returns the correct array of current tips" do
22
+ expect(client.current_tips).to eq (current_tips)
21
23
  end
22
24
  end
23
25
 
24
- describe "#tip_hash_based_upon(username, amount)" do
25
- it "returns the correct tip hash when given an integer" do
26
- expect(client.tip_hash_based_upon("whit537", 1)).to eq(
27
- { "amount" => "1", "platform" => "gittip", "username" => "whit537" })
28
- end
29
-
30
- it "returns the correct tip hash when given an integer in a string" do
31
- expect(client.tip_hash_based_upon("whit537", "1")).to eq(
32
- { "amount" => "1", "platform" => "gittip", "username" => "whit537" })
33
- end
34
-
35
- it "returns the correct tip hash when given a float" do
36
- expect(client.tip_hash_based_upon("whit537", 0.25)).to eq(
37
- { "amount" => "0.25", "platform" => "gittip", "username" => "whit537" })
38
- end
39
-
40
- it "returns the correct tip hash when given a float" do
41
- expect(client.tip_hash_based_upon("whit537", "0.25")).to eq(
42
- { "amount" => "0.25", "platform" => "gittip", "username" => "whit537" })
26
+ describe "#current_tips_total" do
27
+ it "returns the correct total of current tips" do
28
+ expect(client.current_tips_total).to eq(1.25)
43
29
  end
44
- end #single_tip_hash
45
-
46
-
47
- describe "#tips_array" do
48
-
49
- context "when using symbols as keys" do
50
- it "returns the correct tips array when given an array with one tip" do
51
- expect(client.prepared_tips_array([:username => "whit537", :amount => "1"])).to eq(
52
- [{ "amount" => "1", "platform" => "gittip", "username" => "whit537" }])
30
+ end
31
+ end #GET Requests
32
+
33
+ describe "POST Requests" do
34
+ describe "#update_tips" do
35
+ context "when updating a single tip" do
36
+ before { VCR.insert_cassette "post_single_tip" }
37
+ after { VCR.eject_cassette }
38
+ let(:single_tip_response) do
39
+ [{"amount"=>"5", "platform"=>"gittip", "username"=>"whit537"}]
53
40
  end
54
41
 
55
- it "returns the correct tips array when given an array with two tips" do
56
- expect(client.prepared_tips_array([
57
- { :username => "whit537", :amount => "1" },
58
- { :username => "JohnKellyFerguson", :amount => "0.25" }
59
- ])).to eq([
60
- { "amount" => "1", "platform" => "gittip", "username" => "whit537" },
61
- { "amount" => "0.25", "platform" => "gittip", "username" => "JohnKellyFerguson" }
62
- ])
42
+ it "updates the correct tip information" do
43
+ expect(
44
+ client.update_tips(
45
+ [{ :username => "whit537", :amount => "5" }]
46
+ ).parsed_response).to eq(single_tip_response)
63
47
  end
64
- end # symbols as keys
48
+ end #update_tips
65
49
 
66
- context "when using strings as keys" do
67
- it "returns the correct tips array when given an array with one tip" do
68
- expect(client.prepared_tips_array(["username" => "whit537", "amount" => "1"])).to eq(
69
- [{ "amount" => "1", "platform" => "gittip", "username" => "whit537" }])
70
- end
50
+ context "when updating multiple tips" do
51
+ before { VCR.insert_cassette "post_multiple_tips" }
52
+ after { VCR.eject_cassette }
71
53
 
72
- it "returns the correct tips array when given an array with one tip" do
73
- expect(client.prepared_tips_array([
74
- { "username" => "whit537", "amount" => "1" },
75
- { "username" => "JohnKellyFerguson", "amount" => "0.25" }
76
- ])).to eq([
77
- { "amount" => "1", "platform" => "gittip", "username" => "whit537" },
78
- { "amount" => "0.25", "platform" => "gittip", "username" => "JohnKellyFerguson" }
79
- ])
54
+ let(:multi_tip_response) do
55
+ [
56
+ {"amount"=>"10", "platform"=>"gittip", "username"=>"whit537"},
57
+ {"amount"=>"4", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
58
+ ]
80
59
  end
81
- end # strings as keys
82
-
83
- end #tips_array
84
-
85
- end # methods that do not interact with the API
86
-
87
-
88
- describe "authentication and api requests" do
89
-
90
- context "GET Requests" do
91
- let(:current_tips) { [{"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
92
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}] }
93
60
 
94
- before do
95
- VCR.insert_cassette "get_tips"
96
- end
61
+ it "updates the correct tip information" do
62
+ expect(
63
+ client.update_tips(
64
+ [{ :username => "whit537", :amount => "10" },
65
+ { :username => "JohnKellyFerguson", :amount => "4"}]
66
+ ).parsed_response).to eq(multi_tip_response)
67
+ end
68
+ end # updating multiple tips
97
69
 
98
- after do
99
- VCR.eject_cassette
100
- end
70
+ end #update_tips
101
71
 
102
- describe "#current_tips" do
103
- it "returns the correct array of current tips" do
104
- expect(client.current_tips).to eq (current_tips)
105
- end
72
+ describe "#update_tips_and_prune" do
73
+ let(:previous_tips) do
74
+ [
75
+ {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
76
+ {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
77
+ ]
106
78
  end
107
-
108
- describe "#current_tips_total" do
109
- it "returns the correct total of current tips" do
110
- expect(client.current_tips_total).to eq(1.25)
111
- end
79
+ let(:pruned_tips) do
80
+ [{ "amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537" }]
112
81
  end
113
- end #GET Requests
114
-
115
- context "POST Requests" do
116
-
117
- describe "#update_tips" do
118
-
119
- context "when updating a single tip" do
120
- let(:single_tip_response) { [{"amount"=>"5", "platform"=>"gittip", "username"=>"whit537"}] }
121
-
122
- before do
123
- VCR.insert_cassette "post_single_tip"
124
- end
125
-
126
- after do
127
- VCR.eject_cassette
128
- end
129
82
 
130
- it "updates the correct tip information" do
131
- expect(
132
- client.update_tips(
133
- [{ :username => "whit537", :amount => "5" }]
134
- ).parsed_response).to eq(single_tip_response)
135
- end
136
- end #updating a single tip
137
-
138
- context "when updating multiple tips" do
139
- let(:multi_tip_response) { [
140
- {"amount"=>"10", "platform"=>"gittip", "username"=>"whit537"},
141
- {"amount"=>"4", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
142
- ] }
143
-
144
- before do
145
- VCR.insert_cassette "post_multiple_tips"
146
- end
147
-
148
- after do
149
- VCR.eject_cassette
150
- end
151
-
152
- it "updates the correct tip information" do
153
- expect(
154
- client.update_tips(
155
- [{ :username => "whit537", :amount => "10" },
156
- { :username => "JohnKellyFerguson", :amount => "4"}]
157
- ).parsed_response).to eq(multi_tip_response)
158
- end
159
- end # updating multiple tips
160
-
161
- # context "when passing in a non-existent username" do
162
- # before do
163
- # VCR.insert_cassette "post_tip_error"
164
- # end
165
-
166
- # after do
167
- # VCR.eject_cassette
168
- # end
169
-
170
- # it "raises an error" do
171
- # expect(
172
- # client.update_tips(
173
- # [ {:username => "not_a_real_user", :amount => "20"} ]
174
- # ).parsed_response).to eq()
175
- # end
176
- # end # non-existent username
177
-
178
- end #update_tips
179
-
180
- describe "#update_tips_and_prune" do
83
+ before { VCR.insert_cassette "update_and_prune" }
84
+ after { VCR.eject_cassette }
181
85
 
86
+ it "removes tips that were not part of the request" do
87
+ expect { client.update_tips_and_prune(pruned_tips) }
88
+ .to change { client.current_tips }
89
+ .from(previous_tips).to(pruned_tips)
182
90
  end
183
91
 
184
- end #POST Requests
92
+ end
185
93
 
186
- end # authentication and api requests
94
+ end #POST Requests
187
95
  end
@@ -2,6 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe Gratitude do
4
4
  it "has a version" do
5
- expect(Gratitude::VERSION).not_to be_nil
5
+ expect(Gratitude::VERSION).to_not be_nil
6
6
  end
7
- end
7
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,4 +16,4 @@ VCR.configure do |c|
16
16
  c.cassette_library_dir = 'spec/cassettes'
17
17
  c.hook_into :webmock
18
18
  c.default_cassette_options = { record: :new_episodes, serialize_with: :json }
19
- end
19
+ end