caruby-tissue 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/History.txt +4 -0
  2. data/README.md +6 -0
  3. data/lib/catissue/annotation/annotation_class.rb +1 -1
  4. data/lib/catissue/cli/migrate.rb +1 -0
  5. data/lib/catissue/domain/container.rb +13 -8
  6. data/lib/catissue/domain/specimen.rb +9 -3
  7. data/lib/catissue/domain/specimen_event_parameters.rb +1 -8
  8. data/lib/catissue/domain/specimen_requirement.rb +1 -1
  9. data/lib/catissue/domain/storage_container.rb +4 -3
  10. data/lib/catissue/domain/uniquify.rb +82 -0
  11. data/lib/catissue/migration/migrator.rb +15 -7
  12. data/lib/catissue/migration/uniquify.rb +2 -111
  13. data/lib/catissue/util/position.rb +14 -2
  14. data/lib/catissue/version.rb +1 -1
  15. data/test/fixtures/catissue/domain/conf/catissue_override.yaml +9 -0
  16. data/test/fixtures/catissue/extract/conf/scg_extract.yaml +3 -0
  17. data/test/fixtures/catissue/extract/conf/scg_fields.yaml +3 -0
  18. data/test/fixtures/catissue/extract/conf/spc_extract.yaml +3 -0
  19. data/test/fixtures/catissue/extract/conf/spc_fields.yaml +4 -0
  20. data/test/fixtures/lib/catissue/defaults_test_fixture.rb +202 -0
  21. data/test/lib/catissue/database/controlled_values_test.rb +47 -0
  22. data/test/lib/catissue/database/database_test.rb +28 -0
  23. data/test/lib/catissue/domain/address_test.rb +53 -0
  24. data/test/lib/catissue/domain/base_haemotology_pathology_test.rb +25 -0
  25. data/test/lib/catissue/domain/ca_tissue_test_defaults_test.rb +27 -0
  26. data/test/lib/catissue/domain/capacity_test.rb +12 -0
  27. data/test/lib/catissue/domain/collection_event_parameters_test.rb +24 -0
  28. data/test/lib/catissue/domain/collection_protocol_event_test.rb +25 -0
  29. data/test/lib/catissue/domain/collection_protocol_registration_test.rb +71 -0
  30. data/test/lib/catissue/domain/collection_protocol_test.rb +69 -0
  31. data/test/lib/catissue/domain/container_position_test.rb +29 -0
  32. data/test/lib/catissue/domain/department_test.rb +21 -0
  33. data/test/lib/catissue/domain/disposal_event_parameters_test.rb +16 -0
  34. data/test/lib/catissue/domain/location_test.rb +38 -0
  35. data/test/lib/catissue/domain/metadata_test.rb +62 -0
  36. data/test/lib/catissue/domain/participant_medical_identifier_test.rb +26 -0
  37. data/test/lib/catissue/domain/participant_test.rb +96 -0
  38. data/test/lib/catissue/domain/site_test.rb +30 -0
  39. data/test/lib/catissue/domain/specimen_array_test.rb +38 -0
  40. data/test/lib/catissue/domain/specimen_array_type_test.rb +27 -0
  41. data/test/lib/catissue/domain/specimen_characteristics_test.rb +15 -0
  42. data/test/lib/catissue/domain/specimen_collection_group_test.rb +216 -0
  43. data/test/lib/catissue/domain/specimen_event_parameters_test.rb +61 -0
  44. data/test/lib/catissue/domain/specimen_position_test.rb +62 -0
  45. data/test/lib/catissue/domain/specimen_requirement_test.rb +61 -0
  46. data/test/lib/catissue/domain/specimen_test.rb +272 -0
  47. data/test/lib/catissue/domain/storage_container_test.rb +150 -0
  48. data/test/lib/catissue/domain/storage_type_test.rb +70 -0
  49. data/test/lib/catissue/domain/transfer_event_parameters_test.rb +38 -0
  50. data/test/lib/catissue/domain/user_test.rb +50 -0
  51. data/test/lib/catissue/extract/delta_test.rb +25 -0
  52. data/test/lib/catissue/extract/extractor_test.rb +43 -0
  53. data/test/lib/catissue/import/importable_module_test.rb +14 -0
  54. data/test/lib/catissue/migration/test_case.rb +103 -0
  55. data/test/lib/catissue/test_case.rb +225 -0
  56. data/test/lib/examples/galena/domain/examples_test.rb +70 -0
  57. data/test/lib/examples/galena/migration/catissue.log +0 -0
  58. data/test/lib/examples/galena/migration/filter_test.rb +26 -0
  59. data/test/lib/examples/galena/migration/frozen_test.rb +28 -0
  60. data/test/lib/examples/galena/migration/general_test.rb +44 -0
  61. data/test/lib/examples/galena/migration/simple_test.rb +29 -0
  62. data/test/lib/examples/galena/migration/test_case.rb +52 -0
  63. data/test/lib/examples/galena/migration/uniquify.rb +93 -0
  64. metadata +223 -184
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+
4
+ class SiteTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ @site = defaults.tissue_bank
10
+ @site.name = @site.name.uniquify
11
+ end
12
+
13
+ def test_defaults
14
+ verify_defaults(@site)
15
+ end
16
+
17
+ def test_save
18
+ # create the site
19
+ verify_save(@site)
20
+ # modify the site address; this changes the existing address rather than creating a new address
21
+ identifier = @site.address.identifier
22
+ zip_code = @site.address.zip_code = @site.address.zip_code.to_i + 1
23
+ verify_save(@site)
24
+ # clear the address identifier zip code and refetch the site; this sets the zip code to the database value
25
+ @site.address.identifier = @site.address.zip_code = nil
26
+ database.find(@site)
27
+ assert_equal(zip_code, @site.address.zip_code.to_i, "Updated zip code incorrect.")
28
+ assert_equal(identifier, @site.address.identifier, "Address replaced rather than updated.")
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'caruby/util/uniquifier'
3
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
4
+
5
+ class SpecimenArrayTest < Test::Unit::TestCase
6
+ include CaTissue::TestCase
7
+
8
+ def setup
9
+ super
10
+ @spc = defaults.specimen
11
+ array_type = CaTissue::SpecimenArrayType.new(:name => 'SpecimenArray'.uniquify, :specimen_class => @spc.specimen_class,
12
+ :specimen_types => [@spc.specimen_type], :columns => 5, :rows => 5)
13
+ @array = CaTissue::SpecimenArray.new(:container_type => array_type)
14
+ end
15
+
16
+ def test_defaults
17
+ verify_defaults(@array)
18
+ end
19
+
20
+ def test_occupied_positions_occlusion
21
+ assert(!CaTissue::SpecimenArray.attributes.include?(:occupied_positions), "occupied_positions is not excluded from SpecimenArray")
22
+ assert(CaTissue::Container.attributes.include?(:occupied_positions), "occupied_positions is not retained in the SpecimenArray superclass")
23
+ end
24
+
25
+ def test_can_hold_type
26
+ assert(@array.can_hold_child?(@spc), "Array can't hold specimen type")
27
+ @spc.specimen_type = 'Fixed Tissue'
28
+ assert(!@array.can_hold_child?(@spc), "Array can't hold different specimen type")
29
+ end
30
+
31
+ def test_add
32
+ assert_raises(NotImplementedError, "Specimen position specimen incorrect") { @array << @spc }
33
+ end
34
+
35
+ # def test_save
36
+ # verify_save(@array)
37
+ # end
38
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'caruby/util/uniquifier'
3
+
4
+ class SpecimenArrayTypeTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ @type = CaTissue::SpecimenArrayType.new(:name => 'SpecimenArrayType'.uniquify,
10
+ :specimen_class => 'Frozen Tissue', :columns => 5, :rows => 5)
11
+ @type.specimen_types << 'Tissue'
12
+ end
13
+
14
+ def test_defaults
15
+ verify_defaults(@type)
16
+ end
17
+
18
+ def test_create
19
+ array = @type.create
20
+ assert_same(CaTissue::SpecimenArray, array.class, "Created instance class incorrect")
21
+ assert_same(@type, array.container_type, "Created array type incorrect")
22
+ end
23
+
24
+ def test_save
25
+ verify_save(@type)
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+
4
+ class SpecimenCharacteristicsTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ @chr = defaults.specimen_requirement.characteristics
10
+ end
11
+
12
+ def test_defaults
13
+ verify_defaults(@chr)
14
+ end
15
+ end
@@ -0,0 +1,216 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+
4
+ class SpecimenCollectionGroupTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ @scg = defaults.specimen_collection_group
10
+ end
11
+
12
+ # This test case exercises the key method for a domain class with a secondary key.
13
+ def test_secondary_key
14
+ @scg.name = 'Test SCG'
15
+ assert_equal(@scg.name, @scg.key, 'Key incorrect')
16
+ end
17
+
18
+ def test_defaults
19
+ verify_defaults(@scg)
20
+ assert_equal('Complete', @scg.collection_status, "SCG collection status default incorrect")
21
+ @scg.registration.consent_tier_responses.each do |ctr|
22
+ ct = ctr.consent_tier
23
+ cts = @scg.consent_tier_statuses.detect { |s| s.consent_tier == ct }
24
+ assert_not_nil(cts, "Missing SCG consent tier status for #{ct}")
25
+ end
26
+ end
27
+
28
+ def test_default_collection_event
29
+ collection_event = @scg.collection_event
30
+ @scg.collection_event = nil
31
+ assert_nil(@scg.collection_event, 'Collection event not removed')
32
+ @scg.add_defaults
33
+ assert_equal(collection_event, @scg.collection_event, 'Collection event not set to default')
34
+ end
35
+
36
+ def test_base_haematology_pathology
37
+ scg = CaTissue::SpecimenCollectionGroup.new
38
+ pths = scg.radical_prostatectomy_pathology_annotations
39
+ assert(pths.empty?, "Prostatectomy annotations not empty at start")
40
+ pth = CaTissue::SpecimenCollectionGroup::Pathology::RadicalProstatectomyPathologyAnnotation.new
41
+ pth.merge_attributes(:specimen_procedure => 'Biopsy', :specimen_collection_group => scg)
42
+ epx = CaTissue::SpecimenCollectionGroup::Pathology::ExtraprostaticExtension.new
43
+ epx.merge_attributes(:status => 'Present', :radical_prostatectomy_pathology_annotation => pth)
44
+ pths = scg.radical_prostatectomy_pathology_annotations
45
+ assert_not_nil(pths.first, "Prostatectomy annotation not added to #{scg} annotations")
46
+ assert_same(pth, pths.first, "Prostatectomy annotation incorrect")
47
+ assert_same(scg, pth.owner, "Prostatectomy annotation proxy hook not set")
48
+ assert_not_nil(pth.extraprostatic_extension, "#{pth} extraprostatic extension not set")
49
+ assert_same(epx, pth.extraprostatic_extension, "{pth} extraprostatic extension incorrect")
50
+ end
51
+
52
+ def test_collect
53
+ scg = CaTissue::SpecimenCollectionGroup.new
54
+ cdt = DateTime.now
55
+ scg.collect(:collector => @scg.collector, :collection_date => cdt, :receiver => @scg.receiver)
56
+ assert_not_nil(scg.collection_event_parameters, "Collected SCG missing collection event parameters")
57
+ assert_same(@scg.collector, scg.collection_event_parameters.user, "SCG collector incorrect")
58
+ assert_equal(cdt.to_s, scg.collection_event_parameters.timestamp.to_s, "SCG collection time incorrect")
59
+ assert_not_nil(scg.received_event_parameters, "Received SCG missing received event parameters")
60
+ assert_same(@scg.receiver, scg.received_event_parameters.user, "SCG receiver incorrect")
61
+ assert_equal(cdt.to_s, scg.received_event_parameters.timestamp.to_s, "SCG received time not defaulted to collection time")
62
+ end
63
+
64
+ def test_save
65
+ logger.debug { "Verifying SCG create..." }
66
+ verify_save(@scg)
67
+ assert_equal('Complete', @scg.collection_status, "Collection status after store incorrect")
68
+ assert_equal(2, @scg.events.size, "#{@scg} events size incorrect")
69
+ tmpl = @scg.copy(:identifier)
70
+ verify_query(tmpl, :events) do |fetched|
71
+ assert_equal(2, fetched.size, "#{@scg} fetched events size incorrect")
72
+ end
73
+ assert_equal(1, @scg.specimens.size, "#{@scg} specimens size incorrect")
74
+ spc = @scg.specimens.first
75
+ assert_equal(2, spc.events.size, "#{@scg} #{spc} events size incorrect")
76
+ verify_query(spc, :events) do |fetched|
77
+ assert_equal(2, fetched.size, "#{@scg} #{spc} events query result size incorrect")
78
+ end
79
+
80
+ # test update
81
+ @scg.diagnosis = 'Pleomorphic carcinoma'
82
+ # set an event comment
83
+ cep = @scg.specimen_event_parameters.detect { |param| CaTissue::CollectionEventParameters === param }
84
+ cep.comment = 'Test Comment'
85
+ verify_save(@scg)
86
+
87
+ # query the specimens
88
+ logger.debug { "Verifying #{@scg.qp} specimens query..." }
89
+ tmpl = @scg.copy(@scg.class.secondary_key_attributes)
90
+ verify_query(tmpl, :specimens) do |fetched|
91
+ assert_equal(1, fetched.size, "#{@scg} specimens query result size incorrect")
92
+ spc = fetched.first
93
+ assert_equal(@scg.specimens.first.identifier, spc.identifier, "#{@scg} fetched #{spc} identifier incorrect")
94
+ end
95
+
96
+ # query the collection event parameters
97
+ logger.debug { "Verifying that #{@scg.qp} specimen_event_parameters are created..." }
98
+ verify_query(tmpl) do |fetched|
99
+ assert_equal(@scg.specimen_event_parameters.size, fetched.first.specimen_event_parameters.size, "Event query result size incorrect")
100
+ # the fetched CEP
101
+ fcep = fetched.first.specimen_event_parameters.detect { |param| CaTissue::CollectionEventParameters === param }
102
+ assert_not_nil(fcep, "Collection event missing")
103
+ assert_equal('Test Comment', fcep.comment, "Collection event comment not saved")
104
+ end
105
+
106
+ # update the comment
107
+ logger.debug { "Verifying #{@scg.qp} update..." }
108
+ @scg.comment = comment = 'Test Comment'
109
+ verify_save(@scg)
110
+ @scg.comment = nil
111
+ database.find(@scg)
112
+ assert_equal(comment, @scg.comment, "Comment not updated in database")
113
+ logger.debug { "Verified #{@scg.qp} store." }
114
+
115
+ # create a new SCG with two specimens
116
+ logger.debug { "Verifying second SCG create..." }
117
+ cpe = @scg.collection_event
118
+ rcvr = defaults.tissue_bank.coordinator
119
+ reg = @scg.registration
120
+ pnt = reg.participant
121
+ pcl = reg.protocol
122
+ rqmt = defaults.specimen_requirement
123
+ spc1 = CaTissue::Specimen.create_specimen(:requirement => rqmt, :initial_quantity => 1.0)
124
+ spc2 = CaTissue::Specimen.create_specimen(:requirement => rqmt, :initial_quantity => 1.0)
125
+ site = defaults.tissue_bank
126
+ scg = pcl.add_specimens(spc1, spc2, :participant => pnt, :site => site, :collection_event => cpe, :receiver => rcvr)
127
+ verify_save(scg)
128
+ spcs = scg.query(:specimens)
129
+ spc_ids = spcs.map { |spc| spc.identifier }
130
+ assert_equal(2, spcs.size, "#{scg} specimens size incorrect")
131
+ assert(spc_ids.include?(spc1.identifier), "#{scg} specimen #{spc1} not found")
132
+ assert(spc_ids.include?(spc2.identifier), "#{scg} specimen #{spc2} not found")
133
+ end
134
+
135
+ # This test follows caTissue SCG, SEP and Specimen auto-generation as follows:
136
+ # * Create CPR => SCG auto-generated with status Pending, new Specimen, no SCG SEP
137
+ # * Update SCG status to Complete => SCG SEP created
138
+ def test_autogenerated
139
+ # make a new registration
140
+ pnt = CaTissue::Participant.new(:name => 'Test Participant'.uniquify)
141
+ pcl = defaults.protocol
142
+ cpr = pcl.register(pnt)
143
+
144
+ # store the registration without an SCG
145
+ verify_save(cpr)
146
+ # the auto-generated SCG
147
+ scg = cpr.specimen_collection_groups.first
148
+ assert_not_nil(scg, "Missing auto-generated SCG")
149
+ assert_not_nil(scg.identifier, "Auto-generated SCG missing identifier")
150
+ assert_not_nil(scg.collection_event, "Auto-generated SCG missing collection event")
151
+ assert_equal('Pending', scg.collection_status, "Auto-generated SCG status is not Pending")
152
+ # the auto-generated Specimen
153
+ spc = scg.specimens.first
154
+ assert_not_nil(spc, "Auto-generated specimen was not fetched")
155
+ # SEP is not auto-generated
156
+ assert(scg.specimen_event_parameters.empty?, "SEP unexpectedly auto-generated")
157
+ # auto-generated SCG does not have a site, even though it is required for create or update
158
+ assert_nil(scg.collection_site, "SCG collection site unexpectedly auto-generated")
159
+
160
+ # update the SCG with site and SEPs
161
+ rcvr = defaults.tissue_bank.coordinator
162
+ site = defaults.specimen_collection_group.collection_site
163
+ scg.merge_attributes(:receiver => rcvr, :collection_site => site).add_defaults
164
+ logger.debug { "#{self.class.qp} updating the auto-generated #{scg.qp}..." }
165
+ scg.update
166
+ # clear and refetch the status
167
+ scg.collection_status = nil
168
+ logger.debug { "#{self.class.qp} refetching the updated #{scg.qp}..." }
169
+ scg.find
170
+ assert_equal('Pending', spc.collection_status, "Auto-generated specimen status is not Pending after update")
171
+
172
+ # reset some specimen fields and update
173
+ spc.collection_status = 'Collected'
174
+ spc.specimen_type = 'Frozen Tissue'
175
+ spc.initial_quantity = 0.1
176
+ spc.specimen_characteristics.tissue_site = 'Ileum'
177
+ logger.debug { "#{self.class.qp} updating auto-generated #{spc.qp}..." }
178
+ verify_save(spc)
179
+
180
+ # clear and refetch some specimen fields
181
+ spc.collection_status = nil
182
+ spc.specimen_characteristics.tissue_site = nil
183
+ logger.debug { "#{self.class.qp} verifying the persistent state of the updated #{scg.qp} auto-generated specimen..." }
184
+ database.find(spc)
185
+ assert_equal('Collected', spc.collection_status, "Specimen status not updated")
186
+ assert_equal('Ileum', spc.specimen_characteristics.tissue_site, "Specimen tissue site not updated")
187
+
188
+ # update the SCG with complete status
189
+ scg.collection_status = 'Complete'
190
+ logger.debug { "#{self.class.qp} updating the #{scg.qp} collection status #{scg.qp}..." }
191
+ scg.update
192
+ verify_save(scg)
193
+ end
194
+
195
+ def test_save_prostate_annotation
196
+ pa = CaTissue::SpecimenCollectionGroup::Pathology::RadicalProstatectomyPathologyAnnotation.new
197
+ pa.specimen_collection_group = @scg
198
+ htype = CaTissue::SpecimenCollectionGroup::Pathology::HistologicType.new
199
+ htype.merge_attributes(:type => 3, :base_pathology_annotation => pa)
200
+ grade = CaTissue::SpecimenCollectionGroup::Pathology::HistologicGrade.new
201
+ grade.merge_attributes(:grade => 3, :base_solid_tissue_pathology_annotation => pa)
202
+ invn = CaTissue::SpecimenCollectionGroup::Pathology::Invasion.new
203
+ invn.merge_attributes(:lymphatic_invasion => 'Present', :base_solid_tissue_pathology_annotation => pa)
204
+ gleason = CaTissue::SpecimenCollectionGroup::Pathology::GleasonScore.new
205
+ gleason.merge_attributes(:primary_pattern_score => 3, :secondary_pattern_score => 4, :prostate_pathology_annotation => pa)
206
+ margin = CaTissue::SpecimenCollectionGroup::Pathology::RadicalProstatectomyMargin.new
207
+ margin.merge_attributes(:margin_status => 'Benign glands at surgical Margin', :radical_prostatectomy_pathology_annotation => pa)
208
+ verify_save(pa)
209
+ assert_not_nil(pa.identifier, "#{@scg} annotation #{pa} not saved")
210
+ assert_not_nil(htype.identifier, "#{@scg} annotation #{htype} not saved")
211
+ assert_not_nil(grade.identifier, "#{@scg} annotation #{grade} not saved")
212
+ assert_not_nil(invn.identifier, "#{@scg} annotation #{invn} not saved")
213
+ assert_not_nil(gleason.identifier, "#{@scg} annotation #{gleason} not saved")
214
+ assert_not_nil(margin.identifier, "#{@scg} annotation #{margin} not saved")
215
+ end
216
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'catissue/defaults_test_fixture'
3
+
4
+ class SpecimenEventParametersTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ specimen = defaults.specimen
10
+ @sep = CaTissue::SpecimenEventParameters.create_parameters(:frozen, specimen, :user => specimen.specimen_collection_group.receiver, :freeze_method => 'Cryobath')
11
+ end
12
+
13
+ def test_defaults
14
+ verify_defaults(@sep)
15
+ end
16
+
17
+ def test_missing_scg
18
+ @sep.specimen_collection_group = nil
19
+ assert_raises(ValidationError, "Parameters without SCG passes SCG validation") { @sep.validate }
20
+ end
21
+
22
+ def test_java_date
23
+ @sep.timestamp = now = Java.now
24
+ verify_defaults(@sep)
25
+ assert_equal(now.to_ruby_date.to_s, @sep.timestamp.to_s, "Java timestamp incorrect")
26
+ end
27
+
28
+ def test_ruby_date
29
+ @sep.timestamp = now = DateTime.now
30
+ verify_defaults(@sep)
31
+ assert_equal(now.to_s, @sep.timestamp.to_s, "Ruby timestamp incorrect")
32
+ end
33
+
34
+ def test_owner
35
+ assert_same(@sep.specimen, @sep.owner, "Specimen SEP owner incorrect")
36
+ end
37
+
38
+ ## DATABASE TESTS ##
39
+
40
+ def test_scg_event_parameters_update
41
+ scg = @sep.specimen.specimen_collection_group
42
+ assert_nothing_raised("SCG not created") { database.create(scg) }
43
+ logger.debug { "Finding autogenerated #{scg.qp} CEP..." }
44
+ cep = scg.collection_event_parameters
45
+ assert_not_nil(cep, "Autogenerated CEP not found")
46
+ assert_not_nil(cep.identifier, "Autogenerated CEP identifier not set")
47
+ cep.collection_procedure = 'Lavage'
48
+ logger.debug { "Updating autogenerated #{scg.qp} CEP #{cep}..." }
49
+ verify_save(cep)
50
+ end
51
+
52
+ def test_specimen_event_parameters_create
53
+ verify_save(@sep)
54
+ tmpl = @sep.copy(:identifier)
55
+ logger.debug { "Verifying updated #{@sep} user fetch..." }
56
+ assert_not_nil(@sep.user, "User not found")
57
+ # update the parameters
58
+ @sep.freeze_method = 'Cryostat'
59
+ verify_save(@sep)
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+
4
+ class SpecimenPositionTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ spc = defaults.specimen
10
+ ctr = defaults.box
11
+ @pos = CaTissue::SpecimenPosition.new(:specimen => spc, :container => ctr, :column => 0, :row => 0)
12
+ end
13
+
14
+ def test_defaults
15
+ verify_defaults(@pos)
16
+ end
17
+
18
+ def test_inverse_setter
19
+ assert_same(@pos, @pos.specimen.position, "Specimen position not set")
20
+ end
21
+
22
+ # Tests creation of {CaTissue::TransferEventParameters} save proxy.
23
+ def test_saver_proxy
24
+ proxy = @pos.saver_proxy
25
+ assert_nil(proxy.from_row, "#{@pos.qp} proxy from row incorrectly set")
26
+ assert_nil(proxy.from_column, "#{@pos.qp} proxy from column incorrectly set")
27
+ assert_equal(@pos.row, proxy.to_row, "#{@pos.qp} proxy to row incorrect")
28
+ assert_equal(@pos.column, proxy.to_column, "#{@pos.qp} proxy to column incorrect")
29
+
30
+ # simulate move
31
+ @pos.take_snapshot
32
+ @pos.location = @pos.location.succ
33
+ proxy = @pos.saver_proxy
34
+ assert_not_nil(proxy.from_row, "#{@pos.qp} move proxy from row not set")
35
+ assert_equal(@pos.snapshot[:position_dimension_one], proxy.from_position_dimension_one, "#{@pos.qp} move proxy from row incorrect")
36
+ assert_not_nil(proxy.to_row, "#{@pos.qp} move proxy to row not set")
37
+ assert_equal(@pos.snapshot[:position_dimension_two], proxy.from_position_dimension_two, "#{@pos.qp} move proxy from column incorrect")
38
+ assert_equal(@pos.row, proxy.to_row, "#{@pos.qp} proxy to row incorrect")
39
+ assert_equal(@pos.column, proxy.to_column, "#{@pos.qp} proxy to column incorrect")
40
+ end
41
+
42
+ def test_save
43
+ spc = @pos.specimen
44
+ verify_save(@pos)
45
+ assert_not_nil(spc.position, "Specimen position missing after position store")
46
+ assert_same(spc, @pos.specimen, "Stored position specimen differs from prior specimen")
47
+ assert_same(@pos, spc.position, "Specimen position differs from stored position")
48
+ # increment the position
49
+ newloc = @pos.location.succ
50
+ spc.move_to(newloc)
51
+ # verify that a specimen update also updates the position
52
+ logger.debug { "Verifying that specimen update reflects the position change..." }
53
+ spc.update
54
+ newpos = spc.position
55
+ assert_not_nil(newpos.identifier, "Specimen update did not save the new position #{newpos}")
56
+ verify_query(newpos.copy(:identifier)) do |result|
57
+ fetched = result.first
58
+ assert_not_nil(fetched, "New position #{newpos} could not be fetched")
59
+ assert_equal(newloc.coordinate, fetched.location.coordinate, "Location not updated")
60
+ end
61
+ end
62
+ end