<commit_before>require 'spec_helper'

describe Tangocard::Order do
  include TangocardHelpers

  describe 'class methods' do
    describe 'self.all' do
      let(:params) { Object.new }
      let(:success_response) { sample_order_index_response(true) }
      let(:fail_response) { sample_order_index_response(false) }

      it 'should return an array of Tangocard::Order objects if successful' do
        mock(Tangocard::Raas).orders_index(params) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['orders'].first) { true }
        Tangocard::Order.all(params).should == [true]
      end

      it 'should return an empty array if unsuccessful' do
        mock(Tangocard::Raas).orders_index(params) { fail_response }
        Tangocard::Order.all(params).should == []
      end
    end

    describe 'self.find' do
      let(:order_id) { Object.new }
      let(:success_response) { sample_find_order_response(true) }
      let(:fail_response) { sample_find_order_response(false) }

      it 'should return a Tangocard::Order object if successful' do
        mock(Tangocard::Raas).show_order({'order_id' => order_id}) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['order']) { true }
        Tangocard::Order.find(order_id).should be_true
      end

      it 'should throw a Tangocard::OrderNotFoundException if failed' do
        mock(Tangocard::Raas).show_order({'order_id' => order_id}) { fail_response }
        lambda{ Tangocard::Order.find(order_id) }.should raise_error(Tangocard::OrderNotFoundException)
      end
    end

    describe 'self.create' do
      let(:params) { Object.new }
      let(:success_response) { sample_create_order_response(true) }
      let(:fail_response) { sample_create_order_response(false) }

      it 'should return at Tangocard::Order object if successful' do
        mock(Tangocard::Raas).create_order(params) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['order']) { true }
        Tangocard::Order.create(params).should be_true
      end

      it "should throw a Tangocard::OrderCreateFailedException if failed" do
        mock(Tangocard::Raas).create_order(params) { fail_response }
        lambda{ Tangocard::Order.create(params) }.should raise_error(Tangocard::OrderCreateFailedException)
      end
    end
  end<commit_msg>And again<commit_after>require 'spec_helper'

describe Tangocard::Order do
  include TangocardHelpers

  describe 'class methods' do
    describe 'self.all' do
      let(:params) { Object.new }
      let(:success_response) { sample_order_index_response(true) }
      let(:fail_response) { sample_order_index_response(false) }

      it 'should return an array of Tangocard::Order objects if successful' do
        mock(Tangocard::Raas).orders_index(params) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['orders'].first) { true }
        Tangocard::Order.all(params).should == [true]
      end

      it 'should return an empty array if unsuccessful' do
        mock(Tangocard::Raas).orders_index(params) { fail_response }
        Tangocard::Order.all(params).should == []
      end
    end

    describe 'self.find' do
      let(:order_id) { Object.new }
      let(:success_response) { sample_find_order_response(true) }
      let(:fail_response) { sample_find_order_response(false) }

      it 'should return a Tangocard::Order object if successful' do
        mock(Tangocard::Raas).show_order({'order_id' => order_id}) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['order']) { true }
        Tangocard::Order.find(order_id).should be_true
      end

      it 'should throw a Tangocard::OrderNotFoundException if failed' do
        mock(Tangocard::Raas).show_order({'order_id' => order_id}) { fail_response }
        lambda{ Tangocard::Order.find(order_id) }.should raise_error(Tangocard::OrderNotFoundException)
      end
    end

    describe 'self.create' do
      let(:params) { Object.new }
      let(:success_response) { sample_create_order_response(true) }
      let(:fail_response) { sample_create_order_response(false) }

      it 'should return at Tangocard::Order object if successful' do
        mock(Tangocard::Raas).create_order(params) { success_response }
        mock(Tangocard::Order).new(success_response.parsed_response['order']) { true }
        Tangocard::Order.create(params).should be_true
      end

      it 'should throw a Tangocard::OrderCreateFailedException if failed' do
        mock(Tangocard::Raas).create_order(params) { fail_response }
        lambda{ Tangocard::Order.create(params) }.should raise_error(Tangocard::OrderCreateFailedException)
      end
    end
  end
{'fraction_non_alphanumeric': 0.11083228774571309, 'fraction_numerical': 0.0, 'mean_word_length': 3.8313131313131312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4532177', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1401, 'n_words': 274}