docbrown/app/models/broadcast.rb
Ben Halpern 0941b2e4fb
Add some tests around model validations (#459)
* Modify sample_application.yml and write test

* Add ahrefs verification

* Add some tests around model validations

* Indent an end

* Add a few tests

* Add tests and reserved words

* Fix live articles spec typo

* Modify ga_events_controller
2018-06-20 17:14:08 -04:00

32 lines
1,014 B
Ruby

class Broadcast < ApplicationRecord
has_many :notifications, as: :notifiable
validates :title, :type_of, :processed_html, presence: true
validates :type_of, inclusion: { in: %w(Announcement Onboarding) }
def self.send_welcome_notification(user_id)
welcome_broadcast = Broadcast.find_by(title: "Welcome Notification")
return if welcome_broadcast == nil
Notification.create(
user_id: user_id,
notifiable_id: welcome_broadcast.id,
notifiable_type: "Broadcast",
action: welcome_broadcast.type_of,
)
end
# method not in use; will be in use if we choose to use markdown
def evaluate_markdown
return if body_markdown.blank?
begin
parsed_markdown = MarkdownParser.new(body_markdown)
self.processed_html = get_inner_body(parsed_markdown.finalize)
rescue StandardError => e
errors[:base] << ErrorMessageCleaner.new(e.message).clean
end
end
def get_inner_body(content)
Nokogiri::HTML(content).at("body").inner_html
end
end