Sha256: 0fd163268c5887e59034e61ebc39cca1d775823b2d0f8f12a6a0e0b27c22b86d

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

require 'rails_helper'

describe Grape::Middleware::Lograge, type: :rails_integration do
  let(:app) { build :app }
  let(:options) { {} }

  subject { described_class.new(app, options) }

  let(:app_response) { build :app_response }
  let(:grape_request) { build :grape_request }
  let(:grape_endpoint) { build(:grape_endpoint) }
  let(:env) { build(:expected_env, grape_endpoint: grape_endpoint) }

  it 'logs all parts of the request' do
    pending('test payload object')
    expect(subject.logger).to receive(:info).with ''
    expect(subject.logger).to receive(:info).with %Q(Started POST "/api/1.0/users" at #{subject.start_time})
    expect(subject.logger).to receive(:info).with %Q(Processing by TestAPI#users)
    expect(subject.logger).to receive(:info).with %Q(  Parameters: {"id"=>"101001", "name"=>"foo", "password"=>"[FILTERED]"})
    expect(subject.logger).to receive(:info).with /Completed 200 in \d+.\d+ms/
    expect(subject.logger).to receive(:info).with ''
    subject.call!(env)
  end

  describe 'the "processing by" section' do
    before { subject.call!(env) }

    context 'namespacing' do
      let(:grape_endpoint) { build(:namespaced_endpoint) }

      it 'ignores the namespacing' do
        expect(subject.controller).to eq 'TestAPI'
        expect(subject.action_name).to eq 'users'
      end

      context 'with more complex route' do
        let(:grape_endpoint) { build(:namespaced_endpoint, :complex) }

        it 'only escapes the first slash and leaves the rest of the untouched' do
          expect(subject.controller).to eq 'TestAPI'
          expect(subject.action_name).to eq 'users/:name/profile'
        end
      end
    end

    context 'with more complex route' do
      let(:grape_endpoint) { build(:grape_endpoint, :complex) }

      it 'only escapes the first slash and leaves the rest of the untouched' do
        expect(subject.action_name).to eq 'users/:name/profile'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
grape-middleware-lograge-1.2.3 spec/integration_rails/lib/grape/middleware/lograge_spec.rb
grape-middleware-lograge-1.2.2 spec/integration_rails/lib/grape/middleware/lograge_spec.rb
grape-middleware-lograge-1.2.1 spec/integration_rails/lib/grape/middleware/lograge_spec.rb
grape-middleware-lograge-1.2.0 spec/integration_rails/lib/grape/middleware/lograge_spec.rb
grape-middleware-lograge-1.1.0 spec/integration_rails/lib/grape/middleware/lograge_spec.rb
grape-middleware-lograge-1.0.0 spec/integration_rails/lib/grape/middleware/lograge_spec.rb