Module: Ccls::FactoryTestHelper

Defined in:
lib/ccls_engine/factory_test_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



221
222
223
224
# File 'lib/ccls_engine/factory_test_helper.rb', line 221

def self.included(base)
	base.alias_method_chain( :method_missing, :pluralization 
		) unless base.respond_to?(:method_missing_without_pluralization)
end

Instance Method Details

#create_case_study_subject_with_patid(patid) ⇒ Object

def three_study_subjects_with_sent_to_subject_on create_study_subjects_with_sent_to_subject_on( ‘12/31/2005’,‘12/31/2001’,‘12/31/2003’) end

def three_study_subjects_with_received_by_ccls_at create_study_subjects_with_received_by_ccls_at( ‘12/31/2005’,‘12/31/2001’,‘12/31/2003’) end



199
200
201
202
203
204
# File 'lib/ccls_engine/factory_test_helper.rb', line 199

def create_case_study_subject_with_patid(patid)
	StudySubject.any_instance.stubs(:get_next_patid).returns(patid)
	study_subject = create_case_study_subject
	StudySubject.any_instance.unstub(:get_next_patid)
	study_subject.reload
end

#create_eligible_hx_study_subjectObject

../ccls_engine/test/unit/ccls/addressing_test.rb ../homex/test/functional/addressings_controller_test.rb



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ccls_engine/factory_test_helper.rb', line 48

def create_eligible_hx_study_subject()
	study_subject = nil
	assert_nil study_subject
	assert_difference('Enrollment.count',2) {	#	homex and auto-created ccls
	assert_difference('StudySubject.count',1) {
		study_subject = create_hx_study_subject(:enrollment => {
			:is_eligible => YNDK[:yes] })
	} }
	assert_not_nil study_subject
	assert_study_subject_is_eligible(study_subject)
	study_subject
end

#create_home_exposure_with_study_subject(options = {}) ⇒ Object Also known as: create_hx_study_subject

../ccls_engine/test/unit/ccls/study_subject_test.rb ../homex/test/functional/followup/study_subjects_controller_test.rb ../homex/test/functional/home_exposure_responses_controller_test.rb ../homex/test/functional/interview/study_subjects_controller_test.rb ../homex/test/functional/sample/study_subjects_controller_test.rb ../homex/test/functional/study_subjects_controller_test.rb



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ccls_engine/factory_test_helper.rb', line 9

def create_home_exposure_with_study_subject(options={})
	study_subject = project = nil
	unless options[:patient].nil?
		options[:study_subject] ||= {}
		options[:study_subject][:subject_type] = SubjectType['Case']
	end
	assert_difference('StudySubject.count',1) {
		study_subject    = Factory(:study_subject,options[:study_subject]||{})
	}
	project = Project.find_or_create_by_key('HomeExposures')
	assert_not_nil project
	assert_difference('StudySubject.count',0) {
	assert_difference('Enrollment.count',1) {
		Factory(:enrollment, (options[:enrollment]||{}).merge(
			:study_subject => study_subject, :project => project ))
	} }
	unless options[:patient].nil?
		assert_difference('StudySubject.count',0) {
		assert_difference('Patient.count',1) {
			Factory(:patient, :study_subject => study_subject )
		} }
	end
	study_subject
end

#create_hx_interview_study_subject(options = {}) ⇒ Object

../ccls_engine/test/unit/ccls/study_subject_interviews_test.rb ../homex/test/functional/interview/study_subjects_controller_test.rb



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ccls_engine/factory_test_helper.rb', line 63

def create_hx_interview_study_subject(options={})
	study_subject = create_hx_study_subject
	instrument = Factory(:instrument, 
		:project => Project.find_or_create_by_key('HomeExposures'))
	instrument_version = Factory(:instrument_version, 
		:instrument => instrument)
	interview = Factory(:interview, 
		:study_subject => study_subject,
		:instrument_version => instrument_version)
	study_subject
end

#create_study_subject_with_childid(childid) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/ccls_engine/factory_test_helper.rb', line 116

def create_study_subject_with_childid(childid)
	StudySubject.any_instance.stubs(:get_next_childid).returns(childid)
	study_subject = Factory(:study_subject)
	StudySubject.any_instance.unstub(:get_next_childid)
	assert_not_nil study_subject.childid
	assert_equal childid.to_s, study_subject.childid.to_s
	study_subject
end

#create_study_subject_with_dob(dob) ⇒ Object



162
163
164
165
# File 'lib/ccls_engine/factory_test_helper.rb', line 162

def create_study_subject_with_dob(dob)
	#	Time.parse?  Why not Date? Time.parse parses better.
	create_study_subject( :dob => Time.parse(dob) )	
end

#create_study_subject_with_first_name(first_name) ⇒ Object



154
155
156
# File 'lib/ccls_engine/factory_test_helper.rb', line 154

def create_study_subject_with_first_name(first_name)
	create_study_subject( :first_name => first_name )
end

#create_study_subject_with_gift_card_number(gift_card_number) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/ccls_engine/factory_test_helper.rb', line 102

def create_study_subject_with_gift_card_number(gift_card_number)
	study_subject = create_study_subject
	Factory(:gift_card, 
		:study_subject => study_subject,
		:number  => gift_card_number )
	study_subject
end

#create_study_subject_with_last_name(last_name) ⇒ Object



146
147
148
# File 'lib/ccls_engine/factory_test_helper.rb', line 146

def create_study_subject_with_last_name(last_name)
	create_study_subject( :last_name => last_name )
end

#create_study_subject_with_patid(patid) ⇒ Object Also known as: create_study_subject_with_studyid



129
130
131
132
133
134
135
136
# File 'lib/ccls_engine/factory_test_helper.rb', line 129

def create_study_subject_with_patid(patid)
	study_subject = Factory(:study_subject)	#not case so shouldn't create patid
	assert_nil     study_subject.patid
	study_subject.update_attribute(:patid, patid)
	assert_not_nil study_subject.patid
	assert_equal patid.to_s, study_subject.patid.to_s
	study_subject
end

#create_study_subjects(count = 0, options = {}) ⇒ Object



75
76
77
78
79
# File 'lib/ccls_engine/factory_test_helper.rb', line 75

def create_study_subjects(count=0,options={})
	study_subjects = []
	count.times{ study_subjects.push(create_study_subject(options)) }
	return study_subjects
end

#create_study_subjects_with_races(count = 0, options = {}) ⇒ Object



110
111
112
113
114
# File 'lib/ccls_engine/factory_test_helper.rb', line 110

def create_study_subjects_with_races(count=0,options={})
	study_subjects = create_study_subjects(count)
	study_subjects.each{|s|s.races << Factory(:race)}
	study_subjects
end

#create_study_subjects_with_recruitment_priorities(*priorities) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ccls_engine/factory_test_helper.rb', line 81

def create_study_subjects_with_recruitment_priorities(*priorities)
	project = nil
	assert_difference('Project.count',1) {
		project = Factory(:project)
	}
	study_subjects = priorities.collect do |priority|
		study_subject = nil
		assert_difference('Enrollment.count',1){	#	auto-created ccls enrollment
		assert_difference('StudySubject.count',1) {
			study_subject = create_study_subject
		} }
		assert_difference('Enrollment.count',1){
			Factory(:enrollment, :project => project, 
				:study_subject => study_subject,
				:recruitment_priority => priority)
		}
		study_subject
	end
	return [project,*study_subjects]
end

#method_missing_with_pluralization(symb, *args, &block) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ccls_engine/factory_test_helper.rb', line 208

def method_missing_with_pluralization(symb,*args, &block)
	method_name = symb.to_s
	if method_name =~ /^create_(.*)_with_(.*)$/
		model     = $1.singularize
		attribute = $2.singularize
		args.collect do |arg|
			send("create_#{model}_with_#{attribute}",arg)
		end
	else
		method_missing_without_pluralization(symb, *args, &block)
	end
end

#three_study_subjects_with_childidObject



125
126
127
# File 'lib/ccls_engine/factory_test_helper.rb', line 125

def three_study_subjects_with_childid
	create_study_subjects_with_childids(9,3,6)
end

#three_study_subjects_with_dobObject



167
168
169
170
# File 'lib/ccls_engine/factory_test_helper.rb', line 167

def three_study_subjects_with_dob
	create_study_subjects_with_dobs(
		'12/31/2005','12/31/2001','12/31/2003')
end

#three_study_subjects_with_first_nameObject



158
159
160
# File 'lib/ccls_engine/factory_test_helper.rb', line 158

def three_study_subjects_with_first_name
	create_study_subjects_with_first_names('9','3','6')
end

#three_study_subjects_with_interview_outcome_onObject



184
185
186
187
# File 'lib/ccls_engine/factory_test_helper.rb', line 184

def three_study_subjects_with_interview_outcome_on
	create_study_subjects_with_interview_outcome_ons(
		'12/31/2005','12/31/2001','12/31/2003')
end

#three_study_subjects_with_last_nameObject



150
151
152
# File 'lib/ccls_engine/factory_test_helper.rb', line 150

def three_study_subjects_with_last_name
	create_study_subjects_with_last_names('9','3','6')
end

#three_study_subjects_with_patidObject Also known as: three_study_subjects_with_studyid



140
141
142
# File 'lib/ccls_engine/factory_test_helper.rb', line 140

def three_study_subjects_with_patid
	create_study_subjects_with_patids(9,3,6)
end

#three_study_subjects_with_sample_outcomeObject



180
181
182
# File 'lib/ccls_engine/factory_test_helper.rb', line 180

def three_study_subjects_with_sample_outcome
	create_study_subjects_with_sample_outcomes('9','3','6')
end

#three_study_subjects_with_sample_outcome_onObject

three_study_subjects_with_* methods called from StudySubjectSearchTest



175
176
177
178
# File 'lib/ccls_engine/factory_test_helper.rb', line 175

def three_study_subjects_with_sample_outcome_on
	create_study_subjects_with_sample_outcome_ons(
		'12/31/2005','12/31/2001','12/31/2003')
end