<commit_before>require 'spec_helper'

shared_examples_for "encryptable" do
  let(:model) { described_class } # the class that includes the concern

  let(:model_instance) {
    build(described_class.to_s.underscore.to_sym)
  }

  let(:valid_attributes) {
    # exclude date and id fields
    cols = model.column_names.select { |c| !(c.include? "id" or c.include? "_at")}
    cols.map {|c| c.to_sym}
  }

  it "has encryptable attributes" do
    model.encryptable_attributes *valid_attributes
    expect(model_instance.encryptable_attributes).not_to be_empty
  end

  it "encrypts encryptable attributes" do
    model_hash = json_str_to_hash(model_instance.to_json)
    model_instance.encrypt_encryptable_attributes
    model_instance.encryptable_attributes.each do |attribute|
      expect(model_hash[attribute]).not_to eq(model_instance.send(attribute))
    end
  end

  it "decrypts encryptable attributes" do
    model_hash = json_str_to_hash(model_instance.to_json)
    model_instance.encrypt_encryptable_attributes
    model_instance.decrypt_encryptable_attributes
    model_instance.encryptable_attributes.each do |attribute|
      expect(model_hash[attribute]).to eq(model_instance.send(attribute))<commit_msg>created post model and spec<commit_after>require 'spec_helper'

shared_examples_for "encryptable" do
  let(:model) { described_class } # the class that includes the concern

  let(:model_instance) {
    build(described_class.to_s.underscore.to_sym)
  }

  let(:valid_encryptable_attributes) {
    # exclude date and id fields
    cols = model.column_names.select { |c| !(c.include? "id" or c.include? "_at")}
    cols.map {|c| c.to_sym}
  }

  it "has encryptable attributes" do
    model.encryptable_attributes *valid_encryptable_attributes
    expect(model_instance.encryptable_attributes).not_to be_empty
  end

  it "encrypts encryptable attributes" do
    model_hash = json_str_to_hash(model_instance.to_json)
    model_instance.encrypt_encryptable_attributes
    model_instance.encryptable_attributes.each do |attribute|
      expect(model_hash[attribute]).not_to eq(model_instance.send(attribute))
    end
  end

  it "decrypts encryptable attributes" do
    model_hash = json_str_to_hash(model_instance.to_json)
    model_instance.encrypt_encryptable_attributes
    model_instance.decrypt_encryptable_attributes
    model_instance.encryptable_attributes.each do |attribute|
      expect(model_hash[attribute]).to eq(model_instance.send(attribute))
{'fraction_non_alphanumeric': 0.08414239482200647, 'fraction_numerical': 0.0, 'mean_word_length': 5.076167076167076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814115', 'n_tokens_mistral': 805, 'n_tokens_neox': 780, 'n_words': 145}