Add modelling for "popped" bubbles

This commit is contained in:
Kevin McConnell
2024-10-02 14:25:20 +01:00
parent 8ff85b44e0
commit e50144d97f
10 changed files with 81 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class Bubble < ApplicationRecord
include Assignable, Colored, Searchable, Taggable
include Assignable, Colored, Poppable, Searchable, Taggable
belongs_to :bucket
belongs_to :creator, class_name: "User", default: -> { Current.user }
+22
View File
@@ -0,0 +1,22 @@
module Bubble::Poppable
extend ActiveSupport::Concern
included do
has_one :pop, dependent: :destroy
scope :popped, -> { joins(:pop) }
scope :not_popped, -> { where.missing(:pop) }
end
def popped?
pop.present?
end
def pop!(user: Current.user)
create_pop!(user: user) unless popped?
end
def unpop
pop&.destroy
end
end
+4
View File
@@ -0,0 +1,4 @@
class Pop < ApplicationRecord
belongs_to :bubble
belongs_to :user, optional: true
end
+1
View File
@@ -7,6 +7,7 @@ class User < ApplicationRecord
has_many :accesses, dependent: :destroy
has_many :buckets, through: :accesses
has_many :bubbles, through: :buckets
has_many :pops, dependent: :nullify
has_many :assignments, foreign_key: :assignee_id, dependent: :destroy
has_many :assignings, foreign_key: :assigner_id, class_name: "Assignment"
+10
View File
@@ -0,0 +1,10 @@
class CreatePops < ActiveRecord::Migration[8.0]
def change
create_table :pops do |t|
t.references :bubble, null: false, foreign_key: true, index: { unique: true }
t.references :user, null: true, foreign_key: true
t.timestamps
end
end
end
Generated
+11
View File
@@ -105,6 +105,15 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_02_163242) do
t.datetime "updated_at", null: false
end
create_table "pops", force: :cascade do |t|
t.integer "bubble_id", null: false
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bubble_id"], name: "index_pops_on_bubble_id", unique: true
t.index ["user_id"], name: "index_pops_on_user_id"
end
create_table "sessions", force: :cascade do |t|
t.integer "user_id", null: false
t.string "ip_address"
@@ -145,6 +154,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_02_163242) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "pops", "bubbles"
add_foreign_key "pops", "users"
add_foreign_key "sessions", "users"
add_foreign_key "taggings", "bubbles"
add_foreign_key "taggings", "tags"
+6
View File
@@ -16,3 +16,9 @@ text:
creator: kevin
title: The text is too small
color: "#3B4B59"
shipping:
bucket: writebook
creator: kevin
title: We need to ship the app
color: "#ED8008"
+3
View File
@@ -0,0 +1,3 @@
shipping:
bubble: shipping
user: kevin
+16
View File
@@ -0,0 +1,16 @@
require "test_helper"
class Bubble::PoppableTest < ActiveSupport::TestCase
test "popped scope" do
assert_equal [ bubbles(:shipping) ], Bubble.popped
assert_not_includes Bubble.not_popped, bubbles(:shipping)
end
test "popping" do
assert_not bubbles(:logo).popped?
bubbles(:logo).pop!
assert bubbles(:logo).popped?
end
end
+7
View File
@@ -0,0 +1,7 @@
require "test_helper"
class PopTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end