diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 820c5f8..0457d31 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -91,7 +91,7 @@ def set_deleted_at(value, force = nil) # ActiveRecord::RecordInvalid error will be raised if the record isn't # valid. (This prevents reviving records that disregard validation # constraints,) - if PermanentRecords.should_ignore_validations?(force) + if PermanentRecords.should_ignore_validations?(force) || value.present? record.save(validate: false) else record.save! diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 5caada1..0e09444 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '>= 3.5.0' s.add_development_dependency 'rubocop', '~> 0.68.0' # freeze to ensure ruby 2.2 compatibility s.add_development_dependency 'rubocop-performance' - s.add_development_dependency 'sqlite3', '~> 1.3.13' # freeze to ensure specs are working + s.add_development_dependency 'sqlite3', '~> 1.4' # freeze to ensure specs are working end diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 19ab10b..d5cfac0 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -60,8 +60,8 @@ before do allow_any_instance_of(Hole).to receive(:valid?).and_return(false) end - it 'raises' do - expect { subject }.to raise_error(ActiveRecord::RecordInvalid) + it 'does not raise' do + expect { subject }.not_to raise_error(ActiveRecord::RecordInvalid) end context 'with validation opt-out' do @@ -122,9 +122,9 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } - it 'does not mark records as deleted' do - expect { subject }.to raise_error(ActiveRecord::RecordInvalid) - expect(record.muskrats.not_deleted.count).to eq(1) + it 'marks records as deleted' do + expect { subject }.not_to raise_error(ActiveRecord::RecordInvalid) + expect(record.muskrats.not_deleted.count).to eq(0) end end @@ -150,9 +150,9 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } - it('does not mark records as deleted') do - expect { subject }.to raise_error(ActiveRecord::RecordInvalid) - expect(record.reload.location).not_to be_deleted + it('marks records as deleted') do + expect { subject }.not_to raise_error(ActiveRecord::RecordInvalid) + expect(record.reload.location).to be_deleted end end @@ -178,9 +178,9 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } - it 'does not mark records as deleted' do - expect { subject }.to raise_error(ActiveRecord::RecordInvalid) - expect(record.dirt).not_to be_deleted + it 'marks records as deleted' do + expect { subject }.not_to raise_error(ActiveRecord::RecordInvalid) + expect(record.dirt).to be_deleted end end @@ -293,7 +293,7 @@ end context 'that were deleted previously' do - before { muskrat.update_attributes! deleted_at: 2.minutes.ago } + before { muskrat.update_attribute :deleted_at, 2.minutes.ago } it 'does not restore' do expect { subject }.to_not change(muskrat, :deleted?) end