Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include example of class based pinglish #16

Open
technicalpickles opened this issue Jun 9, 2015 · 1 comment
Open

Include example of class based pinglish #16

technicalpickles opened this issue Jun 9, 2015 · 1 comment

Comments

@technicalpickles
Copy link

I was building a pinglish check, and wanted to include more application logic, but was worried about including it in config/application.rb. I figured out a way to include this in app/middleware as it's own class, as well as a way to test it.

Here's the example:

# app/middleware/fancy_pinglish.rb
class FancyPinglish < Pinglish

  def initialize(app, options = nil, &block)
    super

    check :fancy do
      # logic here
    end

    check :exquisite do
      # logic here
    end

    check :epic do
      # logic
    end
  end

end

# config/application.rb
config.middleware.use "FancyPinglish", max: 15, path: '/_ping/fancy'

# spec/middleware/fancy_pinglish_spec.rb
describe FancyPinglish, type: :request do

  context "when all is clear" do
    before do
      # stub logic
    end

    it "returns 200" do
      get "/_ping/fancy"

      expect(response.status).to eq(200)
    end
  end

  context "when pagerduty is failing" do
    before do
      # stub logic
    end

    it "returns 503" do
      get "/_ping/fancy"

      expect(response.status).to eq(503)
    end
  end
  # other variations here
end
@jbarnette
Copy link
Owner

Oh cool, that's a nice technique. I like your old Rails example issue too. I'll leave these open for now + eventually roll them into a doc release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants