summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 23ced536b67..55b011f8b29 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -2,10 +2,13 @@ require 'carrierwave/orm/activerecord'
require 'file_size_validator'
class Note < ActiveRecord::Base
- mount_uploader :attachment, AttachmentUploader
+
attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id,
:attachment, :line_code
+ attr_accessor :notify
+ attr_accessor :notify_author
+
belongs_to :project
belongs_to :noteable, polymorphic: true
belongs_to :author, class_name: "User"
@@ -13,18 +16,17 @@ class Note < ActiveRecord::Base
delegate :name, to: :project, prefix: true
delegate :name, :email, to: :author, prefix: true
- attr_accessor :notify
- attr_accessor :notify_author
-
- validates_presence_of :project
-
+ validates :project, presence: true
validates :note, presence: true, length: { within: 0..5000 }
validates :attachment, file_size: { maximum: 10.megabytes.to_i }
+ mount_uploader :attachment, AttachmentUploader
+
+ # Scopes
scope :common, where(noteable_id: nil)
scope :today, where("created_at >= :date", date: Date.today)
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
- scope :since, lambda { |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 :inc_author_project, includes(:project, :author)
scope :inc_author, includes(:author)