<commit_before>require 'spec_helper'

describe RedisCacheable do
  let(:model) { double }

  before do
    model.extend(described_class)
  end

  describe '#cached_attribute' do
    let(:payload) { { attribute: 'value' } }

    subject { model.cached_attribute(payload.keys.first) }

    it 'gets the cache attribute' do
      expect(model).to receive(:cache_attribute_key).and_return('key')

      Gitlab::Redis::SharedState.with do |redis|
        expect(redis).to receive(:get).with('key')
          .and_return(payload.to_json)
      end

      expect(subject).to eq(payload.values.first)
    end
  end

  describe '#cache_attributes' do
    let(:values) { { name: 'new_name' } }

    subject { model.cache_attributes(values) }

    it 'sets the cache attributes' do
      Gitlab::Redis::SharedState.with do |redis|
        values.each do |key, value|
          redis_key = model.send(:cache_attribute_key)
          expect(redis).to receive(:set).with(redis_key, values.to_json, anything)
        end
      end

      subject
    end
  end
end<commit_msg>Fix RedisCacheable#cache_attributes spec<commit_after>require 'spec_helper'

describe RedisCacheable do
  let(:model) { double }

  before do
    model.extend(described_class)
    allow(model).to receive(:cache_attribute_key).and_return('key')
  end

  describe '#cached_attribute' do
    let(:payload) { { attribute: 'value' } }

    subject { model.cached_attribute(payload.keys.first) }

    it 'gets the cache attribute' do
      Gitlab::Redis::SharedState.with do |redis|
        expect(redis).to receive(:get).with('key')
          .and_return(payload.to_json)
      end

      expect(subject).to eq(payload.values.first)
    end
  end

  describe '#cache_attributes' do
    let(:values) { { name: 'new_name' } }

    subject { model.cache_attributes(values) }

    it 'sets the cache attributes' do
      Gitlab::Redis::SharedState.with do |redis|
        expect(redis).to receive(:set).with('key', values.to_json, anything)
      end

      subject
    end
  end
end
{'fraction_non_alphanumeric': 0.11799410029498525, 'fraction_numerical': 0.0, 'mean_word_length': 3.1700819672131146, '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': '4032814', 'n_tokens_mistral': 655, 'n_tokens_neox': 631, 'n_words': 136}