Browse Source

Les tests liés au geocoding sont vraiment stubbés

recurrent
echarp 8 years ago
parent
commit
1144ae5d82
  1. 2
      app/models/event.rb
  2. 6
      config/initializers/geocoder.rb
  3. 16
      test/models/event_test.rb
  4. 12
      test/test_helper.rb

2
app/models/event.rb

@ -20,7 +20,7 @@ class Event < ActiveRecord::Base
validates :submitter, email: true
validates :tags, presence: false, format: /\A[\p{Alnum}\s-]*\z/
geocoded_by :full_address, lookup: :nominatim
geocoded_by :full_address
# after_validation :geocode, if: -> (obj) { obj.address_changed? }
after_validation :geocode

6
config/initializers/geocoder.rb

@ -0,0 +1,6 @@
Geocoder.configure(
# geocoding options
# timeout: 3, # geocoding service timeout (secs)
lookup: :nominatim, # name of geocoding service (symbol)
language: :fr # ISO-639 language code
)

16
test/models/event_test.rb

@ -4,18 +4,6 @@ require 'test_helper'
class EventTest < ActiveSupport::TestCase
setup do
@event = events :one
Geocoder.configure lookup: :test
Geocoder::Lookup::Test.set_default_stub [{
'latitude' => 40.7143528,
'longitude' => -74.0059731,
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
}]
end
test 'basic event' do
@ -109,8 +97,8 @@ class EventTest < ActiveSupport::TestCase
assert @event.valid?, @event.errors.messages
assert @event.save
assert_nil @event.latitude
assert_nil @event.longitude
assert_equal 40.7143528, @event.latitude
assert_equal(-74.0059731, @event.longitude)
end
test 'json transform' do

12
test/test_helper.rb

@ -20,5 +20,17 @@ module ActiveSupport
fixtures :all
# Add more helper methods to be used by all tests here...
Geocoder.configure lookup: :test
Geocoder::Lookup::Test.set_default_stub [{
'latitude' => 40.7143528,
'longitude' => -74.0059731,
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
}]
end
end

Loading…
Cancel
Save