Add validation to classified_listings user and organization (#2625)
This commit is contained in:
parent
9210f6793b
commit
d2d405ad37
2 changed files with 22 additions and 0 deletions
|
|
@ -10,6 +10,9 @@ class ClassifiedListing < ApplicationRecord
|
|||
before_validation :modify_inputs
|
||||
acts_as_taggable_on :tags
|
||||
|
||||
validates :user_id, presence: true, unless: :organization_id?
|
||||
validates :organization_id, presence: true, unless: :user_id?
|
||||
|
||||
validates :title, presence: true,
|
||||
length: { maximum: 128 }
|
||||
validates :body_markdown, presence: true,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,25 @@ RSpec.describe ClassifiedListing, type: :model do
|
|||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:body_markdown) }
|
||||
|
||||
describe "valid associations" do
|
||||
it "is not valid w/o user and org" do
|
||||
cl = build(:classified_listing, user_id: nil, organization_id: nil)
|
||||
expect(cl).not_to be_valid
|
||||
expect(cl.errors[:user_id]).to be_truthy
|
||||
expect(cl.errors[:organization_id]).to be_truthy
|
||||
end
|
||||
|
||||
it "is valid with user_id" do
|
||||
cl = build(:classified_listing, user_id: user.id, organization_id: nil)
|
||||
expect(cl).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with organization_id" do
|
||||
cl = build(:classified_listing, user_id: nil, organization_id: create(:organization).id)
|
||||
expect(cl).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "body html" do
|
||||
it "converts markdown to html" do
|
||||
expect(classified_listing.processed_html).to include("<p>")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue