mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 04:34:37 +08:00
generated notification related migrations and model tests
This commit is contained in:
parent
1c1a7c231e
commit
485497334d
10 changed files with 98 additions and 3 deletions
4
app/models/notification.rb
Normal file
4
app/models/notification.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class Notification < ActiveRecord::Base
|
||||
has_many :user_notifications, inverse_of: :notification
|
||||
has_many :users, through: :user_notifications
|
||||
end
|
|
@ -84,7 +84,8 @@ class User < ActiveRecord::Base
|
|||
has_many :added_protocols, class_name: 'Protocol', foreign_key: 'added_by_id', inverse_of: :added_by
|
||||
has_many :archived_protocols, class_name: 'Protocol', foreign_key: 'archived_by_id', inverse_of: :archived_by
|
||||
has_many :restored_protocols, class_name: 'Protocol', foreign_key: 'restored_by_id', inverse_of: :restored_by
|
||||
|
||||
has_many :user_notifications, inverse_of: :user
|
||||
has_many :notifications, through: :user_notifications
|
||||
# If other errors besides parameter "avatar" exist,
|
||||
# they will propagate to "avatar" also, so remove them
|
||||
# and put all other (more specific ones) in it
|
||||
|
@ -260,4 +261,3 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
4
app/models/user_notification.rb
Normal file
4
app/models/user_notification.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class UserNotification < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :notification
|
||||
end
|
12
db/migrate/20160928114119_create_notifications.rb
Normal file
12
db/migrate/20160928114119_create_notifications.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class CreateNotifications < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :notifications do |t|
|
||||
t.string :title
|
||||
t.string :message
|
||||
t.integer :type_of, null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
add_index :notifications, :created_at
|
||||
end
|
||||
end
|
11
db/migrate/20160928114915_create_user_notifications.rb
Normal file
11
db/migrate/20160928114915_create_user_notifications.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class CreateUserNotifications < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :user_notifications do |t|
|
||||
t.belongs_to :user, index: true, foreign_key: true
|
||||
t.belongs_to :notification, index: true, foreign_key: true
|
||||
t.boolean :checked
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
25
db/schema.rb
25
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: 20160809074757) do
|
||||
ActiveRecord::Schema.define(version: 20160928114915) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -226,6 +226,16 @@ ActiveRecord::Schema.define(version: 20160809074757) do
|
|||
add_index "my_modules", ["name"], name: "index_my_modules_on_name", using: :gist
|
||||
add_index "my_modules", ["restored_by_id"], name: "index_my_modules_on_restored_by_id", using: :btree
|
||||
|
||||
create_table "notifications", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "message"
|
||||
t.integer "type_of", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "notifications", ["created_at"], name: "index_notifications_on_created_at", using: :btree
|
||||
|
||||
create_table "organizations", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -578,6 +588,17 @@ ActiveRecord::Schema.define(version: 20160809074757) do
|
|||
add_index "user_my_modules", ["my_module_id"], name: "index_user_my_modules_on_my_module_id", using: :btree
|
||||
add_index "user_my_modules", ["user_id"], name: "index_user_my_modules_on_user_id", using: :btree
|
||||
|
||||
create_table "user_notifications", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "notification_id"
|
||||
t.boolean "checked"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "user_notifications", ["notification_id"], name: "index_user_notifications_on_notification_id", using: :btree
|
||||
add_index "user_notifications", ["user_id"], name: "index_user_notifications_on_user_id", using: :btree
|
||||
|
||||
create_table "user_organizations", force: :cascade do |t|
|
||||
t.integer "role", default: 1, null: false
|
||||
t.integer "user_id", null: false
|
||||
|
@ -758,6 +779,8 @@ ActiveRecord::Schema.define(version: 20160809074757) do
|
|||
add_foreign_key "user_my_modules", "my_modules"
|
||||
add_foreign_key "user_my_modules", "users"
|
||||
add_foreign_key "user_my_modules", "users", column: "assigned_by_id"
|
||||
add_foreign_key "user_notifications", "notifications"
|
||||
add_foreign_key "user_notifications", "users"
|
||||
add_foreign_key "user_organizations", "organizations"
|
||||
add_foreign_key "user_organizations", "users"
|
||||
add_foreign_key "user_organizations", "users", column: "assigned_by_id"
|
||||
|
|
11
test/fixtures/notifications.yml
vendored
Normal file
11
test/fixtures/notifications.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
title: MyString
|
||||
message: MyString
|
||||
type_of: 1
|
||||
|
||||
two:
|
||||
title: MyString
|
||||
message: MyString
|
||||
type_of: 1
|
11
test/fixtures/user_notifications.yml
vendored
Normal file
11
test/fixtures/user_notifications.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id:
|
||||
notification_id:
|
||||
checked: false
|
||||
|
||||
two:
|
||||
user_id:
|
||||
notification_id:
|
||||
checked: false
|
12
test/models/notification_test.rb
Normal file
12
test/models/notification_test.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NotificationTest < ActiveSupport::TestCase
|
||||
should have_db_column(:title).of_type(:string)
|
||||
should have_db_column(:message).of_type(:text)
|
||||
should have_db_column(:type_of).of_type(:integer)
|
||||
should have_db_column(:created_at).of_type(:datetime)
|
||||
should have_db_column(:updated_at).of_type(:datetime)
|
||||
|
||||
should have_many(:user_notifications)
|
||||
should have_many(:users)
|
||||
end
|
7
test/models/user_notification_test.rb
Normal file
7
test/models/user_notification_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserNotificationTest < ActiveSupport::TestCase
|
||||
should have_db_column(:checked).of_type(:boolean)
|
||||
should belong_to(:user)
|
||||
should belong_to(:notification)
|
||||
end
|
Loading…
Add table
Reference in a new issue