summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-03-02 12:02:33 -0500
committerRobert Speicher <rspeicher@gmail.com>2017-03-06 14:41:10 -0500
commit23c2b8f6bb35d8a2af41c282ae02824e95c3fbd3 (patch)
treea2683fd329be8eb0d7a12b0481447423f4fb6682
parent5c41338fa30b5795309957c71202b11a71cccef0 (diff)
downloadgitlab-ce-23c2b8f6bb35d8a2af41c282ae02824e95c3fbd3.tar.gz
Add `has_many` associations for models that can have Upload records
-rw-r--r--app/models/appearance.rb1
-rw-r--r--app/models/group.rb1
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/user.rb1
-rw-r--r--spec/models/appearance_spec.rb2
-rw-r--r--spec/models/group_spec.rb1
-rw-r--r--spec/models/project_spec.rb1
-rw-r--r--spec/models/user_spec.rb1
8 files changed, 9 insertions, 0 deletions
diff --git a/app/models/appearance.rb b/app/models/appearance.rb
index e4106e1c2e9..c79326e8427 100644
--- a/app/models/appearance.rb
+++ b/app/models/appearance.rb
@@ -10,4 +10,5 @@ class Appearance < ActiveRecord::Base
mount_uploader :logo, AttachmentUploader
mount_uploader :header_logo, AttachmentUploader
+ has_many :uploads, as: :model, dependent: :destroy
end
diff --git a/app/models/group.rb b/app/models/group.rb
index 7d23f655225..a1f12ed55ea 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -28,6 +28,7 @@ class Group < Namespace
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
mount_uploader :avatar, AvatarUploader
+ has_many :uploads, as: :model, dependent: :destroy
after_create :post_create_hook
after_destroy :post_destroy_hook
diff --git a/app/models/project.rb b/app/models/project.rb
index 1ac4a178a9b..7d211784c3c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -212,6 +212,7 @@ class Project < ActiveRecord::Base
before_save :ensure_runners_token
mount_uploader :avatar, AvatarUploader
+ has_many :uploads, as: :model, dependent: :destroy
# Scopes
default_scope { where(pending_delete: false) }
diff --git a/app/models/user.rb b/app/models/user.rb
index dfba51d3b00..bd57904a2cd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -191,6 +191,7 @@ class User < ActiveRecord::Base
end
mount_uploader :avatar, AvatarUploader
+ has_many :uploads, as: :model, dependent: :destroy
# Scopes
scope :admins, -> { where(admin: true) }
diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb
index 0b72a2f979b..1060bf3cbf4 100644
--- a/spec/models/appearance_spec.rb
+++ b/spec/models/appearance_spec.rb
@@ -7,4 +7,6 @@ RSpec.describe Appearance, type: :model do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:description) }
+
+ it { is_expected.to have_many(:uploads).dependent(:destroy) }
end
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index a4e6eb4e3a6..eac3d962dd1 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -13,6 +13,7 @@ describe Group, models: true do
it { is_expected.to have_many(:shared_projects).through(:project_group_links) }
it { is_expected.to have_many(:notification_settings).dependent(:destroy) }
it { is_expected.to have_many(:labels).class_name('GroupLabel') }
+ it { is_expected.to have_many(:uploads).dependent(:destroy) }
describe '#members & #requesters' do
let(:requester) { create(:user) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ee4f4092062..84bdcbe8e59 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -71,6 +71,7 @@ describe Project, models: true do
it { is_expected.to have_many(:project_group_links).dependent(:destroy) }
it { is_expected.to have_many(:notification_settings).dependent(:destroy) }
it { is_expected.to have_many(:forks).through(:forked_project_links) }
+ it { is_expected.to have_many(:uploads).dependent(:destroy) }
context 'after initialized' do
it "has a project_feature" do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b99cde64675..adb5b538922 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -36,6 +36,7 @@ describe User, models: true do
it { is_expected.to have_many(:builds).dependent(:nullify) }
it { is_expected.to have_many(:pipelines).dependent(:nullify) }
it { is_expected.to have_many(:chat_names).dependent(:destroy) }
+ it { is_expected.to have_many(:uploads).dependent(:destroy) }
describe '#group_members' do
it 'does not include group memberships for which user is a requester' do