提交 4fcae04f 编写于 作者: D Douglas Barbosa Alexandre

Add project_id to subscriptions

上级 8762db3b
class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :project
belongs_to :subscribable, polymorphic: true
validates :user, :project, :subscribable, presence: true
validates :user_id,
uniqueness: { scope: [:subscribable_id, :subscribable_type] },
presence: true
......
class AddProjectIdToSubscriptions < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
add_column :subscriptions, :project_id, :integer
add_foreign_key :subscriptions, :projects, column: :project_id, on_delete: :cascade
end
def down
remove_column :subscriptions, :project_id
end
end
......@@ -1052,6 +1052,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
t.boolean "subscribed"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "project_id"
end
add_index "subscriptions", ["subscribable_id", "subscribable_type", "user_id"], name: "subscriptions_user_id_and_ref_fields", unique: true, using: :btree
......@@ -1250,6 +1251,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
add_foreign_key "personal_access_tokens", "users"
add_foreign_key "protected_branch_merge_access_levels", "protected_branches"
add_foreign_key "protected_branch_push_access_levels", "protected_branches"
add_foreign_key "subscriptions", "projects", on_delete: :cascade
add_foreign_key "trending_projects", "projects", on_delete: :cascade
add_foreign_key "u2f_registrations", "users"
end
require 'spec_helper'
describe Subscription, models: true do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:subscribable) }
it { is_expected.to belong_to(:user) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:subscribable) }
it { is_expected.to validate_presence_of(:user) }
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册