diaspora/app/models/aspect_visibility.rb
cmrd Senya 717554edac
Fix possible duplication of AspectVisibility
No uniqueness control on AspectVisibility resulted in possible having
multiple AspectVisibility objects in the DB for the same aspect and
shareable which doesn't make sense. Introduce uniqueness validation
and fix up tests where duplication happened.
2016-05-27 20:22:03 +03:00

14 lines
433 B
Ruby

# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AspectVisibility < ActiveRecord::Base
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