Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/spree/authentication_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions app/views/spree/shared/_social.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<h4><%= Spree.t(:sign_in_through_one_of_these_services) %></h4>
<% 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 %>
</div>
9 changes: 9 additions & 0 deletions spec/factories/authentication_method.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/factories/user_authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :user_authentication, class: Spree::UserAuthentication do
provider 'facebook'
uid 'fake'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end
35 changes: 35 additions & 0 deletions spec/features/spree/account_page_visit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
RSpec.feature 'account page visit', :js do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block has too many lines. [26/25]
Missing magic comment # frozen_string_literal: true.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

let(:user) { create(:user) }

before do
login_as(user, scope: :spree_user)
end

context 'with existing active authentication methods' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

let!(:authentication_method) { create(:authentication_method) }

before do
visit '/account'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'shows possible methods to connect' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect(page).to have_link(title: Spree.t(:sign_in_with, provider: authentication_method.provider))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [104/80]

end

context 'when authentication method was used' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

before do
create(:user_authentication, provider: authentication_method.provider, user: user)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

visit '/account'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'does not show used method' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect(page).not_to have_link(title: Spree.t(:sign_in_with, provider: authentication_method.provider))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [110/80]

end

it 'shows method as connected' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect(page).to have_text('You Have Signed In With These Services')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect(page).to have_text(authentication_method.provider)
end
end
end
end
16 changes: 4 additions & 12 deletions spec/features/spree/sign_in_spec.rb
Original file line number Diff line number Diff line change
@@ -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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
'provider' => 'facebook',
Expand Down Expand Up @@ -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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
Expand Down
2 changes: 1 addition & 1 deletion spec/support/devise.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :controller
end
4 changes: 4 additions & 0 deletions spec/support/factory_girl.rb → spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods

config.before(:suite) do
FactoryBot.find_definitions
end
end
3 changes: 3 additions & 0 deletions spec/support/warden.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |config|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

config.include Warden::Test::Helpers, type: :feature
end