Skip to content

Commit

Permalink
Merge pull request #831 from neo4jrb/time_as_time
Browse files Browse the repository at this point in the history
fixes handling of Time type, undoes silent change to DateTime
  • Loading branch information
subvertallchris committed Jun 12, 2015
2 parents a35cfef + 4104b8e commit 4ace40a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- QueryProxy associations accept `labels: false` option to prevent generated Cypher from using labels.

### Changed
- Properties explicitly set to type `Time` will no longer be converted to `DateTime`.

## [5.0.0.rc.3] - 2015-06-07

### Fixed
Expand Down
4 changes: 0 additions & 4 deletions lib/neo4j/shared/declared_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def default_value
# Tweaks properties
def register_magic_properties
options[:type] ||= DateTime if name.to_sym == :created_at || name.to_sym == :updated_at
# TODO: Custom typecaster to fix the stuff below
# ActiveAttr does not handle "Time", Rails and Neo4j.rb 2.3 did
# Convert it to DateTime in the interest of consistency
options[:type] = DateTime if options[:type] == Time

register_magic_typecaster
register_type_converter
Expand Down
4 changes: 4 additions & 0 deletions lib/neo4j/shared/type_converters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def convert_type
Time
end

def primitive_type
Integer
end
# Converts the given DateTime (UTC) value to an Integer.
# Only utc times are supported !
def to_db(value)
Expand All @@ -70,6 +73,7 @@ def to_db(value)
def to_ruby(value)
Time.at(value).utc
end
alias_method :call, :to_ruby
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/e2e/active_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ def mark_saved
expect(person.name).to eq('new name')
end

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

it 'declared attribute can have type conversion' do
Expand Down
7 changes: 4 additions & 3 deletions spec/unit/shared/property_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@
clazz.property :updated_at, type: Time
end

it 'changes type to DateTime' do
expect(clazz.attributes[:created_at][:type]).to eq(DateTime)
expect(clazz.attributes[:updated_at][:type]).to eq(DateTime)
# ActiveAttr does not know what to do with Time, so it is stored as Int.
it 'tells ActiveAttr it is an Integer' do
expect(clazz.attributes[:created_at][:type]).to eq(Integer)
expect(clazz.attributes[:updated_at][:type]).to eq(Integer)
end
end
end
Expand Down

0 comments on commit 4ace40a

Please sign in to comment.