Add modelling for "popped" bubbles
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
class Pop < ApplicationRecord
|
||||
belongs_to :bubble
|
||||
belongs_to :user, optional: true
|
||||
end
|
||||
@@ -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"
|
||||
|
||||
@@ -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
@@ -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"
|
||||
|
||||
Vendored
+6
@@ -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"
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
shipping:
|
||||
bubble: shipping
|
||||
user: kevin
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class PopTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user