<commit_before>require 'spec_helper'

describe Spree::OmnikassaController do
  include_context 'omnikassa'

  subject { Spree::OmnikassaController }

  let(:order) { FactoryGirl.create :completed_order_with_totals } 
  let(:payment) { FactoryGirl.create :payment, order: order }


  before :each do
    controller.stub(:authorize!)
    Spree::BillingIntegration::Omnikassa.create! name: 'omnikassa'
  end

  describe 'GET restart' do
    before :each do
      payment.send("started_processing!")
      payment.send("failure!")
      payment.save!
      spree_get(:restart, order_id: order.id, token: order.token)
    end

    describe 'create a new payment' do
      let(:restarted_payment) { order.payments.last }

      it 'a new payment is created' do
        expect(restarted_payment.state).to eq('checkout')  
      end

      it 'has omnikassa as payment method' do
        expect(restarted_payment.payment_method.class).to eq(Spree::BillingIntegration::Omnikassa)  
      end

      it 'has the order outstanding amount as payment amount' do
        expect(restarted_payment.amount).to eq(order.outstanding_balance)
      end

      it 'redirects to the omnikassa start page' do
        u = "http://test.host/omnikassa/start/#{restarted_payment.id}/"
        expect(response.response_code).to redirect_to(u)
      end
    end
  end

  describe 'GET start' do
    describe 'assignment' do
      it 'assigns a @data string' do
        spree_get :start, payment_id: payment.id
        assigns(:data).should == 'amount=4575|currencyCode=978|merchantId=1337|normalReturnUrl=http://test.host/omnikassa/success/1/|automaticResponseUrl=http://test.host/omnikassa/success/automatic/1/|transactionReference=PREFIX11|keyVersion=7'<commit_msg>Reload order in specs<commit_after>require 'spec_helper'

describe Spree::OmnikassaController do
  include_context 'omnikassa'

  subject { Spree::OmnikassaController }

  let(:order) { FactoryGirl.create :completed_order_with_totals } 
  let(:payment) { FactoryGirl.create :payment, order: order }

  before :each do
    controller.stub(:authorize!)
    Spree::BillingIntegration::Omnikassa.create! name: 'omnikassa'
  end

  describe 'GET restart' do
    before :each do
      payment.send("started_processing!")
      payment.send("failure!")
      payment.save!
      spree_get(:restart, order_id: order.id, token: order.token)
    end

    describe 'create a new payment' do
      let(:restarted_payment) { 
        order.reload
        order.payments.last 
      }

      it 'a new payment is created' do
        expect(restarted_payment.state).to eq('checkout')  
      end

      it 'has omnikassa as payment method' do
        expect(restarted_payment.payment_method.class).to eq(Spree::BillingIntegration::Omnikassa)  
      end

      it 'has the order outstanding amount as payment amount' do
        expect(restarted_payment.amount).to eq(order.outstanding_balance)
      end

      it 'redirects to the omnikassa start page' do
        u = "http://test.host/omnikassa/start/#{restarted_payment.id}/"
        expect(response.response_code).to redirect_to(u)
      end
    end
  end

  describe 'GET start' do
    describe 'assignment' do
      it 'assigns a @data string' do
        spree_get :start, payment_id: payment.id
        assigns(:data).should == 'amount=4575|currencyCode=978|merchantId=1337|normalReturnUrl=http://test.host/omnikassa/success/1/|automaticResponseUrl=http://test.host/omnikassa/success/automatic/1/|transactionReference=PREFIX11|keyVersion=7'
{'fraction_non_alphanumeric': 0.10426136363636364, 'fraction_numerical': 0.00909090909090909, 'mean_word_length': 3.5315315315315314, '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': '3395960', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1087, 'n_words': 235}