Skip to content

Commit

Permalink
Fix the way the external provider class is instantiated for providers…
Browse files Browse the repository at this point in the history
… with plural names (Sorcery#305)

* Fix the way the external provider class is instantiated

* added a spec

* Updated changelog

* Fixed mistake in changelog

* Add changelog additions under HEAD instead of under new version number.
  • Loading branch information
epdejager authored Feb 23, 2022
1 parent 25e4b1f commit 7268135
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
## HEAD

* Fix provider instantiation for plural provider names (eg. okta) [#305](https://github.com/Sorcery/sorcery/pull/305)

## 0.16.2

* Inline core migration index definition [#281](https://github.com/Sorcery/sorcery/pull/281)
Expand Down
2 changes: 1 addition & 1 deletion lib/sorcery/controller/submodules/external.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def external_providers=(providers)
providers.each do |name|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{name}
@#{name} ||= Sorcery::Providers.const_get('#{name}'.to_s.classify).new
@#{name} ||= Sorcery::Providers.const_get('#{name}'.to_s.camelcase).new
end
RUBY
end
Expand Down
17 changes: 17 additions & 0 deletions spec/providers/examples_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'spec_helper'
require 'sorcery/providers/base'

describe Sorcery::Providers::Examples do
before(:all) do
sorcery_reload!([:external])
sorcery_controller_property_set(:external_providers, [:examples])
end

context 'fetching a plural custom provider' do
it 'returns the provider' do
expect(Sorcery::Controller::Config.examples).to be_a(Sorcery::Providers::Examples)
end
end
end
11 changes: 11 additions & 0 deletions spec/support/providers/examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'sorcery/providers/base'

module Sorcery
module Providers
class Examples < Base
include Protocols::Oauth2
end
end
end

0 comments on commit 7268135

Please sign in to comment.