|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -# Bugfixes |
4 | | -# JRuby needed an explicit "require 'logger'" for Rails < 7.1 |
5 | | -# See: https://github.com/rails/rails/issues/54260#issuecomment-2594650047 |
6 | | -# Placing above omniauth because it is a dependency of omniauth, |
7 | | -# which is undeclared in older versions. |
8 | | -require "logger" |
| 3 | +if omniauth_identity_sqlite3_enabled? && omniauth_identity_bundled_gem?("activerecord", "anonymous_active_record") |
| 4 | + # Bugfixes |
| 5 | + # JRuby needed an explicit "require 'logger'" for Rails < 7.1 |
| 6 | + # See: https://github.com/rails/rails/issues/54260#issuecomment-2594650047 |
| 7 | + # Placing above omniauth because it is a dependency of omniauth, |
| 8 | + # which is undeclared in older versions. |
| 9 | + require "logger" |
9 | 10 |
|
10 | | -require "active_record" |
11 | | -require "anonymous_active_record" |
| 11 | + require "active_record" |
| 12 | + require "anonymous_active_record" |
12 | 13 |
|
13 | | -class TestIdentity < OmniAuth::Identity::Models::ActiveRecord; end |
| 14 | + class TestIdentity < OmniAuth::Identity::Models::ActiveRecord; end |
14 | 15 |
|
15 | | -RSpec.describe(OmniAuth::Identity::Models::ActiveRecord, :sqlite3) do |
16 | | - describe "model", type: :model do |
17 | | - subject(:model_definition) { -> { model_klass } } |
| 16 | + RSpec.describe(OmniAuth::Identity::Models::ActiveRecord, :sqlite3) do |
| 17 | + describe "model", type: :model do |
| 18 | + subject(:model_definition) { -> { model_klass } } |
18 | 19 |
|
19 | | - let(:model_klass) do |
20 | | - AnonymousActiveRecord.generate( |
21 | | - parent_klass: "OmniAuth::Identity::Models::ActiveRecord", |
22 | | - columns: OmniAuth::Identity::Model::SCHEMA_ATTRIBUTES | %w[provider password_digest], |
23 | | - connection_params: {adapter: distinguish_jdbc_driver ? "jdbcsqlite3" : "sqlite3", encoding: "utf8", database: ":memory:"} |
24 | | - ) do |
25 | | - auth_key :email |
26 | | - def flower |
27 | | - "🌸" |
| 20 | + let(:model_klass) do |
| 21 | + AnonymousActiveRecord.generate( |
| 22 | + parent_klass: "OmniAuth::Identity::Models::ActiveRecord", |
| 23 | + columns: OmniAuth::Identity::Model::SCHEMA_ATTRIBUTES | %w[provider password_digest], |
| 24 | + connection_params: {adapter: distinguish_jdbc_driver ? "jdbcsqlite3" : "sqlite3", encoding: "utf8", database: ":memory:"} |
| 25 | + ) do |
| 26 | + auth_key :email |
| 27 | + def flower |
| 28 | + "🌸" |
| 29 | + end |
28 | 30 | end |
29 | 31 | end |
30 | | - end |
31 | 32 |
|
32 | | - let(:distinguish_jdbc_driver) { RUBY_PLATFORM == "java" && defined?(ArJdbc::Version) && Gem::Version.create(ArJdbc::Version) >= Gem::Version.create("72.0") } |
| 33 | + let(:distinguish_jdbc_driver) { RUBY_PLATFORM == "java" && defined?(ArJdbc::Version) && Gem::Version.create(ArJdbc::Version) >= Gem::Version.create("72.0") } |
33 | 34 |
|
34 | | - include_context "with persistable model" |
| 35 | + include_context "with persistable model" |
35 | 36 |
|
36 | | - describe "::table_name" do |
37 | | - it "does not use STI rules for its table name" do |
38 | | - expect(TestIdentity.table_name).to(eq("test_identities")) |
| 37 | + describe "::table_name" do |
| 38 | + it "does not use STI rules for its table name" do |
| 39 | + expect(TestIdentity.table_name).to(eq("test_identities")) |
| 40 | + end |
39 | 41 | end |
40 | | - end |
41 | 42 |
|
42 | | - describe "::locate" do |
43 | | - it "delegates locate to the where query method" do |
44 | | - args = { |
45 | | - email: "open faced", |
46 | | - category: "sandwiches", |
47 | | - provider: "identity" |
48 | | - } |
49 | | - allow(model_klass).to(receive(:where).with(args).and_return(["wakka"])) |
50 | | - expect(model_klass.locate(args)).to(eq("wakka")) |
| 43 | + describe "::locate" do |
| 44 | + it "delegates locate to the where query method" do |
| 45 | + args = { |
| 46 | + email: "open faced", |
| 47 | + category: "sandwiches", |
| 48 | + provider: "identity" |
| 49 | + } |
| 50 | + allow(model_klass).to(receive(:where).with(args).and_return(["wakka"])) |
| 51 | + expect(model_klass.locate(args)).to(eq("wakka")) |
| 52 | + end |
51 | 53 | end |
52 | | - end |
53 | 54 |
|
54 | | - describe "#inspect" do |
55 | | - it "filters password-related attributes from ActiveRecord inspect output" do |
56 | | - instance = model_klass.new(email: DEFAULT_EMAIL, password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD) |
57 | | - inspected = instance.inspect |
| 55 | + describe "#inspect" do |
| 56 | + it "filters password-related attributes from ActiveRecord inspect output" do |
| 57 | + instance = model_klass.new(email: DEFAULT_EMAIL, password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD) |
| 58 | + inspected = instance.inspect |
58 | 59 |
|
59 | | - expect(inspected).to include(DEFAULT_EMAIL) |
60 | | - expect(inspected).not_to include(DEFAULT_PASSWORD) |
61 | | - expect(inspected).not_to include(instance.password_digest) |
62 | | - expect(inspected).to include("password_digest: [FILTERED]") |
| 60 | + expect(inspected).to include(DEFAULT_EMAIL) |
| 61 | + expect(inspected).not_to include(DEFAULT_PASSWORD) |
| 62 | + expect(inspected).not_to include(instance.password_digest) |
| 63 | + expect(inspected).to include("password_digest: [FILTERED]") |
| 64 | + end |
63 | 65 | end |
64 | 66 | end |
65 | 67 | end |
|
0 commit comments