<commit_before>require 'spec_helper'

describe Shutl::Resource::Rest do
  let(:headers) do
    {'Accept'=>'application/json', 'Authorization'=>'Bearer', 'Content-Type'=>'application/json'}
  end

  it 'should include the REST verb' do
    TestRest.should respond_to :get
    TestRest.should respond_to :post
    TestRest.should respond_to :post
    TestRest.should respond_to :delete
  end

  let(:resource) { TestRest.new(a: 'a', b: 2)  }

  describe '#find' do
    context 'with no arguments' do
      before do
        @request = stub_request(:get, 'http://host/test_rests/a').
          to_return(:status => 200,
                    :body => '{"test_rest": { "a": "a", "b": 2 }}',
                    :headers => headers)
      end

      it 'should query the endpoint' do
        TestRest.find('a')

        @request.should have_been_requested
      end

      it 'should parse the result of the body to create an object' do
        resource = TestRest.find('a')

        resource.should_not be_nil
        resource.should be_kind_of TestRest
      end

      it 'should assign the attributes based on the json returned' do
        resource = TestRest.find('a')

        resource.instance_variable_get('@a').should == 'a'
        resource.instance_variable_get('@b').should == 2
      end

      {
        400 => Shutl::BadRequest,
        401 => Shutl::UnauthorizedAccess,
        403 => Shutl::ForbiddenAccess,
        404 => Shutl::ResourceNotFound,
        409 => Shutl::ResourceConflict,
        410 => Shutl::ResourceGone,
        422 => Shutl::ResourceInvalid,
        503 => Shutl::ServiceUnavailable,
        501..502 => Shutl::ServerError,
        504..599 => Shutl::ServerError<commit_msg>set value back to true for specs<commit_after>require 'spec_helper'

describe Shutl::Resource::Rest do
  let(:headers) do
    {'Accept'=>'application/json', 'Authorization'=>'Bearer', 'Content-Type'=>'application/json'}
  end

  it 'should include the REST verb' do
    TestRest.should respond_to :get
    TestRest.should respond_to :post
    TestRest.should respond_to :post
    TestRest.should respond_to :delete
  end

  let(:resource) { TestRest.new(a: 'a', b: 2)  }

  describe '#find' do
    context 'with no arguments' do
      before do
        @request = stub_request(:get, 'http://host/test_rests/a').
          to_return(:status => 200,
                    :body => '{"test_rest": { "a": "a", "b": 2 }}',
                    :headers => headers)
      end

      it 'should query the endpoint' do
        TestRest.find('a')

        @request.should have_been_requested
      end

      it 'should parse the result of the body to create an object' do
        resource = TestRest.find('a')

        resource.should_not be_nil
        resource.should be_kind_of TestRest
      end

      it 'should assign the attributes based on the json returned' do
        resource = TestRest.find('a')

        resource.instance_variable_get('@a').should == 'a'
        resource.instance_variable_get('@b').should == 2
      end

      Shutl::Resource.raise_exceptions_on_validation = true
      {
        400 => Shutl::BadRequest,
        401 => Shutl::UnauthorizedAccess,
        403 => Shutl::ForbiddenAccess,
        404 => Shutl::ResourceNotFound,
        409 => Shutl::ResourceConflict,
        410 => Shutl::ResourceGone,
        422 => Shutl::ResourceInvalid,
        503 => Shutl::ServiceUnavailable,
        501..502 => Shutl::ServerError,
        504..599 => Shutl::ServerError
{'fraction_non_alphanumeric': 0.12209802235597593, 'fraction_numerical': 0.02407566638005159, 'mean_word_length': 2.5575942915392456, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 35, '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': '4481819', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1005, 'n_words': 265}