spark_api 1.4.34 → 1.5.3
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/README.md +1 -1
- data/VERSION +1 -1
- data/lib/spark_api/authentication/api_auth.rb +5 -3
- data/lib/spark_api/authentication/oauth2.rb +2 -1
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +1 -1
- data/lib/spark_api/client.rb +2 -2
- data/lib/spark_api/models/media.rb +30 -0
- data/lib/spark_api/models/video.rb +108 -0
- data/lib/spark_api/models/virtual_tour.rb +16 -0
- data/lib/spark_api/models.rb +1 -0
- data/lib/spark_api/request.rb +17 -1
- data/lib/spark_api.rb +1 -0
- data/spec/spec_helper.rb +9 -4
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +40 -22
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +3 -3
- data/spec/unit/spark_api/authentication/oauth2_impl/faraday_middleware_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/single_session_provider_spec.rb +2 -2
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +58 -40
- data/spec/unit/spark_api/authentication_spec.rb +2 -2
- data/spec/unit/spark_api/configuration/yaml_spec.rb +44 -44
- data/spec/unit/spark_api/configuration_spec.rb +56 -57
- data/spec/unit/spark_api/faraday_middleware_spec.rb +12 -12
- data/spec/unit/spark_api/models/account_spec.rb +20 -20
- data/spec/unit/spark_api/models/activity_spec.rb +5 -5
- data/spec/unit/spark_api/models/base_spec.rb +32 -32
- data/spec/unit/spark_api/models/concerns/destroyable_spec.rb +2 -2
- data/spec/unit/spark_api/models/concerns/savable_spec.rb +19 -19
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +1 -1
- data/spec/unit/spark_api/models/constraint_spec.rb +1 -1
- data/spec/unit/spark_api/models/contact_spec.rb +50 -50
- data/spec/unit/spark_api/models/dirty_spec.rb +12 -12
- data/spec/unit/spark_api/models/document_spec.rb +3 -3
- data/spec/unit/spark_api/models/fields_spec.rb +17 -17
- data/spec/unit/spark_api/models/finders_spec.rb +7 -7
- data/spec/unit/spark_api/models/floplan_spec.rb +4 -4
- data/spec/unit/spark_api/models/listing_cart_spec.rb +46 -46
- data/spec/unit/spark_api/models/listing_meta_translations_spec.rb +6 -6
- data/spec/unit/spark_api/models/listing_spec.rb +91 -91
- data/spec/unit/spark_api/models/message_spec.rb +10 -10
- data/spec/unit/spark_api/models/note_spec.rb +10 -10
- data/spec/unit/spark_api/models/notification_spec.rb +6 -6
- data/spec/unit/spark_api/models/open_house_spec.rb +4 -4
- data/spec/unit/spark_api/models/photo_spec.rb +8 -8
- data/spec/unit/spark_api/models/portal_spec.rb +4 -4
- data/spec/unit/spark_api/models/property_types_spec.rb +5 -5
- data/spec/unit/spark_api/models/rental_calendar_spec.rb +13 -11
- data/spec/unit/spark_api/models/rule_spec.rb +2 -2
- data/spec/unit/spark_api/models/saved_search_spec.rb +33 -33
- data/spec/unit/spark_api/models/search_template/quick_search_spec.rb +5 -5
- data/spec/unit/spark_api/models/shared_listing_spec.rb +12 -12
- data/spec/unit/spark_api/models/sort_spec.rb +3 -3
- data/spec/unit/spark_api/models/standard_fields_spec.rb +12 -12
- data/spec/unit/spark_api/models/subresource_spec.rb +18 -18
- data/spec/unit/spark_api/models/system_info_spec.rb +7 -7
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +3 -3
- data/spec/unit/spark_api/models/video_spec.rb +9 -9
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +7 -7
- data/spec/unit/spark_api/models/vow_account_spec.rb +8 -8
- data/spec/unit/spark_api/multi_client_spec.rb +14 -14
- data/spec/unit/spark_api/options_hash_spec.rb +4 -4
- data/spec/unit/spark_api/paginate_spec.rb +71 -71
- data/spec/unit/spark_api/primary_array_spec.rb +5 -5
- data/spec/unit/spark_api/request_spec.rb +79 -63
- data/spec/unit/spark_api_spec.rb +6 -6
- metadata +178 -248
@@ -6,9 +6,9 @@ describe SparkApi::OptionsHash do
|
|
6
6
|
"parameter_two" => 2,
|
7
7
|
3 => 3}
|
8
8
|
o_h = SparkApi::OptionsHash.new(h)
|
9
|
-
o_h.keys.size.
|
10
|
-
o_h["parameter_one"].
|
11
|
-
o_h["parameter_two"].
|
12
|
-
o_h[3].
|
9
|
+
expect(o_h.keys.size).to eq(3)
|
10
|
+
expect(o_h["parameter_one"]).to eq(1)
|
11
|
+
expect(o_h["parameter_two"]).to eq(2)
|
12
|
+
expect(o_h[3]).to eq(3)
|
13
13
|
end
|
14
14
|
end
|
@@ -37,54 +37,54 @@ describe SparkApi::PaginateResponse do
|
|
37
37
|
json = "{#{paginate_json}}"
|
38
38
|
hash = JSON.parse(json)
|
39
39
|
results = subject.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
40
|
-
results.offset.
|
41
|
-
results.next_page.
|
42
|
-
results.previous_page.
|
43
|
-
results.current_page.
|
44
|
-
results.per_page.
|
45
|
-
results.total_pages.
|
46
|
-
results.total_entries.
|
47
|
-
results[0].
|
40
|
+
expect(results.offset).to eq(0)
|
41
|
+
expect(results.next_page).to eq(2)
|
42
|
+
expect(results.previous_page).to eq(nil)
|
43
|
+
expect(results.current_page).to eq(1)
|
44
|
+
expect(results.per_page).to eq(10)
|
45
|
+
expect(results.total_pages).to eq(4)
|
46
|
+
expect(results.total_entries).to eq(38)
|
47
|
+
expect(results[0]).to eq(1)
|
48
48
|
end
|
49
49
|
it "should give me the second page" do
|
50
50
|
json = "{#{paginate_json(2)}}"
|
51
51
|
hash = JSON.parse(json)
|
52
52
|
results = subject.paginate_response([11,12,13,14,15,16,17,18,19,20], hash["Pagination"])
|
53
|
-
results.offset.
|
54
|
-
results.next_page.
|
55
|
-
results.previous_page.
|
56
|
-
results.current_page.
|
57
|
-
results.per_page.
|
58
|
-
results.total_pages.
|
59
|
-
results.total_entries.
|
60
|
-
results[0].
|
53
|
+
expect(results.offset).to eq(10)
|
54
|
+
expect(results.next_page).to eq(3)
|
55
|
+
expect(results.previous_page).to eq(1)
|
56
|
+
expect(results.current_page).to eq(2)
|
57
|
+
expect(results.per_page).to eq(10)
|
58
|
+
expect(results.total_pages).to eq(4)
|
59
|
+
expect(results.total_entries).to eq(38)
|
60
|
+
expect(results[0]).to eq(11)
|
61
61
|
end
|
62
62
|
it "should give me the third page" do
|
63
63
|
json = "{#{paginate_json(3)}}"
|
64
64
|
hash = JSON.parse(json)
|
65
65
|
results = subject.paginate_response([21,22,23,24,25,26,27,28,29,30], hash["Pagination"])
|
66
|
-
results.offset.
|
67
|
-
results.next_page.
|
68
|
-
results.previous_page.
|
69
|
-
results.current_page.
|
70
|
-
results.per_page.
|
71
|
-
results.total_pages.
|
72
|
-
results.total_entries.
|
73
|
-
results[0].
|
66
|
+
expect(results.offset).to eq(20)
|
67
|
+
expect(results.next_page).to eq(4)
|
68
|
+
expect(results.previous_page).to eq(2)
|
69
|
+
expect(results.current_page).to eq(3)
|
70
|
+
expect(results.per_page).to eq(10)
|
71
|
+
expect(results.total_pages).to eq(4)
|
72
|
+
expect(results.total_entries).to eq(38)
|
73
|
+
expect(results[0]).to eq(21)
|
74
74
|
end
|
75
75
|
it "should give me the last page" do
|
76
76
|
json = "{#{paginate_json(4)}}"
|
77
77
|
hash = JSON.parse(json)
|
78
78
|
results = subject.paginate_response([31,32,33,34,35,36,37,38], hash["Pagination"])
|
79
|
-
results.offset.
|
80
|
-
results.next_page.
|
81
|
-
results.previous_page.
|
82
|
-
results.current_page.
|
83
|
-
results.per_page.
|
84
|
-
results.total_pages.
|
85
|
-
results.total_entries.
|
86
|
-
results[0].
|
87
|
-
results[-1].
|
79
|
+
expect(results.offset).to eq(30)
|
80
|
+
expect(results.next_page).to eq(nil)
|
81
|
+
expect(results.previous_page).to eq(3)
|
82
|
+
expect(results.current_page).to eq(4)
|
83
|
+
expect(results.per_page).to eq(10)
|
84
|
+
expect(results.total_pages).to eq(4)
|
85
|
+
expect(results.total_entries).to eq(38)
|
86
|
+
expect(results[0]).to eq(31)
|
87
|
+
expect(results[-1]).to eq(38)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -93,27 +93,27 @@ describe SparkApi::Paginate do
|
|
93
93
|
describe "paginate" do
|
94
94
|
it "should give me a will paginate collection" do
|
95
95
|
results = PaginateModelTester.paginate(:page => 1)
|
96
|
-
results.
|
97
|
-
results.offset.
|
98
|
-
results.next_page.
|
99
|
-
results.previous_page.
|
100
|
-
results.current_page.
|
101
|
-
results.per_page.
|
102
|
-
results.total_pages.
|
103
|
-
results.total_entries.
|
96
|
+
expect(results).to be_a(WillPaginate::Collection)
|
97
|
+
expect(results.offset).to eq(0)
|
98
|
+
expect(results.next_page).to eq(2)
|
99
|
+
expect(results.previous_page).to eq(nil)
|
100
|
+
expect(results.current_page).to eq(1)
|
101
|
+
expect(results.per_page).to eq(10)
|
102
|
+
expect(results.total_pages).to eq(4)
|
103
|
+
expect(results.total_entries).to eq(38)
|
104
104
|
|
105
|
-
results[0].
|
106
|
-
results[0].val.
|
105
|
+
expect(results[0]).to be_a(PaginateModelTester)
|
106
|
+
expect(results[0].val).to eq(1)
|
107
107
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should give me pagination options" do
|
111
111
|
PaginateModelTester.paginate(:page => 1)
|
112
112
|
opts = PaginateModelTester.options
|
113
|
-
opts["_pagination"].
|
114
|
-
opts["_limit"].
|
115
|
-
opts["_page"].
|
116
|
-
opts.has_key?(:page).
|
113
|
+
expect(opts["_pagination"]).to eq(1)
|
114
|
+
expect(opts["_limit"]).to eq(25)
|
115
|
+
expect(opts["_page"]).to eq(1)
|
116
|
+
expect(opts.has_key?(:page)).to eq(false)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -121,7 +121,7 @@ describe SparkApi::Paginate do
|
|
121
121
|
it "should set the default model max results per page" do
|
122
122
|
results = PaginateModelTester50.paginate(:page => 1)
|
123
123
|
opts = PaginateModelTester50.options
|
124
|
-
opts["_limit"].
|
124
|
+
expect(opts["_limit"]).to eq(50)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -151,18 +151,18 @@ describe SparkApi::Paginate do
|
|
151
151
|
}).
|
152
152
|
to_return(:body => json)
|
153
153
|
results = subject.paginate(:page=>1, :per_page=>10)
|
154
|
-
results.
|
155
|
-
results.offset.
|
156
|
-
results.next_page.
|
157
|
-
results.previous_page.
|
158
|
-
results.current_page.
|
159
|
-
results.per_page.
|
160
|
-
results.total_pages.
|
161
|
-
results.total_entries.
|
162
|
-
results.length.
|
154
|
+
expect(results).to be_a(WillPaginate::Collection)
|
155
|
+
expect(results.offset).to eq(0)
|
156
|
+
expect(results.next_page).to eq(2)
|
157
|
+
expect(results.previous_page).to eq(nil)
|
158
|
+
expect(results.current_page).to eq(1)
|
159
|
+
expect(results.per_page).to eq(10)
|
160
|
+
expect(results.total_pages).to eq(4)
|
161
|
+
expect(results.total_entries).to eq(38)
|
162
|
+
expect(results.length).to eq(10)
|
163
163
|
|
164
|
-
results[0].
|
165
|
-
results[0].ListPrice.
|
164
|
+
expect(results[0]).to be_a(subject)
|
165
|
+
expect(results[0].ListPrice).to eq(50000.0)
|
166
166
|
|
167
167
|
end
|
168
168
|
it "gives me page two of listings" do
|
@@ -184,9 +184,9 @@ describe SparkApi::Paginate do
|
|
184
184
|
}).
|
185
185
|
to_return(:body => json)
|
186
186
|
results = subject.paginate(:page=>2, :per_page=>10)
|
187
|
-
results.next_page.
|
188
|
-
results.previous_page.
|
189
|
-
results.current_page.
|
187
|
+
expect(results.next_page).to eq(3)
|
188
|
+
expect(results.previous_page).to eq(1)
|
189
|
+
expect(results.current_page).to eq(2)
|
190
190
|
end
|
191
191
|
it "gives me page four of listings" do
|
192
192
|
json = <<-JSON
|
@@ -207,16 +207,16 @@ describe SparkApi::Paginate do
|
|
207
207
|
}).
|
208
208
|
to_return(:body => json)
|
209
209
|
results = subject.paginate(:page=>4, :per_page=>10)
|
210
|
-
results.next_page.
|
211
|
-
results.previous_page.
|
212
|
-
results.current_page.
|
213
|
-
results.per_page.
|
214
|
-
results.total_pages.
|
215
|
-
results.total_entries.
|
210
|
+
expect(results.next_page).to eq(nil)
|
211
|
+
expect(results.previous_page).to eq(3)
|
212
|
+
expect(results.current_page).to eq(4)
|
213
|
+
expect(results.per_page).to eq(10)
|
214
|
+
expect(results.total_pages).to eq(4)
|
215
|
+
expect(results.total_entries).to eq(38)
|
216
216
|
|
217
|
-
results.length.
|
218
|
-
results[0].
|
219
|
-
results[0].ListPrice.
|
217
|
+
expect(results.length).to eq(8)
|
218
|
+
expect(results[0]).to be_a(subject)
|
219
|
+
expect(results[0].ListPrice).to eq(50000.0)
|
220
220
|
end
|
221
221
|
|
222
222
|
end
|
@@ -18,12 +18,12 @@ describe SparkApi::PrimaryArray do
|
|
18
18
|
d = PrimaryModel.new(4, true)
|
19
19
|
e = PrimaryModel.new(5)
|
20
20
|
tester = subject.class.new([d,e])
|
21
|
-
tester.primary.
|
21
|
+
expect(tester.primary).to eq(d)
|
22
22
|
tester = subject.class.new([a,b,c,d,e])
|
23
|
-
tester.primary.
|
23
|
+
expect(tester.primary).to eq(d)
|
24
24
|
# Note, it doesn't care if there is more than one primary, just returns first in the list.
|
25
25
|
b.Primary = true
|
26
|
-
tester.primary.
|
26
|
+
expect(tester.primary).to eq(b)
|
27
27
|
end
|
28
28
|
it "should return nil when there is no primary element" do
|
29
29
|
a = PrimaryModel.new(1)
|
@@ -32,9 +32,9 @@ describe SparkApi::PrimaryArray do
|
|
32
32
|
d = PrimaryModel.new(4)
|
33
33
|
e = PrimaryModel.new(5)
|
34
34
|
tester = subject.class.new([])
|
35
|
-
tester.primary.
|
35
|
+
expect(tester.primary).to be(nil)
|
36
36
|
tester = subject.class.new([a,b,c,d,e])
|
37
|
-
tester.primary.
|
37
|
+
expect(tester.primary).to be(nil)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -4,45 +4,45 @@ describe SparkApi do
|
|
4
4
|
describe SparkApi::ClientError do
|
5
5
|
subject { SparkApi::ClientError.new({:message=>"OMG FAIL", :code=>1234, :status=>500, :request_path => '/v1/foo', :request_id => 'deadbeef'}) }
|
6
6
|
it "should print a helpful to_s" do
|
7
|
-
subject.to_s.
|
8
|
-
subject.message.
|
7
|
+
expect(subject.to_s).to eq("OMG FAIL")
|
8
|
+
expect(subject.message).to eq("OMG FAIL")
|
9
9
|
end
|
10
10
|
it "should have an api code" do
|
11
|
-
subject.code.
|
11
|
+
expect(subject.code).to eq(1234)
|
12
12
|
end
|
13
13
|
it "should have an http status" do
|
14
|
-
subject.status.
|
14
|
+
expect(subject.status).to eq(500)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have a request_path" do
|
18
|
-
subject.request_path.
|
18
|
+
expect(subject.request_path).to eq('/v1/foo')
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should have a request_id" do
|
22
|
-
subject.request_id.
|
22
|
+
expect(subject.request_id).to eq('deadbeef')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise and exception with attached message" do
|
26
26
|
expect { raise subject.class, {:message=>"My Message", :code=>1000, :status=>404}}.to raise_error(SparkApi::ClientError) do |e|
|
27
|
-
e.message.
|
28
|
-
e.code.
|
29
|
-
e.status.
|
27
|
+
expect(e.message).to eq("My Message")
|
28
|
+
expect(e.code).to eq(1000)
|
29
|
+
expect(e.status).to eq(404)
|
30
30
|
end
|
31
31
|
expect { raise subject.class.new({:message=>"My Message", :code=>1000, :status=>404}) }.to raise_error(SparkApi::ClientError) do |e|
|
32
|
-
e.message.
|
33
|
-
e.code.
|
34
|
-
e.status.
|
32
|
+
expect(e.message).to eq("My Message")
|
33
|
+
expect(e.code).to eq(1000)
|
34
|
+
expect(e.status).to eq(404)
|
35
35
|
end
|
36
36
|
expect { raise subject.class.new({:code=>1000, :status=>404}), "My Message"}.to raise_error(SparkApi::ClientError) do |e|
|
37
|
-
e.message.
|
38
|
-
e.code.
|
39
|
-
e.status.
|
37
|
+
expect(e.message).to eq("My Message")
|
38
|
+
expect(e.code).to eq(1000)
|
39
|
+
expect(e.status).to eq(404)
|
40
40
|
end
|
41
41
|
expect { raise subject.class, "My Message"}.to raise_error(SparkApi::ClientError) do |e|
|
42
|
-
e.message.
|
43
|
-
e.code.
|
44
|
-
e.status.
|
45
|
-
e.request_id.
|
42
|
+
expect(e.message).to eq("My Message")
|
43
|
+
expect(e.code).to eq(nil)
|
44
|
+
expect(e.status).to eq(nil)
|
45
|
+
expect(e.request_id).to eq(nil)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -54,34 +54,34 @@ describe SparkApi do
|
|
54
54
|
end
|
55
55
|
it "should have results when successful" do
|
56
56
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => true, "Results" => []}})
|
57
|
-
r.success
|
58
|
-
r.results.empty
|
59
|
-
r.request_id.
|
57
|
+
expect(r.success?).to be(true)
|
58
|
+
expect(r.results.empty?).to be(true)
|
59
|
+
expect(r.request_id).to eq nil
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should return the request_id" do
|
63
63
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => true, "Results" => []}}, 'foobar')
|
64
|
-
r.success
|
65
|
-
r.request_id.
|
64
|
+
expect(r.success?).to be(true)
|
65
|
+
expect(r.request_id).to eq('foobar')
|
66
66
|
end
|
67
67
|
it "should have a message on error" do
|
68
68
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure."}})
|
69
|
-
r.success
|
70
|
-
r.message.
|
69
|
+
expect(r.success?).to be(false)
|
70
|
+
expect(r.message).to eq("I am a failure.")
|
71
71
|
end
|
72
72
|
it "should have SparkQLErrors when present" do
|
73
73
|
err = {"Token" => "ExpirationDate", "Status" => "Dropped"}
|
74
74
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure from .",
|
75
75
|
"SparkQLErrors" => [err]
|
76
76
|
}})
|
77
|
-
r.sparkql_errors.first.
|
77
|
+
expect(r.sparkql_errors.first).to eq(err)
|
78
78
|
end
|
79
79
|
it "should have Errors when present" do
|
80
80
|
err = {"Type" => "InvalidAttribute", "Attribute" => "DisplayName", "Message" => "DisplayName is wrong."}
|
81
81
|
r = SparkApi::ApiResponse.new({"D"=>{"Success" => false, "Message" => "I am a failure from .",
|
82
82
|
"Errors" => [err]
|
83
83
|
}})
|
84
|
-
r.errors.first.
|
84
|
+
expect(r.errors.first).to eq(err)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -160,7 +160,13 @@ describe SparkApi do
|
|
160
160
|
}
|
161
161
|
}']
|
162
162
|
}
|
163
|
-
|
163
|
+
# For testing http_method_override. See associated test for more details.
|
164
|
+
stub.post('/v1/routetoproveweareposting?ApiSig=SignedToken&AuthToken=1234', 'some_param=some_value') { [200, {}, '{"D": {
|
165
|
+
"Success": true,
|
166
|
+
"Results": []
|
167
|
+
}
|
168
|
+
}']
|
169
|
+
}
|
164
170
|
end
|
165
171
|
@connection = test_connection(stubs)
|
166
172
|
end
|
@@ -193,62 +199,72 @@ describe SparkApi do
|
|
193
199
|
r
|
194
200
|
end
|
195
201
|
it "should get a service" do
|
196
|
-
subject.get('/system')[0]["Name"].
|
202
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
197
203
|
end
|
198
204
|
it "should get a service with parameters" do
|
199
|
-
subject.get('/marketstatistics/price', "Options" => "ActiveAverageListPrice")[0]["ActiveAverageListPrice"].
|
205
|
+
expect(subject.get('/marketstatistics/price', "Options" => "ActiveAverageListPrice")[0]["ActiveAverageListPrice"]).to eq([100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000])
|
200
206
|
end
|
201
207
|
it "should post to a service" do
|
202
208
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
203
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
209
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
204
210
|
end
|
205
211
|
it "should put to a service" do
|
206
212
|
# This is a hypothetical unsupported service action at this time
|
207
213
|
data = {"Contacts" => [{"DisplayName"=>"WLMCEWENS Contact","PrimaryEmail"=>"wlmcewen789@fbsdata.com"}]}
|
208
|
-
subject.put('/contacts/1000', data).size.
|
214
|
+
expect(subject.put('/contacts/1000', data).size).to be(0)
|
209
215
|
# No validation here, if no error is raised, everything is hunky dory
|
210
216
|
end
|
211
217
|
it "should delete from a service" do
|
212
218
|
# This is a hypothetical unsupported service action at this time
|
213
|
-
subject.delete('/contacts/1000').size.
|
219
|
+
expect(subject.delete('/contacts/1000').size).to be(0)
|
214
220
|
# No validation here, if no error is raised, everything is hunky dory
|
215
221
|
end
|
216
222
|
|
217
223
|
it "should escape a path correctly" do
|
218
|
-
subject.get('/test path with spaces').length.
|
224
|
+
expect(subject.get('/test path with spaces').length).to eq(0)
|
219
225
|
# now try this with an already escaped path. Kaboom!
|
220
226
|
expect { subject.get('/test%20path%20with%20spaces') }.to raise_error()
|
221
227
|
end
|
222
228
|
|
223
229
|
it "post data should support non json data" do
|
224
230
|
# Other MISC requests
|
225
|
-
subject.post('/stringdata', 'I am a lonely String!').success
|
231
|
+
expect(subject.post('/stringdata', 'I am a lonely String!').success?).to eq(true)
|
226
232
|
end
|
227
233
|
|
228
234
|
it "should support arrays in the body" do
|
229
|
-
subject.put('/arraydata', ["A","B","C"]).success
|
235
|
+
expect(subject.put('/arraydata', ["A","B","C"]).success?).to be true
|
230
236
|
end
|
231
237
|
|
232
238
|
it "should allow response object to be returned instead of body" do
|
233
|
-
r = subject.get('/system', { full_response: true })
|
239
|
+
r = subject.get('/system', { some_param: 'something', full_response: true })
|
234
240
|
|
235
|
-
r.is_a?(Faraday::Response).
|
236
|
-
r.status.
|
241
|
+
expect(r.is_a?(Faraday::Response)).to be(true)
|
242
|
+
expect(r.status).to eq(200)
|
237
243
|
end
|
238
244
|
|
239
245
|
it "should give me BigDecimal results for large floating point numbers" do
|
240
|
-
MultiJson.default_adapter.
|
246
|
+
expect(MultiJson.default_adapter).to eq(:yajl) unless jruby?
|
241
247
|
result = subject.get('/listings/1000')[0]
|
242
|
-
result["StandardFields"]["BuildingAreaTotal"].
|
243
|
-
|
244
|
-
result["StandardFields"]["BuildingAreaTotal"].
|
248
|
+
expect(result["StandardFields"]["BuildingAreaTotal"]).to be_a(Float)
|
249
|
+
skip("our JSON parser does not support large decimal types. Anyone feel like writing some c code?") do
|
250
|
+
expect(result["StandardFields"]["BuildingAreaTotal"]).to be_a(BigDecimal)
|
245
251
|
number = BigDecimal.new(result["StandardFields"]["BuildingAreaTotal"].to_s)
|
246
|
-
number.to_s.
|
252
|
+
expect(number.to_s).to eq(BigDecimal.new("0.000000000000000000000000001").to_s)
|
247
253
|
number = BigDecimal.new(result["StandardFields"]["ListPrice"].to_s)
|
248
|
-
number.to_s.
|
254
|
+
expect(number.to_s).to eq(BigDecimal.new("9999999999999999999999999.99").to_s)
|
249
255
|
end
|
250
256
|
end
|
251
|
-
|
257
|
+
|
258
|
+
# This is a weird feature and it also gets a weird test that probably
|
259
|
+
# merits explanation:
|
260
|
+
#
|
261
|
+
# We have only stubbed POST for this route, so the below succeeding
|
262
|
+
# proves that we have converted our GET into a POST. It is additionally
|
263
|
+
# stubbed to prove that we turn the params into a body which excludes the
|
264
|
+
# http_method_override options as well as the override_headers options.
|
265
|
+
it "should convert GET to POST if http_method_override: true is supplied" do
|
266
|
+
expect(subject.get('/routetoproveweareposting', { http_method_override: true, some_param: "some_value" }).success?).to be true
|
267
|
+
end
|
252
268
|
end
|
253
269
|
|
254
270
|
context "when unauthenticated" do
|
@@ -279,11 +295,11 @@ describe SparkApi do
|
|
279
295
|
r
|
280
296
|
end
|
281
297
|
it "should authenticate and then get a service" do
|
282
|
-
subject.get('/system')[0]["Name"].
|
298
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
283
299
|
end
|
284
300
|
it "should authenticate and then post to a service" do
|
285
301
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
286
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
302
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
287
303
|
end
|
288
304
|
end
|
289
305
|
|
@@ -322,13 +338,13 @@ describe SparkApi do
|
|
322
338
|
r
|
323
339
|
end
|
324
340
|
it "should reauthenticate and then get a service" do
|
325
|
-
subject.get('/system')[0]["Name"].
|
326
|
-
subject.reauthenticated
|
341
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
342
|
+
expect(subject.reauthenticated?).to eq(true)
|
327
343
|
end
|
328
344
|
it "should reauthenticate and then post to a service" do
|
329
345
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
330
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
331
|
-
subject.reauthenticated
|
346
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
347
|
+
expect(subject.reauthenticated?).to eq(true)
|
332
348
|
end
|
333
349
|
end
|
334
350
|
|
@@ -340,13 +356,13 @@ describe SparkApi do
|
|
340
356
|
r
|
341
357
|
end
|
342
358
|
it "should reauthenticate and then get a service" do
|
343
|
-
subject.get('/system')[0]["Name"].
|
344
|
-
subject.reauthenticated
|
359
|
+
expect(subject.get('/system')[0]["Name"]).to eq("My User")
|
360
|
+
expect(subject.reauthenticated?).to eq(true)
|
345
361
|
end
|
346
362
|
it "should reauthenticate and then post to a service" do
|
347
363
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
348
|
-
subject.post('/contacts', data)[0]["ResourceUri"].
|
349
|
-
subject.reauthenticated
|
364
|
+
expect(subject.post('/contacts', data)[0]["ResourceUri"]).to eq("1000")
|
365
|
+
expect(subject.reauthenticated?).to eq(true)
|
350
366
|
end
|
351
367
|
end
|
352
368
|
|
@@ -384,19 +400,19 @@ describe SparkApi do
|
|
384
400
|
end
|
385
401
|
it "should fail horribly on a get" do
|
386
402
|
expect { subject.get('/system')}.to raise_error(SparkApi::PermissionDenied) do |e|
|
387
|
-
e.code.
|
388
|
-
e.request_path.
|
403
|
+
expect(e.code).to eq(SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED)
|
404
|
+
expect(e.request_path.to_s).to match(/\/system/)
|
389
405
|
end
|
390
|
-
subject.reauthenticated.
|
406
|
+
expect(subject.reauthenticated).to eq(2)
|
391
407
|
|
392
408
|
end
|
393
409
|
it "should fail horribly on a post" do
|
394
410
|
data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
|
395
411
|
expect { subject.post('/contacts', data)}.to raise_error(SparkApi::PermissionDenied) do |e|
|
396
|
-
e.code.
|
397
|
-
e.request_path.
|
412
|
+
expect(e.code).to eq(SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED)
|
413
|
+
expect(e.request_path.to_s).to match(/\/contacts/)
|
398
414
|
end
|
399
|
-
subject.reauthenticated.
|
415
|
+
expect(subject.reauthenticated).to eq(2)
|
400
416
|
end
|
401
417
|
end
|
402
418
|
|