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

style(Rails/Date): manual #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 0 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -687,18 +687,6 @@ RSpec/VerifiedDoubles:
- 'spec/mongoid/validatable/associated_spec.rb'
- 'spec/rails/mongoid_spec.rb'

# Offense count: 11
# Configuration parameters: EnforcedStyle, AllowToTime.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'spec/mongoid/association/embedded/embeds_many/proxy_spec.rb'
- 'spec/mongoid/attributes_spec.rb'
- 'spec/mongoid/extensions/time_spec.rb'
- 'spec/mongoid/extensions/time_with_zone_spec.rb'
- 'spec/mongoid/persistable/maxable_spec.rb'
- 'spec/mongoid/persistable/minable_spec.rb'

# Offense count: 20
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforceForPrefixed.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ assignment to a ``Time`` field:
field :registered_at, type: Time
end

Voter.new(registered_at: Date.today)
Voter.new(registered_at: Date.current)
# => #<Voter _id: 5fdd80392c97a618f07ba344, registered_at: 2020-12-18 05:00:00 UTC>

In the above example, the value was interpreted as the beginning of today in
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ values, respectively, are straightforward:

.. code-block:: ruby

Voter.where(born_on: Date.today).selector
Voter.where(born_on: Date.current).selector
# => {"born_on"=>2020-12-18 00:00:00 UTC}

Voter.where(registered_at: Time.now).selector
Expand All @@ -1825,16 +1825,16 @@ in all possible scenarios:

.. code-block:: ruby

Voter.where(born_on: Date.today).selector
Voter.where(born_on: Date.current).selector
# => {"born_on"=>2020-12-18 00:00:00 UTC}

Voter.where(registered_at: Date.today).selector
Voter.where(registered_at: Date.current).selector
# => {"registered_at"=>2020-12-18 00:00:00 -0500}

Voter.where(voted_at: Date.today).selector
Voter.where(voted_at: Date.current).selector
# => {"voted_at"=>Fri, 18 Dec 2020}

Voter.where(deregistered_at: Date.today).selector
Voter.where(deregistered_at: Date.current).selector
# => {"deregistered_at"=>2020-12-18 00:00:00 UTC}

When using the ``registered_at`` field which is of type ``Time``, the date
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/association/embedded/embeds_many/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,7 @@ class TrackingIdValidationHistory

before do
owner.pet = Pet.new(name: 'Fido')
owner.pet.vet_visits << VetVisit.new(date: Date.today)
owner.pet.vet_visits << VetVisit.new(date: Date.current)
owner.save!
owner.pet.vet_visits.destroy_all
end
Expand All @@ -2146,7 +2146,7 @@ class TrackingIdValidationHistory
end

it 'allows addition and a resave' do
owner.pet.vet_visits << VetVisit.new(date: Date.today)
owner.pet.vet_visits << VetVisit.new(date: Date.current)
owner.save!
expect(owner.pet.vet_visits.first).to be_persisted
end
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@
end

let(:vet_visit) do
VetVisit.new(date: Date.today)
VetVisit.new(date: Date.current)
end

before do
Expand All @@ -1884,7 +1884,7 @@
end

let!(:vet_visit) do
pet.vet_visits.create!(date: Date.today)
pet.vet_visits.create!(date: Date.current)
end

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/extensions/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
context 'when demongoizing a Date' do

it 'returns an ActiveSupport::TimeWithZone' do
expect(Time.demongoize(Date.today).class).to eq(ActiveSupport::TimeWithZone)
expect(Time.demongoize(Date.current).class).to eq(ActiveSupport::TimeWithZone)
end
end

Expand Down Expand Up @@ -603,7 +603,7 @@
context 'when given a Date' do

let(:date) do
Date.today
Date.current
end

it 'converts to a utc time' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/extensions/time_with_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
context 'when given a Date' do

let(:date) do
Date.today
Date.current
end

it 'converts to a utc time' do
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/persistable/maxable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
context 'when given > initial' do
let(:given_name) { 'Z' }
let(:given_members) { 10 }
let(:given_founded) { Date.today }
let(:given_founded) { Date.current }

it_behaves_like 'a max-able root document'
end
Expand All @@ -67,7 +67,7 @@
context 'when the document is an embedded document' do
let(:initial_city) { 'Manhattan' }
let(:initial_number) { 100 }
let(:initial_end_date) { Date.today }
let(:initial_end_date) { Date.current }

let(:person) { Person.create! }
let(:address) do
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/persistable/minable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
context 'when given > initial' do
let(:given_name) { 'Z' }
let(:given_members) { 10 }
let(:given_founded) { Date.today }
let(:given_founded) { Date.current }

it_behaves_like 'a min-able root document'
end
Expand All @@ -67,7 +67,7 @@
context 'when the document is an embedded document' do
let(:initial_city) { 'Manhattan' }
let(:initial_number) { 100 }
let(:initial_end_date) { Date.today }
let(:initial_end_date) { Date.current }

let(:person) { Person.create! }
let(:address) do
Expand Down