Sha256: 99aa7aeded1a094079e0df6d82a7b5d519544d81b934059e20d03ab3024312bc

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe Daigaku::GithubClient do

  describe "#master_zip_url" do
    it "returns the url to the master zip file for the given github repo" do
      url = "https://github.com/a/b/archive/master.zip"
      expect(Daigaku::GithubClient.master_zip_url('a/b')).to eq url
    end
  end

  describe "#updated_at" do
    it "fetches the updated_at timestamp from the Github API" do
      expected_timestamp = "2015-10-21T12:00:00Z"
      response = { updated_at: expected_timestamp }.to_json
      url = "https://api.github.com/repos/a/b"

      stub_request(:get, url)
        .with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
        .to_return(status: 200, body: response, headers: {})

      timestamp = Daigaku::GithubClient.updated_at('a/b')

      expect(timestamp).to eq expected_timestamp
    end
  end

  describe "#updated?" do
    before do
      @received_timestamp = "2015-10-21T12:00:00Z"
      response = { updated_at: @received_timestamp }.to_json
      url = "https://api.github.com/repos/a/b"

      stub_request(:get, url)
        .with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
        .to_return(status: 200, body: response, headers: {})
    end

    it "returns true if content was pushed to the Github repo" do
      QuickStore.store.set('courses/b/updated_at', "2015-10-21T11:59:59Z")
      expect(Daigaku::GithubClient.updated?('a/b')).to be_truthy
    end

    it "returns false if no content was pushed to the Github repo" do
      QuickStore.store.set('courses/b/updated_at', @received_timestamp)
      expect(Daigaku::GithubClient.updated?('a/b')).to be_falsey
    end

    it "returns false if param is nil" do
      expect(Daigaku::GithubClient.updated?(nil)).to be_falsey
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daigaku-0.3.0 spec/daigaku/github_client_spec.rb
daigaku-0.2.0 spec/daigaku/github_client_spec.rb
daigaku-0.1.1 spec/daigaku/github_client_spec.rb
daigaku-0.1.0 spec/daigaku/github_client_spec.rb