timezone 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ module Timezone
29
29
  # @return [String]
30
30
  # the Google API key ('abc123')
31
31
  def self.google_api_key
32
- @google_api_key
32
+ @google_api_key ||= nil
33
33
  end
34
34
 
35
35
  # Google API key
@@ -165,7 +165,7 @@ module Timezone
165
165
  # @return [String]
166
166
  # the Geonames API username ('foo-bar')
167
167
  def self.username
168
- @@username
168
+ @@username ||= nil
169
169
  end
170
170
 
171
171
  # The Geonames API username
@@ -13,5 +13,6 @@ module Timezone
13
13
  class GeoNames < Base; end
14
14
  class Google < Base; end
15
15
  class ParseTime < Base; end
16
+ class InvalidConfig < Base ; end
16
17
  end
17
18
  end
@@ -1,9 +1,19 @@
1
+ require 'timezone/error'
2
+
1
3
  module Timezone
2
4
  module Lookup
3
5
  class Basic
4
6
  attr_reader :config
5
7
 
6
8
  def initialize(config)
9
+ if config.protocol.nil?
10
+ raise(::Timezone::Error::InvalidConfig, 'missing protocol')
11
+ end
12
+
13
+ if config.url.nil?
14
+ raise(::Timezone::Error::InvalidConfig, 'missing url')
15
+ end
16
+
7
17
  @config = config
8
18
  end
9
19
 
@@ -6,6 +6,14 @@ require 'uri'
6
6
  module Timezone
7
7
  module Lookup
8
8
  class Geonames < ::Timezone::Lookup::Basic
9
+ def initialize(config)
10
+ if config.username.nil?
11
+ raise(::Timezone::Error::InvalidConfig, 'missing username')
12
+ end
13
+
14
+ super
15
+ end
16
+
9
17
  def lookup(lat, lng)
10
18
  response = client.get(url(lat, lng))
11
19
 
@@ -6,6 +6,13 @@ require 'uri'
6
6
  module Timezone
7
7
  module Lookup
8
8
  class Google < ::Timezone::Lookup::Basic
9
+ def initialize(config)
10
+ if config.google_api_key.nil?
11
+ raise(::Timezone::Error::InvalidConfig, 'missing api key')
12
+ end
13
+ super
14
+ end
15
+
9
16
  def lookup(lat,lng)
10
17
  response = client.get(url(lat,lng))
11
18
 
@@ -1,3 +1,3 @@
1
1
  module Timezone
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'timezone/lookup/basic'
2
+ require 'minitest/autorun'
3
+
4
+ class BasicLookupTest < ::Minitest::Unit::TestCase
5
+ def config
6
+ @config ||= Struct.new(:protocol, :url).new('http', 'example.com')
7
+ end
8
+
9
+ def lookup
10
+ ::Timezone::Lookup::Basic.new(config)
11
+ end
12
+
13
+ def test_missing_protocol
14
+ config.protocol = nil
15
+ assert_raises(::Timezone::Error::InvalidConfig){ lookup }
16
+ end
17
+
18
+ def test_missing_url
19
+ config.url = nil
20
+ assert_raises(::Timezone::Error::InvalidConfig){ lookup }
21
+ end
22
+
23
+ def test_initialization
24
+ assert_equal lookup.config, config
25
+ end
26
+ end
@@ -1,9 +1,9 @@
1
1
  require 'timezone/configure'
2
2
  require 'timezone/lookup/geonames'
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require_relative 'http_test_client'
5
5
 
6
- class GeonamesLookupTest < ::Test::Unit::TestCase
6
+ class GeonamesLookupTest < ::Minitest::Unit::TestCase
7
7
  def setup
8
8
  Timezone::Configure.begin do |c|
9
9
  c.google_api_key = nil
@@ -20,6 +20,13 @@ class GeonamesLookupTest < ::Test::Unit::TestCase
20
20
  ::Timezone::Lookup::Geonames.new(Timezone::Configure)
21
21
  end
22
22
 
23
+ def test_missing_username
24
+ Timezone::Configure.begin{ |c| c.username = nil }
25
+ assert_raises(::Timezone::Error::InvalidConfig){ lookup }
26
+ ensure
27
+ Timezone::Configure.begin{ |c| c.username = 'timezone' }
28
+ end
29
+
23
30
  def test_lookup
24
31
  HTTPTestClient.body = File.open(mock_path + '/lat_lon_coords.txt').read
25
32
 
@@ -29,7 +36,7 @@ class GeonamesLookupTest < ::Test::Unit::TestCase
29
36
  def test_api_limit
30
37
  HTTPTestClient.body = File.open(mock_path + '/api_limit_reached.txt').read
31
38
 
32
- assert_raise Timezone::Error::GeoNames, 'api limit reached' do
39
+ assert_raises Timezone::Error::GeoNames, 'api limit reached' do
33
40
  lookup.lookup(*coordinates)
34
41
  end
35
42
  end
@@ -1,12 +1,11 @@
1
1
  require 'timezone/configure'
2
2
  require 'timezone/lookup/google'
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require_relative 'http_test_client'
5
5
 
6
- class GoogleLookupTest < ::Test::Unit::TestCase
6
+ class GoogleLookupTest < ::Minitest::Unit::TestCase
7
7
  def setup
8
8
  Timezone::Configure.begin do |c|
9
- c.google_api_key = nil
10
9
  c.http_client = HTTPTestClient
11
10
  c.google_api_key = '123abc'
12
11
  end
@@ -20,6 +19,13 @@ class GoogleLookupTest < ::Test::Unit::TestCase
20
19
  ::Timezone::Lookup::Google.new(Timezone::Configure)
21
20
  end
22
21
 
22
+ def test_missing_api_key
23
+ Timezone::Configure.begin{ |c| c.google_api_key = nil }
24
+ assert_raises(::Timezone::Error::InvalidConfig){ lookup }
25
+ ensure
26
+ Timezone::Configure.begin{ |c| c.google_api_key = '123abc' }
27
+ end
28
+
23
29
  def test_google_using_lat_lon_coordinates
24
30
  HTTPTestClient.body = File.open(mock_path + '/google_lat_lon_coords.txt').read
25
31
 
@@ -27,7 +33,8 @@ class GoogleLookupTest < ::Test::Unit::TestCase
27
33
  end
28
34
 
29
35
  def test_google_request_denied_read_lat_lon_coordinates
30
- assert_raise Timezone::Error::Google, 'The provided API key is invalid.' do
36
+ HTTPTestClient.body = nil
37
+ assert_raises Timezone::Error::Google, 'The provided API key is invalid.' do
31
38
  lookup.lookup(*coordinates)
32
39
  end
33
40
  end
@@ -1,24 +1,22 @@
1
1
  require 'timezone'
2
2
  require 'timezone/zone'
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require "mocha/setup"
5
5
  require 'timecop'
6
6
 
7
- class TimezoneTest < Test::Unit::TestCase
7
+ class TimezoneTest < ::Minitest::Unit::TestCase
8
8
  def test_valid_timezone
9
- assert_nothing_raised do
10
- Timezone::Zone.new :zone => 'Australia/Sydney'
11
- end
9
+ refute_nil(Timezone::Zone.new(:zone => 'Australia/Sydney'))
12
10
  end
13
11
 
14
12
  def test_nil_timezone
15
- assert_raise Timezone::Error::NilZone do
13
+ assert_raises Timezone::Error::NilZone do
16
14
  Timezone::Zone.new :zone => nil
17
15
  end
18
16
  end
19
17
 
20
18
  def test_invalid_timezone
21
- assert_raise Timezone::Error::InvalidZone do
19
+ assert_raises Timezone::Error::InvalidZone do
22
20
  Timezone::Zone.new :zone => 'Foo/Bar'
23
21
  end
24
22
  end
@@ -28,7 +26,7 @@ class TimezoneTest < Test::Unit::TestCase
28
26
  assert list.is_a?(Array)
29
27
  assert list.count == 2
30
28
  assert list.first.is_a?(Hash)
31
- assert list.first[:zone] == "Australia/Sydney"
29
+ assert(list.any?{ |l| l[:zone] == 'Australia/Sydney' })
32
30
  end
33
31
 
34
32
  def test_timezone_list_current_time
@@ -53,7 +51,7 @@ class TimezoneTest < Test::Unit::TestCase
53
51
  Timezone::Configure.default_for_list = "America/Chicago", "Australia/Sydney"
54
52
  list = Timezone::Zone.list
55
53
  assert list.count == 2
56
- assert list.first.has_value? "Australia/Sydney"
54
+ assert(list.any?{ |l| l.has_value?("Australia/Sydney") })
57
55
  end
58
56
 
59
57
  def test_timezone_names
@@ -198,6 +196,7 @@ class TimezoneTest < Test::Unit::TestCase
198
196
  end
199
197
 
200
198
  def test_configure_url_default
199
+ Timezone::Configure.begin{ |c| c.google_api_key = nil }
201
200
  assert_equal 'api.geonames.org', Timezone::Configure.url
202
201
  end
203
202
 
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timezone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pan Thomakos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: timecop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: A simple way to get accurate current and historical timezone information
@@ -80,8 +80,8 @@ extra_rdoc_files:
80
80
  - README.markdown
81
81
  - License.txt
82
82
  files:
83
- - .gitignore
84
- - .travis.yml
83
+ - ".gitignore"
84
+ - ".travis.yml"
85
85
  - CHANGES.markdown
86
86
  - CONTRIBUTING.markdown
87
87
  - Gemfile
@@ -685,6 +685,7 @@ files:
685
685
  - lib/timezone/parser.rb
686
686
  - lib/timezone/version.rb
687
687
  - lib/timezone/zone.rb
688
+ - test/basic_lookup_test.rb
688
689
  - test/data/Helsinki_rules_without_timestamps.json
689
690
  - test/data/asia
690
691
  - test/geonames_lookup_test.rb
@@ -702,26 +703,27 @@ licenses:
702
703
  metadata: {}
703
704
  post_install_message:
704
705
  rdoc_options:
705
- - --charset=UTF-8
706
+ - "--charset=UTF-8"
706
707
  require_paths:
707
708
  - lib
708
709
  required_ruby_version: !ruby/object:Gem::Requirement
709
710
  requirements:
710
- - - '>='
711
+ - - ">="
711
712
  - !ruby/object:Gem::Version
712
713
  version: '0'
713
714
  required_rubygems_version: !ruby/object:Gem::Requirement
714
715
  requirements:
715
- - - '>='
716
+ - - ">="
716
717
  - !ruby/object:Gem::Version
717
718
  version: '0'
718
719
  requirements: []
719
720
  rubyforge_project: timezone
720
- rubygems_version: 2.0.14
721
+ rubygems_version: 2.2.3
721
722
  signing_key:
722
723
  specification_version: 4
723
- summary: timezone-0.3.9
724
+ summary: timezone-0.3.10
724
725
  test_files:
726
+ - test/basic_lookup_test.rb
725
727
  - test/data/Helsinki_rules_without_timestamps.json
726
728
  - test/data/asia
727
729
  - test/geonames_lookup_test.rb