From 1144ae5d825965dce288d03692bb045168db3db2 Mon Sep 17 00:00:00 2001 From: echarp Date: Thu, 16 Oct 2014 23:31:02 +0200 Subject: [PATCH] =?UTF-8?q?Les=20tests=20li=C3=A9s=20au=20geocoding=20sont?= =?UTF-8?q?=20vraiment=20stubb=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/event.rb | 2 +- config/initializers/geocoder.rb | 6 ++++++ test/models/event_test.rb | 16 ++-------------- test/test_helper.rb | 12 ++++++++++++ 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 config/initializers/geocoder.rb diff --git a/app/models/event.rb b/app/models/event.rb index 64839e8b..073a997a 100644 --- a/app/models/event.rb +++ b/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 diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb new file mode 100644 index 00000000..db0d3e08 --- /dev/null +++ b/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 +) diff --git a/test/models/event_test.rb b/test/models/event_test.rb index c3664a21..fb3cd52e 100644 --- a/test/models/event_test.rb +++ b/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 diff --git a/test/test_helper.rb b/test/test_helper.rb index c47e4c42..b1d4ead6 100644 --- a/test/test_helper.rb +++ b/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