Add a new "creating" state

This commit is contained in:
Kevin McConnell
2025-02-06 14:16:02 +00:00
parent 5107071315
commit b347d77f4d
4 changed files with 21 additions and 9 deletions
+2 -2
View File
@@ -2,9 +2,9 @@ module Bubble::Draftable
extend ActiveSupport::Concern
included do
enum :status, %w[ drafted published ].index_by(&:itself)
enum :status, %w[ creating drafted published ].index_by(&:itself)
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(creator: user)) }
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) }
end
def publish
@@ -0,0 +1,5 @@
class ChangeBubblesStatusDefaultToCreating < ActiveRecord::Migration[8.1]
def change
change_column_default :bubbles, :status, :creating
end
end
Generated
+2 -2
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2025_02_04_211520) do
ActiveRecord::Schema[8.1].define(version: 2025_02_06_141302) do
create_table "accesses", force: :cascade do |t|
t.integer "bucket_id", null: false
t.integer "user_id", null: false
@@ -106,7 +106,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_02_04_211520) do
t.integer "stage_id"
t.integer "comments_count", default: 0, null: false
t.integer "activity_score", default: 0, null: false
t.text "status", default: "drafted", null: false
t.text "status", default: "creating", null: false
t.index ["bucket_id"], name: "index_bubbles_on_bucket_id"
t.index ["stage_id"], name: "index_bubbles_on_stage_id"
end
+12 -5
View File
@@ -1,19 +1,26 @@
require "test_helper"
class Bubble::DraftableTest < ActiveSupport::TestCase
test "bubbles are only visible to the creator by default" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Drafted Bubble"
test "bubbles start out in a `creating` state" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Newly created bubble"
assert bubble.creating?
assert_not_includes Bubble.published_or_drafted_by(users(:kevin)), bubble
assert_not_includes Bubble.published_or_drafted_by(users(:jz)), bubble
end
test "bubbles are only visible to the creator when drafted" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Drafted Bubble"
bubble.drafted!
assert bubble.drafted?
assert_includes Bubble.published_or_drafted_by(users(:kevin)), bubble
assert_not_includes Bubble.published_or_drafted_by(users(:jz)), bubble
end
test "bubbles are visible to everyone when published" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Drafted Bubble"
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Published Bubble"
bubble.published!
assert bubble.published?
assert_includes Bubble.published_or_drafted_by(users(:kevin)), bubble
assert_includes Bubble.published_or_drafted_by(users(:jz)), bubble
end