Skip to content

Commit 09de8d7

Browse files
committed
Improve logout method configuration by using first sign_out_via option on Devise. Thanks @carlesso
1 parent d5491c9 commit 09de8d7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/helpers/rails_admin/application_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def logout_path
4848
end
4949

5050
def logout_method
51-
return Devise.sign_out_via if defined?(Devise)
51+
return [Devise.sign_out_via].flatten.first if defined?(Devise)
5252
:delete
5353
end
5454

spec/helpers/rails_admin/application_helper_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ def initialize(_user)
110110
end
111111
end
112112

113+
describe '#logout_method' do
114+
it 'defaults to :delete when Devise is not defined' do
115+
allow(Object).to receive(:defined?).with(Devise).and_return(false)
116+
117+
expect(helper.logout_method).to eq(:delete)
118+
end
119+
120+
it 'uses first sign out method from Devise when it is defined' do
121+
allow(Object).to receive(:defined?).with(Devise).and_return(true)
122+
123+
expect(Devise).to receive(:sign_out_via).and_return([:whatever_defined_on_devise, :something_ignored])
124+
expect(helper.logout_method).to eq(:whatever_defined_on_devise)
125+
end
126+
end
127+
113128
describe '#wording_for' do
114129
it 'gives correct wording even if action is not visible' do
115130
RailsAdmin.config do |config|

0 commit comments

Comments
 (0)