Skip to content

Commit

Permalink
5.1 wants virtual attributes to be marked
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed May 24, 2017
1 parent 6053b3b commit 00da7c9
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -16,12 +16,17 @@ env:
- ACTIVERECORD=4.1.0
- ACTIVERECORD=4.2.0
- ACTIVERECORD=5.0.0
- ACTIVERECORD=5.1.1
matrix:
exclude:
- rvm: 2.0
env: ACTIVERECORD=5.0.0
- rvm: 2.0
env: ACTIVERECORD=5.1.1
- rvm: 2.1
env: ACTIVERECORD=5.0.0
- rvm: 2.1
env: ACTIVERECORD=5.1.1
- rvm: 2.4.0
env: ACTIVERECORD=3.0.0
- rvm: 2.4.0
Expand All @@ -34,6 +39,8 @@ matrix:
env: ACTIVERECORD=4.1.0
- rvm: rbx
env: ACTIVERECORD=5.0.0
- rvm: rbx
env: ACTIVERECORD=5.1.1
allow_failures:
- rvm: rbx
fast_finish: true
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -6,6 +6,7 @@ desc 'Test the attr_encrypted gem.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.warning = false
t.verbose = true
end

Expand Down
1 change: 1 addition & 0 deletions lib/attr_encrypted/adapters/active_record.rb
Expand Up @@ -51,6 +51,7 @@ def attr_encrypted(*attrs)
super
options = attrs.extract_options!
attr = attrs.pop
attribute attr if ::ActiveRecord::VERSION::STRING >= "5.1.0"
options.merge! encrypted_attributes[attr]

define_method("#{attr}_was") do
Expand Down
2 changes: 1 addition & 1 deletion test/active_record_test.rb
Expand Up @@ -129,7 +129,7 @@ class Address < ActiveRecord::Base
class ActiveRecordTest < Minitest::Test

def setup
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
drop_all_tables
create_tables
end

Expand Down
2 changes: 1 addition & 1 deletion test/attr_encrypted_test.rb
Expand Up @@ -298,7 +298,7 @@ def test_should_encrypt_empty_with_truthy_allow_empty_value_option
@user = User.new
@user.with_allow_empty_value = nil
refute_nil @user.encrypted_with_allow_empty_value
assert_equal nil, @user.with_allow_empty_value
assert_nil @user.with_allow_empty_value
end

def test_should_work_with_aliased_attr_encryptor
Expand Down
2 changes: 1 addition & 1 deletion test/compatibility_test.rb
Expand Up @@ -41,7 +41,7 @@ class MarshallingPet < ActiveRecord::Base
end

def setup
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
drop_all_tables
create_tables
end

Expand Down
2 changes: 1 addition & 1 deletion test/legacy_active_record_test.rb
Expand Up @@ -50,7 +50,7 @@ class LegacyPersonWithValidation < LegacyPerson
class LegacyActiveRecordTest < Minitest::Test

def setup
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
drop_all_tables
create_people_table
end

Expand Down
2 changes: 1 addition & 1 deletion test/legacy_compatibility_test.rb
Expand Up @@ -41,7 +41,7 @@ class LegacyMarshallingPet < ActiveRecord::Base
end

def setup
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
drop_all_tables
create_tables
end

Expand Down
7 changes: 7 additions & 0 deletions test/test_helper.rb
Expand Up @@ -27,6 +27,7 @@
require 'data_mapper'
require 'digest/sha2'
require 'sequel'
ActiveSupport::Deprecation.behavior = :raise

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$:.unshift(File.dirname(__FILE__))
Expand All @@ -49,3 +50,9 @@
def base64_encoding_regex
/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/
end

def drop_all_tables
connection = ActiveRecord::Base.connection
tables = (ActiveRecord::VERSION::MAJOR >= 5 ? connection.data_sources : connection.tables)
tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
end

0 comments on commit 00da7c9

Please sign in to comment.