Change columns in notifications nonnullable (#6764)
This commit is contained in:
parent
fa310695fa
commit
b2a4ffd3a9
5 changed files with 23 additions and 17 deletions
|
@ -4,12 +4,12 @@
|
||||||
# Table name: notifications
|
# Table name: notifications
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# activity_id :integer
|
# activity_id :integer not null
|
||||||
# activity_type :string
|
# activity_type :string not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# account_id :integer
|
# account_id :integer not null
|
||||||
# from_account_id :integer
|
# from_account_id :integer not null
|
||||||
#
|
#
|
||||||
|
|
||||||
class Notification < ApplicationRecord
|
class Notification < ApplicationRecord
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class ChangeColumnsInNotificationsNonnullable < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
change_column_null :notifications, :activity_id, false
|
||||||
|
change_column_null :notifications, :activity_type, false
|
||||||
|
change_column_null :notifications, :account_id, false
|
||||||
|
change_column_null :notifications, :from_account_id, false
|
||||||
|
end
|
||||||
|
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20180304013859) do
|
ActiveRecord::Schema.define(version: 20180310000000) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -274,12 +274,12 @@ ActiveRecord::Schema.define(version: 20180304013859) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "notifications", force: :cascade do |t|
|
create_table "notifications", force: :cascade do |t|
|
||||||
t.bigint "activity_id"
|
t.bigint "activity_id", null: false
|
||||||
t.string "activity_type"
|
t.string "activity_type", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.bigint "account_id"
|
t.bigint "account_id", null: false
|
||||||
t.bigint "from_account_id"
|
t.bigint "from_account_id", null: false
|
||||||
t.index ["account_id", "activity_id", "activity_type"], name: "account_activity", unique: true
|
t.index ["account_id", "activity_id", "activity_type"], name: "account_activity", unique: true
|
||||||
t.index ["account_id", "id"], name: "index_notifications_on_account_id_and_id", order: { id: :desc }
|
t.index ["account_id", "id"], name: "index_notifications_on_account_id_and_id", order: { id: :desc }
|
||||||
t.index ["activity_id", "activity_type"], name: "index_notifications_on_activity_id_and_activity_type"
|
t.index ["activity_id", "activity_type"], name: "index_notifications_on_activity_id_and_activity_type"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Fabricator(:notification) do
|
Fabricator(:notification) do
|
||||||
activity_id 1
|
activity fabricator: [:mention, :status, :follow, :follow_request, :favourite].sample
|
||||||
activity_type 'Favourite'
|
account
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,14 +6,13 @@ RSpec.describe Notification, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#target_status' do
|
describe '#target_status' do
|
||||||
let(:notification) { Fabricate(:notification, activity_type: type, activity: activity) }
|
let(:notification) { Fabricate(:notification, activity: activity) }
|
||||||
let(:status) { Fabricate(:status) }
|
let(:status) { Fabricate(:status) }
|
||||||
let(:reblog) { Fabricate(:status, reblog: status) }
|
let(:reblog) { Fabricate(:status, reblog: status) }
|
||||||
let(:favourite) { Fabricate(:favourite, status: status) }
|
let(:favourite) { Fabricate(:favourite, status: status) }
|
||||||
let(:mention) { Fabricate(:mention, status: status) }
|
let(:mention) { Fabricate(:mention, status: status) }
|
||||||
|
|
||||||
context 'type is :reblog' do
|
context 'activity is reblog' do
|
||||||
let(:type) { :reblog }
|
|
||||||
let(:activity) { reblog }
|
let(:activity) { reblog }
|
||||||
|
|
||||||
it 'returns status' do
|
it 'returns status' do
|
||||||
|
@ -21,7 +20,7 @@ RSpec.describe Notification, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'type is :favourite' do
|
context 'activity is favourite' do
|
||||||
let(:type) { :favourite }
|
let(:type) { :favourite }
|
||||||
let(:activity) { favourite }
|
let(:activity) { favourite }
|
||||||
|
|
||||||
|
@ -30,8 +29,7 @@ RSpec.describe Notification, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'type is :mention' do
|
context 'activity is mention' do
|
||||||
let(:type) { :mention }
|
|
||||||
let(:activity) { mention }
|
let(:activity) { mention }
|
||||||
|
|
||||||
it 'returns status' do
|
it 'returns status' do
|
||||||
|
|
Loading…
Reference in a new issue