Why: Newsletter attribute `segment_recipient` is an integer to be used as enum. There's no advantage to store a number instead of an string if the ammount of elements in the table is not going to be huge, or we can take advantage of using an enum. Also maintaining both Newsletters enum paired with UserSegments::SEGMENTS would be a maintenance burden. How: * Migration to change segment_recipient column from integer to string * Removing enumeration from Newsletter model class * Using UserSegments::SEGMENTS instead of Newsletter.segment_recipients or integer values
18 lines
359 B
Ruby
18 lines
359 B
Ruby
class Newsletter < ActiveRecord::Base
|
|
|
|
validates :subject, presence: true
|
|
validates :segment_recipient, presence: true
|
|
validates :from, presence: true
|
|
validates :body, presence: true
|
|
|
|
validates_format_of :from, :with => /@/
|
|
|
|
def list_of_recipients
|
|
UserSegments.send(segment_recipient).newsletter
|
|
end
|
|
|
|
def draft?
|
|
sent_at.nil?
|
|
end
|
|
end
|