<commit_before>require 'spec_helper'

describe Session::Mapper, '#load' do
  subject { object.load(tuple) }

  let(:object) { described_class.new(mapper, tracker, im) }

  let(:mapper) { fake(:mapper) { ROM::Mapper } }
  let(:loader) { fake(:loader) { ROM::Mapper::Loader } }
  let(:dumper) { fake(:dumper) { ROM::Mapper::Dumper } }

  let(:tuple)   { Hash[:id => 1, :name => 'Jane'] }
  let(:user)    { model.new(tuple) }
  let(:model)   { mock_model(:id, :name) }
  let(:im)      { Session::IdentityMap.new }
  let(:tracker) { Session::Tracker.new }

  before do
    stub(mapper).loader { loader }
    stub(loader).identity(tuple) { 1 }
  end

  context 'when IM includes the loaded object' do
    before do
      im.store(1, user, tuple)
    end

    after do
      mapper.should_not have_received.load(tuple)
    end

    it { should be(user) }
  end

  context 'when IM does not include the loaded object' do
    before do
      stub(mapper).load(tuple) { user }
    end

    after do
      mapper.should have_received.load(tuple)
    end

    it { should be(user) }

    it 'stores persisted state in the tracker' do
      subject
      expect(tracker.fetch(user)).to be_persisted
    end<commit_msg>Refactor spec for Session::Mapper#load<commit_after>require 'spec_helper'

describe Session::Mapper, '#load' do
  subject { object.load(tuple) }

  let(:object) { described_class.new(mapper, tracker, im) }

  let(:mapper) { fake(:mapper) { ROM::Mapper } }
  let(:loader) { fake(:loader) { ROM::Mapper::Loader } }
  let(:dumper) { fake(:dumper) { ROM::Mapper::Dumper } }

  let(:tuple)   { Hash[:id => 1, :name => 'Jane'] }
  let(:user)    { model.new(tuple) }
  let(:model)   { mock_model(:id, :name) }
  let(:im)      { Session::IdentityMap.new }
  let(:tracker) { Session::Tracker.new }

  before do
    stub(mapper).loader { loader }
    stub(loader).identity(tuple) { 1 }
  end

  context 'when IM does not include the loaded object' do
    it 'loads the object' do
      stub(mapper).load(tuple) { user }
      expect(subject).to be(user)
      mapper.should have_received.load(tuple)
    end

    it 'stores persisted state in the tracker' do
      expect(tracker.fetch(subject)).to be_persisted
    end
  end

  context 'when IM includes the loaded object' do
    before do
      im.store(1, user, tuple)
    end

    it 'returns already loaded object' do
      expect(subject).to be(user)
      mapper.should_not have_received.load(tuple)
    end
{'fraction_non_alphanumeric': 0.1402439024390244, 'fraction_numerical': 0.0024390243902439024, 'mean_word_length': 3.1996587030716723, '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': '3735998', 'n_tokens_mistral': 853, 'n_tokens_neox': 816, 'n_words': 203}