|
84 | 84 | end
|
85 | 85 |
|
86 | 86 | context 'instance authorized' do
|
87 |
| - it 'allows access to an authorized instance' do |
88 |
| - expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 87 | + context 'single record' do |
| 88 | + it 'allows access to an authorized instance' do |
| 89 | + expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
89 | 90 |
|
90 |
| - patient_jane.allow_phi! 'test', 'unit tests' |
| 91 | + patient_jane.allow_phi! 'test', 'unit tests' |
91 | 92 |
|
92 |
| - expect { patient_jane.first_name }.not_to raise_error |
93 |
| - end |
| 93 | + expect { patient_jane.first_name }.not_to raise_error |
| 94 | + end |
94 | 95 |
|
95 |
| - it 'only allows access to the authorized instance' do |
96 |
| - patient_jane.allow_phi! 'test', 'unit tests' |
| 96 | + it 'only allows access to the authorized instance' do |
| 97 | + patient_jane.allow_phi! 'test', 'unit tests' |
97 | 98 |
|
98 |
| - expect { patient_jane.first_name }.not_to raise_error |
99 |
| - expect { patient_john.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
100 |
| - end |
| 99 | + expect { patient_jane.first_name }.not_to raise_error |
| 100 | + expect { patient_john.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 101 | + end |
101 | 102 |
|
102 |
| - it 'revokes access after calling disallow_phi!' do |
103 |
| - expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 103 | + it 'revokes access after calling disallow_phi!' do |
| 104 | + expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
104 | 105 |
|
105 |
| - patient_jane.allow_phi! 'test', 'unit tests' |
| 106 | + patient_jane.allow_phi! 'test', 'unit tests' |
106 | 107 |
|
107 |
| - expect { patient_jane.first_name }.not_to raise_error |
| 108 | + expect { patient_jane.first_name }.not_to raise_error |
108 | 109 |
|
109 |
| - patient_jane.disallow_phi! |
| 110 | + patient_jane.disallow_phi! |
110 | 111 |
|
111 |
| - expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 112 | + expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 113 | + end |
| 114 | + |
| 115 | + it 'allows access on an instance that already exists' do |
| 116 | + john = PatientInfo.create(first_name: 'John', last_name: 'Doe') |
| 117 | + expect { john.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 118 | + |
| 119 | + john_id = john.id |
| 120 | + john = nil |
| 121 | + |
| 122 | + john = PatientInfo.find(john_id) |
| 123 | + expect { john.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 124 | + |
| 125 | + john.allow_phi! 'test', 'unit tests' |
| 126 | + expect { john.first_name }.not_to raise_error |
| 127 | + expect(john.first_name).to eq 'John' |
| 128 | + end |
| 129 | + end |
| 130 | + |
| 131 | + context 'collection' do |
| 132 | + it 'allows access when fetched as a collection' do |
| 133 | + jay = PatientInfo.create(first_name: "Jay") |
| 134 | + bob = PatientInfo.create(first_name: "Bob") |
| 135 | + moe = PatientInfo.create(first_name: "Moe") |
| 136 | + |
| 137 | + patients = PatientInfo.all |
| 138 | + |
| 139 | + expect(patients).to contain_exactly(jay, bob, moe) |
| 140 | + expect { patients.map(&:first_name) }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 141 | + |
| 142 | + patients.map { |p| p.allow_phi! 'test', 'unit tests' } |
| 143 | + expect { patients.map(&:first_name) }.not_to raise_error |
| 144 | + end |
112 | 145 | end
|
113 | 146 | end
|
114 | 147 |
|
|
138 | 171 | expect { patient_jane.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException)
|
139 | 172 | end
|
140 | 173 | end
|
| 174 | + |
| 175 | + context 'extended authorization' do |
| 176 | + let(:mary_detail) { PatientDetail.create(detail: 'Lorem Ipsum') } |
| 177 | + let(:mary_address) { Address.create(address: '123 Street Ave') } |
| 178 | + let(:patient_mary) { PatientInfo.create(first_name: 'Mary', last_name: 'Jay', address: mary_address, patient_detail: mary_detail) } |
| 179 | + |
| 180 | + it 'extends access to extended association' do |
| 181 | + expect { patient_mary.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 182 | + expect { patient_mary.patient_detail }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 183 | + expect { patient_mary.patient_detail.detail }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 184 | + |
| 185 | + patient_mary.allow_phi! 'test', 'unit tests' |
| 186 | + |
| 187 | + expect { patient_mary.first_name }.not_to raise_error |
| 188 | + expect { patient_mary.patient_detail.detail }.not_to raise_error |
| 189 | + expect(patient_mary.patient_detail.detail).to eq 'Lorem Ipsum' |
| 190 | + end |
| 191 | + |
| 192 | + it 'does not extend to unextended association' do |
| 193 | + expect { patient_mary.first_name }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 194 | + expect { patient_mary.address }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 195 | + expect { patient_mary.address.address }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 196 | + |
| 197 | + patient_mary.allow_phi! 'test', 'unit tests' |
| 198 | + expect { patient_mary.first_name }.not_to raise_error |
| 199 | + expect { patient_mary.address }.not_to raise_error |
| 200 | + expect { patient_mary.address.address }.to raise_error(PhiAttrs::Exceptions::PhiAccessException) |
| 201 | + |
| 202 | + patient_mary.address.allow_phi! 'test', 'unit test' |
| 203 | + expect { patient_mary.address.address }.not_to raise_error |
| 204 | + expect(patient_mary.address.address).to eq '123 Street Ave' |
| 205 | + end |
| 206 | + end |
141 | 207 | end
|
0 commit comments