<commit_before>RSpec.shared_examples "acts_as_multilist" do |list_type|

  SpreeMarketing::CONFIG ||= { Rails.env => {} }

  context "#self.load_list" do
    let!(:list) { create(list_type.to_s.demodulize.underscore.to_sym, name: list_type.to_s.demodulize.underscore + "_" + entity_name) }

    it { expect(list_type.send :load_list, entity_key).to eq list }
  end

  context "#self.generator" do

    class GibbonServiceTest
    end

    let(:gibbon_service) { GibbonServiceTest.new }

    before do
      allow(GibbonService).to receive(:new).and_return(gibbon_service)
      allow(gibbon_service).to receive(:delete_lists).and_return(true)
    end

    context "if list already exists" do

      let(:emails) { ['<EMAIL>'] }
      let(:contacts_data) { [{ id: '12345678', email_address: emails.first, unique_email_id: 'test' }.with_indifferent_access] }
      let(:list) { create(list_type.to_s.demodulize.underscore.to_sym, name: list_type.to_s.demodulize.underscore + "_" + entity_name) }

      before do
        allow(list_type).to receive(:find_by).and_return(list)
        allow(gibbon_service).to receive(:update_list).and_return(contacts_data)
      end

      it { expect { list_type.send :generator }.to change { list_type.all.count }.by 0 }
      it { expect { list_type.send :generator }.to change { list_type.last.contacts.count }.by 1 }
    end

    context "if list doesn't exists" do

      let(:list_name) { 'test' }
      let(:list_data) { { id: '12345678', name: list_name }.with_indifferent_access }
      let(:emails) { ['<EMAIL>'] }
      let(:contacts_data) { [{ id: '12345678', email_address: emails.first, unique_email_id: 'test' }.with_indifferent_access] }

      before do
        allow(list_type).to receive(:find_by).and_return(nil)
        allow(gibbon_service).to receive(:generate_list).and_return(list_data)
        allow(gibbon_service).to receive(:subscribe_members).and_return(contacts_data)
      end

      it { expect { list_type.send :generator }.to change { list_type.all.count }.by 1 }
    end
  end

end
<commit_msg>optimize factories and variables which were repeated<commit_after>RSpec.shared_examples "acts_as_multilist" do |list_type|

  SpreeMarketing::CONFIG ||= { Rails.env => {} }

  context "#self.load_list" do
    let!(:list) { create(list_type.to_s.demodulize.underscore.to_sym, name: list_type.to_s.demodulize.underscore + "_" + entity_name) }

    it { expect(list_type.send :load_list, entity_key).to eq list }
  end

  context "#self.generator" do

    class GibbonServiceTest
    end

    let(:gibbon_service) { GibbonServiceTest.new }
    let(:emails) { ['<EMAIL>'] }
    let(:contacts_data) { [{ id: '12345678', email_address: emails.first, unique_email_id: 'test' }.with_indifferent_access] }

    before do
      allow(GibbonService).to receive(:new).and_return(gibbon_service)
      allow(gibbon_service).to receive(:delete_lists).and_return(true)
    end

    context "if list already exists" do

      let(:list) { create(list_type.to_s.demodulize.underscore.to_sym, name: list_type.to_s.demodulize.underscore + "_" + entity_name) }

      before do
        allow(list_type).to receive(:find_by).and_return(list)
        allow(gibbon_service).to receive(:update_list).and_return(contacts_data)
      end

      it { expect { list_type.send :generator }.to change { list_type.all.count }.by 0 }
      it { expect { list_type.send :generator }.to change { list_type.last.contacts.count }.by 1 }
    end

    context "if list doesn't exists" do

      let(:list_name) { 'test' }
      let(:list_data) { { id: '12345678', name: list_name }.with_indifferent_access }

      before do
        allow(list_type).to receive(:find_by).and_return(nil)
        allow(gibbon_service).to receive(:generate_list).and_return(list_data)
        allow(gibbon_service).to receive(:subscribe_members).and_return(contacts_data)
      end

      it { expect { list_type.send :generator }.to change { list_type.all.count }.by 1 }
    end
  end

end

{'fraction_non_alphanumeric': 0.1273455091318489, 'fraction_numerical': 0.011508631473605204, 'mean_word_length': 3.7257683215130024, 'pattern_counts': {'":': 0, '<': 6, '<?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': '6518264', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1360, 'n_words': 252}