debian-mirror-gitlab/spec/initializers/attr_encrypted_no_db_connection_spec.rb

41 lines
1,015 B
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-12-05 23:21:45 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'GitLab monkey-patches to AttrEncrypted' do
2018-12-05 23:21:45 +05:30
describe '#attribute_instance_methods_as_symbols_available?' do
2021-09-30 23:02:18 +05:30
let(:klass) do
Class.new(ActiveRecord::Base) do
2018-12-05 23:21:45 +05:30
# We need some sort of table to work on
self.table_name = 'projects'
attr_encrypted :foo
end
2021-09-30 23:02:18 +05:30
end
it 'returns false' do
expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy
end
2018-12-05 23:21:45 +05:30
2021-09-30 23:02:18 +05:30
it 'does not define virtual attributes' do
2018-12-05 23:21:45 +05:30
instance = klass.new
aggregate_failures do
%w[
encrypted_foo encrypted_foo=
encrypted_foo_iv encrypted_foo_iv=
encrypted_foo_salt encrypted_foo_salt=
].each do |method_name|
expect(instance).not_to respond_to(method_name)
end
end
end
2021-09-30 23:02:18 +05:30
it 'calls attr_changed? method with kwargs' do
obj = klass.new
expect(obj.foo_changed?).to eq(false)
end
2018-12-05 23:21:45 +05:30
end
end