<commit_before>require 'spec_helper'

describe MongodbClone::MongodbReplication do
  before do
    Rails.stub_chain(:root, :join).and_return(File.join(File.dirname(__FILE__), 'support', 'mongoid.yml'))
  end

  describe '#dump' do
    it 'should dump database' do
      subject.id = '201210231843100200'
      subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')

      subject.dump
    end

    context 'when dump the development database' do
      it 'should dump the selected database' do
        subject.id = '201210231843100200'
        subject.should_receive(:execute).with('mongodump -h "localhost:27017" -d "mongodb_clone_development" -o "/tmp/mongodb_clone_development/201210231843100200"')

        subject.dump(:development)
      end
    end
  end

  describe '#restore' do
    it 'should restore database' do
      subject.id = '201210231843100200'
      subject.path = '/tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production'
      subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')
      subject.should_receive(:execute).with('mongorestore --drop -h "localhost:27017" -d "mongodb_clone_development" /tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production')

      subject.dump.restore
    end
  end
end<commit_msg>Refactoring the specs<commit_after>require 'spec_helper'

describe MongodbClone::MongodbReplication do
  before do
    file = File.join(File.dirname(__FILE__), 'support', 'mongoid.yml')
    Rails.stub_chain(:root, :join).and_return(file)
  end

  subject { MongodbClone::MongodbReplication.new.as_null_object }

  describe '#dump' do
    it 'returns the object to create a chain of methods' do
      subject.stub(:execute)
      expect(subject.dump).to be_an_instance_of(described_class)
    end

    it 'should dump database' do
      subject.id = '201210231843100200'
      subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')

      subject.dump
    end

    context 'when dump the development database' do
      it 'should dump the selected database' do
        subject.id = '201210231843100200'
        subject.should_receive(:execute).with('mongodump -h "localhost:27017" -d "mongodb_clone_development" -o "/tmp/mongodb_clone_development/201210231843100200"')

        subject.dump(:development)
      end
    end
  end

  describe '#restore' do
    it 'should restore database' do
      subject.id = '201210231843100200'
      subject.path = '/tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production'
      subject.should_receive(:execute).with('mongorestore --drop -h "localhost:27017" -d "mongodb_clone_development" /tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production')

      subject.restore
    end
  end
end
{'fraction_non_alphanumeric': 0.10559396605908233, 'fraction_numerical': 0.10339409176618479, 'mean_word_length': 4.252475247524752, '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': '3485726', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1020, 'n_words': 201}