yield_star_client 0.1.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.
Files changed (75) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +3 -0
  4. data/Gemfile +4 -0
  5. data/README.md +38 -0
  6. data/Rakefile +17 -0
  7. data/lib/yield_star_client/amenity_methods.rb +77 -0
  8. data/lib/yield_star_client/client.rb +84 -0
  9. data/lib/yield_star_client/errors.rb +52 -0
  10. data/lib/yield_star_client/floor_plan_methods.rb +78 -0
  11. data/lib/yield_star_client/lease_term_rent_methods.rb +185 -0
  12. data/lib/yield_star_client/property_methods.rb +138 -0
  13. data/lib/yield_star_client/rent_methods.rb +179 -0
  14. data/lib/yield_star_client/unit_methods.rb +95 -0
  15. data/lib/yield_star_client/validations.rb +18 -0
  16. data/lib/yield_star_client/version.rb +3 -0
  17. data/lib/yield_star_client.rb +74 -0
  18. data/spec/fixtures/faults/authentication_fault.xml +15 -0
  19. data/spec/fixtures/faults/generic_fault.xml +9 -0
  20. data/spec/fixtures/faults/internal_error_fault.xml +15 -0
  21. data/spec/fixtures/faults/operation_fault.xml +15 -0
  22. data/spec/fixtures/get_available_units/multiple_floor_plans.xml +53 -0
  23. data/spec/fixtures/get_available_units/no_floor_plans.xml +11 -0
  24. data/spec/fixtures/get_available_units/single_floor_plan.xml +28 -0
  25. data/spec/fixtures/get_floor_plan/full_floor_plan.xml +19 -0
  26. data/spec/fixtures/get_floor_plan/simple_floor_plan.xml +14 -0
  27. data/spec/fixtures/get_floor_plan_amenities/multiple_amenities.xml +19 -0
  28. data/spec/fixtures/get_floor_plan_amenities/no_amenities.xml +10 -0
  29. data/spec/fixtures/get_floor_plan_amenities/single_amenity.xml +15 -0
  30. data/spec/fixtures/get_floor_plans/multiple_floor_plans.xml +28 -0
  31. data/spec/fixtures/get_floor_plans/no_floor_plan.xml +10 -0
  32. data/spec/fixtures/get_floor_plans/single_floor_plan.xml +15 -0
  33. data/spec/fixtures/get_lease_term_rent/multiple_rates.xml +41 -0
  34. data/spec/fixtures/get_lease_term_rent/no_rates.xml +13 -0
  35. data/spec/fixtures/get_lease_term_rent/single_rate.xml +21 -0
  36. data/spec/fixtures/get_lease_term_rent_plus/multiple_rates.xml +43 -0
  37. data/spec/fixtures/get_lease_term_rent_plus/no_rates.xml +14 -0
  38. data/spec/fixtures/get_lease_term_rent_plus/single_rate.xml +22 -0
  39. data/spec/fixtures/get_properties/multiple_properties.xml +38 -0
  40. data/spec/fixtures/get_properties/no_property.xml +10 -0
  41. data/spec/fixtures/get_properties/single_property.xml +14 -0
  42. data/spec/fixtures/get_property/full_property.xml +25 -0
  43. data/spec/fixtures/get_property/simple_property.xml +14 -0
  44. data/spec/fixtures/get_property_parameters/full_parameters.xml +38 -0
  45. data/spec/fixtures/get_property_parameters/no_parameters.xml +10 -0
  46. data/spec/fixtures/get_property_parameters/simple_parameters.xml +14 -0
  47. data/spec/fixtures/get_renewal_lease_term_rent/multiple_rates.xml +28 -0
  48. data/spec/fixtures/get_renewal_lease_term_rent/no_rates.xml +10 -0
  49. data/spec/fixtures/get_renewal_lease_term_rent/single_rate.xml +21 -0
  50. data/spec/fixtures/get_rent_summary/multiple_summaries.xml +41 -0
  51. data/spec/fixtures/get_rent_summary/no_summaries.xml +11 -0
  52. data/spec/fixtures/get_rent_summary/single_summary.xml +24 -0
  53. data/spec/fixtures/get_unit/full_unit.xml +22 -0
  54. data/spec/fixtures/get_unit/simple_unit.xml +16 -0
  55. data/spec/fixtures/get_unit_amenities/multiple_amenities.xml +20 -0
  56. data/spec/fixtures/get_unit_amenities/no_amenities.xml +11 -0
  57. data/spec/fixtures/get_unit_amenities/single_amenity.xml +15 -0
  58. data/spec/fixtures/get_units/multiple_units.xml +32 -0
  59. data/spec/fixtures/get_units/no_units.xml +10 -0
  60. data/spec/fixtures/get_units/single_unit.xml +16 -0
  61. data/spec/spec_helper.rb +16 -0
  62. data/spec/support/fault_handler_shared_examples.rb +68 -0
  63. data/spec/support/validator_shared_examples.rb +79 -0
  64. data/spec/yield_star_client/amenity_methods_spec.rb +165 -0
  65. data/spec/yield_star_client/client_spec.rb +150 -0
  66. data/spec/yield_star_client/errors_spec.rb +93 -0
  67. data/spec/yield_star_client/floor_plan_methods_spec.rb +126 -0
  68. data/spec/yield_star_client/lease_term_rent_methods_spec.rb +391 -0
  69. data/spec/yield_star_client/property_methods_spec.rb +189 -0
  70. data/spec/yield_star_client/rent_methods_spec.rb +271 -0
  71. data/spec/yield_star_client/unit_methods_spec.rb +168 -0
  72. data/spec/yield_star_client/validations_spec.rb +19 -0
  73. data/spec/yield_star_client_spec.rb +89 -0
  74. data/yield_star_client.gemspec +34 -0
  75. metadata +348 -0
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ describe "property methods" do
4
+ subject { test_object }
5
+
6
+ let(:test_object) { YieldStarClient::Client.new(:endpoint => 'http://bogusendpoint') }
7
+
8
+ let(:client_name) { 'my client name' }
9
+ let(:external_property_id) { 'my-external-property-id' }
10
+
11
+ it { should respond_to(:get_properties) }
12
+ it { should respond_to(:get_property) }
13
+ it { should respond_to(:get_property_parameters) }
14
+
15
+ describe "#get_properties" do
16
+ before { savon.stubs(:get_properties).returns(nil) }
17
+
18
+ subject { properties }
19
+ let(:properties) { test_object.get_properties(client_name) }
20
+
21
+ it "should retrieve the property data by client_name from the service" do
22
+ savon.expects(:get_properties).with(:request => {:client_name => client_name}).returns(:single_property)
23
+ subject.should be
24
+ end
25
+
26
+ context "with no properties" do
27
+ before { savon.stubs(:get_properties).returns(:no_property) }
28
+
29
+ it { should be }
30
+ it { should be_empty }
31
+ end
32
+
33
+ context "with single property" do
34
+ before { savon.stubs(:get_properties).returns(:single_property) }
35
+
36
+ it { should have(1).property }
37
+
38
+ describe "first property" do
39
+ subject { properties.first }
40
+
41
+ its(:name) { should == 'Minimal' }
42
+ its(:external_property_id) { should == '1' }
43
+ end
44
+ end
45
+
46
+ context "with multiple properties" do
47
+ before { savon.stubs(:get_properties).returns(:multiple_properties) }
48
+
49
+ it { should have(2).properties }
50
+
51
+ describe "first property" do
52
+ subject { properties.first }
53
+
54
+ its(:external_property_id) { should == '2' }
55
+ its(:name) { should == 'Typical' }
56
+ its(:address) { should == '123 Address Ln' }
57
+ its(:city) { should == 'Beverly Hills' }
58
+ its(:state) { should == 'CA' }
59
+ its(:zip) { should == '90210' }
60
+ its(:longitude) { should == -122.605687 }
61
+ its(:latitude) { should == 45.544873 }
62
+ its(:phone) { should_not be }
63
+ its(:fax) { should_not be }
64
+ its(:year_built) { should == 2009 }
65
+ its(:unit_count) { should_not be }
66
+ its(:website) { should_not be }
67
+ end
68
+
69
+ describe "last property" do
70
+ subject { properties.last }
71
+
72
+ its(:external_property_id) { should == '3' }
73
+ its(:name) { should == 'Fully Loaded' }
74
+ its(:address) { should == '550 NW Franklin Ave #200' }
75
+ its(:city) { should == 'Bend' }
76
+ its(:state) { should == 'OR' }
77
+ its(:zip) { should == '97701' }
78
+ its(:longitude) { should == -121.313936 }
79
+ its(:latitude) { should == 44.057411 }
80
+ its(:phone) { should == '5413063374' }
81
+ its(:fax) { should == '1234567890' }
82
+ its(:website) { should == 'http://g5platform.com' }
83
+ its(:unit_count) { should == 100 }
84
+ its(:year_built) { should == 2008 }
85
+ end
86
+ end
87
+
88
+ it_should_behave_like "a client_name validator"
89
+
90
+ it_should_behave_like "a fault handler", :get_properties
91
+ end
92
+
93
+ describe "#get_property" do
94
+ before { savon.stubs(:get_property).returns(nil) }
95
+
96
+ subject { property }
97
+ let(:property) { test_object.get_property(client_name, external_property_id) }
98
+
99
+ it "should retrieve the property data from the service" do
100
+ savon.expects(:get_property).
101
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id}).
102
+ returns(:simple_property)
103
+ subject.should be
104
+ end
105
+
106
+ context "for a simple property" do
107
+ before { savon.stubs(:get_property).returns(:simple_property) }
108
+
109
+ its(:external_property_id) { should == '42' }
110
+ its(:name) { should == 'Galaxy Apartments' }
111
+ end
112
+
113
+ context "for a fully specified property" do
114
+ before { savon.stubs(:get_property).returns(:full_property) }
115
+
116
+ its(:external_property_id) { should == '99' }
117
+ its(:name) { should == 'Full Property' }
118
+ its(:address) { should == '123 My Street' }
119
+ its(:city) { should == 'Anywhere' }
120
+ its(:state) { should == 'AK' }
121
+ its(:zip) { should == '99999' }
122
+ its(:longitude) { should == -95.514257 }
123
+ its(:latitude) { should == 29.732654 }
124
+ its(:year_built) { should == 2008 }
125
+ its(:phone) { should == '555-555-5555' }
126
+ its(:fax) { should == '999-999-9999' }
127
+ its(:website) { should == 'http://google.com' }
128
+ its(:unit_count) { should == 100 }
129
+ end
130
+
131
+ # Validations
132
+ it_should_behave_like 'a client_name validator'
133
+ it_should_behave_like 'an external_property_id validator'
134
+
135
+ # Error handling
136
+ it_should_behave_like "a fault handler", :get_property
137
+ end
138
+
139
+ describe "#get_property_parameters" do
140
+ before { savon.stubs(:get_property_parameters).returns(nil) }
141
+
142
+ subject { parameters }
143
+ let(:parameters) { test_object.get_property_parameters(client_name, external_property_id) }
144
+
145
+ it "should retrieve the data from the service" do
146
+ savon.expects(:get_property_parameters).
147
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id}).
148
+ returns(:no_parameters)
149
+ subject.should be
150
+ end
151
+
152
+ context "with empty parameters" do
153
+ before { savon.stubs(:get_property_parameters).returns(:no_parameters) }
154
+
155
+ it { should be }
156
+ its(:external_property_id) { should == external_property_id }
157
+ end
158
+
159
+ context "with partial parameters" do
160
+ before { savon.stubs(:get_property_parameters).returns(:simple_parameters) }
161
+
162
+ it { should be }
163
+ its(:external_property_id) { should == external_property_id }
164
+ its(:post_date) { should == Date.new(2011, 3, 2) }
165
+ end
166
+
167
+ context "with full parameters" do
168
+ before { savon.stubs(:get_property_parameters).returns(:full_parameters) }
169
+
170
+ it { should be }
171
+
172
+ its(:external_property_id) { should == external_property_id }
173
+ its(:new_lease_term_options) { should == 3 }
174
+ its(:post_date) { should == Date.new(2011, 3, 1) }
175
+ its(:max_renewal_lease_term) { should == 15 }
176
+ its(:min_new_lease_term) { should == 1 }
177
+ its(:min_renewal_lease_term) { should == 1 }
178
+ its(:max_new_lease_term) { should == 15 }
179
+ its(:max_move_in_days) { should == 55 }
180
+ end
181
+
182
+ # Validations
183
+ it_should_behave_like 'a client_name validator'
184
+ it_should_behave_like 'an external_property_id validator'
185
+
186
+ # Error handling
187
+ it_should_behave_like "a fault handler", :get_property_parameters
188
+ end
189
+ end
@@ -0,0 +1,271 @@
1
+ require 'spec_helper'
2
+
3
+ describe "rental/availability methods" do
4
+ subject { test_object }
5
+
6
+ let(:test_object) { YieldStarClient::Client.new(:endpoint => 'http://bogusendpoint') }
7
+
8
+ let(:client_name) { 'my_client_name' }
9
+ let(:external_property_id) { '42' }
10
+
11
+ it { should respond_to(:get_rent_summary) }
12
+
13
+ describe "#get_rent_summary" do
14
+ before { savon.stubs(:get_rent_summary).returns(nil) }
15
+
16
+ subject { rent_summaries }
17
+ let(:rent_summaries) { test_object.get_rent_summary(client_name, external_property_id) }
18
+
19
+ it "should retrieve the data from the service" do
20
+ savon.expects(:get_rent_summary).
21
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id}).
22
+ returns(:no_summaries)
23
+ subject.should be
24
+ end
25
+
26
+ context "with no summaries" do
27
+ before { savon.stubs(:get_rent_summary).returns(:no_summaries) }
28
+
29
+ it { should be_empty }
30
+ end
31
+
32
+ context "with one summary" do
33
+ before { savon.stubs(:get_rent_summary).returns(:single_summary) }
34
+
35
+ it { should have(1).summary }
36
+
37
+ describe "the first summary" do
38
+ subject { rent_summaries.first }
39
+
40
+ its(:external_property_id) { should == external_property_id }
41
+ its(:effective_date) { should == Date.civil(2011, 3, 11) }
42
+ its(:floor_plan_name) { should == '99' }
43
+ its(:unit_type) { should == '1b1ba' }
44
+ its(:bedrooms) { should == 1.0 }
45
+ its(:bathrooms) { should == 1.0 }
46
+ its(:avg_square_feet) { should == 797 }
47
+ its(:min_market_rent) { should == 765 }
48
+ its(:max_market_rent) { should == 820 }
49
+ its(:min_concession) { should == 500 }
50
+ its(:max_concession) { should == 500 }
51
+ its(:min_final_rent) { should == 807 }
52
+ its(:max_final_rent) { should == 862 }
53
+ end
54
+ end
55
+
56
+ context "with multiple summaries" do
57
+ before { savon.stubs(:get_rent_summary).returns(:multiple_summaries) }
58
+ let(:effective_date) { Date.civil(2011, 3, 15) }
59
+ it { should have(2).summaries }
60
+
61
+ describe "the first summary" do
62
+ subject { rent_summaries.first }
63
+
64
+ its(:external_property_id) { should == external_property_id }
65
+ its(:effective_date) { should == effective_date }
66
+ its(:floor_plan_name) { should == 'Economy' }
67
+ its(:unit_type) { should == '2b1.5ba' }
68
+ its(:bedrooms) { should == 2.0 }
69
+ its(:bathrooms) { should == 1.1 }
70
+ its(:avg_square_feet) { should == 1147 }
71
+ its(:min_market_rent) { should == 1019 }
72
+ its(:max_market_rent) { should == 1054 }
73
+ its(:min_concession) { should == 500 }
74
+ its(:max_concession) { should == 500 }
75
+ its(:min_final_rent) { should == 1061 }
76
+ its(:max_final_rent) { should == 1096 }
77
+ end
78
+
79
+ describe "the last summary" do
80
+ subject { rent_summaries.last }
81
+
82
+ its(:external_property_id) { should == external_property_id }
83
+ its(:effective_date) { should == effective_date }
84
+ its(:floor_plan_name) { should == 'Luxury' }
85
+ its(:unit_type) { should == '3b3ba' }
86
+ its(:bedrooms) { should == 3.0 }
87
+ its(:bathrooms) { should == 3.0 }
88
+ its(:avg_square_feet) { should == 1564 }
89
+ its(:min_market_rent) { should == 1291 }
90
+ its(:max_market_rent) { should == 1339 }
91
+ its(:min_concession) { should == 250 }
92
+ its(:max_concession) { should == 750 }
93
+ its(:min_final_rent) { should == 1332 }
94
+ its(:max_final_rent) { should == 1381 }
95
+ its(:floor_plan_description) { should == 'big' }
96
+
97
+ describe "concession_type" do
98
+ subject { rent_summaries.last.concession_type }
99
+
100
+ it { should be }
101
+ it { should have_key(:my_field) }
102
+ its([:my_field]) { should == '99' }
103
+ end
104
+ end
105
+ end
106
+
107
+ # Validation
108
+ it_should_behave_like 'a client_name validator'
109
+ it_should_behave_like 'an external_property_id validator'
110
+
111
+ # Error handling
112
+ it_should_behave_like 'a fault handler', :get_rent_summary
113
+ end
114
+
115
+ it { should respond_to(:get_available_units) }
116
+
117
+ describe "#get_available_units" do
118
+ before { savon.stubs(:get_available_units).returns(nil) }
119
+
120
+ subject { available_floor_plans }
121
+ let(:available_floor_plans) { test_object.get_available_units(client_name, external_property_id) }
122
+
123
+ it "should retrieve the data from the service" do
124
+ savon.expects(:get_available_units).
125
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id}).
126
+ returns(:no_floor_plans)
127
+ subject.should be
128
+ end
129
+
130
+ context "with no floor plans" do
131
+ before { savon.stubs(:get_available_units).returns(:no_floor_plans) }
132
+
133
+ it { should be_empty }
134
+ end
135
+
136
+ context "with one floor plan" do
137
+ before { savon.stubs(:get_available_units).returns(:single_floor_plan) }
138
+
139
+ describe "the first floor plan" do
140
+ subject { floor_plan }
141
+ let(:floor_plan) { available_floor_plans.first }
142
+
143
+ its(:external_property_id) { should == '42' }
144
+ its(:effective_date) { should == Date.civil(2011, 3, 13) }
145
+ its(:floor_plan_name) { should == 'my_floor_plan' }
146
+ its(:bedrooms) { should == 2.0 }
147
+ its(:bathrooms) { should == 2.0 }
148
+ its(:square_feet) { should == 1161 }
149
+
150
+ describe "units" do
151
+ subject { available_units }
152
+ let(:available_units) { floor_plan.units }
153
+
154
+ it { should be }
155
+ it { should have(1).available_unit }
156
+
157
+ describe "#first" do
158
+ subject { available_units.first }
159
+
160
+ its(:unit_type) { should == '2b2ba' }
161
+ its(:unit_number) { should == '112358' }
162
+ its(:status) { should == :on_notice }
163
+ its(:date_available) { should == Date.civil(2011, 4, 1) }
164
+ its(:base_final_rent) { should == 1054 }
165
+ its(:best_lease_term) { should == 14 }
166
+ its(:best_market_rent) { should == 1079 }
167
+ its(:best_concession) { should == 583 }
168
+ its(:best_final_rent) { should == 1038 }
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ context "with multiple floor plans" do
175
+ before { savon.stubs(:get_available_units).returns(:multiple_floor_plans) }
176
+
177
+ let(:external_property_id) { '42' }
178
+ let(:effective_date) { Date.civil(2011, 3, 15) }
179
+
180
+ describe "the first floor plan" do
181
+ subject { available_floor_plans.first }
182
+
183
+ its(:external_property_id) { should == external_property_id }
184
+ its(:effective_date) { should == effective_date }
185
+ its(:floor_plan_name) { should == '1B1B-D' }
186
+ its(:bedrooms) { should == 1.0 }
187
+ its(:bathrooms) { should == 1.0 }
188
+ its(:square_feet) { should == 874 }
189
+ its(:units) { should be_empty }
190
+ end
191
+
192
+ describe "the last floor plan" do
193
+ subject { floor_plan }
194
+ let(:floor_plan) { available_floor_plans.last }
195
+
196
+ its(:external_property_id) { should == external_property_id }
197
+ its(:effective_date) { should == effective_date }
198
+ its(:floor_plan_name) { should == '1B1B' }
199
+ its(:bedrooms) { should == 1.0 }
200
+ its(:bathrooms) { should == 1.0 }
201
+ its(:square_feet) { should == 666 }
202
+
203
+ describe "units" do
204
+ subject { available_units }
205
+ let(:available_units) { floor_plan.units }
206
+
207
+ it { should have(2).units }
208
+
209
+ describe "#first" do
210
+ subject { unit }
211
+ let(:unit) { available_units.first }
212
+
213
+ its(:building) { should == '99' }
214
+ its(:unit_type) { should == '1b1ba-r' }
215
+ its(:unit_number) { should == '11235' }
216
+
217
+ describe "features" do
218
+ subject { unit.features }
219
+
220
+ it { should have(2).features }
221
+ its(:first) { should == '50 Base Rent Adjustment' }
222
+ its(:last) { should == '2nd Floor' }
223
+ end
224
+
225
+ its(:status) { should == :new_unit }
226
+ its(:date_available) { should == Date.civil(2011, 5, 11) }
227
+ its(:base_market_rent) { should == 710 }
228
+ its(:base_concession) { should == 500 }
229
+ its(:base_final_rent) { should == 669 }
230
+ its(:best_lease_term) { should == 15 }
231
+ its(:best_market_rent) { should == 699 }
232
+ its(:best_concession) { should == 625 }
233
+ its(:best_final_rent) { should == 658 }
234
+ end
235
+
236
+ describe "#last" do
237
+ subject { unit }
238
+ let(:unit) { available_units.last }
239
+
240
+ its(:unit_type) { should == '1b1ba' }
241
+ its(:unit_number) { should == '81321' }
242
+
243
+ describe "features" do
244
+ subject { unit.features }
245
+
246
+ it { should have(1).feature }
247
+ its(:first) { should == '1st floor' }
248
+ end
249
+
250
+ its(:status) { should == :vacant }
251
+ its(:date_available) { should == Date.civil(2011, 3, 7) }
252
+ its(:base_market_rent) { should == 732 }
253
+ its(:base_concession) { should == 500 }
254
+ its(:base_final_rent) { should == 690 }
255
+ its(:best_lease_term) { should == 15 }
256
+ its(:best_market_rent) { should == 719 }
257
+ its(:best_concession) { should == 625 }
258
+ its(:best_final_rent) { should == 678 }
259
+ end
260
+ end
261
+ end
262
+ end
263
+
264
+ # Validation
265
+ it_should_behave_like 'a client_name validator'
266
+ it_should_behave_like 'an external_property_id validator'
267
+
268
+ # Error handling
269
+ it_should_behave_like 'a fault handler', :get_available_units
270
+ end
271
+ end
@@ -0,0 +1,168 @@
1
+ require 'spec_helper'
2
+
3
+ describe "unit methods" do
4
+ subject { test_object }
5
+
6
+ let(:test_object) { YieldStarClient::Client.new(:endpoint => 'http://bogusendpoint') }
7
+
8
+ let(:client_name) { 'my_client_name' }
9
+ let(:external_property_id) { 'my_prop_id' }
10
+
11
+ it { should respond_to(:get_unit) }
12
+ it { should respond_to(:get_units) }
13
+
14
+ describe "#get_unit" do
15
+ before { savon.stubs(:get_unit).returns(nil) }
16
+
17
+ subject { unit }
18
+ let(:unit) { test_object.get_unit(client_name, external_property_id, unit_name) }
19
+ let(:unit_name) { 'my_unit_name' }
20
+ let(:soap_body) { {:client_name => client_name, :external_property_id => external_property_id, :name => unit_name}}
21
+
22
+ context "without a building name" do
23
+ it "should retrieve the data from the service" do
24
+ savon.expects(:get_unit).with(:request => soap_body).returns(:simple_unit)
25
+ subject.should be
26
+ end
27
+ end
28
+
29
+ context "with a building name" do
30
+ let(:unit) { test_object.get_unit(client_name, external_property_id, unit_name, building_name) }
31
+ let(:building_name) { 'my_building' }
32
+
33
+ it "should retrieve the data from the service" do
34
+ savon.expects(:get_unit).with(:request => soap_body.merge(:building => building_name)).returns(:simple_unit)
35
+ subject.should be
36
+ end
37
+ end
38
+
39
+ context "for a minimal unit" do
40
+ before { savon.stubs(:get_unit).returns(:simple_unit) }
41
+
42
+ its(:external_property_id) { should == '42' }
43
+ its(:floor_plan_name) { should == 'Economy' }
44
+ its(:name) { should == '1A' }
45
+ its(:availability_status) { should == :occupied_on_notice }
46
+ end
47
+
48
+ context "for a fully populated unit" do
49
+ before { savon.stubs(:get_unit).returns(:full_unit) }
50
+
51
+ its(:external_property_id) { should == '42' }
52
+ its(:floor_plan_name) { should == 'Luxury' }
53
+ its(:name) { should == 'Unit 6' }
54
+ its(:availability_status) { should == :vacant }
55
+ its(:building) { should == '99' }
56
+ its(:bedrooms) { should == 6.0 }
57
+ its(:bathrooms) { should == 5.3 }
58
+ its(:square_feet) { should == 5555 }
59
+ its(:unit_type) { should == 'foo' }
60
+ its(:make_ready_date) { should == Date.new(2011,03,10) }
61
+ end
62
+
63
+ # Validation
64
+ it_should_behave_like 'a client_name validator'
65
+ it_should_behave_like 'an external_property_id validator'
66
+ it_should_behave_like 'a required string validator', :unit_name
67
+ it "should allow a nil building" do
68
+ expect { subject }.to_not raise_error(ArgumentError)
69
+ end
70
+
71
+ # Error handling
72
+ it_should_behave_like "a fault handler", :get_unit
73
+ end
74
+
75
+ describe "#get_units" do
76
+ before { savon.stubs(:get_units).returns(nil) }
77
+
78
+ subject { units }
79
+ let(:units) { test_object.get_units(client_name, external_property_id) }
80
+ let(:soap_body) { {:client_name => client_name, :external_property_id => external_property_id} }
81
+
82
+ context "without a floor_plan name" do
83
+ it "should retrieve the data from the service" do
84
+ savon.expects(:get_units).with(:request => soap_body).returns(:no_units)
85
+ subject.should be
86
+ end
87
+ end
88
+
89
+ context "with a floor_plan name" do
90
+ let(:units) { test_object.get_units(client_name, external_property_id, floor_plan_name) }
91
+ let(:floor_plan_name) { 'my_floor_plan' }
92
+
93
+ it "should retrieve the data from the service" do
94
+ savon.expects(:get_units).with(:request => soap_body.merge(:floor_plan_name => floor_plan_name)).returns(:no_units)
95
+ subject.should be
96
+ end
97
+ end
98
+
99
+ context "for one unit" do
100
+ before { savon.stubs(:get_units).returns(:single_unit) }
101
+
102
+ it { should be }
103
+ it { should have(1).unit }
104
+
105
+ describe "first unit" do
106
+ subject { units.first }
107
+
108
+ its(:external_property_id) { should == '42' }
109
+ its(:floor_plan_name) { should == 'FP99' }
110
+ its(:name) { should == 'Unit 1' }
111
+ its(:availability_status) { should == :occupied }
112
+ end
113
+ end
114
+
115
+ context "for multiple units" do
116
+ before { savon.stubs(:get_units).returns(:multiple_units) }
117
+
118
+ it { should be }
119
+ it { should have(2).units }
120
+
121
+ describe "first unit" do
122
+ subject { units.first }
123
+
124
+ its(:external_property_id) { should == '42' }
125
+ its(:floor_plan_name) { should == 'Economy' }
126
+ its(:name) { should == 'Apt 313' }
127
+ its(:bedrooms) { should == 2.0 }
128
+ its(:bathrooms) { should == 1.1 }
129
+ its(:square_feet) { should == 1000 }
130
+ its(:unit_type) { should == 'apartment' }
131
+ its(:availability_status) { should == :pending }
132
+ end
133
+
134
+ describe "last unit" do
135
+ subject { units.last }
136
+
137
+ its(:external_property_id) { should == '42' }
138
+ its(:floor_plan_name) { should == 'Luxury' }
139
+ its(:name) { should == 'The Villa' }
140
+ its(:bedrooms) { should == 6.0 }
141
+ its(:bathrooms) { should == 4.0 }
142
+ its(:square_feet) { should == 5000 }
143
+ its(:unit_type) { should == 'single-family home' }
144
+ its(:building) { should == '99' }
145
+ its(:make_ready_date) { should == Date.new(2011, 4, 1) }
146
+ its(:availability_status) { should == :unknown }
147
+ end
148
+ end
149
+
150
+ context "for no units" do
151
+ before { savon.stubs(:get_units).returns(:no_units) }
152
+
153
+ it { should be }
154
+ it { should be_empty }
155
+ end
156
+
157
+ # Validation
158
+ it_should_behave_like 'a client_name validator'
159
+ it_should_behave_like 'an external_property_id validator'
160
+
161
+ it "should allow a nil floor_plan_name" do
162
+ expect { subject }.to_not raise_error(ArgumentError)
163
+ end
164
+
165
+ # Error handling
166
+ it_should_behave_like 'a fault handler', :get_units
167
+ end
168
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'validations'
3
+
4
+ describe "validations" do
5
+ subject { validator }
6
+ let(:validator) { Class.new { extend YieldStarClient::Validations } }
7
+
8
+ it { should respond_to(:validate_required) }
9
+
10
+ describe "#validate_client_name!" do
11
+ subject { validator.validate_client_name!(client_name) }
12
+ it_should_behave_like "a client_name validator"
13
+ end
14
+
15
+ describe "#validate_external_property_id!" do
16
+ subject { validator.validate_external_property_id!(external_property_id) }
17
+ it_should_behave_like "an external_property_id validator"
18
+ end
19
+ end