Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #67] TimeZone: Always autocorrect DateTime => Time #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#67](https://github.com/rubocop-hq/rubocop-rails/issues/67): [Fix #67] TimeZone: Always autocorrect `DateTime` => `Time` ([@vfonic][])

## 2.0.0 (2019-05-22)

### New features
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/rails/time_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def autocorrect(node)
corrector.replace(node.loc.selector, 'now')
end
# prefer `Time` over `DateTime` class
if strict?
corrector.replace(node.children.first.source_range, 'Time')
end
corrector.replace(node.children.first.source_range, 'Time')
remove_redundant_in_time_zone(corrector, node)
end
end
Expand Down
10 changes: 1 addition & 9 deletions spec/rubocop/cop/rails/time_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
end

context 'autocorrect' do
let(:cop_config) do
{ 'AutoCorrect' => 'true', 'EnforcedStyle' => 'strict' }
end

it 'autocorrects correctly' do
source = "#{klass}.now.in_time_zone"
new_source = autocorrect_source(source)
Expand Down Expand Up @@ -275,18 +271,14 @@
end

context 'autocorrect' do
let(:cop_config) do
{ 'AutoCorrect' => 'true', 'EnforcedStyle' => 'flexible' }
end

it 'corrects the error' do
source = <<~RUBY
#{klass}.#{a_method}
RUBY
new_source = autocorrect_source(source)
unless a_method == :current
expect(new_source).to eq(<<~RUBY)
#{klass}.zone.#{a_method}
Time.zone.#{a_method}
RUBY
end
end
Expand Down