simple refactoring

This commit is contained in:
Andrey Kumanyaev 2012-10-09 04:10:04 +04:00
parent a635b9da97
commit df7c52489a
21 changed files with 276 additions and 264 deletions

View file

@ -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)