Sha256: e391b99c835533c6a5f5c154177d07f7db781bab285a805d18dc33b3aa7878f2

Contents?: true

Size: 1.58 KB

Versions: 16

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

RSpec.describe AuthenticatedController, type: :controller do
  describe "GET index" do
    context "when engine is embedded" do
      before { BookingSync::Engine.embedded! }

      it "redirects to auth using js" do
        get :index
        expect(response.status).to eq(200)
        expect(response.body).to eq(
          "<script type='text/javascript'>top.location.href = '/auth/bookingsync/?account_id=';</script>")
      end
    end

    context "when engine is standalone" do
      before { BookingSync::Engine.standalone! }

      it "redirects to auth using 302 redirect" do
        get :index
        expect(response.status).to eq(302)
        expect(response.redirect_url).to eq("http://test.host/auth/bookingsync/?account_id=")
        expect(response.body).to eq(
          "<html><body>You are being <a href=\"http://test.host/auth/bookingsync/?account_id=\">redirected</a>.</body></html>")
      end
    end
  end

  describe "XHR index" do
    context "when engine is embedded" do
      before { BookingSync::Engine.embedded! }

      it "renders the target url in response" do
        xhr :get, :index
        expect(response.status).to eq(401)
        expect(response.body).to eq("http://test.host/auth/bookingsync/?account_id=")
      end
    end

    context "when engine is standalone" do
      before { BookingSync::Engine.standalone! }

      it "renders the target url in response" do
        xhr :get, :index
        expect(response.status).to eq(401)
        expect(response.body).to eq("http://test.host/auth/bookingsync/?account_id=")
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
bookingsync-engine-2.0.2 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-2.0.1 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-2.0.0 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-1.1.0 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-1.0.2 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-1.0.1 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-1.0.0 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.5.0 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.4.6 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.4.5 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.4.4 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.4.3 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.3.0 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.2.2 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.2.1 spec/controllers/authenticated_controller_spec.rb
bookingsync-engine-0.2.0 spec/controllers/authenticated_controller_spec.rb