spec/middleware_spec.rb in pdfkit-0.8.6 vs spec/middleware_spec.rb in pdfkit-0.8.7

- old
+ new

@@ -17,11 +17,11 @@ @app = builder.to_app end describe PDFKit::Middleware do let(:headers) do - {'Content-Type' => "text/html"} + {'content-type' => "text/html"} end describe "#call" do describe 'threadsafety' do @@ -53,40 +53,40 @@ end describe "caching" do let(:headers) do { - 'Content-Type' => "text/html", - 'ETag' => 'foo', - 'Cache-Control' => 'max-age=2592000, public' + 'content-type' => "text/html", + 'etag' => 'foo', + 'cache-control' => 'max-age=2592000, public' } end context "by default" do before { mock_app } - it "deletes ETag" do + it "deletes etag" do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["ETag"]).to be_nil + expect(last_response.headers["etag"]).to be_nil end - it "deletes Cache-Control" do + it "deletes cache-control" do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Cache-Control"]).to be_nil + expect(last_response.headers["cache-control"]).to be_nil end end context "when on" do before { mock_app({}, :caching => true) } - it "preserves ETag" do + it "preserves etag" do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["ETag"]).not_to be_nil + expect(last_response.headers["etag"]).not_to be_nil end - it "preserves Cache-Control" do + it "preserves cache-control" do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Cache-Control"]).not_to be_nil + expect(last_response.headers["cache-control"]).not_to be_nil end end end describe "conditions" do @@ -97,19 +97,19 @@ before { mock_app({}, :only => %r[^/public]) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # one regex @@ -117,19 +117,19 @@ before { mock_app({}, :only => [%r[^/invoice], %r[^/public]]) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # multiple regex end # regex @@ -139,19 +139,19 @@ before { mock_app({}, :only => '/public') } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # one string @@ -159,19 +159,19 @@ before { mock_app({}, :only => ['/invoice', '/public']) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # multiple string end # string @@ -185,19 +185,19 @@ before { mock_app({}, :except => %r[^/secret]) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # one regex @@ -205,19 +205,19 @@ before { mock_app({}, :except => [%r[^/prawn], %r[^/secret]]) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # multiple regex end # regex @@ -227,19 +227,19 @@ before { mock_app({}, :except => '/secret') } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # one string @@ -247,19 +247,19 @@ before { mock_app({}, :except => ['/prawn', '/secret']) } context "matching" do specify do get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("application/pdf") + expect(last_response.headers["content-type"]).to eq("application/pdf") expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize) end end context "not matching" do specify do get 'http://www.example.org/secret/test.pdf' - expect(last_response.headers["Content-Type"]).to eq("text/html") + expect(last_response.headers["content-type"]).to eq("text/html") expect(last_response.body).to eq("Hello world!") end end end # multiple string end # string @@ -346,53 +346,53 @@ describe ":disposition" do describe "doesn't overwrite existing value" do let(:headers) do super().merge({ - 'Content-Disposition' => 'attachment; filename=report-20200101.pdf' + 'content-disposition' => 'attachment; filename=report-20200101.pdf' }) end specify do mock_app({}, { :disposition => 'inline' }) get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Disposition"]).to eq('attachment; filename=report-20200101.pdf') + expect(last_response.headers["content-disposition"]).to eq('attachment; filename=report-20200101.pdf') end end describe "inline or blank" do context "default" do specify do mock_app get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Disposition"]).to eq("inline") + expect(last_response.headers["content-disposition"]).to eq("inline") end end context "inline" do specify do mock_app({}, { :disposition => 'inline' }) get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Disposition"]).to eq("inline") + expect(last_response.headers["content-disposition"]).to eq("inline") end end end describe "attachment" do context "attachment" do specify do mock_app({}, { :disposition => 'attachment' }) get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Disposition"]).to eq("attachment") + expect(last_response.headers["content-disposition"]).to eq("attachment") end end context "attachment with filename" do specify do mock_app({}, { :disposition => 'attachment; filename=report.pdf' }) get 'http://www.example.org/public/test.pdf' - expect(last_response.headers["Content-Disposition"]).to eq("attachment; filename=report.pdf") + expect(last_response.headers["content-disposition"]).to eq("attachment; filename=report.pdf") end end end end @@ -444,10 +444,10 @@ context "subdomain matching" do before do main_app = lambda { |env| @env = env @env['SCRIPT_NAME'] = '/example.org' - headers = {'Content-Type' => "text/html"} + headers = {'content-type' => "text/html"} [200, headers, @body || ['Hello world!']] } builder = Rack::Builder.new builder.use PDFKit::Middleware