Make reason not null
This commit is contained in:
@@ -15,7 +15,7 @@ module Bubble::Poppable
|
||||
class_methods do
|
||||
def auto_pop_all_due
|
||||
due_to_be_popped.find_each do |bubble|
|
||||
bubble.pop!(user: bubble.bucket.account.users.system)
|
||||
bubble.pop!(user: bubble.bucket.account.users.system, reason: "Closed")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -40,7 +40,7 @@ module Bubble::Poppable
|
||||
pop&.created_at
|
||||
end
|
||||
|
||||
def pop!(user: Current.user, reason: nil)
|
||||
def pop!(user: Current.user, reason: Account::PopReasons::FALLBACK_LABEL)
|
||||
unless popped?
|
||||
transaction do
|
||||
create_pop! user: user, reason: reason
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
class Pop < ApplicationRecord
|
||||
belongs_to :bubble, touch: true
|
||||
belongs_to :user, optional: true
|
||||
|
||||
def reason
|
||||
super || Account::PopReasons::FALLBACK_LABEL
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<% if bubble.popped? %>
|
||||
<div class="card__popped flex flex-column">
|
||||
<span class="card__popped-title txt-uppercase"><%= bubble.popped_by.system? ? "Closed" : bubble.pop.reason %></span>
|
||||
<span class="card__popped-title txt-uppercase"><%= bubble.pop.reason %></span>
|
||||
<strong><%= bubble.popped_at.strftime("%b %d, %Y") %></strong>
|
||||
<span>by <span class="card__popped-by"><%= bubble.popped_by.name %></span></span>
|
||||
</div>
|
||||
|
||||
@@ -8,5 +8,11 @@ class AddReasonToPops < ActiveRecord::Migration[8.1]
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
execute <<~SQL
|
||||
update pops set reason = 'Closed'
|
||||
SQL
|
||||
|
||||
change_column_null :pops, :reason, false
|
||||
end
|
||||
end
|
||||
|
||||
Generated
+1
-1
@@ -246,7 +246,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_04_083727) do
|
||||
create_table "pops", force: :cascade do |t|
|
||||
t.integer "bubble_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.string "reason"
|
||||
t.string "reason", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.index ["bubble_id"], name: "index_pops_on_bubble_id", unique: true
|
||||
|
||||
+16
-16
@@ -468,16 +468,6 @@ columns:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: last_active_at
|
||||
cast_type: *3
|
||||
sql_type_metadata: *4
|
||||
'null': true
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: stage_id
|
||||
@@ -509,6 +499,16 @@ columns:
|
||||
collation:
|
||||
comment:
|
||||
- *9
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: last_active_at
|
||||
cast_type: *3
|
||||
sql_type_metadata: *4
|
||||
'null': true
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
buckets:
|
||||
- *5
|
||||
- &32 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
@@ -792,7 +792,7 @@ columns:
|
||||
name: reason
|
||||
cast_type: *7
|
||||
sql_type_metadata: *8
|
||||
'null': true
|
||||
'null': false
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
@@ -1354,10 +1354,11 @@ indexes:
|
||||
bubbles:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
|
||||
table: bubbles
|
||||
name: index_bubbles_on_stage_id
|
||||
name: index_bubbles_on_last_active_at_and_status
|
||||
unique: false
|
||||
columns:
|
||||
- stage_id
|
||||
- last_active_at
|
||||
- status
|
||||
lengths: {}
|
||||
orders: {}
|
||||
opclasses: {}
|
||||
@@ -1370,11 +1371,10 @@ indexes:
|
||||
valid: true
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
|
||||
table: bubbles
|
||||
name: index_bubbles_on_last_active_at_and_status
|
||||
name: index_bubbles_on_stage_id
|
||||
unique: false
|
||||
columns:
|
||||
- last_active_at
|
||||
- status
|
||||
- stage_id
|
||||
lengths: {}
|
||||
orders: {}
|
||||
opclasses: {}
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
shipping:
|
||||
bubble: shipping
|
||||
user: kevin
|
||||
reason: Closed
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class PopTest < ActiveSupport::TestCase
|
||||
test "default to the fallback reason if no reason is given" do
|
||||
assert_equal "Not now", Pop.new(reason: "Not now").reason
|
||||
assert_equal Account::PopReasons::FALLBACK_LABEL, Pop.new.reason
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user