quby 4.0.2 → 5.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +0 -1
  3. data/lib/quby.rb +2 -10
  4. data/lib/quby/answers/entities/answer.rb +4 -2
  5. data/lib/quby/answers/services/outcome_calculation.rb +1 -2
  6. data/lib/quby/answers/services/score_calculator.rb +1 -3
  7. data/lib/quby/engine.rb +0 -1
  8. data/lib/quby/questionnaires.rb +1 -0
  9. data/lib/quby/questionnaires/api.rb +5 -1
  10. data/lib/quby/questionnaires/deserializer.rb +439 -0
  11. data/lib/quby/questionnaires/dsl.rb +12 -15
  12. data/lib/quby/questionnaires/entities.rb +1 -0
  13. data/lib/quby/questionnaires/entities/charting/line_chart.rb +23 -0
  14. data/lib/quby/questionnaires/entities/charting/overview_chart.rb +3 -1
  15. data/lib/quby/questionnaires/entities/definition.rb +3 -5
  16. data/lib/quby/questionnaires/entities/fields.rb +0 -15
  17. data/lib/quby/questionnaires/entities/question.rb +9 -32
  18. data/lib/quby/questionnaires/entities/questionnaire.rb +4 -15
  19. data/lib/quby/questionnaires/entities/questions/checkbox_question.rb +0 -24
  20. data/lib/quby/questionnaires/entities/questions/date_question.rb +0 -8
  21. data/lib/quby/questionnaires/entities/score_calculation.rb +36 -3
  22. data/lib/quby/questionnaires/repos.rb +1 -0
  23. data/lib/quby/questionnaires/repos/bundle_disk_repo.rb +51 -0
  24. data/lib/quby/table_backend/range_tree.rb +0 -51
  25. data/lib/quby/version.rb +1 -1
  26. data/spec/features/tables_spec.rb +40 -0
  27. data/spec/internal/log/test-events.log +531 -0
  28. data/spec/internal/log/test.log +21098 -0
  29. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-22-54.041.html +207 -0
  30. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-22-54.041.png +0 -0
  31. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-23.175.html +323 -0
  32. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-23.175.png +0 -0
  33. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-32.352.html +323 -0
  34. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-32.352.png +0 -0
  35. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-35.247.html +323 -0
  36. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-35.247.png +0 -0
  37. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-38.152.html +323 -0
  38. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-38.152.png +0 -0
  39. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-41.012.html +323 -0
  40. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-41.012.png +0 -0
  41. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-43.918.html +323 -0
  42. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-43.918.png +0 -0
  43. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-46.782.html +323 -0
  44. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-46.782.png +0 -0
  45. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-49.678.html +323 -0
  46. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-49.678.png +0 -0
  47. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-52.495.html +323 -0
  48. data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-52.495.png +0 -0
  49. data/spec/internal/tmp/capybara/screenshot_2020-10-27-14-25-21.063.html +207 -0
  50. data/spec/internal/tmp/capybara/screenshot_2020-10-27-14-25-21.063.png +0 -0
  51. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-21-57.510.html +1 -0
  52. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-21-57.510.png +0 -0
  53. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-23-56.006.html +1 -0
  54. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-23-56.006.png +0 -0
  55. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-24-43.842.html +12 -0
  56. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-24-43.842.png +0 -0
  57. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-04.631.html +12 -0
  58. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-04.631.png +0 -0
  59. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-11.690.html +12 -0
  60. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-11.690.png +0 -0
  61. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-25.111.html +12 -0
  62. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-25.111.png +0 -0
  63. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-57.026.html +12 -0
  64. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-57.026.png +0 -0
  65. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-13.545.html +12 -0
  66. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-13.545.png +0 -0
  67. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-45.475.html +12 -0
  68. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-45.475.png +0 -0
  69. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-32-13.907.html +1 -0
  70. data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-32-13.907.png +0 -0
  71. data/spec/quby/answers/services/answer_validations_spec.rb +8 -8
  72. data/spec/quby/answers/services/score_calculator_spec.rb +4 -14
  73. data/spec/quby/questionnaires/deserializer/questionnaire_spec.rb +237 -0
  74. data/spec/quby/questionnaires/dsl_spec.rb +0 -9
  75. data/spec/quby/questionnaires/entities/fields_spec.rb +3 -3
  76. data/spec/quby/questionnaires/entities/question_spec.rb +0 -8
  77. data/spec/quby/questionnaires/entities/questionnaire_spec.rb +2 -26
  78. data/spec/quby/table_backend/range_tree_spec.rb +46 -13
  79. data/spec/spec_helper.rb +1 -1
  80. metadata +108 -55
  81. data/lib/quby/lookup_table.rb +0 -29
  82. data/lib/quby/lookup_table_repo.rb +0 -24
  83. data/lib/quby/questionnaires/dsl/base.rb +0 -20
  84. data/lib/quby/questionnaires/dsl/calls_custom_methods.rb +0 -29
  85. data/lib/quby/questionnaires/dsl/charting/bar_chart_builder.rb +0 -18
  86. data/lib/quby/questionnaires/dsl/charting/chart_builder.rb +0 -91
  87. data/lib/quby/questionnaires/dsl/charting/line_chart_builder.rb +0 -47
  88. data/lib/quby/questionnaires/dsl/charting/overview_chart_builder.rb +0 -31
  89. data/lib/quby/questionnaires/dsl/charting/radar_chart_builder.rb +0 -18
  90. data/lib/quby/questionnaires/dsl/helpers.rb +0 -51
  91. data/lib/quby/questionnaires/dsl/panel_builder.rb +0 -80
  92. data/lib/quby/questionnaires/dsl/question_builder.rb +0 -40
  93. data/lib/quby/questionnaires/dsl/questionnaire_builder.rb +0 -252
  94. data/lib/quby/questionnaires/dsl/questions/base.rb +0 -179
  95. data/lib/quby/questionnaires/dsl/questions/checkbox_question_builder.rb +0 -20
  96. data/lib/quby/questionnaires/dsl/questions/date_question_builder.rb +0 -18
  97. data/lib/quby/questionnaires/dsl/questions/deprecated_question_builder.rb +0 -18
  98. data/lib/quby/questionnaires/dsl/questions/float_question_builder.rb +0 -21
  99. data/lib/quby/questionnaires/dsl/questions/integer_question_builder.rb +0 -21
  100. data/lib/quby/questionnaires/dsl/questions/radio_question_builder.rb +0 -20
  101. data/lib/quby/questionnaires/dsl/questions/select_question_builder.rb +0 -18
  102. data/lib/quby/questionnaires/dsl/questions/string_question_builder.rb +0 -20
  103. data/lib/quby/questionnaires/dsl/questions/text_question_builder.rb +0 -22
  104. data/lib/quby/questionnaires/dsl/score_builder.rb +0 -22
  105. data/lib/quby/questionnaires/dsl/standardized_panel_generators.rb +0 -33
  106. data/lib/quby/questionnaires/dsl/table_builder.rb +0 -48
  107. data/lib/quby/questionnaires/services/definition_validator.rb +0 -298
  108. data/spec/benchmarks/load_normscore_csv.rb +0 -18
  109. data/spec/quby/lookup_table_repo_spec.rb +0 -20
  110. data/spec/quby/lookup_table_spec.rb +0 -38
  111. data/spec/quby/questionnaires/dsl/calls_custom_methods_spec.rb +0 -38
  112. data/spec/quby/questionnaires/dsl/charting/bar_chart_builder_spec.rb +0 -41
  113. data/spec/quby/questionnaires/dsl/charting/chart_builder_spec.rb +0 -127
  114. data/spec/quby/questionnaires/dsl/charting/line_chart_builder_spec.rb +0 -58
  115. data/spec/quby/questionnaires/dsl/charting/radar_chart_builder_spec.rb +0 -41
  116. data/spec/quby/questionnaires/dsl/helpers_spec.rb +0 -80
  117. data/spec/quby/questionnaires/dsl/questionnaire_builder_spec.rb +0 -480
  118. data/spec/quby/questionnaires/services/definition_validator_spec.rb +0 -793
  119. data/spec/support/examples_for_chart_builders.rb +0 -59
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- feature 'Load normscore csv file', benchmark: true do
6
- it 'loads a csv file' do
7
- 10.times do
8
- Quby.lookup_table_repo.retrieve('test')
9
- end
10
- end
11
-
12
- it 'builds a tree' do
13
- data = Quby.lookup_table_repo.retrieve('test')
14
- 10.times do
15
- Quby::TableBackend::RangeTree.new(data).send :tree
16
- end
17
- end
18
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Quby::LookupTableRepo::Disk do
4
- subject { Quby.lookup_table_repo }
5
-
6
- it 'Quby.lookup_table_repo is a disk repo by default' do
7
- expect(subject).to be_an_instance_of(described_class)
8
- end
9
-
10
- describe '#retrieve' do
11
- it 'reads the csv file' do
12
- expect(CSV).to receive(:read).and_call_original
13
- subject.retrieve 'test'
14
- end
15
-
16
- it 'fails when csv file is not found' do
17
- expect { subject.retrieve 'not_there' }.to raise_error(Errno::ENOENT)
18
- end
19
- end
20
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby
6
- describe LookupTable do
7
- let(:table) { described_class.new('test') }
8
- let(:fake_backing) { double(:"present?" => true).as_null_object }
9
-
10
- describe '#lookup' do
11
- it 'passes lookup calls on to the backing' do
12
- expect(Quby::TableBackend::RangeTree).to receive(:from_csv).and_return(fake_backing)
13
- parameters = {a: 1}
14
- expect(table.backing).to receive(:lookup).with(parameters)
15
- table.lookup(parameters)
16
- end
17
-
18
- it 'initializes the disktree lazily' do
19
- headers = double
20
- compare = double
21
- data = double
22
- data_double = [headers, compare, data]
23
- table
24
- expect_any_instance_of(described_class).to receive(:data).and_return(data_double)
25
- expect(Quby::TableBackend::RangeTree).to receive(:from_csv).with(levels: headers, compare: compare, data:[data]).and_return(fake_backing)
26
- table.lookup(some: :thing)
27
- end
28
- end
29
-
30
- describe '#data' do
31
- it 'calls Quby.lookup_table_repo.retrieve(table.key)' do
32
- table
33
- expect(Quby.lookup_table_repo).to receive(:retrieve).with(table.key)
34
- table.data
35
- end
36
- end
37
- end
38
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe CallsCustomMethods do
7
-
8
- class TestCustomMethod
9
- prepend CallsCustomMethods
10
-
11
- attr_reader :test
12
- def initialize(*args)
13
- @test = 'attribute'
14
- end
15
- end
16
-
17
- let(:custom_methods) { {custom: -> { 'custom_method' }} }
18
- let(:test_object) { TestCustomMethod.new(custom_methods: custom_methods) }
19
-
20
- describe 'prepending' do
21
- it 'does not skip the actual initializer' do
22
- expect(test_object.test).to eq('attribute')
23
- end
24
- end
25
-
26
- describe '#method_missing' do
27
- it 'allows the class to receive messages defined in custom_methods' do
28
- expect(test_object.custom).to eq('custom_method')
29
- end
30
- end
31
-
32
- describe '#respond_to_missing?' do
33
- it 'also considers custom methods' do
34
- expect(test_object.send(:respond_to_missing?, :custom)).to eq(true)
35
- end
36
- end
37
- end
38
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe BarChartBuilder do
7
- it_behaves_like ChartBuilder
8
-
9
- let(:questionnaire) { double(key: 'questionnaire_key') }
10
-
11
- it 'makes a bar chart' do
12
- expect(dsl { }).to be_an_instance_of(::Quby::Questionnaires::Entities::Charting::BarChart)
13
- end
14
-
15
- def dsl(key = :test, options = {}, &block)
16
- builder = BarChartBuilder.new(questionnaire, key, options)
17
- builder.build(&block)
18
- end
19
-
20
- it 'sets y-axis range' do
21
- expect(dsl { range 0..40 }.y_range).to eq (0..40)
22
- end
23
-
24
- it 'sets y-axis tick interval' do
25
- expect(dsl { tick_interval 1 }.tick_interval).to eq 1
26
- end
27
-
28
- it 'sets plotlines' do
29
- plotlines =
30
- dsl do
31
- plotline 40, :orange
32
- plotline 60, :red
33
- end.plotlines
34
-
35
- expect(plotlines).to eq [
36
- {value: 40, color: :orange, width: 1, zIndex: 3},
37
- {value: 60, color: :red, width: 1, zIndex: 3}
38
- ]
39
- end
40
- end
41
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe ChartBuilder do
7
-
8
- let(:plottable_key) { :some_key }
9
- let(:plottable) { Quby::Questionnaires::Entities::ScoreCalculation.new plottable_key, {} }
10
- let(:questionnaire) do
11
- double(key: 'questionnaire_key').tap do |questionnaire|
12
- allow(questionnaire).to receive(:find_plottable).with(plottable_key).and_return plottable
13
- end
14
- end
15
- let(:chart_plottables) { [] }
16
- let(:chart_class) { Quby::Questionnaires::Entities::Charting::Chart }
17
- before { ChartBuilder.set_chart_class(chart_class) }
18
- let(:chart_builder) { ChartBuilder.new questionnaire, 'chart_key' }
19
-
20
- def dsl(key = :test, options = {}, &block)
21
- builder = ChartBuilder.new(questionnaire, key, options)
22
- builder.build(&block)
23
- end
24
-
25
- describe '#plot' do
26
- it 'fetches a plottable by key from the questionnaire' do
27
- expect(questionnaire).to receive(:find_plottable).with(plottable_key)
28
- chart_builder.plot plottable_key
29
- end
30
-
31
- it 'creates a plottable with the options merged into the plottable options' do
32
- allow(plottable).to receive(:options).and_return({some: 'options', other: 'options'})
33
- expect(Quby::Questionnaires::Entities::Charting::Plottable).to receive(:new)
34
- .with(plottable.key,
35
- some: 'different_options',
36
- other: 'options',
37
- questionnaire_key: 'questionnaire_key')
38
- chart_builder.plot plottable_key, some: 'different_options'
39
- end
40
-
41
- it 'sets the label from a question title when no label is present' do
42
- plottable = Quby::Questionnaires::Entities::Question.new plottable_key, title: 'some_title'
43
- expect(questionnaire).to receive(:find_plottable).with(plottable_key).and_return plottable
44
- expect(Quby::Questionnaires::Entities::Charting::Plottable).to receive(:new)
45
- .with(plottable_key, questionnaire_key: 'questionnaire_key', label: 'some_title')
46
- chart_builder.plot plottable_key
47
- end
48
-
49
- it 'does not set the label when it is given in the options' do
50
- plottable = Quby::Questionnaires::Entities::Question.new plottable_key, title: 'some_title'
51
- expect(questionnaire).to receive(:find_plottable).with(plottable_key).and_return plottable
52
- expect(Quby::Questionnaires::Entities::Charting::Plottable).to receive(:new)
53
- .with(plottable_key, questionnaire_key: 'questionnaire_key', label: 'some_label')
54
- chart_builder.plot plottable_key, label: 'some_label'
55
- end
56
- end
57
-
58
- describe '#y_categories' do
59
- it 'assigns y_categories' do
60
- categories = %w(Bad Great Best)
61
- chart_builder.y_categories categories
62
- expect(chart_builder.build { }.y_categories).to eq(categories)
63
- end
64
- end
65
-
66
- describe '#plotband' do
67
- it 'can set plotbands' do
68
- plotbands =
69
- dsl do
70
- plotband 2, 5, :yellow
71
- plotband 5, 8, :red
72
- end.plotbands
73
-
74
- expect(plotbands).to eq [
75
- {from: 2, to: 5, color: :yellow},
76
- {from: 5, to: 8, color: :red}
77
- ]
78
- end
79
- end
80
-
81
- describe '#y_range_categories' do
82
- it 'sets RangeCategories.new(*parameters).as_range_hash to the chart y_range_categories' do
83
- expect(RangeCategories).to receive(:new).with(0, 'Zeer laag', 30).and_return(double(as_range_hash: 'foo'))
84
- chart_builder.y_range_categories 0, 'Zeer laag', 30
85
- expect(chart_builder.build { }.y_range_categories).to eq('foo')
86
- end
87
-
88
- it 'converts the parameters to a range hash' do
89
- expected_categories = {(0.0...30.0) => "Zeer laag", (30.0...40.0) => "Laag", (40.0...60.0) => "Gemiddeld",
90
- (60.0...70.0) => "Hoog", (70.0..100.0) => "Zeer hoog"}
91
- chart_builder.y_range_categories 0, 'Zeer laag',
92
- 30, 'Laag',
93
- 40, 'Gemiddeld',
94
- 60, 'Hoog',
95
- 70, 'Zeer hoog', 100
96
- expect(chart_builder.build { }.y_range_categories).to eq(expected_categories)
97
- end
98
- end
99
-
100
- describe '#range' do
101
- it 'assigns y_range' do
102
- chart_builder.range 0..5
103
- expect(chart_builder.build { }.y_range).to eq(0..5)
104
- end
105
- end
106
- describe '#validate' do
107
- describe 'when there is no range defined but y_categories are present' do
108
- it 'uses the 0..y_categories.count-1 as a range' do
109
- chart_builder.y_categories %w(Bad Great Best)
110
- expect(chart_builder.build { }.y_range).to eq(0..2)
111
- end
112
- end
113
- describe 'when range and y_categories are present' do
114
- it 'raises if the range does not correspond to the y_categories length' do
115
- chart_builder.range 0..3
116
- chart_builder.y_categories %w(Bad Great Best)
117
- expect { chart_builder.build { } }.to raise_error(ArgumentError)
118
- end
119
- it 'does not raise if the range matches the y_categories' do
120
- chart_builder.range 0..2
121
- chart_builder.y_categories %w(Bad Great Best)
122
- expect { chart_builder.build { } }.not_to raise_error
123
- end
124
- end
125
- end
126
- end
127
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe LineChartBuilder do
7
- it_behaves_like ChartBuilder
8
-
9
- let(:questionnaire) { double(key: 'questionnaire_key') }
10
-
11
- it 'sets y-axis label' do
12
- expect(dsl { y_axis_label 'Label' }.y_label).to eq 'Label'
13
- end
14
-
15
- it 'sets y-axis range' do
16
- expect(dsl { range 0..40 }.y_range).to eq (0..40)
17
- end
18
-
19
- it 'sets y-axis tick interval' do
20
- expect(dsl { tick_interval 1 }.tick_interval).to eq 1
21
- end
22
-
23
- it 'raises when y-axis range is not specified' do
24
- expect { dsl(:test, {}) { } }.to raise_error(/no range specified/)
25
- end
26
-
27
- it 'sets tonality' do
28
- expect(dsl { tonality :higher_is_better }.tonality).to eq :higher_is_better
29
- end
30
-
31
- it 'sets baseline to constant value' do
32
- expect(dsl { baseline 5 }.baseline.call(1, :male)).to eq 5.0
33
- end
34
-
35
- it 'sets baseline to proc' do
36
- expect(dsl { baseline { |age, gender| age } }.baseline.call(5, :male)).to eq(5.0)
37
- expect { dsl { baseline { |age| age } } }.to raise_error(ArgumentError, /must take two arguments/)
38
- end
39
-
40
- it 'raises error if not giving baseline value or block' do
41
- expect { dsl { baseline } }.to raise_error(ArgumentError, /either value or a block/)
42
- expect { dsl { baseline(5.0) { |age, gender| age } } }.to raise_error(ArgumentError, /either value or a block/)
43
- end
44
-
45
- it 'sets clinically relevant change' do
46
- expect(dsl { clinically_relevant_change 5 }.clinically_relevant_change).to eq 5.0
47
- end
48
-
49
- it 'makes a line chart' do
50
- expect(dsl { }).to be_an_instance_of(::Quby::Questionnaires::Entities::Charting::LineChart)
51
- end
52
-
53
- def dsl(key = :test, options = {y_range: (0..20)}, &block)
54
- builder = LineChartBuilder.new(questionnaire, key, options)
55
- builder.build(&block)
56
- end
57
- end
58
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe RadarChartBuilder do
7
- it_behaves_like ChartBuilder
8
-
9
- let(:questionnaire) { double(key: 'questionnaire_key') }
10
-
11
- it 'makes a radar chart' do
12
- expect(dsl { }).to be_an_instance_of(::Quby::Questionnaires::Entities::Charting::RadarChart)
13
- end
14
-
15
- it 'sets y-axis range' do
16
- expect(dsl { range 0..40 }.y_range).to eq (0..40)
17
- end
18
-
19
- it 'sets y-axis tick interval' do
20
- expect(dsl { tick_interval 1 }.tick_interval).to eq 1
21
- end
22
-
23
- it 'sets plotlines' do
24
- plotlines =
25
- dsl {
26
- plotline 40, :orange
27
- plotline 60, :red
28
- }.plotlines
29
-
30
- expect(plotlines).to eq [
31
- {value: 40, color: :orange, width: 1, zIndex: 3},
32
- {value: 60, color: :red, width: 1, zIndex: 3}
33
- ]
34
- end
35
-
36
- def dsl(key = :test, options = {}, &block)
37
- builder = RadarChartBuilder.new(questionnaire, key, options)
38
- builder.build(&block)
39
- end
40
- end
41
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Quby::Questionnaires::DSL
6
- describe Helpers do
7
- let(:questionnaire) { Quby::Questionnaires::Entities::Questionnaire.new("example") }
8
- let(:builder) { QuestionnaireBuilder.new(questionnaire) }
9
-
10
- # this helper has some extra tests to check that helpers are included everywhere
11
- describe '.image_tag' do
12
- let(:expected_html) { %r{<p><img alt=\"Happy face\" src=\"/assets/quby/happy-face.*.png\" /></p>} }
13
-
14
- it 'builds image tags outside of panels' do
15
- dsl { text image_tag('quby/happy-face.png') }
16
- expect(questionnaire.panels.first.items.first.text).to match(expected_html)
17
- end
18
-
19
- it 'builds image tags inside of panels' do
20
- dsl do
21
- panel do
22
- text image_tag('quby/happy-face.png')
23
- end
24
- end
25
-
26
- expect(questionnaire.panels.first.items.first.text).to match(expected_html)
27
- end
28
-
29
- it 'builds image tags inside of questions' do
30
- # this one is different because markdown/maruku transforms double quotes into single quotes
31
- # and question descriptions are not passed through markdown/maruku
32
- expected_html = %r{<img .*?src="/assets/quby/happy-face.*.png"}
33
- dsl do
34
- panel do
35
- question :v_1, type: :radio do
36
- option :a1, description: image_tag('quby/happy-face.png')
37
- end
38
- end
39
- end
40
- expect(questionnaire.panels.first.items.first.options.first.description).to match(expected_html)
41
- end
42
- end
43
-
44
- describe 'video_tag' do
45
- it 'makes a text item with a html 5 video player for the given video source urls' do
46
- html = builder.video_tag 'https://www.example.com/video.mp4', 'https://www.example.com/video.webm'
47
-
48
- expect(html).to \
49
- eq("<video width=\"100%\" preload=\"none\" controls=\"controls\"><source src=\"https://www.example.com/video.mp4\" type=\"video/mp4\">\
50
- <source src=\"https://www.example.com/video.webm\" type=\"video/webm\">\
51
- Helaas kan je browser dit filmpje niet afspelen. Probeer een andere browser te gebruiken.</video>")
52
- end
53
-
54
- it 'can add a autoplay attribute (with muted added to allow chrome autoplay)' do
55
- html = builder.video_tag 'https://www.example.com/video.mp4', autoplay: true
56
-
57
- expect(html).to \
58
- include('<video width="100%" preload="none" autoplay="autoplay" muted="muted" controls="controls">')
59
- end
60
-
61
- it 'can add a loop attribute' do
62
- html = builder.video_tag 'https://www.example.com/video.mp4', loop: true
63
-
64
- expect(html).to \
65
- include('<video width="100%" preload="none" loop="loop" controls="controls">')
66
- end
67
-
68
- it 'can add a poster url' do
69
- html = builder.video_tag 'https://www.example.com/video.mp4', poster: 'https://www.example.com/poster.jpg'
70
-
71
- expect(html).to \
72
- include('<video width="100%" preload="none" poster="https://www.example.com/poster.jpg" controls="controls">')
73
- end
74
- end
75
-
76
- def dsl(&block)
77
- builder.instance_eval(&block)
78
- end
79
- end
80
- end