Skip to content

Commit f56b482

Browse files
committed
Add kudos_count to projects and update related associations and fixtures
1 parent 4f82870 commit f56b482

7 files changed

Lines changed: 13 additions & 3 deletions

File tree

app/controllers/projects_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class ProjectsController < ApplicationController
44
def index
55
@projects = current_user.projects.where(is_deleted: false)
66
.order_by_recent_journal
7-
.includes(:banner_attachment)
7+
.includes(:demo_picture_attachment)
8+
.preload(:latest_journal_entry)
89
end
910

1011
def explore

app/models/kudo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#
2222
class Kudo < ApplicationRecord
2323
belongs_to :user
24-
belongs_to :project
24+
belongs_to :project, counter_cache: true
2525

2626
validates :content, presence: true
2727
validate :user_cannot_give_kudos_to_own_project

app/models/project.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# hackatime_project_keys :string default([]), is an Array
1717
# is_deleted :boolean default(FALSE)
1818
# journal_entries_count :integer default(0), not null
19+
# kudos_count :integer default(0), not null
1920
# needs_funding :boolean default(TRUE)
2021
# needs_soldering_iron :boolean default(FALSE), not null
2122
# print_legion :boolean default(FALSE), not null
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddKudosCountToProjects < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :projects, :kudos_count, :integer, default: 0, null: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/projects.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# hackatime_project_keys :string default([]), is an Array
1919
# is_deleted :boolean default(FALSE)
2020
# journal_entries_count :integer default(0), not null
21+
# kudos_count :integer default(0), not null
2122
# needs_funding :boolean default(TRUE)
2223
# needs_soldering_iron :boolean default(FALSE), not null
2324
# print_legion :boolean default(FALSE), not null

test/models/project_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# hackatime_project_keys :string default([]), is an Array
1717
# is_deleted :boolean default(FALSE)
1818
# journal_entries_count :integer default(0), not null
19+
# kudos_count :integer default(0), not null
1920
# needs_funding :boolean default(TRUE)
2021
# needs_soldering_iron :boolean default(FALSE), not null
2122
# print_legion :boolean default(FALSE), not null

0 commit comments

Comments
 (0)