parent
6fd865c000
commit
81c76fe375
@ -1,11 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Mention < ApplicationRecord
|
||||
belongs_to :account, inverse_of: :mentions
|
||||
belongs_to :status
|
||||
belongs_to :account, inverse_of: :mentions, required: true
|
||||
belongs_to :status, required: true
|
||||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validates :account, :status, presence: true
|
||||
validates :account, uniqueness: { scope: :status }
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
Fabricator(:account) do
|
||||
username "alice"
|
||||
username { Faker::Internet.user_name(nil, %w(_)) }
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
Fabricator(:block) do
|
||||
|
||||
account
|
||||
target_account { Fabricate(:account) }
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
Fabricator(:follow) do
|
||||
|
||||
account
|
||||
target_account { Fabricate(:account) }
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
Fabricator(:follow_request) do
|
||||
|
||||
account
|
||||
target_account { Fabricate(:account) }
|
||||
end
|
||||
|
@ -0,0 +1,4 @@
|
||||
Fabricator(:mention) do
|
||||
account
|
||||
status
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
Fabricator(:user) do
|
||||
account
|
||||
email "alice@example.com"
|
||||
email { Faker::Internet.email }
|
||||
password "123456789"
|
||||
confirmed_at { Time.now }
|
||||
end
|
||||
|
@ -1,5 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Block, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
block = Fabricate.build(:block)
|
||||
expect(block).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without an account' do
|
||||
block = Fabricate.build(:block, account: nil)
|
||||
block.valid?
|
||||
expect(block).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a target_account' do
|
||||
block = Fabricate.build(:block, target_account: nil)
|
||||
block.valid?
|
||||
expect(block).to model_have_error_on_field(:target_account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,23 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainBlock, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
domain_block = Fabricate.build(:domain_block)
|
||||
expect(domain_block).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without a domain' do
|
||||
domain_block = Fabricate.build(:domain_block, domain: nil)
|
||||
domain_block.valid?
|
||||
expect(domain_block).to model_have_error_on_field(:domain)
|
||||
end
|
||||
|
||||
it 'is invalid if the domain already exists' do
|
||||
domain_block_1 = Fabricate(:domain_block, domain: 'dalek.com')
|
||||
domain_block_2 = Fabricate.build(:domain_block, domain: 'dalek.com')
|
||||
domain_block_2.valid?
|
||||
expect(domain_block_2).to model_have_error_on_field(:domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Mention, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
mention = Fabricate.build(:mention)
|
||||
expect(mention).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without an account' do
|
||||
mention = Fabricate.build(:mention, account: nil)
|
||||
mention.valid?
|
||||
expect(mention).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a status' do
|
||||
mention = Fabricate.build(:mention, status: nil)
|
||||
mention.valid?
|
||||
expect(mention).to model_have_error_on_field(:status)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,49 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe User, type: :model do
|
||||
describe 'validations' do
|
||||
it 'is invalid without an account' do
|
||||
user = Fabricate.build(:user, account: nil)
|
||||
user.valid?
|
||||
expect(user).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a valid locale' do
|
||||
user = Fabricate.build(:user, locale: 'toto')
|
||||
user.valid?
|
||||
expect(user).to model_have_error_on_field(:locale)
|
||||
end
|
||||
|
||||
it 'is invalid without a valid email' do
|
||||
user = Fabricate.build(:user, email: 'john@')
|
||||
user.valid?
|
||||
expect(user).to model_have_error_on_field(:email)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'scopes' do
|
||||
describe 'recent' do
|
||||
it 'returns an array of recent users ordered by id' do
|
||||
user_1 = Fabricate(:user)
|
||||
user_2 = Fabricate(:user)
|
||||
expect(User.recent).to match_array([user_2, user_1])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admins' do
|
||||
it 'returns an array of users who are admin' do
|
||||
user_1 = Fabricate(:user, admin: false)
|
||||
user_2 = Fabricate(:user, admin: true)
|
||||
expect(User.admins).to match_array([user_2])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'confirmed' do
|
||||
it 'returns an array of users who are confirmed' do
|
||||
user_1 = Fabricate(:user, confirmed_at: nil)
|
||||
user_2 = Fabricate(:user, confirmed_at: Time.now)
|
||||
expect(User.confirmed).to match_array([user_2])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,15 @@
|
||||
RSpec::Matchers.define :model_have_error_on_field do |expected|
|
||||
match do |record|
|
||||
if record.errors.empty?
|
||||
record.valid?
|
||||
end
|
||||
|
||||
record.errors.has_key?(expected)
|
||||
end
|
||||
|
||||
failure_message do |record|
|
||||
keys = record.errors.keys
|
||||
|
||||
"expect record.errors(#{keys}) to include #{expected}"
|
||||
end
|
||||
end
|
Loading…
Reference in new issue