<commit_before>require 'spec_helper'

describe Draft do
  before do
    @user = Fabricate(:user)
  end
  it "can get a draft by user" do
    Draft.set(@user, "test", 0, "data")
    expect(Draft.get(@user, "test", 0)).to eq "data"
  end

  it "uses the user id and key correctly" do
    Draft.set(@user, "test", 0,"data")
    expect(Draft.get(Fabricate.build(:coding_horror), "test", 0)).to eq nil
  end

  it "should overwrite draft data correctly" do
    Draft.set(@user, "test", 0, "data")
    Draft.set(@user, "test", 0, "new data")
    expect(Draft.get(@user, "test", 0)).to eq "new data"
  end

  it "should clear drafts on request" do
    Draft.set(@user, "test", 0, "data")
    Draft.clear(@user, "test", 0)
    expect(Draft.get(@user, "test", 0)).to eq nil
  end

  it "should disregard old draft if sequence decreases" do
    Draft.set(@user, "test", 0, "data")
    Draft.set(@user, "test", 1, "hello")
    Draft.set(@user, "test", 0, "foo")
    expect(Draft.get(@user, "test", 0)).to eq nil
    expect(Draft.get(@user, "test", 1)).to eq "hello"
  end

  it 'can cleanup old' do
    user = Fabricate(:user)
    key = Draft::NEW_TOPIC
    seq = DraftSequence.next!(user, key)

    Draft.set(user,key,seq,'draft')
    DraftSequence.update_all('sequence = sequence + 1')

    Draft.cleanup!

    expect(Draft.count).to eq 0
    Draft.set(Fabricate(:user), Draft::NEW_TOPIC, seq+1, 'draft')
<commit_msg>add another test<commit_after>require 'spec_helper'

describe Draft do
  before do
    @user = Fabricate(:user)
  end
  it "can get a draft by user" do
    Draft.set(@user, "test", 0, "data")
    expect(Draft.get(@user, "test", 0)).to eq "data"
  end

  it "uses the user id and key correctly" do
    Draft.set(@user, "test", 0,"data")
    expect(Draft.get(Fabricate.build(:coding_horror), "test", 0)).to eq nil
  end

  it "should overwrite draft data correctly" do
    Draft.set(@user, "test", 0, "data")
    Draft.set(@user, "test", 0, "new data")
    expect(Draft.get(@user, "test", 0)).to eq "new data"
  end

  it "should clear drafts on request" do
    Draft.set(@user, "test", 0, "data")
    Draft.clear(@user, "test", 0)
    expect(Draft.get(@user, "test", 0)).to eq nil
  end

  it "should disregard old draft if sequence decreases" do
    Draft.set(@user, "test", 0, "data")
    Draft.set(@user, "test", 1, "hello")
    Draft.set(@user, "test", 0, "foo")
    expect(Draft.get(@user, "test", 0)).to eq nil
    expect(Draft.get(@user, "test", 1)).to eq "hello"
  end

  it 'can cleanup old' do
    user = Fabricate(:user)
    key = Draft::NEW_TOPIC

    Draft.set(user,key,0,'draft')
    Draft.cleanup!
    expect(Draft.count).to eq 1

    seq = DraftSequence.next!(user, key)

    Draft.set(user,key,seq,'draft')
    DraftSequence.update_all('sequence = sequence + 1')

    Draft.cleanup!

    expect(Draft.count).to eq 0
    Draft.set(Fabricate(:user), Draft::NEW_TOPIC, seq+1, 'draft')

{'fraction_non_alphanumeric': 0.17068134893324158, 'fraction_numerical': 0.01307639366827254, 'mean_word_length': 3.486111111111111, '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': '6242512', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1060, 'n_words': 297}