# frozen_string_literal: true # == Schema Information # # Table name: posts # # id :bigint not null, primary key # anonymous :boolean default(FALSE), not null # commenting_allowed :boolean default(TRUE), not null # comments_count :integer default(0), not null # deletion_reason :string # description :string # description_editing_allowed :boolean default(TRUE), not null # destroyed_content :boolean default(FALSE), not null # downvotes_count :integer default(0), not null # duplication_checked :boolean default(FALSE), not null # faves_count :integer default(0), not null # first_seen_at :datetime # hidden_from_users :boolean default(FALSE), not null # hidden_key :text # hides_count :integer default(0), not null # ip :inet # media_type :string default("image"), not null # processed :boolean default(FALSE), not null # referrer :string default(""), not null # score :integer default(0), not null # scratchpad :string # source_url :string # tag_editing_allowed :boolean default(TRUE), not null # tag_list_cache :string # tag_list_plus_alias_cache :string # upvotes_count :integer default(0), not null # user_agent :string default(""), not null # created_at :datetime not null # updated_at :datetime not null # deleted_by_id :integer # duplicate_id :integer # user_id :integer # # Foreign Keys # # fk_rails_... (deleted_by_id => users.id) # fk_rails_... (duplicate_id => posts.id) # fk_rails_... (user_id => users.id) # require 'rails_helper' RSpec.describe Post, type: :model do it 'is valid with normal attributes' do post = build(:post) expect(post).to be_valid end it 'is valid as a paste' do post = build(:post_with_paste) expect(post).to be_valid end it 'is valid with no user' do post = build(:post_anonymous) expect(post).to be_valid end it 'is invalid with no media' do post = build(:post_with_no_media) expect(post).to_not be_valid end it 'is invalid with the wrong media' do post = build(:post_with_no_media) post.media_type = 'image' post.paste = build(:post_paste, post: post) expect(post).to_not be_valid end it 'is invalid with no tags' do post = build(:post) post.tag_input = '' expect(post).to_not be_valid end end