Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Product < ApplicationRecord
include Notifications


has_many :wishlist_products, dependent: :destroy
has_many :wishlists, through: :wishlist_products
has_one_attached :featured_image
has_rich_text :description
has_many :subscribers, dependent: :destroy
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class User < ApplicationRecord
has_secure_password
has_many :sessions, dependent: :destroy
has_many :wishlists, dependent: :destroy

Check failure on line 4 in app/models/user.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.

attr_readonly :admin

Expand Down
7 changes: 7 additions & 0 deletions app/models/wishlist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Wishlist < ApplicationRecord
belongs_to :user
has_many :wishlist_products, dependent: :destroy
has_many :products, through: :wishlist_products

to_param :name
end
6 changes: 6 additions & 0 deletions app/models/wishlist_product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class WishlistProduct < ApplicationRecord
belongs_to :product, counter_cache: :wishlists_count
belongs_to :wishlist, counter_cache: :products_count

validates :product_id, uniqueness: { scope: :wishlist_id }
end
11 changes: 11 additions & 0 deletions db/migrate/20260127155829_create_wishlists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateWishlists < ActiveRecord::Migration[8.1]
def change
create_table :wishlists do |t|
t.belongs_to :user, null: false, foreign_key: true
t.string :name
t.integer :products_count, default:0

Check failure on line 6 in db/migrate/20260127155829_create_wishlists.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.

Check failure on line 6 in db/migrate/20260127155829_create_wishlists.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceAfterColon: Space missing after colon.

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20260127155849_create_wishlist_products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateWishlistProducts < ActiveRecord::Migration[8.1]
def change
create_table :wishlist_products do |t|
t.belongs_to :product, null: false, foreign_key: true
t.belongs_to :wishlist, null: false, foreign_key: true

t.timestamps
end

add index :wishlist_products, [:product_id, :wishlist_id],

Check failure on line 10 in db/migrate/20260127155849_create_wishlist_products.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 10 in db/migrate/20260127155849_create_wishlist_products.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
unique: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20260127162030_add_wishlists_count_to_products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWishlistsCountToProducts < ActiveRecord::Migration[8.1]
def change
add_column :products, :wishlists_count, :integer, default:0

Check failure on line 3 in db/migrate/20260127162030_add_wishlists_count_to_products.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceAfterColon: Space missing after colon.
end
end
9 changes: 9 additions & 0 deletions test/fixtures/wishlist_products.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
product: one
wishlist: one

two:
product: two
wishlist: two
11 changes: 11 additions & 0 deletions test/fixtures/wishlists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
user: one
name: MyString
products_count: 1

two:
user: two
name: MyString
products_count: 1
2 changes: 1 addition & 1 deletion test/integration/settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
get store_products_path
assert_response :success
end

Check failure on line 37 in test/integration/settings_test.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
test "admins can access /store/users" do
sign_in_as users(:admin)
get store_users_path
assert_response :success
end

Check failure on line 43 in test/integration/settings_test.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end.
end
7 changes: 7 additions & 0 deletions test/models/wishlist_product_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class WishlistProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/wishlist_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class WishlistTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading