chore: allow article to create without content (#14007)
This commit is contained in:
@@ -62,7 +62,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B
|
|||||||
|
|
||||||
def set_article
|
def set_article
|
||||||
@article = @portal.articles.find_by(slug: permitted_params[:article_slug])
|
@article = @portal.articles.find_by(slug: permitted_params[:article_slug])
|
||||||
@parsed_content = render_article_content(@article.content)
|
@parsed_content = render_article_content(@article.content.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_category
|
def set_category
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export default {
|
|||||||
|
|
||||||
created() {
|
created() {
|
||||||
state = createState(
|
state = createState(
|
||||||
this.modelValue,
|
this.modelValue || '',
|
||||||
this.placeholder,
|
this.placeholder,
|
||||||
this.plugins,
|
this.plugins,
|
||||||
{ onImageUpload: this.openFileBrowser },
|
{ onImageUpload: this.openFileBrowser },
|
||||||
@@ -170,7 +170,7 @@ export default {
|
|||||||
},
|
},
|
||||||
reloadState() {
|
reloadState() {
|
||||||
state = createState(
|
state = createState(
|
||||||
this.modelValue,
|
this.modelValue || '',
|
||||||
this.placeholder,
|
this.placeholder,
|
||||||
this.plugins,
|
this.plugins,
|
||||||
{ onImageUpload: this.openFileBrowser },
|
{ onImageUpload: this.openFileBrowser },
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const createNewArticle = async ({ title, content }) => {
|
|||||||
if (title) article.value.title = title;
|
if (title) article.value.title = title;
|
||||||
if (content) article.value.content = content;
|
if (content) article.value.content = content;
|
||||||
|
|
||||||
if (!article.value.title || !article.value.content) return;
|
if (!article.value.title) return;
|
||||||
|
|
||||||
isUpdating.value = true;
|
isUpdating.value = true;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Article < ApplicationRecord
|
|||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
validates :author_id, presence: true
|
validates :author_id, presence: true
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :content, presence: true
|
validates :content, presence: true, if: :published?
|
||||||
|
|
||||||
# ensuring that the position is always set correctly
|
# ensuring that the position is always set correctly
|
||||||
before_create :add_position_to_article
|
before_create :add_position_to_article
|
||||||
|
|||||||
@@ -10,7 +10,16 @@ RSpec.describe Article do
|
|||||||
it { is_expected.to validate_presence_of(:account_id) }
|
it { is_expected.to validate_presence_of(:account_id) }
|
||||||
it { is_expected.to validate_presence_of(:author_id) }
|
it { is_expected.to validate_presence_of(:author_id) }
|
||||||
it { is_expected.to validate_presence_of(:title) }
|
it { is_expected.to validate_presence_of(:title) }
|
||||||
it { is_expected.to validate_presence_of(:content) }
|
|
||||||
|
it 'validates content presence only for published articles' do
|
||||||
|
article = build(:article, portal_id: portal_1.id, author_id: user.id, category_id: category_1.id,
|
||||||
|
title: 'test', content: nil, status: :draft)
|
||||||
|
expect(article).to be_valid
|
||||||
|
|
||||||
|
article.status = :published
|
||||||
|
expect(article).not_to be_valid
|
||||||
|
expect(article.errors[:content]).to include("can't be blank")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'associations' do
|
describe 'associations' do
|
||||||
|
|||||||
Reference in New Issue
Block a user