Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes invalid mapping in shared/social partial #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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'
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
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
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')

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')

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|
config.include Warden::Test::Helpers, type: :feature
end