<commit_before>require 'spec_helper'

describe Spree::OrdersController do
  ORDER_TOKEN = 'ORDER_TOKEN'

  let(:user) { create(:user) }
  let(:guest_user) { create(:user) }
  let(:order) { Spree::Order.new }

  it 'should understand order routes with token' do
    spree.token_order_path('R123456', 'ABCDEF').should == '/orders/R123456/token/ABCDEF'
  end

  before do
    Spree::User.stub :anonymous! => guest_user
  end

  context 'when no order exists in the session' do
    before { Spree::Order.stub :new => order }

    context '#populate' do
      context 'when not logged in' do
        it 'should create an anonymous user' do
          Spree::User.should_receive :anonymous!
          post :populate
        end
      end

      context 'when authenticated as a registered user' do
        before { controller.stub :spree_current_user => user }

        it 'should not create an anonymous user' do
          Spree::User.should_not_receive :anonymous!
          post :populate
          session[:access_token].should be_nil
        end

        it 'should associate the new order with the registered user' do
          post :populate
          order.user.should == user
        end
      end

      context 'when not authenticated' do
        it 'should create an anonymous user' do
          Spree::User.should_receive(:anonymous!).and_return guest_user
          post :populate
        end

        it 'should associate the new order with the anonymous user' do
          post :populate
          order.user.should == guest_user
        end

        context 'when there is an order token' do<commit_msg>Remove checks for Spree::User.anonymous! calls<commit_after>require 'spec_helper'

describe Spree::OrdersController do
  ORDER_TOKEN = 'ORDER_TOKEN'

  let(:user) { create(:user) }
  let(:guest_user) { create(:user) }
  let(:order) { Spree::Order.new }

  it 'should understand order routes with token' do
    spree.token_order_path('R123456', 'ABCDEF').should == '/orders/R123456/token/ABCDEF'
  end

  context 'when no order exists in the session' do
    before { Spree::Order.stub :new => order }

    context '#populate' do
      context 'when authenticated as a registered user' do
        before { controller.stub :spree_current_user => user }

        it 'should associate the new order with the registered user' do
          post :populate
          order.user.should == user
        end
      end

      context 'when not authenticated' do
        context 'when there is an order token' do
{'fraction_non_alphanumeric': 0.08801274392672243, 'fraction_numerical': 0.009557945041816009, 'mean_word_length': 2.667153284671533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5439675', 'n_tokens_mistral': 751, 'n_tokens_neox': 710, 'n_words': 237}