Skip to content

Commit

Permalink
Merge pull request #84 from jmazzi/bugfix/missing_attribute
Browse files Browse the repository at this point in the history
Skip field encodings when attributes are missing
  • Loading branch information
jmazzi committed Oct 20, 2014
2 parents 586499c + 8812945 commit dfaf530
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gemfiles/activerecord_3_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../
specs:
crypt_keeper (0.18.1)
crypt_keeper (0.18.2)
activerecord (>= 3.1, < 4.2)
activesupport (>= 3.1, < 4.2)
aes (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activerecord_3_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../
specs:
crypt_keeper (0.18.1)
crypt_keeper (0.18.2)
activerecord (>= 3.1, < 4.2)
activesupport (>= 3.1, < 4.2)
aes (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activerecord_4_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../
specs:
crypt_keeper (0.18.1)
crypt_keeper (0.18.2)
activerecord (>= 3.1, < 4.2)
activesupport (>= 3.1, < 4.2)
aes (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activerecord_4_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../
specs:
crypt_keeper (0.18.1)
crypt_keeper (0.18.2)
activerecord (>= 3.1, < 4.2)
activesupport (>= 3.1, < 4.2)
aes (~> 0.5.0)
Expand Down
4 changes: 3 additions & 1 deletion lib/crypt_keeper/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def enforce_column_types_callback
# Private: Force string encodings if the option is set
def force_encodings_on_fields
crypt_keeper_fields.each do |field|
send(field).force_encoding(crypt_keeper_encoding) if send(field).respond_to?(:force_encoding)
if attributes.has_key?(field.to_s) && send(field).respond_to?(:force_encoding)
send(field).force_encoding(crypt_keeper_encoding)
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,14 @@ module CryptKeeper
expect { subject.first(5).map(&:storage) }.not_to raise_error
end
end

context "Missing Attributes" do
subject { create_encrypted_model :storage, key: 'tool', salt: 'salt', encryptor: :aes_new, encoding: 'utf-8' }

it "doesn't attempt decryption of missing attributes" do
subject.create!(storage: 'blah')
expect { subject.select(:id).first }.to_not raise_error
end
end
end
end

0 comments on commit dfaf530

Please sign in to comment.