Sha256: 7a6182d3efdba81538359d4a5ea034f36892ab7c9d0e44ec05da6a8d62c56a5e

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

shared_examples_for "a management finder" do
  let(:response) { stub(:body => 'some json') }
  let(:access_token) { stub(:get => response) }
  let(:user) { stub(:access_token => access_token, :api_key => nil) }

  context ".all" do
    after do
      user.should have_received(:access_token)
      access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management'+described_class.default_path)
      response.should have_received(:body)
      MultiJson.should have_received(:decode).with('some json')
    end

    it "returns an array of all #{subject_class_name} available to a user" do
      MultiJson.stubs(:decode).returns({'items' => ['item1', 'item2']})
      described_class.stubs(:new).returns('thing1', 'thing2')

      described_class.all(user).should == ['thing1', 'thing2']

      described_class.should have_received(:new).with('item1', user)
      described_class.should have_received(:new).with('item2', user)
    end

    it "returns an empty array of #{subject_class_name} when there are no results" do
      MultiJson.stubs(:decode).returns({})
      described_class.all(user).should == []

      described_class.should have_received(:new).never
    end
  end

  context ".get" do
    after do
      user.should have_received(:access_token)
      access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management/path')
      response.should have_received(:body)
      MultiJson.should have_received(:decode).with('some json')
    end

    it "returns an instance of #{subject_class_name} for a given path" do
      MultiJson.stubs(:decode).returns('attributes')
      described_class.stubs(:new).returns('thing')

      path = '/path'

      expect(described_class.get(user, path)).to eq('thing')
      expect(described_class).to have_received(:new).with('attributes', user)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
legato-0.5.1 spec/support/examples/management_finder.rb
legato-0.5.0 spec/support/examples/management_finder.rb
legato-0.4.0 spec/support/examples/management_finder.rb