sitra_client 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sitra_client.rb +4 -4
- data/lib/sitra_client/attribute_helper.rb +10 -10
- data/lib/sitra_client/sitra_query.rb +18 -18
- data/lib/sitra_client/sitra_response.rb +43 -43
- data/lib/sitra_client/touristic_object.rb +323 -295
- data/lib/sitra_client/version.rb +1 -1
- data/test/sitra_client/sitra_query_test.rb +15 -15
- data/test/sitra_client/sitra_response_test.rb +67 -67
- data/test/sitra_client/touristic_object_test.rb +381 -332
- metadata +3 -3
data/lib/sitra_client/version.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
gem 'shoulda'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'shoulda'
|
5
|
-
require 'sitra_client/sitra_query'
|
6
|
-
|
7
|
-
class SitraQueryTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
should 'populate query with parameters' do
|
10
|
-
|
11
|
-
query = SitraQuery.new('dummy_key', 'dummy_identifier', {:first_key => 'first_value', :second_key => 'second_value'})
|
12
|
-
|
13
|
-
assert_equal '{"apiKey":"dummy_key","projetId":"dummy_identifier","first_key":"first_value","second_key":"second_value"}', query.to_params
|
14
|
-
end
|
15
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'shoulda'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'sitra_client/sitra_query'
|
6
|
+
|
7
|
+
class SitraQueryTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
should 'populate query with parameters' do
|
10
|
+
|
11
|
+
query = SitraQuery.new('dummy_key', 'dummy_identifier', {:first_key => 'first_value', :second_key => 'second_value'})
|
12
|
+
|
13
|
+
assert_equal '{"apiKey":"dummy_key","projetId":"dummy_identifier","first_key":"first_value","second_key":"second_value"}', query.to_params
|
14
|
+
end
|
15
|
+
|
16
16
|
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
gem 'shoulda'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'shoulda'
|
5
|
-
require 'sitra_client/sitra_response'
|
6
|
-
|
7
|
-
|
8
|
-
class SitraResponseTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
setup do
|
11
|
-
@response = '{"apiKey":"dummy_key","siteWebExportIdV1":"dummy_identifier","first_key":"first_value","second_key":"second_value"}'
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'store raw json response' do
|
15
|
-
|
16
|
-
sitra_response = SitraResponse.new
|
17
|
-
sitra_response.append_line(@response)
|
18
|
-
|
19
|
-
assert_equal @response, sitra_response.as_raw_json
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
should 'return response as hash' do
|
24
|
-
|
25
|
-
sitra_response = SitraResponse.new
|
26
|
-
sitra_response.append_line(@response)
|
27
|
-
|
28
|
-
response_hash = sitra_response.as_hash
|
29
|
-
|
30
|
-
assert_equal 'dummy_key', response_hash[:apiKey]
|
31
|
-
assert_equal 'dummy_identifier', response_hash[:siteWebExportIdV1]
|
32
|
-
assert_equal 'first_value', response_hash[:first_key]
|
33
|
-
assert_equal 'second_value', response_hash[:second_key]
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
should 'return an array of touristic objects' do
|
38
|
-
|
39
|
-
json_response = '{ "numFound" : 2, "objetsTouristiques" : [ {"id" : 1, "nom" : {"libelleFr" : "my_first_object"} }, {"id" : 2, "nom" : {"libelleFr" : "my_second_object"} } ] }'
|
40
|
-
|
41
|
-
sitra_response = SitraResponse.new
|
42
|
-
sitra_response.append_line(json_response)
|
43
|
-
|
44
|
-
touristic_objects = sitra_response.as_array
|
45
|
-
|
46
|
-
assert_equal 2, touristic_objects.length
|
47
|
-
assert_equal "1", touristic_objects[0].id
|
48
|
-
assert_equal "my_first_object", touristic_objects[0].title
|
49
|
-
assert_equal "2", touristic_objects[1].id
|
50
|
-
assert_equal "my_second_object", touristic_objects[1].title
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
should 'return empty array when no data is available' do
|
55
|
-
|
56
|
-
json_response = '{ "numFound" : 2 }'
|
57
|
-
|
58
|
-
sitra_response = SitraResponse.new
|
59
|
-
sitra_response.append_line(json_response)
|
60
|
-
|
61
|
-
touristic_objects = sitra_response.as_array
|
62
|
-
|
63
|
-
assert_equal 2, sitra_response.results_count
|
64
|
-
assert_empty touristic_objects
|
65
|
-
|
66
|
-
end
|
67
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'shoulda'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'sitra_client/sitra_response'
|
6
|
+
|
7
|
+
|
8
|
+
class SitraResponseTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@response = '{"apiKey":"dummy_key","siteWebExportIdV1":"dummy_identifier","first_key":"first_value","second_key":"second_value"}'
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'store raw json response' do
|
15
|
+
|
16
|
+
sitra_response = SitraResponse.new
|
17
|
+
sitra_response.append_line(@response)
|
18
|
+
|
19
|
+
assert_equal @response, sitra_response.as_raw_json
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'return response as hash' do
|
24
|
+
|
25
|
+
sitra_response = SitraResponse.new
|
26
|
+
sitra_response.append_line(@response)
|
27
|
+
|
28
|
+
response_hash = sitra_response.as_hash
|
29
|
+
|
30
|
+
assert_equal 'dummy_key', response_hash[:apiKey]
|
31
|
+
assert_equal 'dummy_identifier', response_hash[:siteWebExportIdV1]
|
32
|
+
assert_equal 'first_value', response_hash[:first_key]
|
33
|
+
assert_equal 'second_value', response_hash[:second_key]
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'return an array of touristic objects' do
|
38
|
+
|
39
|
+
json_response = '{ "numFound" : 2, "objetsTouristiques" : [ {"id" : 1, "nom" : {"libelleFr" : "my_first_object"} }, {"id" : 2, "nom" : {"libelleFr" : "my_second_object"} } ] }'
|
40
|
+
|
41
|
+
sitra_response = SitraResponse.new
|
42
|
+
sitra_response.append_line(json_response)
|
43
|
+
|
44
|
+
touristic_objects = sitra_response.as_array
|
45
|
+
|
46
|
+
assert_equal 2, touristic_objects.length
|
47
|
+
assert_equal "1", touristic_objects[0].id
|
48
|
+
assert_equal "my_first_object", touristic_objects[0].title
|
49
|
+
assert_equal "2", touristic_objects[1].id
|
50
|
+
assert_equal "my_second_object", touristic_objects[1].title
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'return empty array when no data is available' do
|
55
|
+
|
56
|
+
json_response = '{ "numFound" : 2 }'
|
57
|
+
|
58
|
+
sitra_response = SitraResponse.new
|
59
|
+
sitra_response.append_line(json_response)
|
60
|
+
|
61
|
+
touristic_objects = sitra_response.as_array
|
62
|
+
|
63
|
+
assert_equal 2, sitra_response.results_count
|
64
|
+
assert_empty touristic_objects
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
68
|
end
|
@@ -1,332 +1,381 @@
|
|
1
|
-
# encoding : UTF-8
|
2
|
-
require 'rubygems'
|
3
|
-
gem 'shoulda'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'shoulda'
|
6
|
-
require 'sitra_client/touristic_object'
|
7
|
-
|
8
|
-
class TouristicObjectTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
should 'populate title of touristic object' do
|
11
|
-
hash_result = {:nom => {:libelleFr => "my_title"}}
|
12
|
-
touristic_object = TouristicObject.new(hash_result)
|
13
|
-
|
14
|
-
assert_equal 'my_title', touristic_object.title
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'populate description of touristic object' do
|
18
|
-
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description"}}}
|
19
|
-
touristic_object = TouristicObject.new(hash_result)
|
20
|
-
|
21
|
-
assert_equal 'my_description', touristic_object.description
|
22
|
-
end
|
23
|
-
|
24
|
-
should 'populate detailed description of touristic object' do
|
25
|
-
hash_result = {:presentation => {:descriptifDetaille => {:libelleFr => "my_detailed_description"}}}
|
26
|
-
touristic_object = TouristicObject.new(hash_result)
|
27
|
-
|
28
|
-
assert_equal 'my_detailed_description', touristic_object.details
|
29
|
-
end
|
30
|
-
|
31
|
-
should 'populate contact details for provided fields' do
|
32
|
-
hash_result = {
|
33
|
-
:informations => {
|
34
|
-
:moyensCommunication => [
|
35
|
-
{:type => {:libelleFr => "Téléphone", :id => 201}, :coordonnees => {:fr => "0123456789"}},
|
36
|
-
{:type => {:libelleFr => "Mél", :id => 204}, :coordonnees => {:fr => "my@email.fr"}},
|
37
|
-
{:type => {:libelleFr => "Fax", :id => 202}, :coordonnees => {:fr => "9876543201"}}
|
38
|
-
]
|
39
|
-
}
|
40
|
-
}
|
41
|
-
touristic_object = TouristicObject.new(hash_result)
|
42
|
-
|
43
|
-
assert_equal({'Téléphone' => '0123456789', 'Mél' => 'my@email.fr'}, touristic_object.contact([201, 204]))
|
44
|
-
end
|
45
|
-
|
46
|
-
should 'populate image details' do
|
47
|
-
hash_result = {
|
48
|
-
:illustrations => [
|
49
|
-
{:type => 'IMAGE', :traductionFichiers => [{:url => 'my/image/url', :urlListe => 'my/list/url', :urlFiche => 'my/details/url'}]}
|
50
|
-
]
|
51
|
-
}
|
52
|
-
touristic_object = TouristicObject.new(hash_result)
|
53
|
-
|
54
|
-
assert_equal [{:url => 'my/image/url', :urlListe => 'my/list/url', :urlFiche => 'my/details/url'}], touristic_object.pictures
|
55
|
-
end
|
56
|
-
|
57
|
-
should 'populate address details' do
|
58
|
-
hash_result = {
|
59
|
-
:informationsActivite => {
|
60
|
-
:prestataireActivites => {
|
61
|
-
:nom => {:libelleFr => "my_service"},
|
62
|
-
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
63
|
-
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
touristic_object = TouristicObject.new(hash_result)
|
68
|
-
|
69
|
-
assert_equal 'my_service', touristic_object.service_provider
|
70
|
-
assert_equal 'my_address, my_city', touristic_object.address
|
71
|
-
assert_equal 0.2, touristic_object.latitude
|
72
|
-
assert_equal 0.1, touristic_object.longitude
|
73
|
-
end
|
74
|
-
|
75
|
-
should 'use event details when available' do
|
76
|
-
hash_result = {:informationsFeteEtManifestation => {:nomLieu => "my_place"}}
|
77
|
-
touristic_object = TouristicObject.new(hash_result)
|
78
|
-
|
79
|
-
assert_equal 'my_place', touristic_object.service_provider
|
80
|
-
end
|
81
|
-
|
82
|
-
should 'fallback to localisation address when service details are missing' do
|
83
|
-
hash_result = {
|
84
|
-
:localisation => {
|
85
|
-
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
86
|
-
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
87
|
-
},
|
88
|
-
:informationsActivite => {}
|
89
|
-
}
|
90
|
-
touristic_object = TouristicObject.new(hash_result)
|
91
|
-
|
92
|
-
assert_nil touristic_object.service_provider
|
93
|
-
assert_equal 'my_address, my_city', touristic_object.address
|
94
|
-
assert_equal 0.2, touristic_object.latitude
|
95
|
-
assert_equal 0.1, touristic_object.longitude
|
96
|
-
end
|
97
|
-
|
98
|
-
should 'populate opening hours when available' do
|
99
|
-
hash_result = {:ouverture => {:periodeEnClair => {:libelleFr => "my_opening_hours"}}}
|
100
|
-
touristic_object = TouristicObject.new(hash_result)
|
101
|
-
|
102
|
-
assert_equal 'my_opening_hours', touristic_object.horaires
|
103
|
-
end
|
104
|
-
|
105
|
-
should 'populate tariffs data when available' do
|
106
|
-
hash_result = {
|
107
|
-
:descriptionTarif => {:gratuit => false,
|
108
|
-
:tarifsEnClair => {:libelleFr => "my_tariff_description"}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
touristic_object = TouristicObject.new(hash_result)
|
112
|
-
|
113
|
-
assert_equal 'my_tariff_description', touristic_object.tarif
|
114
|
-
end
|
115
|
-
|
116
|
-
should 'tag free oject when relevant' do
|
117
|
-
hash_result = {:descriptionTarif => {:gratuit => true}}
|
118
|
-
touristic_object = TouristicObject.new(hash_result)
|
119
|
-
|
120
|
-
assert_equal 'gratuit', touristic_object.tarif
|
121
|
-
end
|
122
|
-
|
123
|
-
should 'populate populations information' do
|
124
|
-
hash_result = {
|
125
|
-
:prestations => {:typesClientele => [{:libelleFr => "Familles"}]}
|
126
|
-
}
|
127
|
-
touristic_object = TouristicObject.new(hash_result)
|
128
|
-
|
129
|
-
assert_equal ['Familles'], touristic_object.population
|
130
|
-
end
|
131
|
-
|
132
|
-
should 'populate prestations fields' do
|
133
|
-
hash_result = {:prestations => {:tourismesAdaptes => [{:libelleFr => "Accessible en fauteuil roulant en autonomie"}]}}
|
134
|
-
touristic_object = TouristicObject.new(hash_result)
|
135
|
-
|
136
|
-
assert_true touristic_object.prestations(:tourismesAdaptes).values[0].include?('Accessible en fauteuil roulant en autonomie')
|
137
|
-
end
|
138
|
-
|
139
|
-
should 'retrieve merged general and specific information' do
|
140
|
-
hash_result = {
|
141
|
-
:type => 'ACTIVITE',
|
142
|
-
:informations => {
|
143
|
-
:moyensCommunication => [
|
144
|
-
{:type => {:libelleFr => "Téléphone"}, :coordonnees => {:fr => "0123456789"}}
|
145
|
-
]
|
146
|
-
},
|
147
|
-
:informationsActivite => {
|
148
|
-
:prestataireActivites => {
|
149
|
-
:nom => {:libelleFr => "my_service"}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
touristic_object = TouristicObject.new(hash_result)
|
155
|
-
|
156
|
-
assert_equal "0123456789", touristic_object.information[:moyensCommunication][0][:coordonnees][:fr]
|
157
|
-
assert_equal "my_service", touristic_object.information[:prestataireActivites][:nom][:libelleFr]
|
158
|
-
end
|
159
|
-
|
160
|
-
should 'default to fr locale' do
|
161
|
-
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description_fr", :libelleEn => "my_description_en"}}}
|
162
|
-
touristic_object = TouristicObject.new(hash_result)
|
163
|
-
|
164
|
-
assert_equal 'my_description_fr', touristic_object.description
|
165
|
-
end
|
166
|
-
|
167
|
-
should 'use provided locale when available' do
|
168
|
-
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description_fr", :libelleEn => "my_description_en"}}}
|
169
|
-
touristic_object = TouristicObject.new(hash_result)
|
170
|
-
touristic_object.set_locale('en')
|
171
|
-
|
172
|
-
assert_equal 'my_description_en', touristic_object.description
|
173
|
-
end
|
174
|
-
|
175
|
-
should 'return predicate covering openings every day of the week' do
|
176
|
-
opening_hash = {:type => 'OUVERTURE_TOUS_LES_JOURS'}
|
177
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
178
|
-
|
179
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 8))
|
180
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
181
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
182
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
183
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
184
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
185
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
186
|
-
end
|
187
|
-
|
188
|
-
should 'return predicate covering openings all days of the week except one' do
|
189
|
-
opening_hash = {:type => 'OUVERTURE_SAUF', :ouverturesJournalieres => [{:jour => 'DIMANCHE'}]}
|
190
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
191
|
-
|
192
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
193
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
194
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
195
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
196
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
197
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
198
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
199
|
-
end
|
200
|
-
|
201
|
-
should 'return predicate covering openings only on specified days' do
|
202
|
-
opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MERCREDI'}, {:jour => 'VENDREDI'}]}
|
203
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
204
|
-
|
205
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
206
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
207
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
208
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
209
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
210
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
211
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
212
|
-
end
|
213
|
-
|
214
|
-
should 'return predicate covering all week days (alternative)' do
|
215
|
-
opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'TOUS'}]}
|
216
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
217
|
-
|
218
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 8))
|
219
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
220
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
221
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
222
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
223
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
224
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
225
|
-
end
|
226
|
-
|
227
|
-
should 'return predicate covering opening on a specific day of the month' do
|
228
|
-
opening_hash = {:type => 'OUVERTURE_MOIS', :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_2EME'}]}
|
229
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
230
|
-
|
231
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 2))
|
232
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
233
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
234
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
235
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 11))
|
236
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
237
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 13))
|
238
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
239
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 16))
|
240
|
-
end
|
241
|
-
|
242
|
-
should 'return predicate covering openings on several days of the month' do
|
243
|
-
opening_hash = {:type => 'OUVERTURE_MOIS',
|
244
|
-
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_4EME'}, {:jour => 'MARDI', :jourDuMois => 'D_1ER'}]}
|
245
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
246
|
-
|
247
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 3))
|
248
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 9))
|
249
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
250
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 11))
|
251
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
252
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 13))
|
253
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
254
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 15))
|
255
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 23))
|
256
|
-
end
|
257
|
-
|
258
|
-
should 'return predicate covering openings on the first week of the month' do
|
259
|
-
opening_hash = {:type => 'OUVERTURE_MOIS',
|
260
|
-
:ouverturesJourDuMois => [{:jour => 'TOUS', :jourDuMois => 'D_1ER'}]}
|
261
|
-
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
262
|
-
|
263
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 1))
|
264
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 2))
|
265
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 3))
|
266
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 4))
|
267
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 5))
|
268
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 6))
|
269
|
-
assert_equal true, predicate.call(Date.new(2015, 2, 7))
|
270
|
-
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
271
|
-
end
|
272
|
-
|
273
|
-
should 'detect date ranges intersection' do
|
274
|
-
touristic_object = TouristicObject.new({})
|
275
|
-
|
276
|
-
assert_equal false, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 2, 15), Date.new(2015, 2, 25))
|
277
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 12, 31), Date.new(2015, 1, 15), Date.new(2015, 1, 25))
|
278
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 1, 15), Date.new(2015, 2, 5))
|
279
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 27))
|
280
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22))
|
281
|
-
assert_equal false, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), false)
|
282
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), true)
|
283
|
-
assert_equal true, touristic_object.ranges_intersect(Date.new(2012, 12, 25), Date.new(2013, 1, 15), Date.new(2015, 1, 8), Date.new(2015, 1, 14), true)
|
284
|
-
end
|
285
|
-
|
286
|
-
should 'return opening status for date with a single opening period' do
|
287
|
-
opening_hash = {:ouverture => {
|
288
|
-
:periodesOuvertures => [
|
289
|
-
{:dateDebut => '2014-1-1',
|
290
|
-
:dateFin => '2014-12-31',
|
291
|
-
:tousLesAns => true,
|
292
|
-
:type => 'OUVERTURE_MOIS',
|
293
|
-
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]}
|
294
|
-
]
|
295
|
-
}}
|
296
|
-
touristic_object = TouristicObject.new(opening_hash)
|
297
|
-
|
298
|
-
assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
|
299
|
-
assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
|
300
|
-
assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
|
301
|
-
assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
|
302
|
-
assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
|
303
|
-
assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
|
304
|
-
end
|
305
|
-
|
306
|
-
should 'return opening status for date with multiple opening period' do
|
307
|
-
opening_hash = {:ouverture => {
|
308
|
-
:periodesOuvertures => [{:dateDebut => '2014-1-1',
|
309
|
-
:dateFin => '2014-12-31',
|
310
|
-
:tousLesAns => true,
|
311
|
-
:type => 'OUVERTURE_MOIS',
|
312
|
-
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]},
|
313
|
-
{:dateDebut => '2015-1-1',
|
314
|
-
:dateFin => '2015-1-31',
|
315
|
-
:tousLesAns => false,
|
316
|
-
:type => 'OUVERTURE_SEMAINE',
|
317
|
-
:ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MARDI'}, {:jour => 'JEUDI'}]}]
|
318
|
-
}}
|
319
|
-
touristic_object = TouristicObject.new(opening_hash)
|
320
|
-
|
321
|
-
assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
|
322
|
-
assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
|
323
|
-
assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
|
324
|
-
assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
|
325
|
-
assert_equal true, touristic_object.open_on?('2015-1-5', '2016-1-5')
|
326
|
-
assert_equal true, touristic_object.open_on?('2015-1-12', '2015-1-12')
|
327
|
-
assert_equal true, touristic_object.open_on?('2015-1-6', '2015-1-16')
|
328
|
-
assert_equal true, touristic_object.open_on?('2015-1-8', '2015-1-8')
|
329
|
-
assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
|
330
|
-
assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
|
331
|
-
end
|
332
|
-
|
1
|
+
# encoding : UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'shoulda'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'sitra_client/touristic_object'
|
7
|
+
|
8
|
+
class TouristicObjectTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
should 'populate title of touristic object' do
|
11
|
+
hash_result = {:nom => {:libelleFr => "my_title"}}
|
12
|
+
touristic_object = TouristicObject.new(hash_result)
|
13
|
+
|
14
|
+
assert_equal 'my_title', touristic_object.title
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'populate description of touristic object' do
|
18
|
+
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description"}}}
|
19
|
+
touristic_object = TouristicObject.new(hash_result)
|
20
|
+
|
21
|
+
assert_equal 'my_description', touristic_object.description
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'populate detailed description of touristic object' do
|
25
|
+
hash_result = {:presentation => {:descriptifDetaille => {:libelleFr => "my_detailed_description"}}}
|
26
|
+
touristic_object = TouristicObject.new(hash_result)
|
27
|
+
|
28
|
+
assert_equal 'my_detailed_description', touristic_object.details
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'populate contact details for provided fields' do
|
32
|
+
hash_result = {
|
33
|
+
:informations => {
|
34
|
+
:moyensCommunication => [
|
35
|
+
{:type => {:libelleFr => "Téléphone", :id => 201}, :coordonnees => {:fr => "0123456789"}},
|
36
|
+
{:type => {:libelleFr => "Mél", :id => 204}, :coordonnees => {:fr => "my@email.fr"}},
|
37
|
+
{:type => {:libelleFr => "Fax", :id => 202}, :coordonnees => {:fr => "9876543201"}}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
touristic_object = TouristicObject.new(hash_result)
|
42
|
+
|
43
|
+
assert_equal({'Téléphone' => '0123456789', 'Mél' => 'my@email.fr'}, touristic_object.contact([201, 204]))
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'populate image details' do
|
47
|
+
hash_result = {
|
48
|
+
:illustrations => [
|
49
|
+
{:type => 'IMAGE', :traductionFichiers => [{:url => 'my/image/url', :urlListe => 'my/list/url', :urlFiche => 'my/details/url'}]}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
touristic_object = TouristicObject.new(hash_result)
|
53
|
+
|
54
|
+
assert_equal [{:url => 'my/image/url', :urlListe => 'my/list/url', :urlFiche => 'my/details/url'}], touristic_object.pictures
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'populate address details' do
|
58
|
+
hash_result = {
|
59
|
+
:informationsActivite => {
|
60
|
+
:prestataireActivites => {
|
61
|
+
:nom => {:libelleFr => "my_service"},
|
62
|
+
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
63
|
+
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
touristic_object = TouristicObject.new(hash_result)
|
68
|
+
|
69
|
+
assert_equal 'my_service', touristic_object.service_provider
|
70
|
+
assert_equal 'my_address, my_city', touristic_object.address
|
71
|
+
assert_equal 0.2, touristic_object.latitude
|
72
|
+
assert_equal 0.1, touristic_object.longitude
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'use event details when available' do
|
76
|
+
hash_result = {:informationsFeteEtManifestation => {:nomLieu => "my_place"}}
|
77
|
+
touristic_object = TouristicObject.new(hash_result)
|
78
|
+
|
79
|
+
assert_equal 'my_place', touristic_object.service_provider
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'fallback to localisation address when service details are missing' do
|
83
|
+
hash_result = {
|
84
|
+
:localisation => {
|
85
|
+
:adresse => {:adresse1 => "my_address", :codePostal => "1234", :commune => {:nom => "my_city"}},
|
86
|
+
:geolocalisation => {:valide => true, :geoJson => {:coordinates => [0.1, 0.2]}}
|
87
|
+
},
|
88
|
+
:informationsActivite => {}
|
89
|
+
}
|
90
|
+
touristic_object = TouristicObject.new(hash_result)
|
91
|
+
|
92
|
+
assert_nil touristic_object.service_provider
|
93
|
+
assert_equal 'my_address, my_city', touristic_object.address
|
94
|
+
assert_equal 0.2, touristic_object.latitude
|
95
|
+
assert_equal 0.1, touristic_object.longitude
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'populate opening hours when available' do
|
99
|
+
hash_result = {:ouverture => {:periodeEnClair => {:libelleFr => "my_opening_hours"}}}
|
100
|
+
touristic_object = TouristicObject.new(hash_result)
|
101
|
+
|
102
|
+
assert_equal 'my_opening_hours', touristic_object.horaires
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'populate tariffs data when available' do
|
106
|
+
hash_result = {
|
107
|
+
:descriptionTarif => {:gratuit => false,
|
108
|
+
:tarifsEnClair => {:libelleFr => "my_tariff_description"}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
touristic_object = TouristicObject.new(hash_result)
|
112
|
+
|
113
|
+
assert_equal 'my_tariff_description', touristic_object.tarif
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'tag free oject when relevant' do
|
117
|
+
hash_result = {:descriptionTarif => {:gratuit => true}}
|
118
|
+
touristic_object = TouristicObject.new(hash_result)
|
119
|
+
|
120
|
+
assert_equal 'gratuit', touristic_object.tarif
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'populate populations information' do
|
124
|
+
hash_result = {
|
125
|
+
:prestations => {:typesClientele => [{:libelleFr => "Familles"}]}
|
126
|
+
}
|
127
|
+
touristic_object = TouristicObject.new(hash_result)
|
128
|
+
|
129
|
+
assert_equal ['Familles'], touristic_object.population
|
130
|
+
end
|
131
|
+
|
132
|
+
should 'populate prestations fields' do
|
133
|
+
hash_result = {:prestations => {:tourismesAdaptes => [{:libelleFr => "Accessible en fauteuil roulant en autonomie"}]}}
|
134
|
+
touristic_object = TouristicObject.new(hash_result)
|
135
|
+
|
136
|
+
assert_true touristic_object.prestations(:tourismesAdaptes).values[0].include?('Accessible en fauteuil roulant en autonomie')
|
137
|
+
end
|
138
|
+
|
139
|
+
should 'retrieve merged general and specific information' do
|
140
|
+
hash_result = {
|
141
|
+
:type => 'ACTIVITE',
|
142
|
+
:informations => {
|
143
|
+
:moyensCommunication => [
|
144
|
+
{:type => {:libelleFr => "Téléphone"}, :coordonnees => {:fr => "0123456789"}}
|
145
|
+
]
|
146
|
+
},
|
147
|
+
:informationsActivite => {
|
148
|
+
:prestataireActivites => {
|
149
|
+
:nom => {:libelleFr => "my_service"}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
touristic_object = TouristicObject.new(hash_result)
|
155
|
+
|
156
|
+
assert_equal "0123456789", touristic_object.information[:moyensCommunication][0][:coordonnees][:fr]
|
157
|
+
assert_equal "my_service", touristic_object.information[:prestataireActivites][:nom][:libelleFr]
|
158
|
+
end
|
159
|
+
|
160
|
+
should 'default to fr locale' do
|
161
|
+
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description_fr", :libelleEn => "my_description_en"}}}
|
162
|
+
touristic_object = TouristicObject.new(hash_result)
|
163
|
+
|
164
|
+
assert_equal 'my_description_fr', touristic_object.description
|
165
|
+
end
|
166
|
+
|
167
|
+
should 'use provided locale when available' do
|
168
|
+
hash_result = {:presentation => {:descriptifCourt => {:libelleFr => "my_description_fr", :libelleEn => "my_description_en"}}}
|
169
|
+
touristic_object = TouristicObject.new(hash_result)
|
170
|
+
touristic_object.set_locale('en')
|
171
|
+
|
172
|
+
assert_equal 'my_description_en', touristic_object.description
|
173
|
+
end
|
174
|
+
|
175
|
+
should 'return predicate covering openings every day of the week' do
|
176
|
+
opening_hash = {:type => 'OUVERTURE_TOUS_LES_JOURS'}
|
177
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
178
|
+
|
179
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 8))
|
180
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
181
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
182
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
183
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
184
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
185
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
186
|
+
end
|
187
|
+
|
188
|
+
should 'return predicate covering openings all days of the week except one' do
|
189
|
+
opening_hash = {:type => 'OUVERTURE_SAUF', :ouverturesJournalieres => [{:jour => 'DIMANCHE'}]}
|
190
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
191
|
+
|
192
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
193
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
194
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
195
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
196
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
197
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
198
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
199
|
+
end
|
200
|
+
|
201
|
+
should 'return predicate covering openings only on specified days' do
|
202
|
+
opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MERCREDI'}, {:jour => 'VENDREDI'}]}
|
203
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
204
|
+
|
205
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
206
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
207
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
208
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
209
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
210
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
211
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
212
|
+
end
|
213
|
+
|
214
|
+
should 'return predicate covering all week days (alternative)' do
|
215
|
+
opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'TOUS'}]}
|
216
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
217
|
+
|
218
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 8))
|
219
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
220
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 10))
|
221
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 11))
|
222
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 12))
|
223
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 13))
|
224
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 14))
|
225
|
+
end
|
226
|
+
|
227
|
+
should 'return predicate covering opening on a specific day of the month' do
|
228
|
+
opening_hash = {:type => 'OUVERTURE_MOIS', :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_2EME'}]}
|
229
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
230
|
+
|
231
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 2))
|
232
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
233
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 9))
|
234
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
235
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 11))
|
236
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
237
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 13))
|
238
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
239
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 16))
|
240
|
+
end
|
241
|
+
|
242
|
+
should 'return predicate covering openings on several days of the month' do
|
243
|
+
opening_hash = {:type => 'OUVERTURE_MOIS',
|
244
|
+
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_4EME'}, {:jour => 'MARDI', :jourDuMois => 'D_1ER'}]}
|
245
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
246
|
+
|
247
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 3))
|
248
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 9))
|
249
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 10))
|
250
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 11))
|
251
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 12))
|
252
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 13))
|
253
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 14))
|
254
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 15))
|
255
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 23))
|
256
|
+
end
|
257
|
+
|
258
|
+
should 'return predicate covering openings on the first week of the month' do
|
259
|
+
opening_hash = {:type => 'OUVERTURE_MOIS',
|
260
|
+
:ouverturesJourDuMois => [{:jour => 'TOUS', :jourDuMois => 'D_1ER'}]}
|
261
|
+
predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
|
262
|
+
|
263
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 1))
|
264
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 2))
|
265
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 3))
|
266
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 4))
|
267
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 5))
|
268
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 6))
|
269
|
+
assert_equal true, predicate.call(Date.new(2015, 2, 7))
|
270
|
+
assert_equal false, predicate.call(Date.new(2015, 2, 8))
|
271
|
+
end
|
272
|
+
|
273
|
+
should 'detect date ranges intersection' do
|
274
|
+
touristic_object = TouristicObject.new({})
|
275
|
+
|
276
|
+
assert_equal false, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 2, 15), Date.new(2015, 2, 25))
|
277
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 12, 31), Date.new(2015, 1, 15), Date.new(2015, 1, 25))
|
278
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 1, 15), Date.new(2015, 2, 5))
|
279
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 27))
|
280
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22))
|
281
|
+
assert_equal false, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), false)
|
282
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), true)
|
283
|
+
assert_equal true, touristic_object.ranges_intersect(Date.new(2012, 12, 25), Date.new(2013, 1, 15), Date.new(2015, 1, 8), Date.new(2015, 1, 14), true)
|
284
|
+
end
|
285
|
+
|
286
|
+
should 'return opening status for date with a single opening period' do
|
287
|
+
opening_hash = {:ouverture => {
|
288
|
+
:periodesOuvertures => [
|
289
|
+
{:dateDebut => '2014-1-1',
|
290
|
+
:dateFin => '2014-12-31',
|
291
|
+
:tousLesAns => true,
|
292
|
+
:type => 'OUVERTURE_MOIS',
|
293
|
+
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]}
|
294
|
+
]
|
295
|
+
}}
|
296
|
+
touristic_object = TouristicObject.new(opening_hash)
|
297
|
+
|
298
|
+
assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
|
299
|
+
assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
|
300
|
+
assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
|
301
|
+
assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
|
302
|
+
assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
|
303
|
+
assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
|
304
|
+
end
|
305
|
+
|
306
|
+
should 'return opening status for date with multiple opening period' do
|
307
|
+
opening_hash = {:ouverture => {
|
308
|
+
:periodesOuvertures => [{:dateDebut => '2014-1-1',
|
309
|
+
:dateFin => '2014-12-31',
|
310
|
+
:tousLesAns => true,
|
311
|
+
:type => 'OUVERTURE_MOIS',
|
312
|
+
:ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]},
|
313
|
+
{:dateDebut => '2015-1-1',
|
314
|
+
:dateFin => '2015-1-31',
|
315
|
+
:tousLesAns => false,
|
316
|
+
:type => 'OUVERTURE_SEMAINE',
|
317
|
+
:ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MARDI'}, {:jour => 'JEUDI'}]}]
|
318
|
+
}}
|
319
|
+
touristic_object = TouristicObject.new(opening_hash)
|
320
|
+
|
321
|
+
assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
|
322
|
+
assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
|
323
|
+
assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
|
324
|
+
assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
|
325
|
+
assert_equal true, touristic_object.open_on?('2015-1-5', '2016-1-5')
|
326
|
+
assert_equal true, touristic_object.open_on?('2015-1-12', '2015-1-12')
|
327
|
+
assert_equal true, touristic_object.open_on?('2015-1-6', '2015-1-16')
|
328
|
+
assert_equal true, touristic_object.open_on?('2015-1-8', '2015-1-8')
|
329
|
+
assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
|
330
|
+
assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
|
331
|
+
end
|
332
|
+
|
333
|
+
should 'load overridden aspect values' do
|
334
|
+
hash = {
|
335
|
+
nom: {libelleFr: 'my_title'},
|
336
|
+
presentation: {
|
337
|
+
descriptifCourt: {libelleFr: 'my_description'},
|
338
|
+
descriptifDetaille: {libelleFr: 'my_detailed_description'}
|
339
|
+
},
|
340
|
+
ouverture: {
|
341
|
+
periodeEnClair: {libelleFr: 'my_opening_hours'},
|
342
|
+
periodesOuvertures: [
|
343
|
+
{dateDebut: '2014-1-1', dateFin: '2014-12-31', tousLesAns: true, type: 'OUVERTURE_MOIS'},
|
344
|
+
{dateDebut: '2015-1-1', dateFin: '2015-1-31', tousLesAns: false, type: 'OUVERTURE_SEMAINE'}
|
345
|
+
]
|
346
|
+
},
|
347
|
+
aspects: [
|
348
|
+
{
|
349
|
+
aspect: 'HIVER',
|
350
|
+
champsAspect: ['presentation.descriptifCourt', 'presentation.descriptifDetaille', 'ouverture.periodesOuvertures'],
|
351
|
+
presentation: {
|
352
|
+
descriptifCourt: {libelleFr: 'my_description hiver'}
|
353
|
+
},
|
354
|
+
ouverture: {
|
355
|
+
periodesOuvertures: [
|
356
|
+
{dateDebut: '2014-2-1', dateFin: '2014-4-30', tousLesAns: true, type: 'OUVERTURE_MOIS'}
|
357
|
+
]
|
358
|
+
},
|
359
|
+
}
|
360
|
+
]
|
361
|
+
}
|
362
|
+
|
363
|
+
std_object = TouristicObject.new(hash)
|
364
|
+
winter_object = TouristicObject.new(hash.deep_dup, TouristicObject::ASPECT_WINTER)
|
365
|
+
|
366
|
+
assert_equal 'my_title', std_object.title
|
367
|
+
assert_equal 'my_description', std_object.description
|
368
|
+
assert_equal 'my_detailed_description', std_object.details
|
369
|
+
assert_equal 'my_opening_hours', std_object.horaires
|
370
|
+
assert_equal [{dateDebut: '2014-1-1', dateFin: '2014-12-31', tousLesAns: true, type: 'OUVERTURE_MOIS'},
|
371
|
+
{dateDebut: '2015-1-1', dateFin: '2015-1-31', tousLesAns: false, type: 'OUVERTURE_SEMAINE'}],
|
372
|
+
std_object.attributes['ouverture'][:periodesOuvertures]
|
373
|
+
|
374
|
+
assert_equal 'my_title', winter_object.title
|
375
|
+
assert_equal 'my_description hiver', winter_object.description
|
376
|
+
assert_nil winter_object.details
|
377
|
+
assert_equal 'my_opening_hours', winter_object.horaires
|
378
|
+
assert_equal [{dateDebut: '2014-2-1', dateFin: '2014-4-30', tousLesAns: true, type: 'OUVERTURE_MOIS'}],
|
379
|
+
winter_object.attributes['ouverture'][:periodesOuvertures]
|
380
|
+
end
|
381
|
+
end
|