diff --git a/app/models/spree/authentication_method.rb b/app/models/spree/authentication_method.rb
index f9dcde56..26b43ed8 100644
--- a/app/models/spree/authentication_method.rb
+++ b/app/models/spree/authentication_method.rb
@@ -7,6 +7,8 @@ def self.active_authentication_methods?
where(environment: ::Rails.env, active: true).exists?
end
+ scope :active, -> { where(active: true) }
+
scope :available_for, lambda { |user|
sc = where(environment: ::Rails.env)
sc = sc.where.not(provider: user.user_authentications.pluck(:provider)) if user && !user.user_authentications.empty?
diff --git a/app/views/spree/shared/_social.html.erb b/app/views/spree/shared/_social.html.erb
index 816660e9..45d02afb 100644
--- a/app/views/spree/shared/_social.html.erb
+++ b/app/views/spree/shared/_social.html.erb
@@ -3,10 +3,10 @@
<%= Spree.t(:sign_in_through_one_of_these_services) %>
<% end %>
- <% Spree::AuthenticationMethod.available_for(@spree_user).each do |method| %>
+ <% Spree::AuthenticationMethod.available_for(spree_current_user).active.each do |method| %>
<%= link_to(content_tag(:i, '', class: "icon-spree-#{method.provider.to_url}-circled"),
- path_for_omniauth(@spree_user, method.provider),
+ path_for_omniauth(:spree_user, method.provider),
id: method.provider.to_url,
- title: Spree.t(:sign_in_with, provider: method.provider)) if method.active %>
+ title: Spree.t(:sign_in_with, provider: method.provider)) %>
<% end %>
diff --git a/spec/factories/authentication_method.rb b/spec/factories/authentication_method.rb
new file mode 100644
index 00000000..40a3ab77
--- /dev/null
+++ b/spec/factories/authentication_method.rb
@@ -0,0 +1,9 @@
+FactoryBot.define do
+ factory :authentication_method, class: Spree::AuthenticationMethod do
+ provider 'facebook'
+ api_key 'fake'
+ api_secret 'fake'
+ environment { Rails.env }
+ active true
+ end
+end
diff --git a/spec/factories/user_authentication.rb b/spec/factories/user_authentication.rb
new file mode 100644
index 00000000..058ccda8
--- /dev/null
+++ b/spec/factories/user_authentication.rb
@@ -0,0 +1,6 @@
+FactoryBot.define do
+ factory :user_authentication, class: Spree::UserAuthentication do
+ provider 'facebook'
+ uid 'fake'
+ end
+end
diff --git a/spec/features/spree/account_page_visit_spec.rb b/spec/features/spree/account_page_visit_spec.rb
new file mode 100644
index 00000000..5167e264
--- /dev/null
+++ b/spec/features/spree/account_page_visit_spec.rb
@@ -0,0 +1,35 @@
+RSpec.feature 'account page visit', :js do
+ let(:user) { create(:user) }
+
+ before do
+ login_as(user, scope: :spree_user)
+ end
+
+ context 'with existing active authentication methods' do
+ let!(:authentication_method) { create(:authentication_method) }
+
+ before do
+ visit '/account'
+ end
+
+ it 'shows possible methods to connect' do
+ expect(page).to have_link(title: Spree.t(:sign_in_with, provider: authentication_method.provider))
+ end
+
+ context 'when authentication method was used' do
+ before do
+ create(:user_authentication, provider: authentication_method.provider, user: user)
+ visit '/account'
+ end
+
+ it 'does not show used method' do
+ expect(page).not_to have_link(title: Spree.t(:sign_in_with, provider: authentication_method.provider))
+ end
+
+ it 'shows method as connected' do
+ expect(page).to have_text('You Have Signed In With These Services')
+ expect(page).to have_text(authentication_method.provider)
+ end
+ end
+ end
+end
diff --git a/spec/features/spree/sign_in_spec.rb b/spec/features/spree/sign_in_spec.rb
index fc22463d..3cc9de58 100644
--- a/spec/features/spree/sign_in_spec.rb
+++ b/spec/features/spree/sign_in_spec.rb
@@ -1,12 +1,8 @@
RSpec.feature 'signing in using Omniauth', :js do
context 'facebook' do
background do
- Spree::AuthenticationMethod.create!(
- provider: 'facebook',
- api_key: 'fake',
- api_secret: 'fake',
- environment: Rails.env,
- active: true)
+ create(:authentication_method, provider: 'facebook')
+
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
'provider' => 'facebook',
@@ -47,12 +43,8 @@
context 'twitter' do
background do
- Spree::AuthenticationMethod.create!(
- provider: 'twitter',
- api_key: 'fake',
- api_secret: 'fake',
- environment: Rails.env,
- active: true)
+ create(:authentication_method, provider: 'twitter')
+
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
diff --git a/spec/support/devise.rb b/spec/support/devise.rb
index 79998955..3225fc7d 100644
--- a/spec/support/devise.rb
+++ b/spec/support/devise.rb
@@ -1,3 +1,3 @@
RSpec.configure do |config|
- config.include Devise::TestHelpers, type: :controller
+ config.include Devise::Test::ControllerHelpers, type: :controller
end
diff --git a/spec/support/factory_girl.rb b/spec/support/factory_bot.rb
similarity index 60%
rename from spec/support/factory_girl.rb
rename to spec/support/factory_bot.rb
index 0ca19863..e043539c 100644
--- a/spec/support/factory_girl.rb
+++ b/spec/support/factory_bot.rb
@@ -2,4 +2,8 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
+
+ config.before(:suite) do
+ FactoryBot.find_definitions
+ end
end
diff --git a/spec/support/warden.rb b/spec/support/warden.rb
new file mode 100644
index 00000000..9fdede43
--- /dev/null
+++ b/spec/support/warden.rb
@@ -0,0 +1,3 @@
+RSpec.configure do |config|
+ config.include Warden::Test::Helpers, type: :feature
+end