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,93 @@
1
+ require 'spec_helper'
2
+ require 'errors'
3
+
4
+ describe YieldStarClient::ServerError do
5
+ subject { error }
6
+ let(:error) { YieldStarClient::ServerError.new(message, code) }
7
+ let(:code) { 'my code' }
8
+ let(:message) { 'my message' }
9
+
10
+ context "default initialization" do
11
+ let(:error) { YieldStarClient::ServerError.new }
12
+
13
+ it { should respond_to(:code) }
14
+ its(:code) { should_not be }
15
+
16
+ it { should respond_to(:message) }
17
+ its(:message) { should == error.class.name }
18
+ end
19
+
20
+ context "message initialization" do
21
+ let(:error) { YieldStarClient::ServerError.new(message) }
22
+
23
+ its(:code) { should_not be }
24
+ its(:message) { should == message }
25
+ end
26
+
27
+ context "full initialization" do
28
+ its(:code) { should == code }
29
+ its(:message) { should == message }
30
+ end
31
+
32
+ describe "#to_s" do
33
+ subject { error.to_s }
34
+
35
+ context "when there is a message" do
36
+ it { should match(message) }
37
+ end
38
+
39
+ context "when there isn't a message" do
40
+ let(:message) { nil }
41
+ it { should match(error.class.name) }
42
+ end
43
+ end
44
+
45
+ describe ".translate_fault" do
46
+ subject { YieldStarClient::ServerError.translate_fault(fault) }
47
+ let(:fault) { Savon::SOAP::Fault.new(response)}
48
+
49
+ context "for an authentication fault" do
50
+ let(:response) { mock() { stubs(:body).returns(Savon::Spec::Fixture[:faults, :authentication_fault]) } }
51
+
52
+ it { should be_a YieldStarClient::AuthenticationError }
53
+ its(:message) { should == 'Client [foo] not found for this user [12e7e719764-21c]' }
54
+ its(:code) { should == '12e7e719764-21c' }
55
+ end
56
+
57
+ context "for an internal error fault" do
58
+ let(:response) { mock() { stubs(:body).returns(Savon::Spec::Fixture[:faults, :internal_error_fault]) } }
59
+
60
+ it { should be_a YieldStarClient::InternalError }
61
+ its(:message) { should == 'Internal error [12e7cfbb782-37a]' }
62
+ its(:code) { should == '12e7cfbb782-37a' }
63
+ end
64
+
65
+ context "for an operation fault" do
66
+ let(:response) { mock() { stubs(:body).returns(Savon::Spec::Fixture[:faults, :operation_fault]) } }
67
+
68
+ it { should be_a YieldStarClient::OperationError }
69
+ its(:message) { should == 'Invalid floor plan name null [12e7e6acc24-1b]' }
70
+ its(:code) { should == '12e7e6acc24-1b' }
71
+ end
72
+
73
+ context "for a generic fault" do
74
+ let(:response) { mock() { stubs(:body).returns(Savon::Spec::Fixture[:faults, :generic_fault]) } }
75
+
76
+ it { should be_a YieldStarClient::ServerError }
77
+ its(:message) { should == 'java.lang.NullPointerException' }
78
+ its(:code) { should == 'S:Server' }
79
+ end
80
+ end
81
+ end
82
+
83
+ describe YieldStarClient::AuthenticationError do
84
+ it { should be }
85
+ end
86
+
87
+ describe YieldStarClient::InternalError do
88
+ it { should be }
89
+ end
90
+
91
+ describe YieldStarClient::OperationError do
92
+ it { should be }
93
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe "floor plan 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_floor_plan) }
12
+
13
+ describe "#get_floor_plan" do
14
+ before { savon.stubs(:get_floor_plan).returns(nil) }
15
+
16
+ subject { floor_plan }
17
+ let(:floor_plan) { test_object.get_floor_plan(client_name, external_property_id, floor_plan_name) }
18
+ let(:floor_plan_name) { 'my_floor_plan_name' }
19
+
20
+ it "should retrieve the floor plan data from the service" do
21
+ savon.expects(:get_floor_plan).
22
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id, :name => floor_plan_name}).
23
+ returns(:simple_floor_plan)
24
+ subject.should be
25
+ end
26
+
27
+ context "with a minimal floor plan" do
28
+ before { savon.stubs(:get_floor_plan).returns(:simple_floor_plan) }
29
+
30
+ its(:external_property_id) { should == '42' }
31
+ its(:name) { should == 'simple-plan' }
32
+ end
33
+
34
+ context "with a fully defined floor plan" do
35
+ before { savon.stubs(:get_floor_plan).returns(:full_floor_plan) }
36
+
37
+ its(:external_property_id) { should == '99' }
38
+ its(:name) { should == 'The Oxford' }
39
+ its(:description) { should == 'An apartment' }
40
+ its(:square_feet) { should == 797 }
41
+ its(:unit_count) { should == 49 }
42
+ its(:bedrooms) { should == 1.0 }
43
+ its(:bathrooms) { should == 1.1 }
44
+ end
45
+
46
+ # Validations
47
+ it_should_behave_like 'a client_name validator'
48
+ it_should_behave_like 'an external_property_id validator'
49
+ it_should_behave_like 'a required string validator', :floor_plan_name
50
+
51
+ # Error handling
52
+ it_should_behave_like 'a fault handler', :get_floor_plan
53
+ end
54
+
55
+ it { should respond_to(:get_floor_plans) }
56
+
57
+ describe "#get_floor_plans" do
58
+ before { savon.stubs(:get_floor_plans).returns(nil) }
59
+
60
+ subject { floor_plans }
61
+ let(:floor_plans) { test_object.get_floor_plans(client_name, external_property_id) }
62
+
63
+ it "should retrieve the floor plan data from the service" do
64
+ savon.expects(:get_floor_plans).
65
+ with(:request => {:client_name => client_name, :external_property_id => external_property_id}).
66
+ returns(:single_floor_plan)
67
+ subject.should be
68
+ end
69
+
70
+ context "with no floor plan" do
71
+ before { savon.stubs(:get_floor_plans).returns(:no_floor_plan) }
72
+
73
+ it { should be }
74
+ it { should be_empty }
75
+ end
76
+
77
+ context "with one floor plan" do
78
+ before { savon.stubs(:get_floor_plans).returns(:single_floor_plan) }
79
+
80
+ it { should have(1).floor_plan }
81
+
82
+ describe "first floor plan" do
83
+ subject { floor_plans.first }
84
+
85
+ its(:external_property_id) { should == '42' }
86
+ its(:name) { should == 'simple' }
87
+ its(:description) { should == 'A simple floor plan.' }
88
+ end
89
+ end
90
+
91
+ context "with multiple floor plans" do
92
+ before { savon.stubs(:get_floor_plans).returns(:multiple_floor_plans) }
93
+
94
+ describe "first floor plan" do
95
+ subject { floor_plans.first }
96
+
97
+ its(:external_property_id) { should == '99' }
98
+ its(:name) { should == 'The Economy' }
99
+ its(:description) { should == 'An affordable choice for the frugal resident.' }
100
+ its(:square_feet) { should == 450 }
101
+ its(:unit_count) { should == 42 }
102
+ its(:bedrooms) { should == 1.0 }
103
+ its(:bathrooms) { should == 1.0 }
104
+ end
105
+
106
+ describe "last floor plan" do
107
+ subject { floor_plans.last }
108
+
109
+ its(:external_property_id) { should == '99' }
110
+ its(:name) { should == 'The Luxury' }
111
+ its(:description) { should == 'A palatial estate for the independently wealthy.' }
112
+ its(:square_feet) { should == 10000 }
113
+ its(:unit_count) { should == 3 }
114
+ its(:bedrooms) { should == 7.0 }
115
+ its(:bathrooms) { should == 7.3 }
116
+ end
117
+ end
118
+
119
+ # Validation
120
+ it_should_behave_like 'a client_name validator'
121
+ it_should_behave_like 'an external_property_id validator'
122
+
123
+ # Error handling
124
+ it_should_behave_like 'a fault handler', :get_floor_plans
125
+ end
126
+ end
@@ -0,0 +1,391 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a lease_term_rent service caller' do |soap_action|
4
+ let(:unit_number) { '112358' }
5
+
6
+ context "without options" do
7
+ it "should retrieve the data from the service" do
8
+ savon.expects(soap_action).
9
+ with(:request => {:client_name => client_name,
10
+ :external_property_id => external_property_id,
11
+ :lease_term_rent_unit_request => {:unit_number => unit_number}}).
12
+ returns(:no_rates)
13
+ subject.should be
14
+ end
15
+
16
+ # Validation
17
+ it_should_behave_like 'a client_name validator'
18
+ it_should_behave_like 'an external_property_id validator'
19
+ it_should_behave_like 'a required string validator', :unit_number
20
+
21
+ # Error handling
22
+ it_should_behave_like 'a fault handler', soap_action
23
+ end
24
+
25
+ context "with options" do
26
+ let(:opts) { {:building => building,
27
+ :min_lease_term => min_lease_term,
28
+ :max_lease_term => max_lease_term,
29
+ :first_move_in_date => first_move_in_date,
30
+ :last_move_in_date => last_move_in_date,
31
+ :ready_for_move_in_date => ready_for_move_in_date,
32
+ :unit_available_date => unit_available_date} }
33
+
34
+ let(:building) { '123' }
35
+ let(:min_lease_term) { 1 }
36
+ let(:max_lease_term) { '12' }
37
+ let(:first_move_in_date) { '2011-03-10' }
38
+ let(:last_move_in_date) { Date.civil(2011, 4, 1) }
39
+ let(:ready_for_move_in_date) { '2011-03-15' }
40
+ let(:unit_available_date) { DateTime.civil(2011, 3, 10) }
41
+
42
+ let(:soap_body) { {:request => {:client_name => client_name,
43
+ :external_property_id => external_property_id,
44
+ :lease_term_rent_unit_request => request_options}} }
45
+
46
+ let(:valid_request_options) { {:building => '123',
47
+ :unit_number => unit_number,
48
+ :min_lease_term => '1',
49
+ :max_lease_term => '12',
50
+ :first_move_in_date => '2011-03-10',
51
+ :last_move_in_date => '2011-04-01',
52
+ :ready_for_move_in_date => '2011-03-15',
53
+ :unit_available_date => '2011-03-10'} }
54
+
55
+ context "when all options are present and valid" do
56
+ let(:request_options) { valid_request_options }
57
+
58
+ it "should retrieve the data from the service" do
59
+ savon.expects(soap_action).with(soap_body).returns(:no_rates)
60
+ subject.should be
61
+ end
62
+ end
63
+
64
+ # Validation
65
+ it_should_behave_like 'a client_name validator'
66
+ it_should_behave_like 'an external_property_id validator'
67
+ it_should_behave_like 'a required string validator', :unit_number
68
+
69
+ it_should_behave_like 'an integer validator', :min_lease_term
70
+ it_should_behave_like 'an integer validator', :max_lease_term
71
+ it_should_behave_like 'a date validator', :first_move_in_date
72
+ it_should_behave_like 'a date validator', :last_move_in_date
73
+ it_should_behave_like 'a date validator', :ready_for_move_in_date
74
+ it_should_behave_like 'a date validator', :unit_available_date
75
+
76
+ # Error handling
77
+ it_should_behave_like 'a fault handler', soap_action
78
+ end
79
+ end
80
+
81
+ describe "lease term rent methods" do
82
+ subject { test_object }
83
+ let(:test_object) { YieldStarClient::Client.new(:endpoint => 'http://bogusendpoint' ) }
84
+
85
+ let(:client_name) { 'my_client' }
86
+ let(:external_property_id) { '42' }
87
+ let(:unit_number) { '112358' }
88
+
89
+ it { should respond_to(:get_lease_term_rent) }
90
+
91
+ describe "#get_lease_term_rent" do
92
+ before { savon.stubs(:get_lease_term_rent).returns(nil) }
93
+
94
+ subject { unit_rates }
95
+ let(:unit_rates) { test_object.get_lease_term_rent(client_name, external_property_id, unit_number, opts) }
96
+ let(:opts) { {} }
97
+
98
+ it_should_behave_like 'a lease_term_rent service caller', :get_lease_term_rent
99
+
100
+ context "when there are no unit rates" do
101
+ before { savon.stubs(:get_lease_term_rent).returns(:no_rates) }
102
+
103
+ it { should be }
104
+ it { should be_empty }
105
+ end
106
+
107
+ context "when there is a single unit rate" do
108
+ before { savon.stubs(:get_lease_term_rent).returns(:single_rate) }
109
+
110
+ it { should have(1).unit_rate }
111
+
112
+ describe "first record" do
113
+ subject { unit_rates.first }
114
+
115
+ its(:external_property_id) { should == '42' }
116
+ its(:unit_number) { should == '112358' }
117
+ its(:building) { should_not be }
118
+ its(:make_ready_date) { should == Date.civil(2011, 3, 13) }
119
+ its(:lease_term) { should == 12 }
120
+ its(:end_date) { should == Date.civil(2012, 3, 7) }
121
+ its(:market_rent) { should == 1096 }
122
+ its(:final_rent) { should == 1054 }
123
+ its(:best) { should be_true }
124
+ its(:move_in_date) { should == Date.civil(2011, 3, 13) }
125
+ its(:total_concession) { should == 0 }
126
+ its(:monthly_fixed_concession) { should == 0 }
127
+ its(:monthly_percent_concession) { should == 0.0 }
128
+ its(:months_concession) { should == 0.0 }
129
+ its(:one_time_fixed_concession) { should == 0 }
130
+ end
131
+ end
132
+
133
+ context "when there are multiple unit rates" do
134
+ before { savon.stubs(:get_lease_term_rent).returns(:multiple_rates) }
135
+
136
+ it { should have(2).unit_rates }
137
+
138
+ describe "the first record" do
139
+ subject { unit_rates.first }
140
+
141
+ its(:external_property_id) { should == '42' }
142
+ its(:unit_number) { should == '112358' }
143
+ its(:building) { should == '123' }
144
+ its(:make_ready_date) { should == Date.civil(2011, 3, 7) }
145
+ its(:lease_term) { should == 1 }
146
+ its(:end_date) { should == Date.civil(2011, 7, 1) }
147
+ its(:market_rent) { should == 5277 }
148
+ its(:final_rent) { should == 5237 }
149
+ its(:best) { should be_true }
150
+ its(:move_in_date) { should == Date.civil(2011, 6, 1) }
151
+ its(:total_concession) { should == 41 }
152
+ its(:monthly_fixed_concession) { should == 0 }
153
+ its(:monthly_percent_concession) { should == 0.0 }
154
+ its(:months_concession) { should == 0.0 }
155
+ its(:one_time_fixed_concession) { should == 500 }
156
+ end
157
+
158
+ describe "the second record" do
159
+ subject { unit_rates.last }
160
+
161
+ its(:external_property_id) { should == '42' }
162
+ its(:unit_number) { should == '112358' }
163
+ its(:building) { should == '123' }
164
+ its(:make_ready_date) { should == Date.civil(2011, 3, 7) }
165
+ its(:lease_term) { should == 15 }
166
+ its(:end_date) { should == Date.civil(2012, 8, 24) }
167
+ its(:market_rent) { should == 1272 }
168
+ its(:final_rent) { should == 1230 }
169
+ its(:best) { should be_false }
170
+ its(:move_in_date) { should == Date.civil(2011, 6, 1) }
171
+ its(:total_concession) { should == 625 }
172
+ its(:monthly_fixed_concession) { should == 10 }
173
+ its(:monthly_percent_concession) { should == 0.02 }
174
+ its(:months_concession) { should == 0.5 }
175
+ its(:one_time_fixed_concession) { should == 500 }
176
+ end
177
+ end
178
+ end
179
+
180
+ describe "#get_lease_term_rent_plus" do
181
+ before { savon.stubs(:get_lease_term_rent_plus).returns(nil) }
182
+
183
+ subject { unit_rates }
184
+ let(:unit_rates) { test_object.get_lease_term_rent_plus(client_name, external_property_id, unit_number, opts) }
185
+ let(:opts) { {} }
186
+
187
+ it_should_behave_like 'a lease_term_rent service caller', :get_lease_term_rent_plus
188
+
189
+ context "when there are no unit rates" do
190
+ before { savon.stubs(:get_lease_term_rent_plus).returns(:no_rates) }
191
+
192
+ it { should be_empty }
193
+ end
194
+
195
+ context "when there is a single unit rate" do
196
+ before { savon.stubs(:get_lease_term_rent_plus).returns(:single_rate) }
197
+
198
+ it { should have(1).unit_rate }
199
+
200
+ describe "the only record" do
201
+ subject { unit_rates.first }
202
+
203
+ its(:external_property_id) { should == '42' }
204
+ its(:unit_number) { should == '112358' }
205
+ its(:building) { should_not be }
206
+ its(:make_ready_date) { should == Date.civil(2011, 3, 23) }
207
+ its(:lease_term) { should == 12 }
208
+ its(:end_date) { should == Date.civil(2012, 3, 24) }
209
+ its(:market_rent) { should == 1149 }
210
+ its(:final_rent) { should == 1108 }
211
+ its(:best) { should be_true }
212
+ its(:move_in_date) { should == Date.civil(2011, 3, 23) }
213
+ its(:total_concession) { should == 0 }
214
+ its(:monthly_fixed_concession) { should == 0 }
215
+ its(:monthly_percent_concession) { should == 0.0 }
216
+ its(:months_concession) { should == 0.0 }
217
+ its(:one_time_fixed_concession) { should == 0 }
218
+ its(:price_valid_end_date) { should == Date.civil(2011, 3, 25) }
219
+ end
220
+ end
221
+
222
+ context "when there are multiple unit rates" do
223
+ before { savon.stubs(:get_lease_term_rent_plus).returns(:multiple_rates) }
224
+
225
+ it { should have(2).unit_rates }
226
+
227
+ describe "the first record" do
228
+ subject { unit_rates.first }
229
+
230
+ its(:external_property_id) { should == '42' }
231
+ its(:unit_number) { should == '112358' }
232
+ its(:building) { should == '123' }
233
+ its(:make_ready_date) { should == Date.civil(2011, 3, 23) }
234
+ its(:lease_term) { should == 6 }
235
+ its(:end_date) { should == Date.civil(2011, 9, 28) }
236
+ its(:market_rent) { should == 1249 }
237
+ its(:final_rent) { should == 1207 }
238
+ its(:best) { should be_true }
239
+ its(:move_in_date) { should == Date.civil(2011, 4, 1) }
240
+ its(:total_concession) { should == 250 }
241
+ its(:monthly_fixed_concession) { should == 0 }
242
+ its(:monthly_percent_concession) { should == 0.0 }
243
+ its(:months_concession) { should == 0.0 }
244
+ its(:one_time_fixed_concession) { should == 500 }
245
+ its(:price_valid_end_date) { should == Date.civil(2011, 4, 3) }
246
+ end
247
+
248
+ describe "the second record" do
249
+ subject { unit_rates.last }
250
+
251
+ its(:external_property_id) { should == '42' }
252
+ its(:unit_number) { should == '112358' }
253
+ its(:building) { should == '123' }
254
+ its(:make_ready_date) { should == Date.civil(2011, 3, 23) }
255
+ its(:lease_term) { should == 12 }
256
+ its(:end_date) { should == Date.civil(2012, 3, 26) }
257
+ its(:market_rent) { should == 1176 }
258
+ its(:final_rent) { should == 1135 }
259
+ its(:best) { should be_false }
260
+ its(:move_in_date) { should == Date.civil(2011, 4, 1) }
261
+ its(:total_concession) { should == 500 }
262
+ its(:monthly_fixed_concession) { should == 11 }
263
+ its(:monthly_percent_concession) { should == 0.02 }
264
+ its(:months_concession) { should == 2.0 }
265
+ its(:one_time_fixed_concession) { should == 500 }
266
+ its(:price_valid_end_date) { should == Date.civil(2011, 4, 3) }
267
+ end
268
+ end
269
+ end
270
+
271
+ describe "#get_renewal_lease_term_rent" do
272
+ before { savon.stubs(:get_renewal_lease_term_rent).returns(nil) }
273
+
274
+ subject { unit_rates }
275
+ let(:unit_rates) { test_object.get_renewal_lease_term_rent(client_name, external_property_id, unit_number, opts) }
276
+
277
+ let(:opts) { Hash.new }
278
+
279
+ context "without options" do
280
+ it "should retrieve the data from the service" do
281
+ savon.expects(:get_renewal_lease_term_rent).
282
+ with(:request => {:client_name => client_name,
283
+ :external_property_id => external_property_id,
284
+ :renewal_lease_term_rent_unit_request => {:unit_number => unit_number}}).
285
+ returns(:no_rates)
286
+ subject.should be
287
+ end
288
+
289
+ # Validation
290
+ it_should_behave_like 'a client_name validator'
291
+ it_should_behave_like 'an external_property_id validator'
292
+ it_should_behave_like 'a required string validator', :unit_number
293
+
294
+ # Error handling
295
+ it_should_behave_like 'a fault handler', :get_renewal_lease_term_rent
296
+ end
297
+
298
+ context "with options" do
299
+ let(:opts) { {:building => building,
300
+ :min_lease_term => min_lease_term,
301
+ :max_lease_term => max_lease_term,
302
+ :start_date => start_date} }
303
+
304
+ let(:building) { '123' }
305
+ let(:min_lease_term) { 6 }
306
+ let(:max_lease_term) { 12 }
307
+ let(:start_date) { '2011-03-10' }
308
+
309
+ it "should retrieve the data from the service" do
310
+ savon.expects(:get_renewal_lease_term_rent).
311
+ with(:request => {:client_name => client_name,
312
+ :external_property_id => external_property_id,
313
+ :renewal_lease_term_rent_unit_request => {:unit_number => unit_number,
314
+ :building => building.to_s,
315
+ :min_lease_term => min_lease_term.to_s,
316
+ :max_lease_term => max_lease_term.to_s,
317
+ :start_date => start_date.to_s}}).
318
+ returns(:no_rates)
319
+ subject.should be
320
+ end
321
+
322
+ # Validation
323
+ it_should_behave_like 'a client_name validator'
324
+ it_should_behave_like 'an external_property_id validator'
325
+ it_should_behave_like 'a required string validator', :unit_number
326
+ it_should_behave_like 'an integer validator', :min_lease_term
327
+ it_should_behave_like 'an integer validator', :max_lease_term
328
+ it_should_behave_like 'a date validator', :start_date
329
+
330
+ # Error handling
331
+ it_should_behave_like 'a fault handler', :get_renewal_lease_term_rent
332
+ end
333
+
334
+ context "when there are no rates" do
335
+ before { savon.stubs(:get_renewal_lease_term_rent).returns(:no_rates) }
336
+
337
+ it { should be_empty }
338
+ end
339
+
340
+ context "when there is a single rate" do
341
+ before { savon.stubs(:get_renewal_lease_term_rent).returns(:single_rate) }
342
+
343
+ it { should have(1).unit_rate }
344
+
345
+ describe "the only record" do
346
+ subject { unit_rates.first }
347
+
348
+ its(:external_property_id) { should == external_property_id }
349
+ its(:unit_number) { should == unit_number }
350
+ its(:building) { should == '123' }
351
+ its(:lease_term) { should == 12 }
352
+ its(:end_date) { should == Date.civil(2012, 10, 26) }
353
+ its(:market_rent) { should == 1086 }
354
+ its(:final_rent) { should == 1086 }
355
+ its(:best) { should be_true }
356
+ end
357
+ end
358
+
359
+ context "when there are multiple rates" do
360
+ before { savon.stubs(:get_renewal_lease_term_rent).returns(:multiple_rates) }
361
+
362
+ it { should have(2).unit_rates }
363
+
364
+ describe "the first record" do
365
+ subject { unit_rates.first }
366
+
367
+ its(:external_property_id) { should == external_property_id }
368
+ its(:unit_number) { should == unit_number }
369
+ its(:start_date) { should == Date.civil(2011, 10, 24) }
370
+ its(:lease_term) { should == 1 }
371
+ its(:end_date) { should == Date.civil(2011, 11, 24) }
372
+ its(:market_rent) { should == 1331 }
373
+ its(:final_rent) { should == 1300 }
374
+ its(:best) { should be_true }
375
+ end
376
+
377
+ describe "the second record" do
378
+ subject { unit_rates.last }
379
+
380
+ its(:external_property_id) { should == external_property_id }
381
+ its(:unit_number) { should == unit_number }
382
+ its(:start_date) { should == Date.civil(2011, 10, 24) }
383
+ its(:lease_term) { should == 12 }
384
+ its(:end_date) { should == Date.civil(2012, 10, 26) }
385
+ its(:market_rent) { should == 1086 }
386
+ its(:final_rent) { should == 1086 }
387
+ its(:best) { should be_false}
388
+ end
389
+ end
390
+ end
391
+ end