Skip to content

Commit c320c20

Browse files
committed
test: #count_month_sale_product
1 parent 2a0c8b7 commit c320c20

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

spec/factories/sale_product.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
value { Faker::Commerce.price }
77
created_at { Faker::Time.between(from: DateTime.now - 1, to: DateTime.now) }
88
updated_at { Faker::Time.between(from: DateTime.now - 1, to: DateTime.now) }
9-
account_id { Faker::Number.between(1, 100) }
10-
product_id { Faker::Number.between(1, 100) }
11-
sale_id { create(:sale).id }
9+
account
10+
product
11+
sale
1212
end
13-
end
13+
end

spec/models/product_spec.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@
7373
end
7474
end
7575

76-
# describe '#count_month_sale_product' do
77-
# it 'returns the sum of quantities for sale products in the given month' do
78-
# year = Time.zone.now.year
79-
# month = Time.zone.now.month
80-
# create(:sale_product, product: product, quantity: 5, created_at: Time.zone.local(year, month, 15))
81-
# create(:sale_product, product: product, quantity: 3, created_at: Time.zone.local(year, month, 20))
82-
# expect(product.count_month_sale_product(year, month)).to eq(8)
83-
# end
84-
# end
76+
describe '#count_month_sale_product' do
77+
let(:account) { create(:account) }
78+
79+
it 'returns the sum of quantities for sale products in the given month' do
80+
year = Time.zone.now.year
81+
month = Time.zone.now.month
82+
create(:sale_product, product:, account:, quantity: 5, created_at: Time.zone.local(year, month, 15))
83+
create(:sale_product, product:, account:, quantity: 3, created_at: Time.zone.local(year, month, 20))
84+
85+
expect(product.count_month_sale_product(year, month)).to eq(8)
86+
end
87+
end
8588

8689
# describe '#sum_simplo_items' do
8790
# it 'returns the sum of quantities for simplo items' do

0 commit comments

Comments
 (0)