require "ar_helper" require "study_engine/screen_results" require "timecop" require "study_engine/report" require "study_engine/assessment" require "study_engine/result" module StudyEngine describe ScreenResults do before do StudyEngine.configure do |config| config.cat_path = "spec/support" config.groups = { "12 month" => %w(A B C) } config.bank_finder = -> (assessment) { if assessment.event == "12 month" (0..8).to_a else (0..9).to_a end } end end after do StudyEngine.bank_finder = -> (_) { StudyEngine.banks } end before do Timecop.freeze "2011-01-01 11:11:11 UTC" do Assessment.by_event("Baseline").create! study_id: "FIX-AAA-1234", method_applied: "In-person", notes: "note 1-b" Assessment.by_event("6 month").create! study_id: "FIX-AAA-1234", method_applied: "In-person", notes: "note 1-6" Assessment.by_event("12 month").create! study_id: "FIX-AAA-1234", method_applied: "In-person", notes: "note 1-12" end Timecop.freeze "2012-02-02 12:12:12 UTC" do Assessment.by_event("6 month").create! study_id: "FIX-AAA-1234", method_applied: "In-person", notes: "note 2-6" end Timecop.freeze "2013-03-03 13:13:13 UTC" do Assessment.by_event("Baseline").create! study_id: "FIX-AAA-2345", method_applied: "In-person", notes: "note 3-b" Assessment.by_event("6 month").create! study_id: "FIX-AAA-2345", method_applied: "In-person", notes: "note 3-6" Assessment.by_event("12 month").create! study_id: "FIX-AAA-2345", method_applied: "In-person", notes: "note 3-12" end end let(:report) do Report.new(Assessment.all, "study_id", "ASC") end subject do ScreenResults.new(report.groups) end describe "#each" do it "yields the header and body" do results = [] subject.each { |row| results << row } results.should == [ ["Study ID", "Baseline incomplete", "Baseline timestamp", "Baseline method", "Baseline coordinator", "Baseline note", "6 month incomplete", "6 month timestamp", "6 month method", "6 month coordinator", "6 month note", "12 month incomplete", "12 month timestamp", "12 month method", "12 month coordinator", "12 month note", "12 month set"], ["FIX-AAA-1234", "0/10", "2011-01-01 11:11:11 UTC", "In-person", nil, "note 1-b", "0/10", "2011-01-01 11:11:11 UTC", "In-person", nil, "note 1-6", "0/9", "2011-01-01 11:11:11 UTC", "In-person", nil, "note 1-12", "A"], ["FIX-AAA-1234", "", "", "", "", "", "0/10", "2012-02-02 12:12:12 UTC", "In-person", nil, "note 2-6", "", "", "", "", "", "" ], ["FIX-AAA-2345", "0/10", "2013-03-03 13:13:13 UTC", "In-person", nil, "note 3-b", "0/10", "2013-03-03 13:13:13 UTC", "In-person", nil, "note 3-6", "0/9", "2013-03-03 13:13:13 UTC", "In-person", nil, "note 3-12", "B"], ] end end end end