<commit_before>require 'spec_helper'

describe Question do
  fixtures :questions
  fixtures :tags

  let(:tag) { tags(:test) }
  let(:five_tags ) { [ tags(:test), tags(:test2), tags(:test3), tags(:test4), tags(:test5)] }

  subject do
    question = questions(:test)
    question
  end

  context "with valid attributes" do
    it { should be_valid }
    describe "1 to 5 tags" do
      context "one existing tag in tags_string" do
        before do
          subject.tags_string = "tagtest"
          subject.valid? # to trigger the validate_existing_of_tags
        end

        it  "should have the tags" do
          subject.tags.should == [tag]
        end
      end

      context "5 existing tag in tags_string" do
        before do
          five_tags
          subject.tags_string = "tagtest, tagtest2, tagtest3, tagtest4, tagtest5"
          subject.valid? # to trigger the validate_existing_of_tags
        end

        it  "should have the tags" do
          subject.tags.should == five_tags
        end
      end
    end

  end

  describe "with invalid attributes" do

    context "empty title" do
      before(:each) do
        subject.title = ''
      end
      it { should_not be_valid }
    end

    context "with non-existing tag" do
      before(:each) do
        subject.tags_string = 'non-existing-tag'
      end
      it { should_not be_valid }
    end

  end

  it "should have answers" do
    expect {
      subject.answers << Answer.new
    }.to change(subject.answers, :size).by(1)
  end

  it "should update the state updated timestamp when the state is changed" do
    expect {
      subject.state = "closed"
      subject.save
    }.to change(subject, :state_last_updated)
  end
end<commit_msg>Use tags list instead of tags string<commit_after>require 'spec_helper'

describe Question do
  fixtures :questions
  fixtures :tags

  let(:tag) { tags(:test) }
  let(:five_tags ) { [ tags(:test), tags(:test2), tags(:test3), tags(:test4), tags(:test5)] }

  subject do
    question = questions(:test)
    question
  end

  context "with valid attributes" do
    it { should be_valid }
    describe "1 to 5 tags" do
      context "one existing tag in tags_list" do
        before do
          subject.tags_list = tag.name
        end

        it  "should have the tags" do
          subject.tags.should == [tag]
        end
      end

      context "5 existing tag in tags_string" do
        before do
          five_tags
          subject.tags_list = five_tags.pluck(:name).join(',')
        end

        it  "should have the tags" do
          subject.tags.should == five_tags
        end
      end
    end

  end

  describe "with invalid attributes" do

    context "empty title" do
      before(:each) do
        subject.title = ''
      end
      it { should_not be_valid }
    end

    context "with non-existing tag" do
      before(:each) do
        subject.tags_list = 'non-existing-tag'
      end
      it { should_not be_valid }
    end

  end

  it "should have answers" do
    expect {
      subject.answers << Answer.new
    }.to change(subject.answers, :size).by(1)
  end

  it "should update the state updated timestamp when the state is changed" do
    expect {
      subject.state = "closed"
      subject.save
    }.to change(subject, :state_last_updated)
  end
end
{'fraction_non_alphanumeric': 0.08673315200967059, 'fraction_numerical': 0.0060441220912662436, 'mean_word_length': 2.1826923076923075, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5804283', 'n_tokens_mistral': 1015, 'n_tokens_neox': 974, 'n_words': 319}