diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-03-28 13:41:00 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-03-30 10:44:20 +0200 |
commit | 31b0e53015e38e51d9c02cca85c9279600b1bf85 (patch) | |
tree | 2b0e9dcdb9ba11099b13fc790677bb59052d47fc | |
parent | a9346cab20f7e54a849877e2aa8601b8b3707652 (diff) | |
download | gitlab-ce-31b0e53015e38e51d9c02cca85c9279600b1bf85.tar.gz |
Introduce NotificationSetting model
It will hold notification setting per group or per project. It will
allow get rid of notification level stored in Member model
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | app/models/notification_setting.rb | 14 | ||||
-rw-r--r-- | db/migrate/20160328112808_create_notification_settings.rb | 12 | ||||
-rw-r--r-- | db/schema.rb | 15 | ||||
-rw-r--r-- | spec/models/notification_setting_spec.rb | 15 |
4 files changed, 53 insertions, 3 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb new file mode 100644 index 00000000000..0dce146b7a9 --- /dev/null +++ b/app/models/notification_setting.rb @@ -0,0 +1,14 @@ +class NotificationSetting < ActiveRecord::Base + belongs_to :user + belongs_to :source, polymorphic: true + + validates :user, presence: true + validates :source, presence: true + validates :level, presence: true + validates :user_id, uniqueness: { scope: [:source_type, :source_id], + message: "already exists in source", + allow_nil: true } + # Notification level + # Note: When adding an option, it MUST go on the end of the array. + enum level: [:disabled, :participating, :watch, :global, :mention] +end diff --git a/db/migrate/20160328112808_create_notification_settings.rb b/db/migrate/20160328112808_create_notification_settings.rb new file mode 100644 index 00000000000..88652821ac3 --- /dev/null +++ b/db/migrate/20160328112808_create_notification_settings.rb @@ -0,0 +1,12 @@ +class CreateNotificationSettings < ActiveRecord::Migration + def change + create_table :notification_settings do |t| + t.integer :user_id + t.integer :level + t.integer :source_id + t.string :source_type + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index dce2bfe62ca..a9a68e723ab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160320204112) do +ActiveRecord::Schema.define(version: 20160328112808) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -417,9 +417,9 @@ ActiveRecord::Schema.define(version: 20160320204112) do t.string "state" t.integer "iid" t.integer "updated_by_id" - t.integer "moved_to_id" - t.boolean "confidential", default: false + t.boolean "confidential", default: false t.datetime "deleted_at" + t.integer "moved_to_id" end add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree @@ -638,6 +638,15 @@ ActiveRecord::Schema.define(version: 20160320204112) do add_index "notes", ["project_id"], name: "index_notes_on_project_id", using: :btree add_index "notes", ["updated_at"], name: "index_notes_on_updated_at", using: :btree + create_table "notification_settings", force: :cascade do |t| + t.integer "user_id" + t.integer "level" + t.integer "source_id" + t.string "source_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "oauth_access_grants", force: :cascade do |t| t.integer "resource_owner_id", null: false t.integer "application_id", null: false diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb new file mode 100644 index 00000000000..f9d668ed75b --- /dev/null +++ b/spec/models/notification_setting_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe NotificationSetting, type: :model do + describe "Associations" do + it { is_expected.to belong_to(:user) } + end + + describe "Validation" do + subject { NotificationSetting.new } + + it { is_expected.to validate_presence_of(:user) } + it { is_expected.to validate_presence_of(:source) } + it { is_expected.to validate_presence_of(:level) } + end +end |