|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | + |
| 5 | +describe OmniAuth::AuthHash do |
| 6 | + let(:auth_hash) do |
| 7 | + OmniAuth::AuthHash.new( |
| 8 | + provider: "idcat_mobil", |
| 9 | + uid: "123456789", |
| 10 | + info: { |
| 11 | + email: "email@example.net", |
| 12 | + name: "Oriol", |
| 13 | + surname1: "Junquerol", |
| 14 | + surname2: "Balaguer" |
| 15 | + }, |
| 16 | + credentials: { |
| 17 | + token: "fake_token", |
| 18 | + expires: false |
| 19 | + }, |
| 20 | + extra: { |
| 21 | + identifier_type: "1", |
| 22 | + method: "idcatmobil", |
| 23 | + status: "ok" |
| 24 | + } |
| 25 | + ) |
| 26 | + end |
| 27 | + |
| 28 | + describe "indifferent access" do |
| 29 | + it "is accessible with string keys at root level" do |
| 30 | + expect(auth_hash["provider"]).to eq("idcat_mobil") |
| 31 | + expect(auth_hash["uid"]).to eq("123456789") |
| 32 | + expect(auth_hash["info"]).to be_a(Hash) |
| 33 | + expect(auth_hash["credentials"]).to be_a(Hash) |
| 34 | + expect(auth_hash["extra"]).to be_a(Hash) |
| 35 | + end |
| 36 | + |
| 37 | + it "is accessible with symbol keys at root level" do |
| 38 | + expect(auth_hash[:provider]).to eq("idcat_mobil") |
| 39 | + expect(auth_hash[:uid]).to eq("123456789") |
| 40 | + expect(auth_hash[:info]).to be_a(Hash) |
| 41 | + expect(auth_hash[:credentials]).to be_a(Hash) |
| 42 | + expect(auth_hash[:extra]).to be_a(Hash) |
| 43 | + end |
| 44 | + |
| 45 | + it "is accessible with string keys in nested hashes" do |
| 46 | + expect(auth_hash["info"]["email"]).to eq("email@example.net") |
| 47 | + expect(auth_hash["info"]["name"]).to eq("Oriol") |
| 48 | + expect(auth_hash["credentials"]["token"]).to eq("fake_token") |
| 49 | + expect(auth_hash["extra"]["method"]).to eq("idcatmobil") |
| 50 | + end |
| 51 | + |
| 52 | + it "is accessible with symbol keys in nested hashes" do |
| 53 | + expect(auth_hash[:info][:email]).to eq("email@example.net") |
| 54 | + expect(auth_hash[:info][:name]).to eq("Oriol") |
| 55 | + expect(auth_hash[:credentials][:token]).to eq("fake_token") |
| 56 | + expect(auth_hash[:extra][:method]).to eq("idcatmobil") |
| 57 | + end |
| 58 | + |
| 59 | + it "supports mixed string and symbol access" do |
| 60 | + expect(auth_hash["info"][:email]).to eq("email@example.net") |
| 61 | + expect(auth_hash[:info]["name"]).to eq("Oriol") |
| 62 | + expect(auth_hash["credentials"][:token]).to eq("fake_token") |
| 63 | + expect(auth_hash[:extra]["method"]).to eq("idcatmobil") |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments