Sha256: 039a8cfc8e25d20f8fd3bda9793728e7d484a2c96d870d69ddc2ecc5d244c342

Contents?: true

Size: 1.88 KB

Versions: 10

Compression:

Stored size: 1.88 KB

Contents

describe Hyrax::Analytics, :no_clean do
  before do
    described_class.send(:remove_instance_variable, :@config) if described_class.send(:instance_variable_defined?, :@config)
  end

  describe "configuration" do
    let(:config) { described_class.send(:config) }

    context "When the yaml file has values" do
      it "is valid" do
        expect(config).to be_valid
      end

      it 'reads its config from a yaml file' do
        expect(config.app_name).to eql 'My App Name'
        expect(config.app_version).to eql '0.0.1'
        expect(config.privkey_path).to eql '/tmp/privkey.p12'
        expect(config.privkey_secret).to eql 's00pers3kr1t'
        expect(config.client_email).to eql 'oauth@example.org'
      end
    end

    context "When the yaml file has no values" do
      before do
        allow(File).to receive(:read).and_return("# Just comments\n# and comments\n")
      end

      it "is not valid" do
        expect(Rails.logger).to receive(:error)
          .with(starting_with("Unable to fetch any keys from"))
        expect(config).not_to be_valid
      end
    end
  end

  describe "#user" do
    before do
      token = OAuth2::AccessToken.new(nil, nil)
      allow(subject).to receive(:token).and_return(token)
    end
    it 'instantiates a user' do
      expect(subject.send(:user)).to be_a(Legato::User)
    end
  end

  describe "#profile" do
    subject { described_class.profile }

    context "when the private key file is missing" do
      it "raises an error" do
        expect { subject }.to raise_error RuntimeError, "Private key file for Google analytics was expected at '/tmp/privkey.p12', but no file was found."
      end
    end

    context "when the config is not valid" do
      before do
        allow(File).to receive(:read).and_return("# Just comments\n# and comments\n")
      end

      it "returns nil" do
        expect(subject).to be_nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/lib/hyrax/analytics_spec.rb
hyrax-1.1.0 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.5 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.4 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.3 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.2 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.1 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.0.rc2 spec/lib/hyrax/analytics_spec.rb
hyrax-1.0.0.rc1 spec/lib/hyrax/analytics_spec.rb
test_hyrax-0.0.1.alpha spec/lib/hyrax/analytics_spec.rb