Skip to content

Commit

Permalink
Switching Time.now with Time.current
Browse files Browse the repository at this point in the history
  • Loading branch information
yogodoshi committed Apr 18, 2015
1 parent e12eee3 commit 393c212
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/models/starburst/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class Announcement < ActiveRecord::Base
attr_accessible :title, :body, :start_delivering_at, :stop_delivering_at, :limit_to_users
end

scope :ready_for_delivery, lambda {
where("(start_delivering_at < ? OR start_delivering_at IS NULL)
AND (stop_delivering_at > ? OR stop_delivering_at IS NULL)", Time.now, Time.now)
scope :ready_for_delivery, lambda {
where("(start_delivering_at < ? OR start_delivering_at IS NULL)
AND (stop_delivering_at > ? OR stop_delivering_at IS NULL)", Time.current, Time.current)
}

scope :unread_by, lambda {|current_user|
joins("LEFT JOIN starburst_announcement_views ON
starburst_announcement_views.announcement_id = starburst_announcements.id AND
joins("LEFT JOIN starburst_announcement_views ON
starburst_announcement_views.announcement_id = starburst_announcements.id AND
starburst_announcement_views.user_id = #{Announcement.sanitize(current_user.id)}")
.where("starburst_announcement_views.announcement_id IS NULL AND starburst_announcement_views.user_id IS NULL")
}
Expand Down
16 changes: 8 additions & 8 deletions spec/models/starburst/announcement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ module Starburst
end

it "shows before its end date" do
Announcement.create(:body => "test", :stop_delivering_at => Time.now + 1.day)
Announcement.create(:body => "test", :stop_delivering_at => Time.current + 1.day)
expect(Announcement.current.present?).to eq true
end

it "does not show up before its start date" do
Announcement.create(:body => "test", :start_delivering_at => Time.now + 1.day)
Announcement.create(:body => "test", :start_delivering_at => Time.current + 1.day)
expect(Announcement.current.blank?).to eq true
end

Expand All @@ -43,12 +43,12 @@ module Starburst
end

it "shows up between its start and end dates" do
Announcement.create(:body => "test", :start_delivering_at => Time.now, :stop_delivering_at => Time.now + 1.day)
Announcement.create(:body => "test", :start_delivering_at => Time.current, :stop_delivering_at => Time.current + 1.day)
expect(Announcement.current.present?).to eq true
end

it "does not show when its start and end dates are the same" do
Announcement.create(:body => "test", :start_delivering_at => Time.now, :stop_delivering_at => Time.now)
Announcement.create(:body => "test", :start_delivering_at => Time.current, :stop_delivering_at => Time.current)
expect(Announcement.current.blank?).to eq true
end

Expand All @@ -58,15 +58,15 @@ module Starburst

it "shows up" do
read_announcement = Announcement.create(:body => "test", :start_delivering_at => 1.day.ago)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.now)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.current)
user_who_read_announcement = FactoryGirl.create(:user)
AnnouncementView.create(:announcement => read_announcement, :user => user_who_read_announcement)
expect(Announcement.unread_by(user_who_read_announcement)).to eq [unread_announcement]
end

it "shows up for the current user even when others have read it" do
read_announcement = Announcement.create(:body => "test", :start_delivering_at => 1.day.ago)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.now)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.current)
user_who_read_announcement = FactoryGirl.create(:user)
user_who_read_no_announcements = FactoryGirl.create(:user)
AnnouncementView.create(:announcement => read_announcement, :user => user_who_read_announcement)
Expand All @@ -75,7 +75,7 @@ module Starburst

it "shows up for the current user even when they have read other announcements" do
read_announcement = Announcement.create(:body => "test", :start_delivering_at => 1.day.ago)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.now)
unread_announcement = Announcement.create(:body => "test", :start_delivering_at => Time.current)
user_who_read_announcement = FactoryGirl.create(:user)
AnnouncementView.create(:announcement => read_announcement, :user => user_who_read_announcement)
expect(Starburst::Announcement.current(user_who_read_announcement)).to eq unread_announcement
Expand Down Expand Up @@ -126,7 +126,7 @@ module Starburst
# it "performs" do
# pending
# require 'benchmark'

# (1 .. 500).each do
# Announcement.create(:limit_to_users => [
# {
Expand Down

0 comments on commit 393c212

Please sign in to comment.