2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-05-25 16:42:16 -05:00
|
|
|
describe CategoryDetailedSerializer do
|
|
|
|
|
|
|
|
describe "counts" do
|
|
|
|
it "works for categories with no subcategories" do
|
2016-08-17 16:23:16 -05:00
|
|
|
no_subcats = Fabricate(:category, topics_year: 10, topics_month: 5, topics_day: 2)
|
2015-05-25 16:42:16 -05:00
|
|
|
json = CategoryDetailedSerializer.new(no_subcats, scope: Guardian.new, root: false).as_json
|
2015-05-26 04:42:37 -05:00
|
|
|
expect(json[:topics_year]).to eq(10)
|
|
|
|
expect(json[:topics_month]).to eq(5)
|
|
|
|
expect(json[:topics_day]).to eq(2)
|
2015-05-25 16:42:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes counts from subcategories" do
|
2016-08-17 16:23:16 -05:00
|
|
|
parent = Fabricate(:category, topics_year: 10, topics_month: 5, topics_day: 2)
|
|
|
|
subcategory = Fabricate(:category, parent_category_id: parent.id, topics_year: 1, topics_month: 1, topics_day: 1)
|
2015-05-25 16:42:16 -05:00
|
|
|
json = CategoryDetailedSerializer.new(parent, scope: Guardian.new, root: false).as_json
|
2015-05-26 04:42:37 -05:00
|
|
|
expect(json[:topics_year]).to eq(11)
|
|
|
|
expect(json[:topics_month]).to eq(6)
|
|
|
|
expect(json[:topics_day]).to eq(3)
|
2015-05-25 16:42:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|