docbrown/app/models/block.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

41 lines
853 B
Ruby

class Block < ApplicationRecord
attr_accessor :publish_now
belongs_to :user
validate :permissions
before_save :process_html
before_save :process_javascript
before_save :process_css
def publish!
self.published_html = processed_html
self.published_javascript = processed_javascript
self.published_css = processed_css
self.featured = true
self.save
end
private
def process_html
self.processed_html = input_html
end
def process_javascript
self.processed_javascript = input_javascript
end
def process_css
scoped_scss = ".block-wrapper-#{id} { #{input_css}}"
se = Sass::Engine.new(scoped_scss, :syntax => :scss)
self.processed_css = se.render
end
def permissions
if !user || !user.has_role?(:super_admin)
errors.add(:commentable_id, "is not valid.")
end
end
end