From e117f4e5af567f4b5eac29df8118ab519436a0d6 Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Tue, 19 Nov 2024 14:22:51 -0600 Subject: [PATCH] boost_count -> boosts_count This aligns better with counter_cache conventions, in case we turn boosts into a model later --- app/models/bubble.rb | 2 +- app/models/bubble/boostable.rb | 4 ++-- app/views/boosts/_boosts.html.erb | 4 ++-- .../20241119201943_rename_boost_count_to_boosts_count.rb | 5 +++++ db/schema.rb | 4 ++-- test/controllers/boosts_controller_test.rb | 2 +- test/fixtures/bubbles.yml | 2 +- test/models/bubble_test.rb | 6 +++--- 8 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20241119201943_rename_boost_count_to_boosts_count.rb diff --git a/app/models/bubble.rb b/app/models/bubble.rb index 7364a0841..5da059a49 100644 --- a/app/models/bubble.rb +++ b/app/models/bubble.rb @@ -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 diff --git a/app/models/bubble/boostable.rb b/app/models/bubble/boostable.rb index 330f80cdf..226671803 100644 --- a/app/models/bubble/boostable.rb +++ b/app/models/bubble/boostable.rb @@ -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 diff --git a/app/views/boosts/_boosts.html.erb b/app/views/boosts/_boosts.html.erb index ec91dcb16..975684583 100644 --- a/app/views/boosts/_boosts.html.erb +++ b/app/views/boosts/_boosts.html.erb @@ -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 %> diff --git a/db/migrate/20241119201943_rename_boost_count_to_boosts_count.rb b/db/migrate/20241119201943_rename_boost_count_to_boosts_count.rb new file mode 100644 index 000000000..aff5d0b3a --- /dev/null +++ b/db/migrate/20241119201943_rename_boost_count_to_boosts_count.rb @@ -0,0 +1,5 @@ +class RenameBoostCountToBoostsCount < ActiveRecord::Migration[8.0] + def change + rename_column :bubbles, :boost_count, :boosts_count + end +end diff --git a/db/schema.rb b/db/schema.rb index 87b4b4222..9754ac707 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/test/controllers/boosts_controller_test.rb b/test/controllers/boosts_controller_test.rb index ce8135c78..ae644d5bd 100644 --- a/test/controllers/boosts_controller_test.rb +++ b/test/controllers/boosts_controller_test.rb @@ -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 diff --git a/test/fixtures/bubbles.yml b/test/fixtures/bubbles.yml index 99a0fa5bc..556637e7c 100644 --- a/test/fixtures/bubbles.yml +++ b/test/fixtures/bubbles.yml @@ -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 diff --git a/test/models/bubble_test.rb b/test/models/bubble_test.rb index bf0dde5f4..40cdbe4ad 100644 --- a/test/models/bubble_test.rb +++ b/test/models/bubble_test.rb @@ -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