-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec for serializer and start of spec for queries
- Loading branch information
1 parent
c5bf191
commit 738b79e
Showing
6 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :daily_classification_count, class: 'ClassificationCounts::DailyClassificationCount' do | ||
day { Date.today } | ||
classification_count { 212 } | ||
period { Date.today } | ||
count { 212 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe CountClassifications do | ||
describe 'relation' do | ||
let(:params) { {} } | ||
let(:count_classifications) { described_class.new(params) } | ||
it 'returns DailyClassificationCount if not given workflow or project ids' do | ||
expect(count_classifications.counts.model).to be ClassificationCounts::DailyClassificationCount | ||
end | ||
|
||
it 'returns DailyWorkflowClassificationCount if workflow_id given' do | ||
params[:workflow_id] = 2 | ||
expect(count_classifications.counts.model).to be ClassificationCounts::DailyWorkflowClassificationCount | ||
end | ||
|
||
it 'returns DailyProjectClassificationCount if workflow_id given' do | ||
params[:project_id] = 2 | ||
expect(count_classifications.counts.model).to be ClassificationCounts::DailyProjectClassificationCount | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ClassificationCountsSerializer do | ||
let(:classification_count) { build(:daily_classification_count) } | ||
let(:count_serializer) { described_class.new([classification_count]) } | ||
|
||
it 'returns total_count when period not given' do | ||
serialized = count_serializer.as_json(serializer_options: {}) | ||
expect(serialized).to have_key(:total_count) | ||
expect(serialized).not_to have_key(:data) | ||
expect(serialized[:total_count]).to eq(classification_count.count) | ||
end | ||
|
||
it 'returns total_count and data when period is given' do | ||
serialized = count_serializer.as_json(serializer_options: { period: 'year' }) | ||
expect(serialized).to have_key(:total_count) | ||
expect(serialized).to have_key(:data) | ||
expect(serialized[:data].size).to eq(1) | ||
end | ||
|
||
it 'sums up total_count correctly' do | ||
classification_count2 = build(:daily_classification_count) | ||
classification_counts = [classification_count, classification_count2] | ||
serializer = described_class.new(classification_counts) | ||
serialized = serializer.as_json(serializer_options: {}) | ||
expect(serialized[:total_count]).to eq(classification_counts.sum(&:count)) | ||
end | ||
end |