Skip to content

Commit 4ace40a

Browse files
Merge pull request #831 from neo4jrb/time_as_time
fixes handling of Time type, undoes silent change to DateTime
2 parents a35cfef + 4104b8e commit 4ace40a

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
### Added
1313
- QueryProxy associations accept `labels: false` option to prevent generated Cypher from using labels.
1414

15+
### Changed
16+
- Properties explicitly set to type `Time` will no longer be converted to `DateTime`.
17+
1518
## [5.0.0.rc.3] - 2015-06-07
1619

1720
### Fixed

lib/neo4j/shared/declared_property.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def default_value
3434
# Tweaks properties
3535
def register_magic_properties
3636
options[:type] ||= DateTime if name.to_sym == :created_at || name.to_sym == :updated_at
37-
# TODO: Custom typecaster to fix the stuff below
38-
# ActiveAttr does not handle "Time", Rails and Neo4j.rb 2.3 did
39-
# Convert it to DateTime in the interest of consistency
40-
options[:type] = DateTime if options[:type] == Time
4137

4238
register_magic_typecaster
4339
register_type_converter

lib/neo4j/shared/type_converters.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def convert_type
5757
Time
5858
end
5959

60+
def primitive_type
61+
Integer
62+
end
6063
# Converts the given DateTime (UTC) value to an Integer.
6164
# Only utc times are supported !
6265
def to_db(value)
@@ -70,6 +73,7 @@ def to_db(value)
7073
def to_ruby(value)
7174
Time.at(value).utc
7275
end
76+
alias_method :call, :to_ruby
7377
end
7478
end
7579

spec/e2e/active_model_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ def mark_saved
335335
expect(person.name).to eq('new name')
336336
end
337337

338-
it 'accepts Time type, converts to DateTime' do
338+
it 'accepts Time type, does not convert to DateTime' do
339339
person = Person.create(start: Time.now)
340-
person.start.class.should eq(DateTime)
340+
expect(person.start).to be_a(Time)
341341
end
342342

343343
it 'declared attribute can have type conversion' do

spec/unit/shared/property_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@
5555
clazz.property :updated_at, type: Time
5656
end
5757

58-
it 'changes type to DateTime' do
59-
expect(clazz.attributes[:created_at][:type]).to eq(DateTime)
60-
expect(clazz.attributes[:updated_at][:type]).to eq(DateTime)
58+
# ActiveAttr does not know what to do with Time, so it is stored as Int.
59+
it 'tells ActiveAttr it is an Integer' do
60+
expect(clazz.attributes[:created_at][:type]).to eq(Integer)
61+
expect(clazz.attributes[:updated_at][:type]).to eq(Integer)
6162
end
6263
end
6364
end

0 commit comments

Comments
 (0)