summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/product_review.rb4
-rw-r--r--db/migrate/20230331001256_create_product_reviews.rb12
-rw-r--r--db/schema.rb15
-rw-r--r--spec/models/product_review_spec.rb5
-rw-r--r--spec/requests/cards_controller/update_spec.rb3
5 files changed, 37 insertions, 2 deletions
diff --git a/app/models/product_review.rb b/app/models/product_review.rb
new file mode 100644
index 0000000..49e344c
--- /dev/null
+++ b/app/models/product_review.rb
@@ -0,0 +1,4 @@
+class ProductReview < ApplicationRecord
+ belongs_to :user_account
+ belongs_to :product
+end
diff --git a/db/migrate/20230331001256_create_product_reviews.rb b/db/migrate/20230331001256_create_product_reviews.rb
new file mode 100644
index 0000000..a5fec1a
--- /dev/null
+++ b/db/migrate/20230331001256_create_product_reviews.rb
@@ -0,0 +1,12 @@
+class CreateProductReviews < ActiveRecord::Migration[7.0]
+ def change
+ create_table :product_reviews do |t|
+ t.references :user_account, null: false, foreign_key: true
+ t.references :product, null: false, foreign_key: true
+ t.text :review
+ t.integer :rating
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 11c178a..8506e8d 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[7.0].define(version: 2023_03_25_061452) do
+ActiveRecord::Schema[7.0].define(version: 2023_03_31_001256) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -69,6 +69,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_25_061452) do
t.datetime "updated_at", null: false
end
+ create_table "product_reviews", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
+ t.bigint "user_account_id", null: false
+ t.bigint "product_id", null: false
+ t.text "review"
+ t.integer "rating"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["product_id"], name: "index_product_reviews_on_product_id"
+ t.index ["user_account_id"], name: "index_product_reviews_on_user_account_id"
+ end
+
create_table "products", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "public_id"
t.string "name"
@@ -106,5 +117,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_25_061452) 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 "cards", "user_accounts"
+ add_foreign_key "product_reviews", "products"
+ add_foreign_key "product_reviews", "user_accounts"
add_foreign_key "products", "companies"
end
diff --git a/spec/models/product_review_spec.rb b/spec/models/product_review_spec.rb
new file mode 100644
index 0000000..9dfbff2
--- /dev/null
+++ b/spec/models/product_review_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ProductReview, type: :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/requests/cards_controller/update_spec.rb b/spec/requests/cards_controller/update_spec.rb
index 013eba3..77b4c4f 100644
--- a/spec/requests/cards_controller/update_spec.rb
+++ b/spec/requests/cards_controller/update_spec.rb
@@ -24,7 +24,8 @@ RSpec.describe 'PUT /api/account/addresses', type: :request do
"Security code can't be blank"]
end
let(:expected_text) do
- [new_card.number, new_card.expiration_year, new_card.expiration_month, new_card.expiration_day, new_card.security_code]
+ [new_card.number, new_card.expiration_year, new_card.expiration_month, new_card.expiration_day,
+ new_card.security_code]
end
let(:wrong_params) do
{ number: SecureRandom.hex(24), expiration_year: -20, expiration_month: 13, expiration_day: 33,