Commit 2335d7b9 authored by Scott Holden's avatar Scott Holden

Fix broken Note scopes with lambdas, 4.0 compat

Without lambdas, Date.today will be evaluated in the class body.
For it to have a running scope of last week etc, it will need to
be evaluated each time the scope is called.
In Rails 4.0, lambdas will be required for all scopes, so not a bad
idea to go ahead and change them all now.
parent 5add5f76
...@@ -23,13 +23,13 @@ class Note < ActiveRecord::Base ...@@ -23,13 +23,13 @@ class Note < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader mount_uploader :attachment, AttachmentUploader
# Scopes # Scopes
scope :common, where(noteable_id: nil) scope :common, ->{ where(noteable_id: nil) }
scope :today, where("created_at >= :date", date: Date.today) scope :today, ->{ where("created_at >= :date", date: Date.today) }
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) }
scope :since, ->(day) { where("created_at >= :date", date: (day)) } scope :since, ->(day) { where("created_at >= :date", date: (day)) }
scope :fresh, order("created_at ASC, id ASC") scope :fresh, ->{ order("created_at ASC, id ASC") }
scope :inc_author_project, includes(:project, :author) scope :inc_author_project, ->{ includes(:project, :author) }
scope :inc_author, includes(:author) scope :inc_author, ->{ includes(:author) }
def self.create_status_change_note(noteable, author, status) def self.create_status_change_note(noteable, author, status)
create({ create({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment