Skip to content

Commit

Permalink
Use Date and Time classes in specs
Browse files Browse the repository at this point in the history
Instead of the flawed DateTime class. Rubcop complained and was right so.
  • Loading branch information
tvdeyen committed Feb 26, 2018
1 parent 9c29308 commit fe171c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
name 'My Event'
hidden_name 'not shown'
location
starts_at DateTime.new(2012, 03, 02, 8, 15)
ends_at DateTime.new(2012, 03, 02, 19, 30)
lunch_starts_at DateTime.new(2012, 03, 02, 12, 15)
lunch_ends_at DateTime.new(2012, 03, 02, 13, 45)
starts_at Time.local(2012, 03, 02, 8, 15)
ends_at Time.local(2012, 03, 02, 19, 30)
lunch_starts_at Time.local(2012, 03, 02, 12, 15)
lunch_ends_at Time.local(2012, 03, 02, 13, 45)
description "something\nfancy"
published false
entrance_fee 12.3
Expand Down
12 changes: 6 additions & 6 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def reload_event_class
before do
visit '/admin/events/new'
fill_in 'event_name', with: 'My second event'
fill_in 'event_starts_at', with: DateTime.new(2012, 03, 03, 20, 00)
fill_in 'event_starts_at', with: Time.local(2012, 03, 03, 20, 00)
select location.name, from: 'Location'
click_on 'Save'
end
Expand Down Expand Up @@ -180,16 +180,16 @@ def self.alchemy_resource_filters
%w(starting_today future)
end

scope :starting_today, -> { where(starts_at: DateTime.current.at_midnight..DateTime.tomorrow.at_midnight) }
scope :future, -> { where("starts_at > ?", DateTime.tomorrow.at_midnight) }
scope :starting_today, -> { where(starts_at: Time.current.at_midnight..Date.tomorrow.at_midnight) }
scope :future, -> { where("starts_at > ?", Date.tomorrow.at_midnight) }
end
example.run
reload_event_class
end

let!(:past_event) { create(:event, name: "Horse Expo", starts_at: DateTime.current - 100.years) }
let!(:today_event) { create(:event, name: "Car Expo", starts_at: DateTime.current.at_noon) }
let!(:future_event) { create(:event, name: "Hovercar Expo", starts_at: DateTime.current + 30.years) }
let!(:past_event) { create(:event, name: "Horse Expo", starts_at: Time.current - 100.years) }
let!(:today_event) { create(:event, name: "Car Expo", starts_at: Time.current.at_noon) }
let!(:future_event) { create(:event, name: "Hovercar Expo", starts_at: Time.current + 30.years) }

it "lets the user filter by the defined scopes", aggregate_failures: true do
visit "/admin/events"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/alchemy/essence_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Alchemy

it_behaves_like "an essence" do
let(:essence) { EssenceDate.new }
let(:ingredient_value) { DateTime.current.iso8601 }
let(:ingredient_value) { Time.current.iso8601 }
end

describe '#preview_text' do
Expand All @@ -18,7 +18,7 @@ module Alchemy

context "if date set" do
it "should format the date by i18n" do
essence.date = DateTime.current
essence.date = Time.current
expect(::I18n).to receive(:l).with(essence.date, format: :date)
essence.preview_text
end
Expand Down

0 comments on commit fe171c5

Please sign in to comment.