bookingsync-api 0.1.2 → 0.1.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +11 -11
  5. data/Guardfile +1 -1
  6. data/README.md +1 -0
  7. data/Rakefile +13 -3
  8. data/bookingsync-api.gemspec +3 -3
  9. data/lib/bookingsync-api.rb +1 -1
  10. data/lib/bookingsync/api/client.rb +7 -4
  11. data/lib/bookingsync/api/client/booking_comments.rb +1 -1
  12. data/lib/bookingsync/api/client/living_rooms.rb +65 -0
  13. data/lib/bookingsync/api/error.rb +1 -1
  14. data/lib/bookingsync/api/middleware/logger.rb +6 -6
  15. data/lib/bookingsync/api/resource.rb +1 -1
  16. data/lib/bookingsync/api/response.rb +2 -2
  17. data/lib/bookingsync/api/serializer.rb +5 -5
  18. data/lib/bookingsync/api/version.rb +1 -1
  19. data/spec/bookingsync/api/client/bathrooms_spec.rb +10 -9
  20. data/spec/bookingsync/api/client/bedrooms_spec.rb +10 -9
  21. data/spec/bookingsync/api/client/bookings_spec.rb +13 -13
  22. data/spec/bookingsync/api/client/clients_spec.rb +13 -11
  23. data/spec/bookingsync/api/client/fees_spec.rb +2 -2
  24. data/spec/bookingsync/api/client/inquiries_spec.rb +12 -10
  25. data/spec/bookingsync/api/client/living_rooms_spec.rb +62 -0
  26. data/spec/bookingsync/api/client/nightly_rate_maps_spec.rb +1 -1
  27. data/spec/bookingsync/api/client/payments_spec.rb +8 -11
  28. data/spec/bookingsync/api/client/periods_spec.rb +5 -5
  29. data/spec/bookingsync/api/client/photos_spec.rb +6 -6
  30. data/spec/bookingsync/api/client/preferences_general_settings_spec.rb +1 -1
  31. data/spec/bookingsync/api/client/preferences_payments_spec.rb +0 -1
  32. data/spec/bookingsync/api/client/rates_rules_spec.rb +3 -4
  33. data/spec/bookingsync/api/client/rates_tables_spec.rb +4 -5
  34. data/spec/bookingsync/api/client/rental_agreements_spec.rb +5 -5
  35. data/spec/bookingsync/api/client/rentals_amenities_spec.rb +4 -4
  36. data/spec/bookingsync/api/client/rentals_fees_spec.rb +1 -1
  37. data/spec/bookingsync/api/client/rentals_spec.rb +7 -10
  38. data/spec/bookingsync/api/client/reviews_spec.rb +3 -6
  39. data/spec/bookingsync/api/client/seasons_spec.rb +4 -9
  40. data/spec/bookingsync/api/client/sources_spec.rb +4 -5
  41. data/spec/bookingsync/api/client/special_offers_spec.rb +6 -6
  42. data/spec/bookingsync/api/client/strict_bookings_spec.rb +8 -8
  43. data/spec/bookingsync/api/client_spec.rb +29 -15
  44. data/spec/bookingsync/api/error_spec.rb +3 -3
  45. data/spec/bookingsync/api/relation_spec.rb +8 -6
  46. data/spec/bookingsync/api/resource_spec.rb +29 -26
  47. data/spec/bookingsync/api/response_spec.rb +16 -15
  48. data/spec/fixtures/cassettes/BookingSync_API_Client_LivingRooms/_cancel_living_room/cancels_given_living_room.yml +69 -0
  49. data/spec/fixtures/cassettes/BookingSync_API_Client_LivingRooms/_create_living_room/creates_a_new_living_room.yml +82 -0
  50. data/spec/fixtures/cassettes/BookingSync_API_Client_LivingRooms/_edit_living_room/updates_given_living_room_by_ID.yml +75 -0
  51. data/spec/fixtures/cassettes/BookingSync_API_Client_LivingRooms/_living_room/returns_a_single_living_room.yml +84 -0
  52. data/spec/fixtures/cassettes/BookingSync_API_Client_LivingRooms/_living_rooms/returns_living_rooms.yml +84 -0
  53. data/spec/spec_helper.rb +12 -12
  54. metadata +29 -3
@@ -34,7 +34,7 @@ describe BookingSync::API::Client::RentalsFees do
34
34
  end
35
35
 
36
36
  it "returns newly created rentals_fee" do
37
- VCR.use_cassette('BookingSync_API_Client_RentalsFees/_create_rentals_fee/creates_a_new_rentals_fee') do
37
+ VCR.use_cassette("BookingSync_API_Client_RentalsFees/_create_rentals_fee/creates_a_new_rentals_fee") do
38
38
  rentals_fee = client.create_rentals_fee(rental, attributes)
39
39
  expect(rentals_fee.links.fee).to eq 659
40
40
  expect(rentals_fee.maximum_bookable).to eq 10
@@ -57,10 +57,7 @@ describe BookingSync::API::Client::Rentals do
57
57
  end
58
58
 
59
59
  describe ".create_rental", :vcr do
60
- let(:attributes) { {
61
- name: "New rental",
62
- sleeps: 2
63
- } }
60
+ let(:attributes) { { name: "New rental", sleeps: 2 } }
64
61
 
65
62
  it "creates a new rental" do
66
63
  client.create_rental(attributes)
@@ -69,7 +66,7 @@ describe BookingSync::API::Client::Rentals do
69
66
  end
70
67
 
71
68
  it "returns newly created rental" do
72
- VCR.use_cassette('BookingSync_API_Client_Rentals/_create_rental/creates_a_new_rental') do
69
+ VCR.use_cassette("BookingSync_API_Client_Rentals/_create_rental/creates_a_new_rental") do
73
70
  rental = client.create_rental(attributes)
74
71
  expect(rental.name).to eql("New rental")
75
72
  expect(rental.sleeps).to eql(2)
@@ -79,16 +76,16 @@ describe BookingSync::API::Client::Rentals do
79
76
 
80
77
  describe ".edit_rental", :vcr do
81
78
  it "updates given rental by ID" do
82
- client.edit_rental(2, name: 'Updated Rental name')
79
+ client.edit_rental(2, name: "Updated Rental name")
83
80
  assert_requested :put, bs_url("rentals/2"),
84
- body: { rentals: [{ name: 'Updated Rental name' }] }.to_json
81
+ body: { rentals: [{ name: "Updated Rental name" }] }.to_json
85
82
  end
86
83
 
87
84
  it "returns updated rental" do
88
- VCR.use_cassette('BookingSync_API_Client_Rentals/_edit_rental/updates_given_rental_by_ID') do
89
- rental = client.edit_rental(2, name: 'Updated Rental name')
85
+ VCR.use_cassette("BookingSync_API_Client_Rentals/_edit_rental/updates_given_rental_by_ID") do
86
+ rental = client.edit_rental(2, name: "Updated Rental name")
90
87
  expect(rental).to be_kind_of(BookingSync::API::Resource)
91
- expect(rental.name).to eq('Updated Rental name')
88
+ expect(rental.name).to eq("Updated Rental name")
92
89
  end
93
90
  end
94
91
  end
@@ -18,20 +18,17 @@ describe BookingSync::API::Client::Reviews do
18
18
  end
19
19
 
20
20
  describe ".create_review", :vcr do
21
- let(:attributes) {{
22
- comment: "Awesome place",
23
- rating: 5
24
- }}
21
+ let(:attributes) { { comment: "Awesome place", rating: 5 } }
25
22
  let(:booking) { BookingSync::API::Resource.new(client, id: 1) }
26
23
 
27
24
  it "creates a new review" do
28
25
  client.create_review(booking, attributes)
29
26
  assert_requested :post, bs_url("bookings/1/reviews"),
30
- body: {reviews: [attributes]}.to_json
27
+ body: { reviews: [attributes] }.to_json
31
28
  end
32
29
 
33
30
  it "returns newly created review" do
34
- VCR.use_cassette('BookingSync_API_Client_Reviews/_create_review/creates_a_new_review') do
31
+ VCR.use_cassette("BookingSync_API_Client_Reviews/_create_review/creates_a_new_review") do
35
32
  review = client.create_review(booking, attributes)
36
33
  expect(review.comment).to eql(attributes[:comment])
37
34
  expect(review.rating).to eql(attributes[:rating])
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe BookingSync::API::Client::Seasons do
4
-
5
4
  let(:client) { BookingSync::API::Client.new(test_access_token) }
6
5
 
7
6
  describe ".seasons", :vcr do
@@ -19,21 +18,17 @@ describe BookingSync::API::Client::Seasons do
19
18
  end
20
19
 
21
20
  describe ".create_season", :vcr do
22
- let(:attributes) {{
23
- name: "New season",
24
- ratio: 0.2,
25
- minimum_stay: 4
26
- }}
21
+ let(:attributes) { { name: "New season", ratio: 0.2, minimum_stay: 4 } }
27
22
  let(:rates_table) { BookingSync::API::Resource.new(client, id: 13) }
28
23
 
29
24
  it "creates a new season" do
30
25
  client.create_season(rates_table, attributes)
31
26
  assert_requested :post, bs_url("rates_tables/13/seasons"),
32
- body: {seasons: [attributes]}.to_json
27
+ body: { seasons: [attributes] }.to_json
33
28
  end
34
29
 
35
30
  it "returns newly created season" do
36
- VCR.use_cassette('BookingSync_API_Client_Seasons/_create_season/creates_a_new_season') do
31
+ VCR.use_cassette("BookingSync_API_Client_Seasons/_create_season/creates_a_new_season") do
37
32
  season = client.create_season(rates_table, attributes)
38
33
  expect(season.name).to eql(attributes[:name])
39
34
  expect(season.minimum_stay).to eql(attributes[:minimum_stay])
@@ -52,7 +47,7 @@ describe BookingSync::API::Client::Seasons do
52
47
  end
53
48
 
54
49
  it "returns updated season" do
55
- VCR.use_cassette('BookingSync_API_Client_Seasons/_edit_season/updates_given_season_by_ID') do
50
+ VCR.use_cassette("BookingSync_API_Client_Seasons/_edit_season/updates_given_season_by_ID") do
56
51
  season = client.edit_season(6, attributes)
57
52
  expect(season).to be_kind_of(BookingSync::API::Resource)
58
53
  expect(season.name).to eq(attributes[:name])
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe BookingSync::API::Client::Sources do
4
-
5
4
  let(:client) { BookingSync::API::Client.new(test_access_token) }
6
5
 
7
6
  describe ".sources", :vcr do
@@ -20,7 +19,7 @@ describe BookingSync::API::Client::Sources do
20
19
 
21
20
  describe ".create_source", :vcr do
22
21
  let(:attributes) {
23
- { name: 'New source' }
22
+ { name: "New source" }
24
23
  }
25
24
 
26
25
  it "creates a new source" do
@@ -30,7 +29,7 @@ describe BookingSync::API::Client::Sources do
30
29
  end
31
30
 
32
31
  it "returns newly created source" do
33
- VCR.use_cassette('BookingSync_API_Client_Sources/_create_source/creates_a_new_source') do
32
+ VCR.use_cassette("BookingSync_API_Client_Sources/_create_source/creates_a_new_source") do
34
33
  source = client.create_source(attributes)
35
34
  expect(source.name).to eql(attributes[:name])
36
35
  end
@@ -39,7 +38,7 @@ describe BookingSync::API::Client::Sources do
39
38
 
40
39
  describe ".edit_source", :vcr do
41
40
  let(:attributes) {
42
- { name: 'HomeAway.com' }
41
+ { name: "HomeAway.com" }
43
42
  }
44
43
 
45
44
  it "updates given source by ID" do
@@ -49,7 +48,7 @@ describe BookingSync::API::Client::Sources do
49
48
  end
50
49
 
51
50
  it "returns updated source" do
52
- VCR.use_cassette('BookingSync_API_Client_Sources/_edit_source/updates_given_source_by_ID') do
51
+ VCR.use_cassette("BookingSync_API_Client_Sources/_edit_source/updates_given_source_by_ID") do
53
52
  source = client.edit_source(4, attributes)
54
53
  expect(source).to be_kind_of(BookingSync::API::Resource)
55
54
  expect(source.name).to eql(attributes[:name])
@@ -21,8 +21,8 @@ describe BookingSync::API::Client::SpecialOffers do
21
21
  let(:attributes) {
22
22
  {
23
23
  name: "New special offer",
24
- start_at: '2014-04-28',
25
- end_at: '2014-05-28',
24
+ start_at: "2014-04-28",
25
+ end_at: "2014-05-28",
26
26
  discount: 5
27
27
  }
28
28
  }
@@ -31,11 +31,11 @@ describe BookingSync::API::Client::SpecialOffers do
31
31
  it "creates a new special_offer" do
32
32
  client.create_special_offer(rental, attributes)
33
33
  assert_requested :post, bs_url("rentals/12/special_offers"),
34
- body: {special_offers: [attributes]}.to_json
34
+ body: { special_offers: [attributes] }.to_json
35
35
  end
36
36
 
37
37
  it "returns newly created special_offer" do
38
- VCR.use_cassette('BookingSync_API_Client_SpecialOffers/_create_special_offer/creates_a_new_special_offer') do
38
+ VCR.use_cassette("BookingSync_API_Client_SpecialOffers/_create_special_offer/creates_a_new_special_offer") do
39
39
  special_offer = client.create_special_offer(rental, attributes)
40
40
  expect(special_offer.name).to eql(attributes[:name])
41
41
  end
@@ -44,7 +44,7 @@ describe BookingSync::API::Client::SpecialOffers do
44
44
 
45
45
  describe ".edit_special_offer", :vcr do
46
46
  let(:attributes) {
47
- { name: 'Updated special offer' }
47
+ { name: "Updated special offer" }
48
48
  }
49
49
 
50
50
  it "updates given special_offer by ID" do
@@ -54,7 +54,7 @@ describe BookingSync::API::Client::SpecialOffers do
54
54
  end
55
55
 
56
56
  it "returns updated special_offer" do
57
- VCR.use_cassette('BookingSync_API_Client_SpecialOffers/_edit_special_offer/updates_given_special_offer_by_ID') do
57
+ VCR.use_cassette("BookingSync_API_Client_SpecialOffers/_edit_special_offer/updates_given_special_offer_by_ID") do
58
58
  special_offer = client.edit_special_offer(3, attributes)
59
59
  expect(special_offer).to be_kind_of(BookingSync::API::Resource)
60
60
  expect(special_offer.name).to eq(attributes[:name])
@@ -35,15 +35,15 @@ describe BookingSync::API::Client::StrictBookings do
35
35
  it "creates a booking" do
36
36
  client.create_strict_booking(params)
37
37
  assert_requested :post, bs_url("strict_bookings"),
38
- body: {bookings: [params]}.to_json
38
+ body: { bookings: [params] }.to_json
39
39
  end
40
40
 
41
- it "returns newly created booking" do
42
- VCR.use_cassette('BookingSync_API_Client_StrictBookings/_create_strict_booking/creates_a_booking') do
43
- booking = client.create_strict_booking(params)
44
- expect(booking.start_at).to eql(Time.parse("2016-01-15 16:00:00 UTC"))
45
- expect(booking.end_at).to eql(Time.parse("2016-01-23 10:00:00 UTC"))
46
- end
47
- end
41
+ it "returns newly created booking" do
42
+ VCR.use_cassette("BookingSync_API_Client_StrictBookings/_create_strict_booking/creates_a_booking") do
43
+ booking = client.create_strict_booking(params)
44
+ expect(booking.start_at).to eql(Time.parse("2016-01-15 16:00:00 UTC"))
45
+ expect(booking.end_at).to eql(Time.parse("2016-01-23 10:00:00 UTC"))
46
+ end
47
+ end
48
48
  end
49
49
  end
@@ -29,7 +29,7 @@ describe BookingSync::API::Client do
29
29
  before { VCR.turn_off! }
30
30
  it "makes a HTTP POST request with body" do
31
31
  stub_post("resource")
32
- client.post("resource", {key: :value})
32
+ client.post("resource", key: :value)
33
33
  assert_requested :post, bs_url("resource"), body: '{"key":"value"}'
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ describe BookingSync::API::Client do
38
38
  stub_post("resource", status: 422, body: { errors: { country_code:
39
39
  ["is required"] } }.to_json)
40
40
  expect {
41
- client.post("resource", { key: :value })
41
+ client.post("resource", key: :value)
42
42
  }.to raise_error(BookingSync::API::UnprocessableEntity) { |error|
43
43
  expect(error.message).to include '{"errors":{"country_code":["is required"]}}'
44
44
  }
@@ -50,7 +50,7 @@ describe BookingSync::API::Client do
50
50
  before { VCR.turn_off! }
51
51
  it "makes a HTTP PUT request with body" do
52
52
  stub_put("resource")
53
- client.put("resource", {key: :value})
53
+ client.put("resource", key: :value)
54
54
  assert_requested :put, bs_url("resource"), body: '{"key":"value"}'
55
55
  end
56
56
  end
@@ -67,7 +67,7 @@ describe BookingSync::API::Client do
67
67
  describe "#request" do
68
68
  context "on response which responds to :resources" do
69
69
  it "returns an array of resources" do
70
- stub_get("resource", body: {resources: [{name: "Megan"}]}.to_json)
70
+ stub_get("resource", body: { resources: [{ name: "Megan" }] }.to_json)
71
71
  resources = client.request(:get, "resource")
72
72
  expect(resources).to be_kind_of(Array)
73
73
  expect(resources.first.name).to eq("Megan")
@@ -92,25 +92,25 @@ describe BookingSync::API::Client do
92
92
  stub_get("resource")
93
93
  client.call(:get, "resource")
94
94
  assert_requested :get, bs_url("resource"),
95
- headers: {"Authorization" => "Bearer fake-access-token"}
95
+ headers: { "Authorization" => "Bearer fake-access-token" }
96
96
  end
97
97
 
98
98
  it "requests proper accept header for JSON API" do
99
99
  stub_get("resource")
100
100
  client.call(:get, "resource")
101
101
  assert_requested :get, bs_url("resource"),
102
- headers: {"Accept" => "application/vnd.api+json"}
102
+ headers: { "Accept" => "application/vnd.api+json" }
103
103
  end
104
104
 
105
105
  it "requests sends data with JSON API content type" do
106
106
  stub_post("resource")
107
107
  client.call(:post, "resource")
108
108
  assert_requested :post, bs_url("resource"),
109
- headers: {"Content-Type" => "application/vnd.api+json"}
109
+ headers: { "Content-Type" => "application/vnd.api+json" }
110
110
  end
111
111
 
112
112
  it "returns an Response object of resources" do
113
- attributes = {resources: [{name: "Megan"}]}
113
+ attributes = { resources: [{ name: "Megan" }] }
114
114
  stub_post("resource", body: attributes.to_json)
115
115
  response = client.call(:post, "resource", attributes)
116
116
  expect(response).to be_kind_of(BookingSync::API::Response)
@@ -120,8 +120,8 @@ describe BookingSync::API::Client do
120
120
  stub_get("resource", body: {}.to_json)
121
121
  response = client.call(:get, "resource")
122
122
  assert_requested :get, bs_url("resource"),
123
- headers: {"User-Agent" =>
124
- "BookingSync API gem v#{BookingSync::API::VERSION}"}
123
+ headers: { "User-Agent" =>
124
+ "BookingSync API gem v#{BookingSync::API::VERSION}" }
125
125
  end
126
126
 
127
127
  context "API returns 401" do
@@ -168,7 +168,7 @@ describe BookingSync::API::Client do
168
168
  client.get("resource")
169
169
  }.to raise_error(BookingSync::API::UnsupportedResponse) { |error|
170
170
  expect(error.status).to eql(405)
171
- expect(error.headers).to eq({ "content-type" => "application/vnd.api+json" })
171
+ expect(error.headers).to eq("content-type" => "application/vnd.api+json")
172
172
  expect(error.body).to eq("Whoops!")
173
173
  expect(error.message).to include("Received unsupported response from BookingSync API")
174
174
  }
@@ -207,7 +207,7 @@ describe BookingSync::API::Client do
207
207
  context "user passes additional query options" do
208
208
  it "constructs url with query options" do
209
209
  stub_get("resource?months=12&status=booked,unavailable")
210
- client.get("resource", status: [:booked, :unavailable], months: '12')
210
+ client.get("resource", status: [:booked, :unavailable], months: "12")
211
211
  assert_requested :get, bs_url("resource?months=12&status=booked,unavailable")
212
212
  end
213
213
  end
@@ -241,7 +241,7 @@ describe BookingSync::API::Client do
241
241
 
242
242
  it "uses logger provided by user" do
243
243
  client = BookingSync::API::Client.new(test_access_token, logger: logger)
244
- stub_get("resources", body: {"resources" => [{id: 1}, {id: 2}]}.to_json)
244
+ stub_get("resources", body: { "resources" => [{ id: 1 }, { id: 2 }] }.to_json)
245
245
  client.get("resources")
246
246
  messages = log.rewind && log.read
247
247
  expect(messages).to include("GET https://www.bookingsync.com/api/v3/resources")
@@ -263,7 +263,7 @@ describe BookingSync::API::Client do
263
263
  it "logs X-Request-Id from headers" do
264
264
  client = BookingSync::API::Client.new(test_access_token, logger: logger)
265
265
  stub_get("resources", body: {}.to_json,
266
- headers: {'X-Request-Id' => "021bfb82"})
266
+ headers: { "X-Request-Id" => "021bfb82" })
267
267
  client.get("resources")
268
268
 
269
269
  messages = log.rewind && log.read
@@ -273,9 +273,23 @@ describe BookingSync::API::Client do
273
273
 
274
274
  describe "#last_response" do
275
275
  it "returns last response" do
276
- stub_get("resources", body: {meta: {count: 10}, resources: []}.to_json)
276
+ stub_get("resources", body: { meta: { count: 10 }, resources: [] }.to_json)
277
277
  client.get("resources")
278
278
  expect(client.last_response.meta).to eql(count: 10)
279
279
  end
280
280
  end
281
+
282
+ context "pagination" do
283
+ before do
284
+ stub_get("resources", headers: { "Link" => '<resources?page=2>; rel="next"' }, body: { meta: { text: "first request" }, resources: [] }.to_json)
285
+ stub_get("resources?page=2", body: { meta: { text: "second request" }, resources: [] }.to_json)
286
+ end
287
+
288
+ describe "#pagination_first_response" do
289
+ it "returns first response of a paginated call" do
290
+ client.paginate("resources", auto_paginate: true)
291
+ expect(client.pagination_first_response.meta).to eql(text: "first request")
292
+ end
293
+ end
294
+ end
281
295
  end
@@ -27,8 +27,8 @@ describe BookingSync::API::Error do
27
27
  describe "#headers" do
28
28
  it "returns response headers" do
29
29
  expect { request }.to raise_error(BookingSync::API::Error) { |exception|
30
- expect(exception.headers).to eq({"content-type" =>
31
- "application/vnd.api+json"})
30
+ expect(exception.headers).to eq("content-type" =>
31
+ "application/vnd.api+json")
32
32
  }
33
33
  end
34
34
  end
@@ -36,7 +36,7 @@ describe BookingSync::API::Error do
36
36
  describe "#message" do
37
37
  it "returns standard exception message" do
38
38
  expect { request }.to raise_error(BookingSync::API::Error) { |exception|
39
- expect(exception.message).to eq(%Q{BookingSync::API::UnprocessableEntity
39
+ expect(exception.message).to eq(%{BookingSync::API::UnprocessableEntity
40
40
  HTTP status code : 422
41
41
  Headers : {"content-type"=>"application/vnd.api+json"}
42
42
  Body : {"errors":{"name":["can't be blank"]}}})
@@ -1,12 +1,14 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe BookingSync::API::Relation do
4
4
  before { VCR.turn_off! }
5
5
  let(:client) { BookingSync::API::Client.new(test_access_token,
6
- base_url: "http://example.com") }
7
- let(:links) { {"foo.photos" => "http://example.com/photos/{foo.photos}"} }
6
+ base_url: "http://example.com")
7
+ }
8
+ let(:links) { { "foo.photos" => "http://example.com/photos/{foo.photos}" } }
8
9
  let(:relation) { BookingSync::API::Relation.new(client, :"foo.photos",
9
- "http://example.com/photos/{foo.photos}") }
10
+ "http://example.com/photos/{foo.photos}")
11
+ }
10
12
 
11
13
  describe ".from_links" do
12
14
  it "returns a hash of relations" do
@@ -28,7 +30,7 @@ describe BookingSync::API::Relation do
28
30
  describe "#get" do
29
31
  it "makes a HTTP GET request using call on client" do
30
32
  url_template = ::Addressable::Template.new("http://example.com/photos/{foo.photos}")
31
- expect(client).to receive(:call).with(:get, url_template, {fields: [:name, :description]}, {})
33
+ expect(client).to receive(:call).with(:get, url_template, { fields: [:name, :description] }, {})
32
34
  relation.get(fields: [:name, :description])
33
35
  end
34
36
  end
@@ -36,7 +38,7 @@ describe BookingSync::API::Relation do
36
38
  describe "#post" do
37
39
  it "makes a HTTP POST request using call on client" do
38
40
  url_template = ::Addressable::Template.new("http://example.com/photos/{foo.photos}")
39
- expect(client).to receive(:call).with(:post, url_template, {fields: [:name, :description]}, {})
41
+ expect(client).to receive(:call).with(:post, url_template, { fields: [:name, :description] }, {})
40
42
  relation.post(fields: [:name, :description])
41
43
  end
42
44
  end
@@ -1,22 +1,25 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe BookingSync::API::Resource do
4
- let(:links) { {photos: [9, 10]} }
4
+ let(:links) { { photos: [9, 10] } }
5
5
  let(:relation) {
6
- BookingSync::API::Relation.from_links(client, {
7
- :"foo.photos" => "http://foo.com/photos/{foo.photos}",
8
- :"foo.category" => "http://foo.com/categories/{foo.category}",
9
- :"foo.article" => "http://foo.com/articles/{foo.taggable.id}"
10
- })
6
+ BookingSync::API::Relation.from_links(client,
7
+ :"foo.photos" => "http://foo.com/photos/{foo.photos}", # rubocop:disable Style/HashSyntax
8
+ :"foo.category" => "http://foo.com/categories/{foo.category}", # rubocop:disable Style/HashSyntax
9
+ :"foo.article" => "http://foo.com/articles/{foo.taggable.id}") # rubocop:disable Style/HashSyntax
11
10
  }
12
11
  let(:client) { BookingSync::API::Client.new(test_access_token,
13
- base_url: "http://foo.com") }
14
- let(:data) { {
15
- name: "foo", width: 700,
16
- links: links,
17
- details: {count: 1},
18
- id: 10
19
- } }
12
+ base_url: "http://foo.com")
13
+ }
14
+ let(:data) do
15
+ {
16
+ name: "foo",
17
+ width: 700,
18
+ links: links,
19
+ details: { count: 1 },
20
+ id: 10
21
+ }
22
+ end
20
23
  let(:resource) {
21
24
  BookingSync::API::Resource.new(client, data, relation, "foo")
22
25
  }
@@ -50,35 +53,35 @@ describe BookingSync::API::Resource do
50
53
  context "has_many (ids given as an array)" do
51
54
  it "fetches an association based on links" do
52
55
  stub_request(:get, "http://foo.com/photos/9,10")
53
- .to_return(body: {photos: [{file: 'a.jpg'}]}.to_json)
54
- expect(resource.photos).to eql([{:file => "a.jpg"}])
56
+ .to_return(body: { photos: [{ file: "a.jpg" }] }.to_json)
57
+ expect(resource.photos).to eql([{ file: "a.jpg" }])
55
58
  end
56
59
  end
57
60
 
58
61
  context "has_one (id given as a single integer)" do
59
- let(:links) { {category: 15} }
62
+ let(:links) { { category: 15 } }
60
63
  it "fetches an association based on links" do
61
64
  stub_request(:get, "http://foo.com/categories/15")
62
- .to_return(body: {categories: [{name: "Secret one"}]}.to_json)
63
- expect(resource.category).to eql([{name: "Secret one"}])
65
+ .to_return(body: { categories: [{ name: "Secret one" }] }.to_json)
66
+ expect(resource.category).to eql([{ name: "Secret one" }])
64
67
  end
65
68
  end
66
69
 
67
70
  context "polymorphic association" do
68
71
  let(:links) do
69
- { taggable: { "type" => "Article", "id" => "15" },
72
+ { taggable: { "type" => "Article", "id" => "15" },
70
73
  other_polymorphable: { "type" => "Other", "id" => "15" },
71
74
  category: 15 }
72
75
  end
73
76
  it "fetches association based on links and type" do
74
77
  stub_request(:get, "http://foo.com/articles/15")
75
- .to_return(body: {articles: [{name: "Secret one"}]}.to_json)
76
- expect(resource.taggable).to eql([{name: "Secret one"}])
78
+ .to_return(body: { articles: [{ name: "Secret one" }] }.to_json)
79
+ expect(resource.taggable).to eql([{ name: "Secret one" }])
77
80
  end
78
81
  end
79
82
 
80
83
  context "when there are not associated ids" do
81
- let(:links) { {photos: []} }
84
+ let(:links) { { photos: [] } }
82
85
  it "returns an empty array" do
83
86
  expect(resource.photos).to eql([])
84
87
  end
@@ -92,12 +95,12 @@ describe BookingSync::API::Resource do
92
95
 
93
96
  it "passes query option to request" do
94
97
  stub_request(:get, "http://foo.com/photos/9,10?fields=description")
95
- .to_return(body: {photos: [{file: 'a.jpg'}]}.to_json)
98
+ .to_return(body: { photos: [{ file: "a.jpg" }] }.to_json)
96
99
  resource.photos(fields: :description)
97
100
  end
98
101
 
99
102
  context "when association loaded by eager loading" do
100
- let(:data) { {links: links, photos: [{file: 'b.jpg'}]} }
103
+ let(:data) { { links: links, photos: [{ file: "b.jpg" }] } }
101
104
 
102
105
  it "doesn't fetch it again" do
103
106
  resource.photos
@@ -105,7 +108,7 @@ describe BookingSync::API::Resource do
105
108
  end
106
109
 
107
110
  it "returns previously loaded data" do
108
- expect(resource.photos).to eq([{file: 'b.jpg'}])
111
+ expect(resource.photos).to eq([{ file: "b.jpg" }])
109
112
  end
110
113
  end
111
114
  end