<commit_before>require 'spec_helper'
require 'mock_redis'

shared_examples_for 'a redis model' do
  before(:each) do
    subject.stub(:valid?).and_return(true)
  end
  
  it 'is convertible to an hash' do
    expect(subject.attributes).to be_a(Hash)
  end 
  
  context 'when already saved' do
    before(:each) do
      subject.save
    end

    context 'when saved again' do
      it 'has the same id' do
        old_id = subject.id
        subject.save
        expect(subject.id).to eq(old_id)
      end
      
      context 'with different attributes' do
        it "hasn't the same id" do
          old_id = subject.id
          attribute = subject.attributes.first.first
          value = subject.attributes.first.second

          subject.send("#{attribute}=", "#{value}0")
          subject.save
          expect(subject.id).not_to eq(old_id)
        end
      end
    end

    it 'is persistent' do
      expect(subject).to be_persisted
    end

    it 'can be found by its id' do
      expected = described_class.find(subject.id)
      expect(subject.attributes).to eq(expected.attributes)
    end

    it 'is destroyable' do
      subject.destroy
      expect(subject).not_to be_persisted
    end
  end
  
  context 'when not saved' do
    it 'has no id' do
      expect(subject.id).to be_nil
    end

    it 'can be saved' do
      expect(subject.save).not_to be_nil
    end

    it "can't be found" do
      expect { described_class.find(subject.id) }.to raise_error
    end
  end
  
  context 'when invalid' do
    before(:each) do
      subject.stub(:valid?).and_return(false)
    end
  
    it "can't be saved" do<commit_msg>upgrades stubs to rspec 3.1 to avoid deprecation warning<commit_after>require 'spec_helper'
require 'mock_redis'

shared_examples_for 'a redis model' do
  before(:each) do
    allow(subject).to receive(:valid?).and_return(true)
  end
  
  it 'is convertible to an hash' do
    expect(subject.attributes).to be_a(Hash)
  end 
  
  context 'when already saved' do
    before(:each) do
      subject.save
    end
    
    it 'has an id' do
      expect(subject.id).not_to be_nil
    end

    it 'is persistent' do
      expect(subject).to be_persisted
    end

    it 'can be found by its id' do
      expected = described_class.find(subject.id)
      expect(subject.attributes).to eq(expected.attributes)
    end

    it 'is destroyable' do
      subject.destroy
      expect(subject).not_to be_persisted
    end

    context 'when saved again' do
      it 'has the same id' do
        old_id = subject.id
        subject.save
        expect(subject.id).to eq(old_id)
      end
      
      context 'with different attributes' do
        it "hasn't the same id" do
          old_id = subject.id
          attribute = subject.attributes.first.first
          value = subject.attributes.first.second

          subject.send("#{attribute}=", "#{value}0")
          subject.save
          expect(subject.id).not_to eq(old_id)
        end
      end
    end
  end
  
  context 'when not saved' do
    it 'has no id' do
      expect(subject.id).to be_nil
    end

    it 'can be saved' do
      expect(subject.save).not_to be_nil
    end

    it "can't be found" do
      expect { described_class.find(subject.id) }.to raise_error
    end
  end
  
  context 'when invalid' do
    before(:each) do
      allow(subject).to receive(:valid?).and_return(false)
    end
  
    it "can't be saved" do
{'fraction_non_alphanumeric': 0.09021897810218978, 'fraction_numerical': 0.0011678832116788322, 'mean_word_length': 2.24739336492891, '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': '1777375', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1076, 'n_words': 313}