Skip to content

Commit 95f6751

Browse files
committed
PC-24: Fixed lint and specs
1 parent 311e5f1 commit 95f6751

8 files changed

Lines changed: 29 additions & 17 deletions

File tree

app/models/categorization.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Categorization < ApplicationRecord
2+
belongs_to :quote
3+
belongs_to :category
4+
end

app/models/category.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class Category < ApplicationRecord
22
ASCII_CHARACTERS = /\A[[:ascii:]]*\z/
33

44
has_many :items, dependent: :nullify
5-
has_and_belongs_to_many :quotes
5+
has_many :categorizations, dependent: :destroy
6+
has_many :quotes, through: :categorizations
67

78
normalizes :name, with: ->(name) { name.gsub(/\s+/, ' ').strip }
89

app/models/quote.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class Quote < ApplicationRecord
22
belongs_to :customer
33
belongs_to :user
44
has_many :quote_items, dependent: :destroy
5-
has_and_belongs_to_many :categories
5+
has_many :categorizations, dependent: :destroy
6+
has_many :categories, through: :categorizations
67

78
validates :total_price, presence: true, numericality: { greater_than_or_equal_to: 0 }
89

db/migrate/20250423145035_create_join_table_quotes_categories.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateCategorizations < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :categorizations do |t|
4+
t.references :quote, null: false, foreign_key: true
5+
t.references :category, null: false, foreign_key: true
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/quote_items.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
association :item, factory: :item
55
price { 100.00 }
66
discount { 10 }
7-
open_parameters { {} }
7+
pricing_parameters { {} }
88
end
99
end

spec/models/customer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
require 'rails_helper'
22

33
RSpec.describe Customer, type: :model do
4+
subject { build(:customer) }
5+
46
describe 'associations' do
57
it { is_expected.to have_many(:quotes).dependent(:destroy) }
68
end
79

810
describe 'validations' do
9-
let(:customer) { build(:customer) }
10-
1111
it { is_expected.to be_valid }
1212

1313
describe 'company_name' do

0 commit comments

Comments
 (0)