<commit_before>require "spec_helper"

describe Judge::ValidationsController do

  let(:base_params) do
    {
      :use_route => :judge,
      :format => :json
    }
  end
  
  let(:valid_params) do
    {
      :class => "User",
      :attribute => "username",
      :value => "invisibleman",
      :kind => "uniqueness"
    }
  end

  let(:invalid_params) do
    {
      :class => "User",
      :attribute => "city",
      :value => "",
      :kind => "city"
    }
  end

  describe "GET 'perform'" do

    it "responds with empty array if valid" do
      get :perform, valid_params.merge(base_params)
      response.should be_success
      response.body.should eql "[]"
    end

    it "responds with array of error messages if invalid" do
      get :perform, invalid_params.merge(base_params)<commit_msg>xhr with proper accept header in validations controller spec<commit_after>require "spec_helper"

describe Judge::ValidationsController do

  let(:base_params) do
    { :use_route => :judge }
  end

  let(:headers) do
    { :accept => "application/json" }
  end
  
  let(:valid_params) do
    {
      :class => "User",
      :attribute => "username",
      :value => "invisibleman",
      :kind => "uniqueness"
    }.merge(base_params)
  end

  let(:invalid_params) do
    {
      :class => "User",
      :attribute => "city",
      :value => "",
      :kind => "city"
    }.merge(base_params)
  end

  describe "perform" do

    it "responds with empty array if valid" do
      xhr :get, :perform, valid_params, headers
      response.should be_success
      response.body.should eql "[]"
    end

    it "responds with array of error messages if invalid" do
      xhr :get, :perform, invalid_params, headers
{'fraction_non_alphanumeric': 0.12478134110787172, 'fraction_numerical': 0.0, 'mean_word_length': 2.627906976744186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5103070', 'n_tokens_mistral': 554, 'n_tokens_neox': 535, 'n_words': 147}