Commit 2335d7b9cf577fb03ed4efc660b8e3e706c1c01b

Authored by Scott Holden
1 parent 5add5f76

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.
Showing 1 changed file with 6 additions and 6 deletions   Show diff stats
app/models/note.rb
@@ -23,13 +23,13 @@ class Note < ActiveRecord::Base @@ -23,13 +23,13 @@ class Note < ActiveRecord::Base
23 mount_uploader :attachment, AttachmentUploader 23 mount_uploader :attachment, AttachmentUploader
24 24
25 # Scopes 25 # Scopes
26 - scope :common, where(noteable_id: nil)  
27 - scope :today, where("created_at >= :date", date: Date.today)  
28 - scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) 26 + scope :common, ->{ where(noteable_id: nil) }
  27 + scope :today, ->{ where("created_at >= :date", date: Date.today) }
  28 + scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) }
29 scope :since, ->(day) { where("created_at >= :date", date: (day)) } 29 scope :since, ->(day) { where("created_at >= :date", date: (day)) }
30 - scope :fresh, order("created_at ASC, id ASC")  
31 - scope :inc_author_project, includes(:project, :author)  
32 - scope :inc_author, includes(:author) 30 + scope :fresh, ->{ order("created_at ASC, id ASC") }
  31 + scope :inc_author_project, ->{ includes(:project, :author) }
  32 + scope :inc_author, ->{ includes(:author) }
33 33
34 def self.create_status_change_note(noteable, author, status) 34 def self.create_status_change_note(noteable, author, status)
35 create({ 35 create({