diff --git a/README.md b/README.md index 47daf6b..742a615 100644 --- a/README.md +++ b/README.md @@ -438,9 +438,8 @@ Tests are written using [RSpec](http://rspec.info/) and are setup to use [Apprai $ bundle exec appraisal rspec spec/path/to/spec.rb To run just a particular rails version: - $ bundle exec appraisal rails-5.1 rspec - $ bundle exec appraisal rails-5.2 rspec - $ bundle exec appraisal rails-6.0 rspec + $ bundle exec appraisal rails_6.1 rspec + $ bundle exec appraisal rails-7.0 rspec ### Console diff --git a/bin/ssh_to_container b/bin/ssh_to_container index 9bf6655..58dc4ed 100755 --- a/bin/ssh_to_container +++ b/bin/ssh_to_container @@ -5,4 +5,4 @@ if [[ -z $CONTAINER ]]; then CONTAINER='ruby3' fi -docker-compose run $CONTAINER sh +docker-compose run $CONTAINER bash diff --git a/lib/phi_attrs/phi_record.rb b/lib/phi_attrs/phi_record.rb index a19205d..5ee9324 100644 --- a/lib/phi_attrs/phi_record.rb +++ b/lib/phi_attrs/phi_record.rb @@ -624,6 +624,10 @@ def set_all_phi_context_logged # # through access logging. # def phi_wrap_method(method_name) + unless self.respond_to?(method_name) + PhiAttrs::Logger.warn("#{self.class.name} tried to wrap non-existant method (#{method_name})") + return + end return if self.class.__phi_methods_wrapped.include? method_name wrapped_method = :"__#{method_name}_phi_wrapped" @@ -659,6 +663,7 @@ def phi_wrap_method(method_name) # @private # def phi_wrap_extension(method_name) + raise NameError, "Undefined relationship in `extend_phi_access`: #{method_name}" unless self.respond_to?(method_name) return if self.class.__phi_methods_to_extend.include? method_name wrapped_method = wrapped_extended_name(method_name) diff --git a/spec/dummy/app/models/missing_attribute_model.rb b/spec/dummy/app/models/missing_attribute_model.rb new file mode 100644 index 0000000..452f5b0 --- /dev/null +++ b/spec/dummy/app/models/missing_attribute_model.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class MissingAttributeModel < ApplicationRecord + phi_model + phi_include_methods :non_existent_method +end diff --git a/spec/dummy/app/models/missing_extend_model.rb b/spec/dummy/app/models/missing_extend_model.rb new file mode 100644 index 0000000..3a2ebde --- /dev/null +++ b/spec/dummy/app/models/missing_extend_model.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class MissingExtendModel < ApplicationRecord + phi_model + extend_phi_access :non_existent_model +end diff --git a/spec/dummy/db/migrate/20170214100255_create_patient_infos.rb b/spec/dummy/db/migrate/20170214100255_create_patient_infos.rb index a18c93d..673b66c 100644 --- a/spec/dummy/db/migrate/20170214100255_create_patient_infos.rb +++ b/spec/dummy/db/migrate/20170214100255_create_patient_infos.rb @@ -24,5 +24,13 @@ def change t.belongs_to :patient_info t.string :data end + + create_table :missing_attribute_model do |t| + t.timestamps + end + + create_table :missing_extend_model do |t| + t.timestamps + end end end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index f88772f..563d7b3 100755 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -23,6 +23,16 @@ t.index ["patient_info_id"], name: "index_health_records_on_patient_info_id" end + create_table "missing_attribute_model", force: :cascade do |t| + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + end + + create_table "missing_extend_model", force: :cascade do |t| + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + end + create_table "patient_details", force: :cascade do |t| t.integer "patient_info_id" t.string "detail" diff --git a/spec/dummy/factories/missing_attribute_models.rb b/spec/dummy/factories/missing_attribute_models.rb new file mode 100644 index 0000000..97bf43c --- /dev/null +++ b/spec/dummy/factories/missing_attribute_models.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :missing_attribute_model do + end +end diff --git a/spec/dummy/factories/missing_extend_models.rb b/spec/dummy/factories/missing_extend_models.rb new file mode 100644 index 0000000..d7e02f4 --- /dev/null +++ b/spec/dummy/factories/missing_extend_models.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :missing_extend_model do + end +end diff --git a/spec/phi_attrs/phi_record/phi_wrapping.rb b/spec/phi_attrs/phi_record/phi_wrapping.rb new file mode 100644 index 0000000..7f52693 --- /dev/null +++ b/spec/phi_attrs/phi_record/phi_wrapping.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'phi_wrapping' do + file_name = __FILE__ + + let(:missing_attribute_model) { build(:missing_attribute_model) } + let(:missing_extend_model) { build(:missing_extend_model) } + + context 'non existant attributes' do + it 'wrapping a method' do |t| + expect{missing_attribute_model}.not_to raise_error + end + + it 'extending a model' do |t| + expect{missing_extend_model}.to raise_error(NameError) + end + end +end