boost_count -> boosts_count
This aligns better with counter_cache conventions, in case we turn boosts into a model later
This commit is contained in:
@@ -25,7 +25,7 @@ class Bubble < ApplicationRecord
|
||||
end
|
||||
|
||||
def rescore
|
||||
update! activity_score: boost_count + comments_count
|
||||
update! activity_score: boosts_count + comments_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -2,13 +2,13 @@ module Bubble::Boostable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :ordered_by_boosts, -> { order boost_count: :desc }
|
||||
scope :ordered_by_boosts, -> { order boosts_count: :desc }
|
||||
end
|
||||
|
||||
def boost!
|
||||
transaction do
|
||||
track_event :boosted
|
||||
increment! :boost_count
|
||||
increment! :boosts_count
|
||||
rescore
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
animation_play_class: "boosting",
|
||||
toggle_class_toggle_class: "boosting",
|
||||
action: "animationend->toggle-class#toggle" },
|
||||
hidden: !bubble.boost_count.positive? do %>
|
||||
hidden: !bubble.boosts_count.positive? do %>
|
||||
<%= button_to bucket_bubble_boosts_path(bubble.bucket, bubble),
|
||||
class: "btn btn--plain",
|
||||
data: { action: "toggle-class#toggle" },
|
||||
form_class: "full-width" do %>
|
||||
<%= tag.span("+ #{bubble.boost_count}") if bubble.boost_count.positive? %>
|
||||
<%= tag.span("+ #{bubble.boosts_count}") if bubble.boosts_count.positive? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameBoostCountToBoostsCount < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
rename_column :bubbles, :boost_count, :boosts_count
|
||||
end
|
||||
end
|
||||
Generated
+2
-2
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2024_11_15_234505) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2024_11_19_201943) do
|
||||
create_table "accesses", force: :cascade do |t|
|
||||
t.integer "bucket_id", null: false
|
||||
t.integer "user_id", null: false
|
||||
@@ -90,7 +90,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_15_234505) do
|
||||
t.integer "creator_id", null: false
|
||||
t.date "due_on"
|
||||
t.integer "bucket_id", null: false
|
||||
t.integer "boost_count", default: 0, null: false
|
||||
t.integer "boosts_count", default: 0, null: false
|
||||
t.integer "stage_id"
|
||||
t.integer "comments_count", default: 0, null: false
|
||||
t.integer "activity_score", default: 0, null: false
|
||||
|
||||
@@ -6,7 +6,7 @@ class BoostsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_difference "bubbles(:logo).reload.boost_count", +1 do
|
||||
assert_difference "bubbles(:logo).reload.boosts_count", +1 do
|
||||
post bucket_bubble_boosts_url(buckets(:writebook), bubbles(:logo), format: :turbo_stream)
|
||||
end
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ logo:
|
||||
color: "#ED8008"
|
||||
due_on: <%= 3.days.from_now %>
|
||||
created_at: <%= 1.week.ago %>
|
||||
boost_count: 5
|
||||
boosts_count: 5
|
||||
comments_count: 2
|
||||
activity_score: 7
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class BubbleTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "boosting" do
|
||||
assert_difference %w[ bubbles(:logo).boost_count bubbles(:logo).activity_score Event.count ], +1 do
|
||||
assert_difference %w[ bubbles(:logo).boosts_count bubbles(:logo).activity_score Event.count ], +1 do
|
||||
bubbles(:logo).boost!
|
||||
end
|
||||
end
|
||||
@@ -33,7 +33,7 @@ class BubbleTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "ordering by activity" do
|
||||
bubbles(:layout).tap { |b| b.update!(boost_count: 1_000) }.rescore
|
||||
bubbles(:layout).tap { |b| b.update!(boosts_count: 1_000) }.rescore
|
||||
assert_equal bubbles(:layout, :logo, :shipping, :text), Bubble.ordered_by_activity
|
||||
end
|
||||
|
||||
@@ -42,7 +42,7 @@ class BubbleTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "ordering by boosts" do
|
||||
bubbles(:layout).update! boost_count: 1_000
|
||||
bubbles(:layout).update! boosts_count: 1_000
|
||||
assert_equal bubbles(:layout, :logo, :shipping, :text), Bubble.ordered_by_boosts
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user