require 'spec_helper'

describe Admin::SnapshotsController do

  describe "POST create" do

    let(:repository) { FactoryGirl.create(:repository) }
    let(:file) { "spec/data/archives/example.com/2013-10-29-example.com.raw.json.gz" }

    subject { post "create", repository_id: repository.id, file: file }

    it "renders nothing" do
      expect(subject).to have_text(' ')
    end

    it "creates a new snapshot" do
      expect { subject }.to change { repository.reload.snapshots.count }.by(1)
    end

    it "creates the test snapshot" do
      post "create", repository_id: repository.id, file: file
      snapshot = repository.reload.snapshots.first
      expect(snapshot.date).to eq(Date.new(2013, 10, 29))
    end

    it "creates a new metadata record" do
      post "create", repository_id: repository.id, file: file
      snapshot = repository.reload.snapshots.first
      expect(snapshot.metadata_records.count).to be(1)
    end
  end

end

require 'spec_helper'

describe Admin::SnapshotsController do

  describe "POST create" do

    let(:repository) { FactoryGirl.create(:repository) }
    let(:file) { "spec/data/archives/example.com/2013-10-29-example.com.raw.json.gz" }

    subject { post "create", repository_id: repository.id, file: file }

    it "renders nothing" do
      expect(subject).to have_text(' ')
    end

    it "creates a new snapshot" do
      expect { subject }.to change { repository.reload.snapshots.count }.by(1)
    end

    it "creates the test snapshot" do
      post "create", repository_id: repository.id, file: file
      snapshot = repository.reload.snapshots.first
      expect(snapshot.date).to eq(Date.new(2013, 10, 29))
    end

    it "creates a new metadata record" do
      post "create", repository_id: repository.id, file: file
      snapshot = repository.reload.snapshots.first
      expect(snapshot.metadata_records.count).to be(1)
    end

    it "compiles statistics about the metadata record" do
      statistics = { "languages" => { "Unknown" => 1 },
                     "resources" => { "min" => 0,
                                      "avg" => 0.0,
                                      "max" => 0,
                                      "sum" => 0,
                                      "med" => 0 } }

      post "create", repository_id: repository.id, file: file
      snapshot = repository.reload.snapshots.first
      expect(snapshot.statistics).to eq(statistics)
    end
  end

end

Add test case for the statistic compilation
Add test case for the statistic compilation

The statistic compilation is now covered, too. Although this is more
like a dummy test, since the test snapshot does not contain any
resources. So it is likely that this test is updated in the future.

Signed-off-by: Konrad Reiche <4ff0213f56e2082fcd8c882d04c546881c579ce4@gmail.com>
