Fix belongs_to, it is now required by default
This commit is contained in:
parent
eb19c327e2
commit
d0b634852b
29 changed files with 56 additions and 69 deletions
|
|
@ -6,8 +6,7 @@ module Api
|
|||
belongs_to :user
|
||||
belongs_to :o_auth_application
|
||||
|
||||
validates :user, presence: true, uniqueness: {scope: :o_auth_application}
|
||||
validates :o_auth_application, presence: true
|
||||
validates :user, uniqueness: {scope: :o_auth_application}
|
||||
validate :validate_scope_names
|
||||
serialize :scopes, JSON
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ module Api
|
|||
before_validation :setup, on: :create
|
||||
|
||||
validates :token, presence: true, uniqueness: true
|
||||
validates :authorization, presence: true
|
||||
|
||||
scope :valid, ->(time) { where("expires_at >= ?", time) }
|
||||
|
||||
|
|
|
|||
|
|
@ -26,10 +26,9 @@ module Api
|
|||
class PairwisePseudonymousIdentifier < ApplicationRecord
|
||||
self.table_name = "ppid"
|
||||
|
||||
belongs_to :o_auth_application
|
||||
belongs_to :o_auth_application, optional: true
|
||||
belongs_to :user
|
||||
|
||||
validates :user, presence: true
|
||||
validates :identifier, presence: true, uniqueness: {scope: :user}
|
||||
validates :guid, presence: true, uniqueness: true
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@
|
|||
class AspectVisibility < ApplicationRecord
|
||||
|
||||
belongs_to :aspect
|
||||
validates :aspect, :presence => true
|
||||
|
||||
belongs_to :shareable, :polymorphic => true
|
||||
validates :shareable, :presence => true
|
||||
|
||||
validates :aspect, uniqueness: {scope: %i(shareable_id shareable_type)}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ class Block < ApplicationRecord
|
|||
|
||||
delegate :name, to: :person, prefix: true
|
||||
|
||||
validates :user_id, :presence => true
|
||||
validates :person_id, :presence => true, :uniqueness => { :scope => :user_id }
|
||||
validates :person_id, uniqueness: {scope: :user_id}
|
||||
|
||||
validate :not_blocking_yourself
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ class Comment < ApplicationRecord
|
|||
delegate :author_name, to: :parent, prefix: true
|
||||
|
||||
validates :text, :presence => true, :length => {:maximum => 65535}
|
||||
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
|
||||
|
||||
has_many :reports, as: :item
|
||||
|
||||
|
|
|
|||
|
|
@ -3,5 +3,4 @@ class CommentSignature < ApplicationRecord
|
|||
|
||||
self.primary_key = :comment_id
|
||||
belongs_to :comment
|
||||
validates :comment, presence: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ class Contact < ApplicationRecord
|
|||
include Diaspora::Federated::Base
|
||||
|
||||
belongs_to :user
|
||||
validates :user, presence: true
|
||||
|
||||
belongs_to :person
|
||||
validates :person, presence: true
|
||||
|
||||
validates :person_id, uniqueness: {scope: :user_id}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
class InvitationCode < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :user
|
||||
|
||||
before_create :generate_token, :set_default_invite_count
|
||||
|
||||
delegate :name, to: :user, prefix: true
|
||||
|
|
|
|||
|
|
@ -3,5 +3,4 @@ class LikeSignature < ApplicationRecord
|
|||
|
||||
self.primary_key = :like_id
|
||||
belongs_to :like
|
||||
validates :like, presence: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
class Mention < ApplicationRecord
|
||||
belongs_to :mentions_container, polymorphic: true
|
||||
belongs_to :person
|
||||
validates :mentions_container, presence: true
|
||||
validates :person, presence: true
|
||||
|
||||
scope :local, -> {
|
||||
joins(:person).where.not(people: {owner_id: nil})
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ class Message < ApplicationRecord
|
|||
|
||||
delegate :name, to: :author, prefix: true
|
||||
|
||||
validates :conversation, presence: true
|
||||
validates :text, presence: true
|
||||
validate :participant_of_parent_conversation
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ class Person < ApplicationRecord
|
|||
|
||||
has_many :roles
|
||||
|
||||
belongs_to :owner, :class_name => 'User'
|
||||
belongs_to :pod
|
||||
belongs_to :owner, class_name: "User", optional: true
|
||||
belongs_to :pod, optional: true
|
||||
|
||||
has_many :notification_actors
|
||||
has_many :notifications, :through => :notification_actors
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Photo < ApplicationRecord
|
|||
mount_uploader :processed_image, ProcessedImage
|
||||
mount_uploader :unprocessed_image, UnprocessedImage
|
||||
|
||||
belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid
|
||||
belongs_to :status_message, foreign_key: :status_message_guid, primary_key: :guid, optional: true
|
||||
validates_associated :status_message
|
||||
delegate :author_name, to: :status_message, prefix: true
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ class PollParticipation < ApplicationRecord
|
|||
|
||||
alias_attribute :parent, :poll
|
||||
|
||||
validates :poll_answer, presence: true
|
||||
validate :not_already_participated
|
||||
|
||||
def poll_answer_guid=(new_poll_answer_guid)
|
||||
|
|
|
|||
|
|
@ -3,5 +3,4 @@ class PollParticipationSignature < ApplicationRecord
|
|||
|
||||
self.primary_key = :poll_participation_id
|
||||
belongs_to :poll_participation
|
||||
validates :poll_participation, presence: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class Post < ApplicationRecord
|
|||
has_many :reshares, class_name: "Reshare", foreign_key: :root_guid, primary_key: :guid
|
||||
has_many :resharers, class_name: "Person", through: :reshares, source: :author
|
||||
|
||||
belongs_to :o_embed_cache
|
||||
belongs_to :open_graph_cache
|
||||
belongs_to :o_embed_cache, optional: true
|
||||
belongs_to :open_graph_cache, optional: true
|
||||
|
||||
validates_uniqueness_of :id
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ class Report < ApplicationRecord
|
|||
validate :post_or_comment_does_exist, :on => :create
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :post
|
||||
belongs_to :comment
|
||||
belongs_to :post, optional: true
|
||||
belongs_to :comment, optional: true
|
||||
belongs_to :item, polymorphic: true
|
||||
|
||||
after_commit :send_report_notification, :on => :create
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class Reshare < Post
|
||||
belongs_to :root, :class_name => 'Post', :foreign_key => :root_guid, :primary_key => :guid
|
||||
belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true
|
||||
validate :root_must_be_public
|
||||
validates_presence_of :root, :on => :create
|
||||
validates_uniqueness_of :root_guid, :scope => :author_id
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
class Role < ApplicationRecord
|
||||
belongs_to :person
|
||||
|
||||
validates :person, presence: true
|
||||
validates :name, uniqueness: {scope: :person_id}
|
||||
validates :name, inclusion: {in: %w(admin moderator spotlight)}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ class User < ApplicationRecord
|
|||
|
||||
has_many :aspects, -> { order('order_id ASC') }
|
||||
|
||||
belongs_to :auto_follow_back_aspect, :class_name => 'Aspect'
|
||||
belongs_to :invited_by, :class_name => 'User'
|
||||
belongs_to :auto_follow_back_aspect, class_name: "Aspect", optional: true
|
||||
belongs_to :invited_by, class_name: "User", optional: true
|
||||
|
||||
has_many :aspect_memberships, :through => :aspects
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,8 @@ module Diaspora
|
|||
poll.poll_answers = entity.poll_answers.map do |answer|
|
||||
PollAnswer.new(
|
||||
guid: answer.guid,
|
||||
answer: answer.answer
|
||||
answer: answer.answer,
|
||||
poll: poll
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ module Diaspora
|
|||
belongs_to :target, polymorphic: true
|
||||
|
||||
validates :target_id, uniqueness: {scope: %i(target_type author_id)}
|
||||
validates :target, presence: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module Diaspora
|
|||
module Relayable
|
||||
def self.included(model)
|
||||
model.class_eval do
|
||||
validates :parent, presence: true
|
||||
validates_associated :parent
|
||||
validate :author_is_not_ignored
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ describe Contact, type: :model do
|
|||
|
||||
it "requires a user" do
|
||||
contact.valid?
|
||||
expect(contact.errors.full_messages).to include "User can't be blank"
|
||||
expect(contact.errors.full_messages).to include "User must exist"
|
||||
end
|
||||
|
||||
it "requires a person" do
|
||||
contact.valid?
|
||||
expect(contact.errors.full_messages).to include "Person can't be blank"
|
||||
expect(contact.errors.full_messages).to include "Person must exist"
|
||||
end
|
||||
|
||||
it "validates uniqueness" do
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
describe Location, :type => :model do
|
||||
describe 'before validation' do
|
||||
it 'should create new location when it has coordinates' do
|
||||
location = Location.new(coordinates:'1,2')
|
||||
describe Location, type: :model do
|
||||
describe "before validation" do
|
||||
let(:status) { FactoryGirl.create(:status_message) }
|
||||
|
||||
it "should create new location when it has coordinates" do
|
||||
location = Location.new(coordinates: "1,2", status_message: status)
|
||||
expect(location.save).to be true
|
||||
end
|
||||
|
||||
it 'should not create new location when it does not have coordinates' do
|
||||
location = Location.new()
|
||||
it "should not create new location when it does not have coordinates" do
|
||||
location = Location.new(status_message: status)
|
||||
expect(location.save).to be false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
describe PollParticipation, type: :model do
|
||||
let(:status) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
|
||||
let(:poll) { Poll.new(question: "Who is in charge?") }
|
||||
|
||||
before do
|
||||
@alices_aspect = alice.aspects.first
|
||||
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
|
||||
@poll = Poll.new(:question => 'Who is in charge?')
|
||||
@poll.poll_answers.build(:answer => "a")
|
||||
@poll.poll_answers.build(:answer => "b")
|
||||
@status.poll = @poll
|
||||
poll.poll_answers.build(answer: "a").poll = poll
|
||||
poll.poll_answers.build(answer: "b").poll = poll
|
||||
status.poll = poll
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
it 'forbids multiple participations in the same poll' do
|
||||
expect {
|
||||
2.times do |run|
|
||||
bob.participate_in_poll!(@status, @poll.poll_answers.first)
|
||||
bob.participate_in_poll!(status, poll.poll_answers.first)
|
||||
end
|
||||
}.to raise_error ActiveRecord::RecordInvalid
|
||||
end
|
||||
|
||||
it 'allows a one time participation in a poll' do
|
||||
expect {
|
||||
bob.participate_in_poll!(@status, @poll.poll_answers.first)
|
||||
bob.participate_in_poll!(status, poll.poll_answers.first)
|
||||
}.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
@ -38,6 +38,6 @@ describe PollParticipation, type: :model do
|
|||
let(:remote_object_on_local_parent) {
|
||||
FactoryGirl.create(:poll_participation, poll_answer: local_parent.poll.poll_answers.first, author: remote_raphael)
|
||||
}
|
||||
let(:relayable) { PollParticipation::Generator.new(alice, @status, @poll.poll_answers.first).build }
|
||||
let(:relayable) { PollParticipation::Generator.new(alice, status, poll.poll_answers.first).build }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
describe Poll, :type => :model do
|
||||
before do
|
||||
@poll = Poll.new(:question => "What do you think about apples?")
|
||||
end
|
||||
describe Poll, type: :model do
|
||||
let(:status) { FactoryGirl.create(:status_message) }
|
||||
let(:poll) { Poll.new(question: "What do you think about apples?", status_message: status) }
|
||||
|
||||
describe 'validation' do
|
||||
it 'should not create a poll when it has less than two answers' do
|
||||
@poll.poll_answers.build(:answer => '1')
|
||||
expect(@poll).not_to be_valid
|
||||
describe "validation" do
|
||||
it "should not create a poll when it has less than two answers" do
|
||||
poll.poll_answers.build(answer: "1").poll = poll
|
||||
expect(poll).not_to be_valid
|
||||
end
|
||||
|
||||
it 'should create a poll when it has more than two answers' do
|
||||
@poll.poll_answers.build(:answer => '1')
|
||||
@poll.poll_answers.build(:answer => '2')
|
||||
expect(@poll).to be_valid
|
||||
it "should create a poll when it has more than two answers" do
|
||||
poll.poll_answers.build(answer: "1").poll = poll
|
||||
poll.poll_answers.build(answer: "2").poll = poll
|
||||
expect(poll).to be_valid
|
||||
end
|
||||
|
||||
it 'should not create a poll when question in blank' do
|
||||
@poll.question = ' '
|
||||
@poll.valid?
|
||||
expect(@poll.errors).to have_key(:question)
|
||||
it "should not create a poll when question in blank" do
|
||||
poll.question = " "
|
||||
poll.valid?
|
||||
expect(poll.errors).to have_key(:question)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,12 @@ describe Role do
|
|||
let!(:moderator_role) { moderator.roles.create(name: "moderator") }
|
||||
|
||||
describe "validations" do
|
||||
it { should validate_presence_of(:person) }
|
||||
it "validates the presence of the person" do
|
||||
role = Role.new(name: "admin")
|
||||
role.valid?
|
||||
expect(role.errors.full_messages).to include "Person must exist"
|
||||
end
|
||||
|
||||
it { should validate_uniqueness_of(:name).scoped_to(:person_id) }
|
||||
it { should validate_inclusion_of(:name).in_array(%w(admin spotlight moderator)) }
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue