ruby - ActiveSupport::TimeZone not recognized in Rspec tests -


i using activesupport::timezone set time zone on location based on zip code.

def set_time_zone   self.time_zone = activesupport::timezone.find_by_zipcode(self.zip) end 

this works fine in application itself. calling set_time_zone on before_save.

in running tests rspec, when tries run set_time_zone method errors out "undefined method 'find_by_zipcode'in activesupport::timezone"

i have included "require 'active_support/time_with_zone'" in spec helper well.

for work around excluding before save if in test environment.

any ideas great.

find_by_zipcode not part of main activesupport::timezone object. docs object here, , won't find mention of zip codes.

a google search found method part of tzip gem. since said works in application, guess have gem there. need add test project. (sorry, not familiar ruby or rspec well, can't guide there).

being quite familiar time zones, thought take opportunity address few concerns general idea of mapping zip codes time zones. i'm not sure great idea.

  • it u.s. focused. time zones worldwide, , zip codes work in usa.
  • zip codes change frequently. usps publishes databases can subscribe changes data. appear tzip commit history , issue tracker have been manually adding zip code mappings problems reported. not way handle data changing.
  • a zip code not best boundary identify location. there many zip codes cover disparate, non-contiguous areas. there administrative zip codes don't map particular location (like overseas military mail).
  • for databases assign latitude , longitude particular zip code, coordinates artificially chosen, approximation of centroid of area serviced zip code. again, not discrete location.
  • according the tzip source code, there 7 time zones covered these mappings. have forgotten territories have zip codes, such guam. others, puerto rico have been erroneously mapped eastern time zone instead of atlantic time zone.

so recommendation avoid approach entirely. instead, use 1 of methods described in community wiki.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -