Sha256: 049e0ce03b3ab0df3ddd7a2046fbafa1cf7e70ae04b98e435eb2cd12a37faae2

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"

RSpec.describe ApplicationHelper, type: :helper do
  describe "#current_account" do
    context "without an account_id in session" do
      before { session[:account_id] = nil }

      it "returns nil" do
        expect(helper.current_account).to be_nil
      end
    end

    context "with an account_id in session" do
      before { session[:account_id] = 123 }

      context "when using single application setup" do
        before do
          allow(BookingSyncEngine).to receive(:support_multi_applications?).and_return(false)
        end

        let!(:account) { Account.create!(synced_id: 123) }

        it "finds and return the current account by synced_id" do
          expect(helper.current_account).to eq account
        end
      end

      context "when using multi application setup" do
        before do
          allow(BookingSyncEngine).to receive(:support_multi_applications?).and_return(true)
        end

        let!(:account_1) { MultiApplicationsAccount.create!(host: "example.host", synced_id: 123) }
        let!(:account_2) { MultiApplicationsAccount.create!(host: "test.host", synced_id: 123) }

        it "finds and return the current account by host and synced_id" do
          expect(helper.current_account).to eq account_2
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bookingsync-engine-6.0.1 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-6.0.0 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-5.1.0 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-5.0.0 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-4.0.3 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-4.0.2 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-4.0.1 spec/helpers/auth_helpers_spec.rb
bookingsync-engine-4.0.0 spec/helpers/auth_helpers_spec.rb