-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstimulus_case_study_spec.rb
66 lines (52 loc) · 2.11 KB
/
stimulus_case_study_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Question::StimulusCaseStudy do
it_behaves_like "a Question", has_parts: true
its(:type_label) { is_expected.to eq("Case Study") }
its(:type_name) { is_expected.to eq("Stimulus Case Study") }
it { is_expected.to have_many(:as_parent_question_aggregations) }
it { is_expected.to have_many(:child_questions) }
describe '.build_row' do
subject { described_class.build_row(row:, questions: { 1 => FactoryBot.build(:question_stimulus_case_study) }) }
context 'when PART_OF another question' do
let(:row) do
CsvRow.new("TITLE" => "Title",
"PART_OF" => 1,
"IMPORT_ID" => 2,
"TEXT" => "Hello World")
end
it { is_expected.not_to be_valid }
end
context 'when PART_OF another question' do
let(:row) do
CsvRow.new("TITLE" => "Title",
"IMPORT_ID" => 2,
"TEXT" => "Hello World")
end
it { is_expected.to be_valid }
end
end
describe 'factories' do
it "generates child questions" do
expect do
expect do
FactoryBot.create(:question_stimulus_case_study)
end.to change(Question::StimulusCaseStudy, :count).by(1)
end.to change(QuestionAggregation, :count)
# We want to verify that the factory also creates the child questions
expect(Question.where(child_of_aggregation: true).count).to eq(QuestionAggregation.count)
end
end
describe '#data' do
subject { FactoryBot.create(:question_stimulus_case_study).data }
it "is comprised of the child_question's metadata" do
expect(subject).to be_a(Array)
# All elements are Hashes
expect(subject.all? { |d| d.is_a?(Hash) }).to eq(true)
# Making an assumption about the factory; namely that the first element is a scenario.
expect(subject[0].keys).to match_array(["type_label", "type_name", "text"])
# The second element is a non-scenario Question, and thus has data.
expect(subject[1].keys).to match_array(["type_label", "type_name", "text", "data"])
end
end
end