* Refactored Pages::BustCacheJob to Pages::BustCacheWorker * Removed Pages::BustCacheJob and specs Co-authored-by: Edward Tam <edward6882990@gmail.com>
63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Page, type: :model do
|
|
describe "#validations" do
|
|
it "requires either body_markdown or body_html" do
|
|
page = build(:page)
|
|
page.body_html = nil
|
|
page.body_markdown = nil
|
|
expect(page).not_to be_valid
|
|
end
|
|
|
|
it "takes organization slug into account" do
|
|
create(:organization, slug: "benandfriends")
|
|
page = build(:page, slug: "benandfriends")
|
|
expect(page).not_to be_valid
|
|
expect(page.errors[:slug].to_s.include?("taken")).to be true
|
|
end
|
|
|
|
it "takes podcast slug into account" do
|
|
create(:podcast, slug: "benmeetsworld")
|
|
page = build(:page, slug: "benmeetsworld")
|
|
expect(page).not_to be_valid
|
|
expect(page.errors[:slug].to_s.include?("taken")).to be true
|
|
end
|
|
|
|
it "takes user username into account" do
|
|
create(:user, username: "bennybenben")
|
|
page = build(:page, slug: "bennybenben")
|
|
expect(page).not_to be_valid
|
|
expect(page.errors[:slug].to_s.include?("taken")).to be true
|
|
end
|
|
end
|
|
|
|
context "when callbacks are triggered before save" do
|
|
let(:page) { create(:page) }
|
|
|
|
describe "#processed_html" do
|
|
it "accepts body markdown and turns it into html" do
|
|
page.update(body_markdown: "Hello `heyhey`")
|
|
expect(page.processed_html).to include("<code>")
|
|
end
|
|
|
|
it "accepts body html without changing it" do
|
|
html = "Hello `heyhey`"
|
|
page.update(body_html: html, body_markdown: "")
|
|
expect(page.processed_html).to eq(html)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when callbacks are triggered after save" do
|
|
let(:page) { build(:page) }
|
|
|
|
before do
|
|
allow(Pages::BustCacheWorker).to receive(:perform_async)
|
|
end
|
|
|
|
it "triggers cache busting on save" do
|
|
page.save
|
|
expect(Pages::BustCacheWorker).to have_received(:perform_async).with(page.slug)
|
|
end
|
|
end
|
|
end
|