<commit_before>shared_examples_for 'a shipping class setter' do |method, action|
  let(:shipping_class) { FactoryGirl.create(:shipping_class) }
  let(:shipping_delivery_address) { FactoryGirl.create(:address) }

  before do
    session[:shipping_class_id] = session_shipping_class_id
    allow(controller).to receive(:delivery_address).and_return(shipping_delivery_address)
  end

  context 'when shipping_class_id in the session' do
    let(:session_shipping_class_id) { shipping_class.id }

    it 'sets @shipping_class from the session' do
      send(method, action)
      expect(assigns(:shipping_class)).to eq shipping_class
    end
  end

  context 'when shipping_class_id not in the session' do
    let(:session_shipping_class_id) { nil }

    it 'sets @shipping_class to the cheapest shipping class valid for the delivery address' do
      sc1 = double(ShippingClass, :valid_for_basket? => false, amount_for_basket: 5)
      sc2 = double(ShippingClass, :valid_for_basket? => true, amount_for_basket: 15)
      sc3 = double(ShippingClass, :valid_for_basket? => true, amount_for_basket: 10)
      allow(shipping_delivery_address).to receive(:shipping_classes).and_return [sc1, sc2, sc3]
      send(method, action)<commit_msg>Allow double ShippingClass to receive #name<commit_after>shared_examples_for 'a shipping class setter' do |method, action|
  let(:shipping_class) { FactoryGirl.create(:shipping_class) }
  let(:shipping_delivery_address) { FactoryGirl.create(:address) }

  before do
    session[:shipping_class_id] = session_shipping_class_id
    allow(controller).to receive(:delivery_address).and_return(shipping_delivery_address)
  end

  context 'when shipping_class_id in the session' do
    let(:session_shipping_class_id) { shipping_class.id }

    it 'sets @shipping_class from the session' do
      send(method, action)
      expect(assigns(:shipping_class)).to eq shipping_class
    end
  end

  context 'when shipping_class_id not in the session' do
    let(:session_shipping_class_id) { nil }

    it 'sets @shipping_class to the cheapest shipping class valid for the delivery address' do
      sc1 = double(ShippingClass, :valid_for_basket? => false, amount_for_basket: 5, name: 'sc1')
      sc2 = double(ShippingClass, :valid_for_basket? => true, amount_for_basket: 15, name: 'sc2')
      sc3 = double(ShippingClass, :valid_for_basket? => true, amount_for_basket: 10, name: 'sc3')
      allow(shipping_delivery_address).to receive(:shipping_classes).and_return [sc1, sc2, sc3]
      send(method, action)
{'fraction_non_alphanumeric': 0.09442907941525089, 'fraction_numerical': 0.009877518767285659, 'mean_word_length': 5.086538461538462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3823325', 'n_tokens_mistral': 835, 'n_tokens_neox': 804, 'n_words': 192}