flexmls_api 0.6.5 → 0.7.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 (89) hide show
  1. data/History.txt +12 -1
  2. data/VERSION +1 -1
  3. data/lib/flexmls_api.rb +13 -11
  4. data/lib/flexmls_api/authentication/api_auth.rb +5 -3
  5. data/lib/flexmls_api/authentication/oauth2.rb +23 -17
  6. data/lib/flexmls_api/authentication/oauth2_impl/password_provider.rb +25 -0
  7. data/lib/flexmls_api/cli.rb +51 -25
  8. data/lib/flexmls_api/cli/oauth2.rb +1 -30
  9. data/lib/flexmls_api/cli/setup.rb +4 -1
  10. data/lib/flexmls_api/client.rb +1 -1
  11. data/lib/flexmls_api/configuration.rb +10 -0
  12. data/lib/flexmls_api/configuration/yaml.rb +81 -0
  13. data/lib/flexmls_api/faraday.rb +12 -2
  14. data/lib/flexmls_api/models.rb +25 -23
  15. data/lib/flexmls_api/models/constraint.rb +16 -0
  16. data/lib/flexmls_api/models/listing.rb +45 -2
  17. data/lib/flexmls_api/models/photo.rb +57 -2
  18. data/lib/flexmls_api/models/subresource.rb +5 -2
  19. data/lib/flexmls_api/multi_client.rb +21 -6
  20. data/lib/flexmls_api/paginate.rb +18 -1
  21. data/lib/flexmls_api/request.rb +1 -71
  22. data/lib/flexmls_api/response.rb +69 -0
  23. data/spec/fixtures/{contacts.json → contacts/contacts.json} +0 -0
  24. data/spec/fixtures/{contact_my.json → contacts/my.json} +0 -0
  25. data/spec/fixtures/{contact_new.json → contacts/new.json} +0 -0
  26. data/spec/fixtures/{contact_new_empty.json → contacts/new_empty.json} +0 -0
  27. data/spec/fixtures/{contact_new_notify.json → contacts/new_notify.json} +0 -0
  28. data/spec/fixtures/{contacts_post.json → contacts/post.json} +0 -0
  29. data/spec/fixtures/{contact_tags.json → contacts/tags.json} +0 -0
  30. data/spec/fixtures/{listing_cart_add_listing.json → listing_carts/add_listing.json} +0 -0
  31. data/spec/fixtures/{listing_cart_add_listing_post.json → listing_carts/add_listing_post.json} +0 -0
  32. data/spec/fixtures/{listing_cart_empty.json → listing_carts/empty.json} +0 -0
  33. data/spec/fixtures/{listing_cart.json → listing_carts/listing_cart.json} +0 -0
  34. data/spec/fixtures/{listing_cart_new.json → listing_carts/new.json} +0 -0
  35. data/spec/fixtures/{listing_cart_post.json → listing_carts/post.json} +0 -0
  36. data/spec/fixtures/{listing_cart_remove_listing.json → listing_carts/remove_listing.json} +0 -0
  37. data/spec/fixtures/listings/constraints.json +18 -0
  38. data/spec/fixtures/listings/constraints_with_pagination.json +24 -0
  39. data/spec/fixtures/{listing_document_index.json → listings/document_index.json} +0 -0
  40. data/spec/fixtures/{listing_no_subresources.json → listings/no_subresources.json} +0 -0
  41. data/spec/fixtures/{open_houses.json → listings/open_houses.json} +0 -0
  42. data/spec/fixtures/{listing_photos_index.json → listings/photos/index.json} +0 -0
  43. data/spec/fixtures/listings/photos/new.json +12 -0
  44. data/spec/fixtures/listings/photos/post.json +20 -0
  45. data/spec/fixtures/listings/put.json +5 -0
  46. data/spec/fixtures/{saved_search.json → listings/saved_search.json} +0 -0
  47. data/spec/fixtures/{shared_listing_new.json → listings/shared_listing_new.json} +0 -0
  48. data/spec/fixtures/{shared_listing_post.json → listings/shared_listing_post.json} +0 -0
  49. data/spec/fixtures/{tour_of_homes.json → listings/tour_of_homes.json} +0 -0
  50. data/spec/fixtures/{listing_videos_index.json → listings/videos_index.json} +0 -0
  51. data/spec/fixtures/{listing_virtual_tours_index.json → listings/virtual_tours_index.json} +0 -0
  52. data/spec/fixtures/{listing_with_documents.json → listings/with_documents.json} +0 -0
  53. data/spec/fixtures/listings/with_permissions.json +44 -0
  54. data/spec/fixtures/{listing_with_photos.json → listings/with_photos.json} +0 -0
  55. data/spec/fixtures/{listing_with_supplement.json → listings/with_supplement.json} +0 -0
  56. data/spec/fixtures/{listing_with_videos.json → listings/with_videos.json} +0 -0
  57. data/spec/fixtures/{listing_with_vtour.json → listings/with_vtour.json} +0 -0
  58. data/spec/fixtures/logo_fbs.png +0 -0
  59. data/spec/fixtures/{add_note.json → notes/add.json} +0 -0
  60. data/spec/fixtures/{agent_shared_note.json → notes/agent_shared.json} +0 -0
  61. data/spec/fixtures/{agent_shared_note_empty.json → notes/agent_shared_empty.json} +0 -0
  62. data/spec/fixtures/{note_new.json → notes/new.json} +0 -0
  63. data/spec/fixtures/{standardfields_city.json → standardfields/city.json} +0 -0
  64. data/spec/fixtures/{standardfields_nearby.json → standardfields/nearby.json} +0 -0
  65. data/spec/fixtures/{standardfields.json → standardfields/standardfields.json} +0 -0
  66. data/spec/fixtures/{standardfields_stateorprovince.json → standardfields/stateorprovince.json} +0 -0
  67. data/spec/mock_helper.rb +5 -3
  68. data/spec/unit/flexmls_api/authentication/api_auth_spec.rb +11 -2
  69. data/spec/unit/flexmls_api/authentication/base_auth_spec.rb +10 -0
  70. data/spec/unit/flexmls_api/authentication/oauth2_spec.rb +3 -3
  71. data/spec/unit/flexmls_api/configuration/yaml_spec.rb +70 -0
  72. data/spec/unit/flexmls_api/models/constraint_spec.rb +19 -0
  73. data/spec/unit/flexmls_api/models/contact_spec.rb +8 -8
  74. data/spec/unit/flexmls_api/models/document_spec.rb +1 -1
  75. data/spec/unit/flexmls_api/models/listing_cart_spec.rb +15 -15
  76. data/spec/unit/flexmls_api/models/listing_spec.rb +78 -13
  77. data/spec/unit/flexmls_api/models/note_spec.rb +4 -4
  78. data/spec/unit/flexmls_api/models/open_house_spec.rb +1 -1
  79. data/spec/unit/flexmls_api/models/photo_spec.rb +73 -40
  80. data/spec/unit/flexmls_api/models/saved_search_spec.rb +3 -3
  81. data/spec/unit/flexmls_api/models/shared_listing_spec.rb +1 -1
  82. data/spec/unit/flexmls_api/models/standard_fields_spec.rb +4 -7
  83. data/spec/unit/flexmls_api/models/tour_of_home_spec.rb +1 -1
  84. data/spec/unit/flexmls_api/models/video_spec.rb +1 -1
  85. data/spec/unit/flexmls_api/models/virtual_tour_spec.rb +1 -1
  86. data/spec/unit/flexmls_api/multi_client_spec.rb +9 -1
  87. data/spec/unit/flexmls_api/paginate_spec.rb +1 -1
  88. data/spec/unit/flexmls_api/request_spec.rb +2 -2
  89. metadata +182 -152
@@ -16,7 +16,7 @@ describe Document do
16
16
 
17
17
  it "should get documents for a listing" do
18
18
  stub_auth_request
19
- stub_api_get('/listings/1234/documents','listing_document_index.json')
19
+ stub_api_get('/listings/1234/documents','listings/document_index.json')
20
20
 
21
21
  v = Document.find_by_listing_key('1234')
22
22
  v.should be_an(Array)
@@ -3,7 +3,7 @@ require './spec/spec_helper'
3
3
  describe ListingCart do
4
4
 
5
5
  it "should get all listing carts" do
6
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
6
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
7
7
  resources = subject.class.get
8
8
  resources.should be_an(Array)
9
9
  resources.length.should eq(2)
@@ -11,7 +11,7 @@ describe ListingCart do
11
11
  end
12
12
 
13
13
  it "should get a listing cart" do
14
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
14
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
15
15
  resource = subject.class.get.first
16
16
  resource.Id.should eq("20100912153422758914000000")
17
17
  resource.Name.should eq("My Listing Cart")
@@ -20,10 +20,10 @@ describe ListingCart do
20
20
 
21
21
  it "should add a listing to a cart" do
22
22
  list_id = "20110621133454434543000000"
23
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
23
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
24
24
  resource = subject.class.get.first
25
25
  resource.Id.should eq("20100912153422758914000000")
26
- stub_api_post("/#{subject.class.element_name}/#{resource.Id}",'listing_cart_add_listing_post.json', 'listing_cart_add_listing.json')
26
+ stub_api_post("/#{subject.class.element_name}/#{resource.Id}",'listing_carts/add_listing_post.json', 'listing_carts/add_listing.json')
27
27
  resource.ListingCount.should eq(10)
28
28
  resource.add_listing(list_id)
29
29
  resource.ListingCount.should eq(11)
@@ -31,10 +31,10 @@ describe ListingCart do
31
31
 
32
32
  it "should remove a listing from a cart" do
33
33
  list_id = "20110621133454434543000000"
34
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
34
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
35
35
  resource = subject.class.get.first
36
36
  resource.Id.should eq("20100912153422758914000000")
37
- stub_api_delete("/#{subject.class.element_name}/#{resource.Id}/listings/#{list_id}", 'listing_cart_remove_listing.json')
37
+ stub_api_delete("/#{subject.class.element_name}/#{resource.Id}/listings/#{list_id}", 'listing_carts/remove_listing.json')
38
38
  resource.ListingCount.should eq(10)
39
39
  resource.remove_listing(list_id)
40
40
  resource.ListingCount.should eq(9)
@@ -42,7 +42,7 @@ describe ListingCart do
42
42
 
43
43
  let(:listing){ Listing.new(:Id => "20110112234857732941000000") }
44
44
  it "should get all carts for a listing" do
45
- stub_api_get("/#{subject.class.element_name}/for/#{listing.Id}", 'listing_cart.json')
45
+ stub_api_get("/#{subject.class.element_name}/for/#{listing.Id}", 'listing_carts/listing_cart.json')
46
46
  [listing, listing.Id ].each do |l|
47
47
  resources = subject.class.for(l)
48
48
  resources.should be_an(Array)
@@ -52,7 +52,7 @@ describe ListingCart do
52
52
  end
53
53
 
54
54
  it "should get the carts for a user" do
55
- stub_api_get("/my/#{subject.class.element_name}", 'listing_cart.json')
55
+ stub_api_get("/my/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
56
56
  resources = subject.class.my
57
57
  resources.should be_an(Array)
58
58
  resources.length.should eq(2)
@@ -60,7 +60,7 @@ describe ListingCart do
60
60
  end
61
61
 
62
62
  it "should get the carts specific to a portal user" do
63
- stub_api_get("/#{subject.class.element_name}/portal", 'listing_cart.json')
63
+ stub_api_get("/#{subject.class.element_name}/portal", 'listing_carts/listing_cart.json')
64
64
  resources = subject.class.portal
65
65
  resources.should be_an(Array)
66
66
  resources.length.should eq(2)
@@ -68,7 +68,7 @@ describe ListingCart do
68
68
  end
69
69
 
70
70
  it "should save a new listing cart" do
71
- stub_api_post("/#{subject.class.element_name}", 'listing_cart_new.json', 'listing_cart_post.json')
71
+ stub_api_post("/#{subject.class.element_name}", 'listing_carts/new.json', 'listing_carts/post.json')
72
72
  subject.ListingIds = [
73
73
  '20110112234857732941000000',
74
74
  '20110302120238448431000000',
@@ -79,9 +79,9 @@ describe ListingCart do
79
79
  end
80
80
 
81
81
  it "should save a listing cart" do
82
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
82
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
83
83
  resource = subject.class.get.first
84
- stub_api_put("/#{subject.class.element_name}/#{resource.Id}", 'listing_cart_new.json', 'success.json')
84
+ stub_api_put("/#{subject.class.element_name}/#{resource.Id}", 'listing_carts/new.json', 'success.json')
85
85
  resource.ListingIds = [
86
86
  '20110112234857732941000000',
87
87
  '20110302120238448431000000',
@@ -93,7 +93,7 @@ describe ListingCart do
93
93
  end
94
94
 
95
95
  it "should fail saving" do
96
- stub_api_post("/#{subject.class.element_name}",'listing_cart_empty.json') do |request|
96
+ stub_api_post("/#{subject.class.element_name}",'listing_carts/empty.json') do |request|
97
97
  request.to_return(:status => 400, :body => fixture('errors/failure.json'))
98
98
  end
99
99
  subject
@@ -102,13 +102,13 @@ describe ListingCart do
102
102
  end
103
103
 
104
104
  it "should delete a listing cart" do
105
- stub_api_get("/#{subject.class.element_name}", 'listing_cart.json')
105
+ stub_api_get("/#{subject.class.element_name}", 'listing_carts/listing_cart.json')
106
106
  resource = subject.class.get.first
107
107
  resource.Id.should eq("20100912153422758914000000")
108
108
  resource.Name.should eq("My Listing Cart")
109
109
  resource.ListingCount.should eq(10)
110
110
  stub_api_delete("/#{subject.class.element_name}/#{resource.Id}", 'success.json')
111
- resource.delete.should be(nil)
111
+ resource.delete.empty?.should be(true)
112
112
  end
113
113
 
114
114
  end
@@ -1,16 +1,14 @@
1
- require './spec/spec_helper'
2
-
3
1
  describe Listing do
4
2
  before(:each) do
5
3
 
6
4
  @listing = Listing.new({
7
5
  "ResourceUri"=>"/v1/listings/20080619000032866372000000",
8
6
  "StandardFields"=>{
9
- "StreetNumber"=>"********",
7
+ "StreetNumber"=>"100",
10
8
  "ListingId"=>"07-32",
11
9
  "City"=>"Fargo",
12
10
  "Longitude"=>"",
13
- "StreetName"=>"********",
11
+ "StreetName"=>"Someone's",
14
12
  "YearBuilt"=>nil,
15
13
  "BuildingAreaTotal"=>"1321.0",
16
14
  "PublicRemarks"=>nil,
@@ -25,6 +23,7 @@ describe Listing do
25
23
  "BathsTotal"=>"0.0",
26
24
  "BathsFull"=>nil,
27
25
  "ListingKey"=>"20080619000032866372000000",
26
+ "StreetSuffix"=>"St",
28
27
  "StreetDirSuffix"=>"********",
29
28
  "BedsTotal"=>2,
30
29
  "ModificationTimestamp"=>"2010-11-22T23:36:42Z",
@@ -42,7 +41,7 @@ describe Listing do
42
41
  "Caption"=>"apostrophe test for CUR-10508",
43
42
  "Uri1280"=>"http=>//devresize.flexmls.com/fgo/1280x1024/true/20101115201631519737000000-o.jpg",
44
43
  "UriThumb"=>"http=>//images.dev.fbsdata.com/fgo/20101115201631519737000000-t.jpg",
45
- "Uri640"=>"http=>//devresize.flexmls.com/fgo/640x480/true/20101115201631519737000000-o.jpg"
44
+ "Uri640"=>"http=>//devresize.flexmls.com/fgo/640x480/true/20101115201631519737000000-o.jpg"
46
45
  }]
47
46
  },
48
47
  "Id"=>"20080619000032866372000000"
@@ -94,6 +93,7 @@ describe Listing do
94
93
  count = Listing.count()
95
94
  count.should == 2001
96
95
  end
96
+
97
97
  end
98
98
 
99
99
  describe "subresources" do
@@ -102,7 +102,7 @@ describe Listing do
102
102
  end
103
103
 
104
104
  it "should return an array of photos" do
105
- stub_api_get("/listings/1234", 'listing_with_photos.json', { :_expand => "Photos" })
105
+ stub_api_get("/listings/1234", 'listings/with_photos.json', { :_expand => "Photos" })
106
106
 
107
107
  l = Listing.find('1234', :_expand => "Photos")
108
108
  l.photos.length.should == 5
@@ -112,7 +112,7 @@ describe Listing do
112
112
  end
113
113
 
114
114
  it "should return an array of documents" do
115
- stub_api_get("/listings/1234", 'listing_with_documents.json', { :_expand => "Documents" })
115
+ stub_api_get("/listings/1234", 'listings/with_documents.json', { :_expand => "Documents" })
116
116
 
117
117
  l = Listing.find('1234', :_expand => "Documents")
118
118
  l.photos.length.should == 0
@@ -122,7 +122,7 @@ describe Listing do
122
122
  end
123
123
 
124
124
  it "should return an array of virtual tours" do
125
- stub_api_get("/listings/1234", 'listing_with_vtour.json', { :_expand => "VirtualTours" })
125
+ stub_api_get("/listings/1234", 'listings/with_vtour.json', { :_expand => "VirtualTours" })
126
126
 
127
127
  l = Listing.find('1234', :_expand => "VirtualTours")
128
128
  l.virtual_tours.length.should == 1
@@ -131,9 +131,8 @@ describe Listing do
131
131
  l.videos.length.should == 0
132
132
  end
133
133
 
134
-
135
134
  it "should return an array of videos" do
136
- stub_api_get("/listings/1234", 'listing_with_videos.json', { :_expand => "Videos" })
135
+ stub_api_get("/listings/1234", 'listings/with_videos.json', { :_expand => "Videos" })
137
136
 
138
137
  l = Listing.find('1234', :_expand => "Videos")
139
138
  l.videos.length.should == 2
@@ -143,8 +142,8 @@ describe Listing do
143
142
  end
144
143
 
145
144
  it "should return tour of homes" do
146
- stub_api_get("/listings/20060725224713296297000000", 'listing_no_subresources.json')
147
- stub_api_get("/listings/20060725224713296297000000/tourofhomes", 'tour_of_homes.json')
145
+ stub_api_get("/listings/20060725224713296297000000", 'listings/no_subresources.json')
146
+ stub_api_get("/listings/20060725224713296297000000/tourofhomes", 'listings/tour_of_homes.json')
148
147
 
149
148
  l = Listing.find('20060725224713296297000000')
150
149
  l.tour_of_homes().length.should == 2
@@ -152,6 +151,73 @@ describe Listing do
152
151
  l.photos.length.should == 0
153
152
  l.documents.length.should == 0
154
153
  end
154
+
155
+ it "should return street address" do
156
+ @listing.street_address.should eq("100 Someone's St")
157
+ end
158
+
159
+ it "should return the regional address" do
160
+ @listing.region_address.should eq("Fargo, ND 55320")
161
+ end
162
+
163
+ it "should return full address" do
164
+ @listing.full_address.should eq("100 Someone's St, Fargo, ND 55320")
165
+ end
166
+
167
+ it "should return permissions" do
168
+ stub_api_get("/listings/20060725224713296297000000", 'listings/with_permissions.json', { :_expand => "Permissions" })
169
+ l = Listing.find('20060725224713296297000000', :_expand => "Permissions")
170
+ l.Permissions["Editable"].should eq(true)
171
+ l.editable?().should eq(true)
172
+ l.editable?(:PriceChange).should eq(true)
173
+ l.editable?(:Photos).should eq(false)
174
+ end
175
+ end
176
+
177
+ context "on save" do
178
+ it "should save a listing that has modified" do
179
+ list_id = "20060725224713296297000000"
180
+ stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
181
+ stub_api_put("/listings/#{list_id}", 'listings/put.json', 'success.json')
182
+ l = Listing.find(list_id)
183
+ l.ListPrice = 10000.0
184
+ l.save.should be(true)
185
+ end
186
+ it "should not save a listing that does not exist" do
187
+ list_id = "20060725224713296297000000"
188
+ stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
189
+ stub_api_put("/listings/lolwut", 'listings/put.json') do |request|
190
+ request.to_return(:status => 400, :body => fixture('errors/failure.json'))
191
+ end
192
+ l = Listing.find(list_id)
193
+ l.Id = "lolwut"
194
+ l.ListPrice = 10000.0
195
+ l.save.should be(false)
196
+ expect{ l.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
197
+ end
198
+ it "should save a listing with constraints" do
199
+ list_id = "20060725224713296297000000"
200
+ stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
201
+ stub_api_put("/listings/#{list_id}", 'listings/put.json', 'listings/constraints.json')
202
+ l = Listing.find(list_id)
203
+ l.ListPrice = 10000.0
204
+ l.save.should be(true)
205
+ l.constraints.size.should eq(1)
206
+ l.constraints.first.RuleName.should eq("MaxValue")
207
+ end
208
+ context "with pagination" do
209
+ # This is really a bogus call, but we should make sure our pagination collection impl still behaves sanely
210
+ it "should save a listing with constraints" do
211
+ list_id = "20060725224713296297000000"
212
+ stub_api_get("/listings/#{list_id}", 'listings/no_subresources.json')
213
+ stub_api_put("/listings/#{list_id}", 'listings/put.json', 'listings/constraints_with_pagination.json', :_pagination => '1')
214
+ l = Listing.find(list_id)
215
+ l.ListPrice = 10000.0
216
+ l.save(:_pagination => '1').should be(true)
217
+ l.constraints.size.should eq(1)
218
+ l.constraints.first.RuleName.should eq("MaxValue")
219
+ end
220
+ end
155
221
 
156
222
  end
157
223
 
@@ -159,5 +225,4 @@ describe Listing do
159
225
  @listing = nil
160
226
  end
161
227
 
162
-
163
228
  end
@@ -20,13 +20,13 @@ describe Note do
20
20
  end
21
21
 
22
22
  it "should get my notes" do
23
- stub_api_get("#{@note.path}", 'agent_shared_note.json')
23
+ stub_api_get("#{@note.path}", 'notes/agent_shared.json')
24
24
  ret = @note.get
25
25
  ret.Note.should == "lorem ipsum dolor sit amet"
26
26
  end
27
27
 
28
28
  it "should return a nil when no shared notes exist" do
29
- stub_api_get("#{@note.path}", 'agent_shared_note_empty.json')
29
+ stub_api_get("#{@note.path}", 'notes/agent_shared_empty.json')
30
30
  @note.get.should be_nil
31
31
  end
32
32
 
@@ -38,7 +38,7 @@ describe Note do
38
38
  it "should raise an exception when adding a note fails" do
39
39
  n = @note.new(:Note => "lorem ipsum dolor")
40
40
 
41
- stub_api_put("#{@note.path}", 'note_new.json') do |request|
41
+ stub_api_put("#{@note.path}", 'notes/new.json') do |request|
42
42
  request.to_return(:status => 500, :body => fixture('generic_failure.json'))
43
43
  end
44
44
 
@@ -48,7 +48,7 @@ describe Note do
48
48
 
49
49
  it "should allow adding of a note" do
50
50
  n = @note.new(:Note => "lorem ipsum dolor")
51
- stub_api_put("#{@note.path}", 'note_new.json', 'add_note.json')
51
+ stub_api_put("#{@note.path}", 'notes/new.json', 'notes/add.json')
52
52
  n.save
53
53
  n.ResourceUri.should == '/v1/listings/20100909200152674436000000/shared/notes/contacts/20110407212043616271000000/'
54
54
  end
@@ -26,7 +26,7 @@ describe OpenHouse do
26
26
 
27
27
  it "should get open house for a listing" do
28
28
  stub_auth_request
29
- stub_api_get('/listings/20060412165917817933000000/openhouses','open_houses.json')
29
+ stub_api_get('/listings/20060412165917817933000000/openhouses','listings/open_houses.json')
30
30
  houses = subject.class.find_by_listing_key('20060412165917817933000000')
31
31
  houses.should be_an(Array)
32
32
  houses.length.should eq(2)
@@ -1,49 +1,82 @@
1
1
  require './spec/spec_helper'
2
2
 
3
3
  describe Photo do
4
- before(:each) do
5
- @photo = Photo.new({
6
- "ResourceUri" => "/listings/20100815153524571646000000/photos/20101124153422574618000000",
7
- "Id" => "20101124153422574618000000",
8
- "Name" => "Photo 1 name",
9
- "Caption" => "caption here",
10
- "UriThumb" => "http://photos.cdn.flexmls.com/xyz-t.jpg",
11
- "Uri300" => "http://photos.cdn.flexmls.com/xyz.jpg",
12
- "Uri640" => "http://cdn.resize.flexmls.com/az/640x480/true/20101124153422574618000000-o.jpg",
13
- "Uri800" => "http://cdn.resize.flexmls.com/az/800x600/true/20101124153422574618000000-o.jpg",
14
- "Uri1024" => "http://cdn.resize.flexmls.com/az/1024x768/true/20101124153422574618000000-o.jpg",
15
- "Uri1280" => "http://cdn.resize.flexmls.com/az/1280x1024/true/20101124153422574618000000-o.jpg",
16
- "UriLarge" => "http://photos.cdn.flexmls.com/xyz-o.jpg",
17
- "Primary" => true
18
- })
19
-
20
- end
21
-
22
- it "responds to" do
23
- @photo.should respond_to(:primary?)
24
- Photo.should respond_to(:find_by_listing_key)
25
- end
26
-
27
- it "knows if it's the primary photo" do
28
- @photo.primary?.should be_true
29
- @photo.Primary = false
30
- @photo.primary?.should be_false
31
- end
32
-
33
- describe "find photos by listing id" do
34
- before do
35
- stub_auth_request
36
- stub_api_get('/listings/1234/photos', 'listing_photos_index.json')
4
+ describe "find" do
5
+ subject do
6
+ Photo.new({
7
+ "ResourceUri" => "/listings/20100815153524571646000000/photos/20101124153422574618000000",
8
+ "Id" => "20101124153422574618000000",
9
+ "Name" => "Photo 1 name",
10
+ "Caption" => "caption here",
11
+ "UriThumb" => "http://photos.cdn.flexmls.com/xyz-t.jpg",
12
+ "Uri300" => "http://photos.cdn.flexmls.com/xyz.jpg",
13
+ "Uri640" => "http://cdn.resize.flexmls.com/az/640x480/true/20101124153422574618000000-o.jpg",
14
+ "Uri800" => "http://cdn.resize.flexmls.com/az/800x600/true/20101124153422574618000000-o.jpg",
15
+ "Uri1024" => "http://cdn.resize.flexmls.com/az/1024x768/true/20101124153422574618000000-o.jpg",
16
+ "Uri1280" => "http://cdn.resize.flexmls.com/az/1280x1024/true/20101124153422574618000000-o.jpg",
17
+ "UriLarge" => "http://photos.cdn.flexmls.com/xyz-o.jpg",
18
+ "Primary" => true
19
+ })
37
20
  end
38
-
39
- it "should get an array of photos" do
40
- p = Photo.find_by_listing_key('1234')
41
- p.should be_an(Array)
21
+
22
+ it "responds to" do
23
+ subject.should respond_to(:primary?)
24
+ Photo.should respond_to(:find_by_listing_key)
25
+ end
26
+
27
+ it "knows if it's the primary photo" do
28
+ subject.primary?.should be_true
29
+ subject.Primary = false
30
+ subject.primary?.should be_false
31
+ end
32
+
33
+ describe "find photos by listing id" do
34
+ before do
35
+ stub_auth_request
36
+ stub_api_get('/listings/1234/photos', 'listings/photos/index.json')
37
+ end
38
+
39
+ it "should get an array of photos" do
40
+ p = Photo.find_by_listing_key('1234')
41
+ p.should be_an(Array)
42
+ end
42
43
  end
43
44
  end
44
-
45
- after(:each) do
46
- @photo = nil
45
+
46
+ describe "save" do
47
+ subject do
48
+ p = Photo.build_subclass.tap do |photo|
49
+ photo.prefix = "/listings/1234"
50
+ photo.element_name ="/photos"
51
+ end.new
52
+ p.update_path = "/listings/1234/photos"
53
+ p
54
+ end
55
+ it "should be scoped to a listing" do
56
+ subject.class.path.should eq("/listings/1234/photos")
57
+ end
58
+ it "should upload a new photo" do
59
+ stub_api_post('/listings/1234/photos', 'listings/photos/new.json', 'listings/photos/post.json')
60
+ subject.Name = "FBS Logo"
61
+ subject.Caption = "Creators of flexMLS!"
62
+ subject.load_picture("spec/fixtures/logo_fbs.png")
63
+ subject.save!
64
+ subject.Id.should eq("20110826220032167405000000")
65
+ end
66
+ it "should upload a modified photo" do
67
+ stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/new.json', 'listings/photos/post.json')
68
+ subject.Id = "20110826220032167405000000"
69
+ subject.Name = "FBS Logo"
70
+ subject.Caption = "Creators of flexMLS!"
71
+ subject.load_picture("spec/fixtures/logo_fbs.png")
72
+ subject.save!
73
+ subject.Id.should eq("20110826220032167405000000")
74
+ end
75
+ it "should delete a photo" do
76
+ stub_api_delete('/listings/1234/photos/20110826220032167405000000','success.json')
77
+ subject.Id = "20110826220032167405000000"
78
+ subject.delete
79
+ end
47
80
  end
48
81
 
49
82
  end