greenwich 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,84 +1,178 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Greenwich::Utilities do
4
- describe "#truncate" do
5
- before { @expected_time = Time.utc(2011, 5, 13, 17, 31, 13, 0) }
4
+ describe '.get_time_zone_field' do
5
+ subject { Greenwich::Utilities.get_time_zone_field(name, columns) }
6
6
 
7
- context "when passed a String" do
8
- it "returns the correct time if no offset is given" do
9
- truncated = Greenwich::Utilities.truncate("2011-05-13 17:31:13")
10
- truncated.should eql @expected_time
7
+ let(:name) { 'foo_at' }
8
+
9
+ context 'when columns includes a field-specific time zone field' do
10
+ let(:columns) { %w(foo bar foo_at_time_zone) }
11
+
12
+ it 'is the field-specific time zone field' do
13
+ subject.should eql 'foo_at_time_zone'
11
14
  end
15
+ end
16
+
17
+ context 'when columns does not include a field-specific time zone field' do
18
+ context 'but does include the general time zone field' do
19
+ let(:columns) { %w(foo bar time_zone) }
12
20
 
13
- it "returns the correct time if an offset is given" do
14
- truncated = Greenwich::Utilities.truncate("2011-05-13 17:31:13 -0600")
15
- truncated.should eql @expected_time
21
+ it 'is the general time zone field' do
22
+ subject.should eql 'time_zone'
23
+ end
24
+ end
25
+
26
+ context 'and does not include the general time zone field' do
27
+ let(:columns) { %w(foo bar) }
28
+
29
+ it 'is nil' do
30
+ subject.should be_nil
31
+ end
16
32
  end
17
33
  end
34
+ end
18
35
 
19
- context "when passed a TimeWithZone" do
20
- before { @time = Time.utc(2011, 5, 13, 17, 31, 13) }
36
+ describe '.get_time_zone' do
37
+ subject { Greenwich::Utilities.get_time_zone model, 'time_zone' }
21
38
 
22
- it "returns the correct time if TimeWithZone is UTC" do
23
- utc_time_zone = ActiveSupport::TimeZone.new('UTC')
24
- time_with_zone = ActiveSupport::TimeWithZone.new(@time, utc_time_zone)
39
+ context 'when the object does not have a time zone' do
40
+ context 'because it does not exist' do
41
+ let(:model) { stub :time_zone => nil }
25
42
 
26
- truncated = Greenwich::Utilities.truncate(time_with_zone)
27
- truncated.should eql @expected_time
43
+ it 'is nil' do
44
+ subject.should be_nil
45
+ end
28
46
  end
29
47
 
30
- it "returns the correct time if TimeWithZone is not UTC" do
31
- alaskan_time_zone = ActiveSupport::TimeZone.new('Alaska')
32
- time_with_zone = ActiveSupport::TimeWithZone.new(nil, alaskan_time_zone, @time)
48
+ context 'because it cannot be found' do
49
+ let(:model) { Object.new.stub(:time_zone).and_raise NoMethodError }
33
50
 
34
- truncated = Greenwich::Utilities.truncate(time_with_zone)
35
- truncated.should eql @expected_time
51
+ it 'is nil' do
52
+ subject.should be_nil
53
+ end
54
+ end
55
+
56
+ context 'because it is not valid' do
57
+ let(:model) { stub :time_zone => "Look at me! I'm an invalid time zone!" }
58
+
59
+ it 'is nil' do
60
+ subject.should be_nil
61
+ end
36
62
  end
37
63
  end
38
64
 
39
- context "when passed a DateTime" do
40
- it "returns the correct time if DateTime is UTC" do
41
- datetime = DateTime.civil(2011, 5, 13, 17, 31, 13, 0)
65
+ context 'when the object does have a time zone' do
66
+ context 'because it is a time zone' do
67
+ let(:model) { stub :time_zone => ActiveSupport::TimeZone.new('Alaska') }
42
68
 
43
- truncated = Greenwich::Utilities.truncate(datetime)
44
- truncated.should eql @expected_time
69
+ it 'is the proper time zone object' do
70
+ subject.should eql ActiveSupport::TimeZone.new('Alaska')
71
+ end
45
72
  end
46
73
 
47
- it "returns the correct time if DateTime is not UTC" do
48
- datetime = DateTime.civil(2011, 5, 13, 17, 31, 13, -0.25)
74
+ context 'because it is a valid time zone string' do
75
+ let(:model) { stub :time_zone => 'Alaska' }
49
76
 
50
- truncated = Greenwich::Utilities.truncate(datetime)
51
- truncated.should eql @expected_time
77
+ it 'is the proper time zone object' do
78
+ subject.should eql ActiveSupport::TimeZone.new('Alaska')
79
+ end
52
80
  end
53
81
  end
54
82
  end
55
83
 
56
- describe "#get_time_zone" do
57
- context "when passed a valid time zone" do
58
- it "returns that time zone" do
59
- time_zone = Greenwich::Utilities.get_time_zone(nil, 'foo')
60
- time_zone.should eql 'foo'
84
+ describe '.coerce_to_time_zone' do
85
+ subject { Greenwich::Utilities.coerce_to_time_zone(value) }
86
+
87
+ context 'when the value is nil' do
88
+ let(:value) { nil }
89
+
90
+ it 'is nil' do
91
+ subject.should be_nil
61
92
  end
62
93
  end
63
94
 
64
- context "when not passed a time zone" do
65
- before { @time = Time.utc(2011, 5, 13, 17, 31, 13) }
95
+ context 'when the value is blank' do
96
+ let(:value) { '' }
97
+
98
+ it 'is nil' do
99
+ subject.should be_nil
100
+ end
101
+ end
66
102
 
67
- context "and passed a TimeWithZone for the time" do
68
- it "returns the time zone associated with the time" do
69
- alaskan_time_zone = ActiveSupport::TimeZone.new('Alaska')
70
- time_with_zone = ActiveSupport::TimeWithZone.new(nil, alaskan_time_zone, @time)
103
+ context 'when the value is not the name of a valid time zone' do
104
+ let(:value) { 'foo' }
71
105
 
72
- time_zone = Greenwich::Utilities.get_time_zone(time_with_zone, nil)
73
- time_zone.should eql alaskan_time_zone
74
- end
106
+ it 'is nil' do
107
+ subject.should be_nil
108
+ end
109
+ end
75
110
 
76
- it "returns the time zone associated with the time" do
77
- utc_time_zone = ActiveSupport::TimeZone.new('UTC')
111
+ context 'when the value is the name of a valid time zone' do
112
+ let(:value) { 'Alaska' }
78
113
 
79
- time_zone = Greenwich::Utilities.get_time_zone(@time, nil)
80
- time_zone.should eql utc_time_zone
81
- end
114
+ it 'is the corresponding TimeZone' do
115
+ subject.should eql ActiveSupport::TimeZone.new('Alaska')
116
+ end
117
+ end
118
+
119
+ context 'when the value is a time zone' do
120
+ let(:value) { ActiveSupport::TimeZone.new('Alaska') }
121
+
122
+ it 'is the time zone' do
123
+ subject.should eql value
124
+ end
125
+ end
126
+ end
127
+
128
+ describe '.coerce_to_time_without_zone' do
129
+ subject { Greenwich::Utilities.coerce_to_time_without_zone value }
130
+
131
+ context 'when nil is passed in' do
132
+ let(:value) { nil }
133
+
134
+ it 'is nil' do
135
+ subject.should be_nil
136
+ end
137
+ end
138
+
139
+ context 'when something which cannot be converted to a time is passed in' do
140
+ let(:value) { 5 }
141
+
142
+ it 'is nil' do
143
+ subject.should be_nil
144
+ end
145
+ end
146
+
147
+ context 'when something which cannot be properly converted to a time is passed in' do
148
+ let(:value) { 'foo' }
149
+
150
+ it 'is nil' do
151
+ subject.should be_nil
152
+ end
153
+ end
154
+
155
+ context 'when a string that does not contain a UTC offset is passed in' do
156
+ let(:value) { '2012-01-02 12:59:01' }
157
+
158
+ it 'is the UTC representation of that time' do
159
+ subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
160
+ end
161
+ end
162
+
163
+ context 'when a string that does contain a UTC offset is passed in' do
164
+ let(:value) { '2012-01-02 12:59:01 -0800' }
165
+
166
+ it 'is the UTC representation of that time ignoring any time zone offset information' do
167
+ subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
168
+ end
169
+ end
170
+
171
+ context 'when a UTC time is passed in' do
172
+ let(:value) { Time.utc(2012, 1, 2, 12, 59, 1) }
173
+
174
+ it 'is the UTC representation of that time ignoring any time zone offset information' do
175
+ subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
82
176
  end
83
177
  end
84
178
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,3 @@
1
1
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
2
2
 
3
3
  require 'greenwich'
4
-
5
- RSpec.configure do |config|
6
- config.before do
7
- load File.join(File.dirname(__FILE__), "model.rb")
8
- end
9
- end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ # Configure RSpec to run focused specs, and also respect the alias 'fit' for focused specs
3
+ config.treat_symbols_as_metadata_keys_with_true_values = true
4
+ config.filter_run :focused => true
5
+ config.alias_example_to :fit, :focused => true
6
+ config.run_all_when_everything_filtered = true
7
+ end
@@ -0,0 +1,4 @@
1
+ RSpec.configure do |config|
2
+ # Configure RSpec to respect the alias 'pit' for pending specs
3
+ config.alias_example_to :pit, :pending => true
4
+ end
metadata CHANGED
@@ -1,74 +1,155 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: greenwich
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.0.5
6
6
  platform: ruby
7
- authors:
8
- - thekompanee
7
+ authors:
9
8
  - jfelchner
9
+ - m5rk
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-09-30 00:00:00 -05:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2012-08-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
19
24
  prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: activesupport
33
+ requirement: !ruby/object:Gem::Requirement
21
34
  none: false
22
- requirements:
35
+ requirements:
23
36
  - - ~>
24
- - !ruby/object:Gem::Version
25
- version: "3.0"
37
+ - !ruby/object:Gem::Version
38
+ version: '3.0'
26
39
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: bundler
30
40
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: tzinfo
49
+ requirement: !ruby/object:Gem::Requirement
32
50
  none: false
33
- requirements:
51
+ requirements:
34
52
  - - ~>
35
- - !ruby/object:Gem::Version
36
- version: "1.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '0.3'
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '1.0'
37
71
  type: :development
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: rspec
41
72
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ requirement: !ruby/object:Gem::Requirement
43
82
  none: false
44
- requirements:
83
+ requirements:
45
84
  - - ~>
46
- - !ruby/object:Gem::Version
47
- version: "2.6"
85
+ - !ruby/object:Gem::Version
86
+ version: '2.6'
48
87
  type: :development
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '2.6'
95
+ - !ruby/object:Gem::Dependency
51
96
  name: yard
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '0.7'
103
+ type: :development
52
104
  prerelease: false
53
- requirement: &id004 !ruby/object:Gem::Requirement
105
+ version_requirements: !ruby/object:Gem::Requirement
54
106
  none: false
55
- requirements:
107
+ requirements:
56
108
  - - ~>
57
- - !ruby/object:Gem::Version
58
- version: "0.7"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '1.3'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: '1.3'
127
+ - !ruby/object:Gem::Dependency
128
+ name: pry
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
59
135
  type: :development
60
- version_requirements: *id004
61
- description: Store all of your times in the database as UTC but want to give your users the ability to choose a custom time zone for each instance of a DateTime field?
62
- email:
63
- - support@thekompanee.com
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ description: Store all of your times in the database as UTC but want to give your
144
+ users the ability to choose a custom time zone for each instance of a DateTime field?
145
+ email:
146
+ - jeff+greenwich@chirrpy.com
64
147
  executables: []
65
-
66
148
  extensions: []
67
-
68
- extra_rdoc_files:
149
+ extra_rdoc_files:
69
150
  - README.md
70
151
  - LICENSE
71
- files:
152
+ files:
72
153
  - .gitignore
73
154
  - .rspec
74
155
  - .rvmrc
@@ -78,40 +159,50 @@ files:
78
159
  - Rakefile
79
160
  - greenwich.gemspec
80
161
  - lib/greenwich.rb
81
- - lib/greenwich/rails.rb
82
- - lib/greenwich/time_with_zone.rb
162
+ - lib/greenwich/conversion.rb
163
+ - lib/greenwich/time_zone.rb
83
164
  - lib/greenwich/utilities.rb
84
165
  - lib/greenwich/version.rb
166
+ - spec/greenwich/conversion_spec.rb
85
167
  - spec/greenwich/utilities_spec.rb
86
168
  - spec/spec_helper.rb
87
- has_rdoc: true
88
- homepage: http://github.com/jfelchner/greenwich
169
+ - spec/support/focused.rb
170
+ - spec/support/pending.rb
171
+ homepage: http://github.com/chirrpy/greenwich
89
172
  licenses: []
90
-
91
173
  post_install_message:
92
- rdoc_options:
174
+ rdoc_options:
93
175
  - --charset = UTF-8
94
- require_paths:
176
+ require_paths:
95
177
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
178
+ required_ruby_version: !ruby/object:Gem::Requirement
97
179
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ segments:
185
+ - 0
186
+ hash: -1444067313011442519
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
188
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: "0"
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ segments:
194
+ - 0
195
+ hash: -1444067313011442519
108
196
  requirements: []
109
-
110
197
  rubyforge_project: greenwich
111
- rubygems_version: 1.6.2
198
+ rubygems_version: 1.8.24
112
199
  signing_key:
113
200
  specification_version: 3
114
201
  summary: Allowing users to select dates with custom time zones since 2011.
115
- test_files:
202
+ test_files:
203
+ - spec/greenwich/conversion_spec.rb
116
204
  - spec/greenwich/utilities_spec.rb
117
205
  - spec/spec_helper.rb
206
+ - spec/support/focused.rb
207
+ - spec/support/pending.rb
208
+ has_rdoc: