solidus_social 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -2
  3. data/CHANGELOG.md +8 -0
  4. data/Gemfile +14 -2
  5. data/README.md +14 -31
  6. data/app/controllers/spree/admin/authentication_methods_controller.rb +0 -12
  7. data/app/controllers/spree/omniauth_callbacks_controller.rb +3 -3
  8. data/app/models/spree/authentication_method.rb +5 -1
  9. data/app/models/spree/social_configuration.rb +1 -0
  10. data/app/models/spree/user_decorator.rb +1 -1
  11. data/app/views/spree/admin/authentication_methods/_form.html.erb +2 -18
  12. data/app/views/spree/admin/authentication_methods/index.html.erb +2 -2
  13. data/config/locales/es-MX.yml +3 -3
  14. data/config/locales/it.yml +26 -0
  15. data/config/routes.rb +2 -2
  16. data/db/migrate/20120120163432_create_user_authentications.rb +1 -1
  17. data/db/migrate/20120123163222_create_authentication_methods.rb +1 -1
  18. data/lib/generators/solidus_social/install/install_generator.rb +6 -0
  19. data/lib/generators/solidus_social/install/templates/config/initializers/solidus_social.rb +48 -0
  20. data/lib/solidus_social.rb +2 -1
  21. data/lib/solidus_social/engine.rb +17 -18
  22. data/lib/solidus_social/version.rb +1 -1
  23. data/solidus_social.gemspec +3 -0
  24. data/spec/controllers/spree/omniauth_callbacks_controller_spec.rb +28 -0
  25. data/spec/features/spree/admin/authentication_methods_configuration_spec.rb +6 -15
  26. data/spec/features/spree/sign_in_spec.rb +9 -13
  27. data/spec/lib/spree/social_config_spec.rb +9 -0
  28. data/spec/lib/spree_social/engine_spec.rb +18 -11
  29. data/spec/models/spree/authentication_method_spec.rb +17 -0
  30. data/spec/models/spree/social_configuration_spec.rb +4 -0
  31. data/spec/models/spree/user_decorator_spec.rb +21 -0
  32. data/spec/support/capybara.rb +3 -10
  33. metadata +53 -5
  34. data/app/views/spree/admin/shared/_configurations_menu.html.erb +0 -4
  35. data/config/initializers/devise.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1a51d0589d5c133e7feade204f1e502a9381ddc
4
- data.tar.gz: 3a1c269db431f9221b2db01cf828dec5614981f2
3
+ metadata.gz: 140e2c41e3d39cdb72559e8eab2d16602332f7e4
4
+ data.tar.gz: 3f067cd1244a2beb69c29cef84fb24b678fd86c0
5
5
  SHA512:
6
- metadata.gz: 4bde42eaf3d0cfc966111ab8d0f094827b5d6004b74f37b0cc7d8ee677f20e44c6e579e57ace4a3599bdb23bd460f8b071c14aad6180e2896742d154cddc33c1
7
- data.tar.gz: 74e0eac9c4637558d86d4bc1891a80712c921f03b9273e861123d06fcb9eba51b73140b0e7cf92063976b253b40c8c2a04cf3068bc97f93baba530a887053878
6
+ metadata.gz: 642531bdd1876b9b45bf951f5a1d996885066243f79c16c118f2f3a65fc9a6ea419e6ca653433421e00d0403354ad9f9aa07436b374880cfb08f206fb46dec0d
7
+ data.tar.gz: 6e5a6858b94fc566ba9685d381b302d8ad7a62940b35ba7deaacd6a7881c4ae4ce24558ac1801cc23a0e91f9d59d39d025a6f8fd50ebe30a3a420c7f0890274e
@@ -1,8 +1,13 @@
1
- sudo: false
1
+ sudo: required
2
2
  cache: bundler
3
3
  language: ruby
4
+ dist: trusty
5
+ addons:
6
+ apt:
7
+ packages:
8
+ - google-chrome-beta
4
9
  rvm:
5
- - 2.3.1
10
+ - 2.3.5
6
11
  env:
7
12
  matrix:
8
13
  - SOLIDUS_BRANCH=v1.0 DB=postgres
@@ -11,6 +16,9 @@ env:
11
16
  - SOLIDUS_BRANCH=v1.3 DB=postgres
12
17
  - SOLIDUS_BRANCH=v1.4 DB=postgres
13
18
  - SOLIDUS_BRANCH=v2.0 DB=postgres
19
+ - SOLIDUS_BRANCH=v2.1 DB=postgres
20
+ - SOLIDUS_BRANCH=v2.2 DB=postgres
21
+ - SOLIDUS_BRANCH=v2.3 DB=postgres
14
22
  - SOLIDUS_BRANCH=master DB=postgres
15
23
  - SOLIDUS_BRANCH=v1.0 DB=mysql
16
24
  - SOLIDUS_BRANCH=v1.1 DB=mysql
@@ -18,4 +26,7 @@ env:
18
26
  - SOLIDUS_BRANCH=v1.3 DB=mysql
19
27
  - SOLIDUS_BRANCH=v1.4 DB=mysql
20
28
  - SOLIDUS_BRANCH=v2.0 DB=mysql
29
+ - SOLIDUS_BRANCH=v2.1 DB=mysql
30
+ - SOLIDUS_BRANCH=v2.2 DB=mysql
31
+ - SOLIDUS_BRANCH=v2.3 DB=mysql
21
32
  - SOLIDUS_BRANCH=master DB=mysql
@@ -1,3 +1,11 @@
1
+ ## Unreleased
2
+
3
+ * The `SolidusSocial::OAUTH_PROVIDERS` constant has been removed in favour
4
+ of the `Spree::AuthenticationMethod.providers_options` class method. This is populated using
5
+ the `Spree::SocialConfig#providers` Hash.
6
+ * Use the install generator to import the solidus social initializer into your app.
7
+ Please run `bundle exec rails g solidus_social:install` in order to upgrade.
8
+
1
9
  ## Solidus Social 1.0.0
2
10
 
3
11
  * Renamed SpreeSocial to SolidusSocial
data/Gemfile CHANGED
@@ -1,10 +1,22 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
4
+
3
5
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
6
  gem "solidus", github: "solidusio/solidus", branch: branch
5
7
 
6
- if branch == 'master' || branch >= "v2.0"
7
- gem "rails-controller-testing", group: :test
8
+ group :test do
9
+ if branch == 'master' || branch >= "v2.0"
10
+ gem "rails-controller-testing"
11
+ end
12
+ gem 'ffaker'
13
+ end
14
+
15
+ # hack for broken bundler dependency resolution
16
+ if branch == 'master' || branch >= "v2.3"
17
+ gem 'rails', '~> 5.1.0'
18
+ elsif branch >= "v2.0"
19
+ gem 'rails', '~> 5.0.0'
8
20
  end
9
21
 
10
22
  gem 'pg'
data/README.md CHANGED
@@ -22,41 +22,18 @@ $ bundle && bundle exec rails g solidus_social:install
22
22
  $ bundle exec rake db:migrate
23
23
  ```
24
24
 
25
+ This will install a new initializer `config/initializers/solidus_social.rb` into
26
+ your project that allows you to setup the services you want configured for your app.
27
+
25
28
  Optional: By default the login path will be '/users/auth/:provider'. If you
26
29
  want something else, configure it in `config/initializers/solidus_social.rb`.
27
30
 
28
- ```ruby
29
- Spree::SocialConfig[:path_prefix] = 'member' # for /member/auth/:provider
30
- Spree::SocialConfig[:path_prefix] = 'profile' # for /profile/auth/:provider
31
- Spree::SocialConfig[:path_prefix] = '' # for /auth/:provider
32
- ```
33
31
 
34
32
  ## Using OAuth Sources
35
33
 
36
34
  Login as an admin user and navigate to Configuration > Social Authentication Methods
37
35
 
38
- Click "New Authentication Method" and enter your API key for the service. (See
39
- below for instructions on setting up the different providers.)
40
-
41
- Multiple key entries can now be entered based on the Rails environment. This
42
- allows for portability and the lack of need to check in your key to your
43
- repository. You also have the ability to enable and disable sources. These
44
- setting will be reflected on the client UI as well.
45
-
46
- If you store your configuration/credentials in environment variables, you can
47
- create Authentication Methods on application boot via an initializer if they
48
- don't already exist.
49
-
50
- ```ruby
51
- # Ensure our environment is bootstrapped with a Facebook Connect app
52
- if ActiveRecord::Base.connection.table_exists? 'spree_authentication_methods'
53
- Spree::AuthenticationMethod.where(environment: Rails.env, provider: 'facebook').first_or_create do |auth_method|
54
- auth_method.api_key = ENV['FACEBOOK_APP_ID']
55
- auth_method.api_secret = ENV['FACEBOOK_APP_SECRET']
56
- auth_method.active = true
57
- end
58
- end
59
- ```
36
+ Click "New Authentication Method" and choose one of your configured providers.
60
37
 
61
38
  **You MUST restart your application after configuring or updating an authentication method.**
62
39
 
@@ -91,7 +68,7 @@ Make sure you specifity the right IP address.
91
68
  - Application Website: `http://yourhostname.local:3000` for development and
92
69
  `http://your-site.com` for production
93
70
  - Application Type: "Browser"
94
- - Callback URL: `http://yourhostname.local:3000 for development and
71
+ - Callback URL: `http://yourhostname.local:3000` for development and
95
72
  `http://your-site.com` for production
96
73
  - Default Access Type: "Read & Write"
97
74
  6. Save the application.
@@ -136,10 +113,16 @@ strategy][12] for them. (If there isn't, you can [write one][13].)
136
113
  for SolidusSocial:
137
114
 
138
115
  ```ruby
139
- SolidusSocial::OAUTH_PROVIDERS << ['LinkedIn', 'linkedin']
140
- SolidusSocial.init_provider('linkedin')
116
+
117
+ config.providers = {
118
+ # The configuration key has to match your omniauth strategy.
119
+ linkedin: {
120
+ api_key: ENV['LINKEDIN_API_KEY'],
121
+ api_secret: ENV['LINKEDIN_API_SECRET'],
122
+ },
123
+ # More providers here
141
124
  ```
142
- 3. Activate your provider as usual (via initializer or admin interface).
125
+ 3. Activate your provider as usual.
143
126
  4. Do **one** of the following:
144
127
 
145
128
  - Override the `spree/users/social` view to render OAuth links to display
@@ -1,18 +1,6 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class AuthenticationMethodsController < ResourceController
4
- create.after :update_oauth_method
5
- update.after :update_oauth_method
6
-
7
- private
8
-
9
- def update_oauth_method
10
- auth_method = params[:authentication_method]
11
- return unless auth_method[:active] == 'true' && auth_method[:environment] == ::Rails.env
12
- Devise.setup do |config|
13
- config.omniauth auth_method[:provider], auth_method[:api_key], auth_method[:api_secret]
14
- end
15
- end
16
4
  end
17
5
  end
18
6
  end
@@ -12,8 +12,8 @@ class Spree::OmniauthCallbacksController < Devise::OmniauthCallbacksController
12
12
  end
13
13
  end
14
14
 
15
- SolidusSocial::OAUTH_PROVIDERS.each do |provider|
16
- provides_callback_for provider[1].to_sym
15
+ Spree::SocialConfig.providers.keys.each do |provider|
16
+ provides_callback_for provider
17
17
  end
18
18
 
19
19
  def omniauth_callback
@@ -34,7 +34,7 @@ class Spree::OmniauthCallbacksController < Devise::OmniauthCallbacksController
34
34
  flash[:notice] = I18n.t('devise.sessions.signed_in')
35
35
  redirect_back_or_default(account_url)
36
36
  else
37
- user = Spree::User.find_by_email(auth_hash['info']['email']) || Spree::User.new
37
+ user = Spree.user_class.find_by_email(auth_hash['info']['email']) || Spree.user_class.new
38
38
  user.apply_omniauth(auth_hash)
39
39
  if user.save
40
40
  flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
@@ -1,5 +1,9 @@
1
1
  class Spree::AuthenticationMethod < ActiveRecord::Base
2
- validates :provider, :api_key, :api_secret, presence: true
2
+ def self.provider_options
3
+ SolidusSocial.configured_providers.map { |provider_name| [provider_name.split("_").first.camelize, provider_name] }
4
+ end
5
+
6
+ validates :provider, presence: true
3
7
 
4
8
  def self.active_authentication_methods?
5
9
  where(environment: ::Rails.env, active: true).exists?
@@ -1,5 +1,6 @@
1
1
  module Spree
2
2
  class SocialConfiguration < Preferences::Configuration
3
+ attr_accessor :providers
3
4
  preference :path_prefix, :string, default: 'users'
4
5
  end
5
6
  end
@@ -4,7 +4,7 @@ Spree.user_class.class_eval do
4
4
  devise :omniauthable
5
5
 
6
6
  def apply_omniauth(omniauth)
7
- if %w(facebook google_oauth2).include? omniauth['provider']
7
+ if omniauth.fetch('info', {})['email'].present?
8
8
  self.email = omniauth['info']['email'] if email.blank?
9
9
  end
10
10
  user_authentications.build(provider: omniauth['provider'], uid: omniauth['uid'])
@@ -2,7 +2,7 @@
2
2
  <div class="alpha five columns">
3
3
  <div data-hook="environment" class="field">
4
4
  <%= f.field_container :environment do %>
5
- <%= label_tag nil, Spree.t(:environment) %>
5
+ <%= label_tag nil, Spree::AuthenticationMethod.human_attribute_name(:environment) %>
6
6
  <%= collection_select(:authentication_method, :environment, Rails.configuration.database_configuration.keys, :to_s, :titleize, {}, { class: 'select2 fullwidth' }) %>
7
7
  <% end %>
8
8
  </div>
@@ -11,23 +11,7 @@
11
11
  <div data-hook="environment" class="field">
12
12
  <%= f.field_container :provider do %>
13
13
  <%= f.label :provider, Spree.t(:social_provider) %>
14
- <%= f.select :provider, SolidusSocial::OAUTH_PROVIDERS, {}, { include_blank: false, class: 'select2 fullwidth' } %>
15
- <% end %>
16
- </div>
17
- </div>
18
- <div class="alpha five columns">
19
- <div data-hook="environment" class="field">
20
- <%= f.field_container :api_key do %>
21
- <%= f.label :api_key, Spree.t(:social_api_key) %> <span class="required">*</span><br />
22
- <%= f.text_field :api_key, class: 'fullwidth' %>
23
- <% end %>
24
- </div>
25
- </div>
26
- <div class="alpha five columns">
27
- <div data-hook="environment" class="field">
28
- <%= f.field_container :api_secret do %>
29
- <%= f.label :api_secret, Spree.t(:social_api_secret) %> <span class="required">*</span><br />
30
- <%= f.text_field :api_secret, class: 'fullwidth' %>
14
+ <%= f.select :provider, Spree::AuthenticationMethod.provider_options, {}, { include_blank: false, class: 'select2 fullwidth' } %>
31
15
  <% end %>
32
16
  </div>
33
17
  </div>
@@ -34,8 +34,8 @@
34
34
  <% @authentication_methods.each do |method|%>
35
35
  <tr id="<%= dom_id method %>" data-hook="admin_trackers_index_rows">
36
36
  <td class="align-center"><%= method.provider %></td>
37
- <td class="align-center"><%= truncate method.api_key, length: 20 %></td>
38
- <td class="align-center"><%= truncate method.api_secret, length: 20 %></td>
37
+ <td class="align-center"><%= truncate method.api_key, length: 10 %></td>
38
+ <td class="align-center"><%= truncate method.api_secret, length: 10 %></td>
39
39
  <td class="align-center"><%= method.environment.to_s.titleize %></td>
40
40
  <td class="align-center"><%= method.active ? Spree.t(:yes) : Spree.t(:no) %></td>
41
41
  <td class="actions">
@@ -7,11 +7,11 @@ es-MX:
7
7
  user_was_not_valid: "El usuario no fue válido."
8
8
  add_another_service: 'Añadir otro servicio para inicio de sesión:'
9
9
  authentications:
10
- destroy: 'Método de autenticación destruido exitosamente.'
10
+ destroy: 'Método de autenticación eliminado exitosamente.'
11
11
  back_to_authentication_methods_list: "Volver a la lista de métodos de autenticación"
12
12
  edit_social_method: 'Editando metodo de autenticación'
13
13
  new_social_method: 'Nuevo método de autenticación'
14
- no_authentication_methods_found: "No se encuentran ni métodos de autenticación"
14
+ no_authentication_methods_found: "No se encuentran ningún método de autenticación"
15
15
  one_more_step: 'Un paso más para completar tu registro desde %{kind}'
16
16
  remove_authentication_option_confirmation: '¿Está seguro que quiere eliminar este método de autenticación?'
17
17
  sign_into_account: 'Puedes iniciar sesión usando:'
@@ -22,5 +22,5 @@ es-MX:
22
22
  social_authentication_methods_description: 'Configurar métodos de autenticación de OAuth'
23
23
  social_provider: 'Proveedor social'
24
24
  please_confirm_your_email: 'Por favor confirme su email para continuar'
25
- sign_in_with: 'Autententicado con %{provider}'
25
+ sign_in_with: 'Autenticado con %{provider}'
26
26
  you_have_signed_in_with_these_services: "Has iniciado sesión con estos servicios"
@@ -0,0 +1,26 @@
1
+ ---
2
+ it:
3
+ devise:
4
+ omniauth_callbacks:
5
+ success: "Sei ora loggato con il tuo account di tipo %{kind}."
6
+ spree:
7
+ user_was_not_valid: L'utente non è valido
8
+ add_another_service: "Aggiungi un servizio per il log-in:"
9
+ authentications:
10
+ destroy: 'Metodo di autenticazione cancellato con successo.'
11
+ back_to_authentication_methods_list: "Torna alla lista dei metodi di autenticazione"
12
+ edit_social_method: "Modifica metodo di autenticazione social"
13
+ new_social_method: "Nuovo metodo di autenticazione"
14
+ no_authentication_methods_found: "Nessun metodo di autenticazione trovato"
15
+ one_more_step: 'Un altro passo per completare il processo di autenticazione %{kind}'
16
+ remove_authentication_option_confirmation: "Sei sicuro di voler cancellare questo metodo di autenticazione?"
17
+ sign_into_account: "Puoi fare log-in utilizzando:"
18
+ sign_in_through_one_of_these_services: "Entra con uno di questi servizi:"
19
+ social_api_key: "API Key"
20
+ social_api_secret: "API Secret"
21
+ social_authentication_methods: "Metodi di autenticazione social"
22
+ social_authentication_methods_description: "Setup metodi di autenticazione OAuth"
23
+ social_provider: "Social Provider"
24
+ please_confirm_your_email: "Per favore, conferma il tuo indirizzo e-mail per continuare."
25
+ sign_in_with: "Login con %{provider}"
26
+ you_have_signed_in_with_these_services: "Hai fatto log-in con questi servizi"
@@ -1,6 +1,6 @@
1
- Spree::Core::Engine.add_routes do
1
+ Spree::Core::Engine.routes.draw do
2
2
  devise_for :spree_user,
3
- class_name: Spree::User,
3
+ class_name: Spree.user_class,
4
4
  only: [:omniauth_callbacks],
5
5
  controllers: { omniauth_callbacks: 'spree/omniauth_callbacks' },
6
6
  path: Spree::SocialConfig[:path_prefix]
@@ -1,4 +1,4 @@
1
- class CreateUserAuthentications < ActiveRecord::Migration
1
+ class CreateUserAuthentications < SolidusSupport::Migration[4.2]
2
2
  def change
3
3
  create_table :spree_user_authentications do |t|
4
4
  t.integer :user_id
@@ -1,4 +1,4 @@
1
- class CreateAuthenticationMethods < ActiveRecord::Migration
1
+ class CreateAuthenticationMethods < SolidusSupport::Migration[4.2]
2
2
  def change
3
3
  create_table :spree_authentication_methods do |t|
4
4
  t.string :environment
@@ -1,6 +1,8 @@
1
1
  module SolidusSocial
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
+ source_root File.dirname(__FILE__) + "/templates"
5
+
4
6
  class_option :auto_run_migrations, type: :boolean, default: false
5
7
 
6
8
  def add_stylesheets
@@ -11,6 +13,10 @@ module SolidusSocial
11
13
  run 'bundle exec rake railties:install:migrations FROM=solidus_social'
12
14
  end
13
15
 
16
+ def copy_initializer
17
+ template "config/initializers/solidus_social.rb"
18
+ end
19
+
14
20
  def run_migrations
15
21
  run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
16
22
  if run_migrations
@@ -0,0 +1,48 @@
1
+ Spree::SocialConfig.configure do |config|
2
+ config.use_static_preferences!
3
+
4
+ # Configure the Path prefix for OAuth paths
5
+ # The default is /user/auth/:provider
6
+ #
7
+ # for /member/auth/:provider
8
+ # config.path_prefix = 'member'
9
+ # for /profile/auth/:provider
10
+ # config.path_prefix = 'profile'
11
+ # for /auth/:provider
12
+ # config.path_prefix = ''
13
+
14
+ config.providers = {
15
+ facebook: {
16
+ api_key: ENV['FACEBOOK_API_KEY'],
17
+ api_secret: ENV['FACEBOOK_API_SECRET'],
18
+ },
19
+ twitter: {
20
+ api_key: ENV['TWITTER_API_KEY'],
21
+ api_secret: ENV['TWITTER_API_SECRET'],
22
+ },
23
+ github: {
24
+ api_key: ENV['GITHUB_API_KEY'],
25
+ api_secret: ENV['GITHUB_API_SECRET'],
26
+ },
27
+ google_oauth2: {
28
+ api_key: ENV['GOOGLE_OAUTH2_API_KEY'],
29
+ api_secret: ENV['GOOGLE_OAUTH2_API_SECRET'],
30
+ },
31
+ amazon: {
32
+ api_key: ENV['AMAZON_API_KEY'],
33
+ api_secret: ENV['AMAZON_API_SECRET'],
34
+ }
35
+ }
36
+ end
37
+
38
+ SolidusSocial.init_providers
39
+
40
+ OmniAuth.config.logger = Logger.new(STDOUT)
41
+ OmniAuth.logger.progname = 'omniauth'
42
+
43
+ OmniAuth.config.on_failure = proc do |env|
44
+ env['devise.mapping'] = Devise.mappings[Spree.user_class.table_name.singularize.to_sym]
45
+ controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
46
+ controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
47
+ controller_klass.action(:failure).call(env)
48
+ end
@@ -1,4 +1,5 @@
1
- require 'spree_core'
1
+ require 'solidus_core'
2
+ require 'solidus_support'
2
3
  require 'solidus_auth_devise'
3
4
  require 'omniauth-twitter'
4
5
  require 'omniauth-facebook'
@@ -1,12 +1,4 @@
1
1
  module SolidusSocial
2
- OAUTH_PROVIDERS = [
3
- %w(Facebook facebook),
4
- %w(Twitter twitter),
5
- %w(Github github),
6
- %w(Google google_oauth2),
7
- %w(Amazon amazon)
8
- ]
9
-
10
2
  class Engine < Rails::Engine
11
3
  engine_name 'solidus_social'
12
4
 
@@ -16,6 +8,16 @@ module SolidusSocial
16
8
  Spree::SocialConfig = Spree::SocialConfiguration.new
17
9
  end
18
10
 
11
+ initializer 'solidus_social.decorate_spree_user' do
12
+ next unless Rails.application.respond_to?(:reloader)
13
+
14
+ Rails.application.reloader.after_class_unload do
15
+ # Reload and decorate the spree user class immediately after it is
16
+ # unloaded so that it is available to devise when loading routes
17
+ load File.join(__dir__, '../../app/models/spree/user_decorator.rb')
18
+ end
19
+ end
20
+
19
21
  def self.activate
20
22
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
21
23
  Rails.configuration.cache_classes ? require(c) : load(c)
@@ -25,17 +27,14 @@ module SolidusSocial
25
27
  config.to_prepare(&method(:activate).to_proc)
26
28
  end
27
29
 
28
- # Setup all OAuth providers
29
- def self.init_provider(provider)
30
- return unless ActiveRecord::Base.connection.table_exists?('spree_authentication_methods')
31
- key, secret = nil
32
- Spree::AuthenticationMethod.where(environment: ::Rails.env).each do |auth_method|
33
- next unless auth_method.provider == provider
34
- key = auth_method.api_key
35
- secret = auth_method.api_secret
36
- Rails.logger.info("[Spree Social] Loading #{auth_method.provider.capitalize} as authentication source")
30
+ def self.configured_providers
31
+ Spree::SocialConfig.providers.keys.map(&:to_s)
32
+ end
33
+
34
+ def self.init_providers
35
+ Spree::SocialConfig.providers.each do |provider, credentials|
36
+ setup_key_for(provider, credentials[:api_key], credentials[:api_secret])
37
37
  end
38
- setup_key_for(provider.to_sym, key, secret)
39
38
  end
40
39
 
41
40
  def self.setup_key_for(provider, key, secret)
@@ -9,7 +9,7 @@ module SolidusSocial
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 1
12
+ MINOR = 2
13
13
  TINY = 0
14
14
  PRE = nil
15
15
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.requirements << 'none'
23
23
 
24
24
  s.add_runtime_dependency 'solidus_core', [">= 1.0", "< 3"]
25
+ s.add_runtime_dependency 'solidus_support'
25
26
  s.add_runtime_dependency 'solidus_auth_devise'
26
27
  s.add_runtime_dependency 'omniauth'
27
28
  s.add_runtime_dependency 'oa-core'
@@ -32,10 +33,12 @@ Gem::Specification.new do |s|
32
33
  s.add_runtime_dependency 'omniauth-amazon'
33
34
 
34
35
  s.add_development_dependency 'capybara', '~> 2.4'
36
+ s.add_development_dependency 'capybara-screenshot'
35
37
  s.add_development_dependency 'database_cleaner', '1.3'
36
38
  s.add_development_dependency 'rspec-rails', '~> 3.1'
37
39
  s.add_development_dependency 'factory_girl', '~> 4.4'
38
40
  s.add_development_dependency 'selenium-webdriver', '>= 2.41.0'
41
+ s.add_development_dependency 'chromedriver-helper'
39
42
  s.add_development_dependency 'poltergeist', '~> 1.5'
40
43
  s.add_development_dependency 'simplecov', '~> 0.9.0'
41
44
  s.add_development_dependency 'sqlite3', '~> 1.3.10'
@@ -141,6 +141,34 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
141
141
  expect(controller).to receive(:sign_in_and_redirect)
142
142
  expect { controller.twitter }.to change(Spree::User, :count).by(1)
143
143
  end
144
+
145
+ context 'when `Spree.user_class` has changed' do
146
+ before do
147
+ @previous_user_class = Spree.user_class.to_s
148
+ Spree.user_class = Spree::LegacyUser.to_s
149
+
150
+ # the application was initialized with Spree::User, so some
151
+ # some methods do not exist on LegacyUser. In practice, this will
152
+ # not happen as Spree.user_class will not change on the fly like
153
+ # this.
154
+ # this statement simply stubs the required missing method
155
+ allow_any_instance_of(Spree::LegacyUser)
156
+ .to receive(:apply_omniauth)
157
+ end
158
+
159
+ after do
160
+ # in order to not affect other tests, restore the original class
161
+ Spree.user_class = @previous_user_class
162
+ end
163
+
164
+ it 'creates a new user' do
165
+ expect(Spree::User).not_to receive :new
166
+ expect_any_instance_of(Spree::User).not_to receive :save
167
+
168
+ expect { controller.twitter }
169
+ .to change(Spree::LegacyUser, :count).by(1)
170
+ end
171
+ end
144
172
  end
145
173
 
146
174
  context 'email belongs to existing user' do
@@ -21,20 +21,12 @@ RSpec.feature 'Admin Authentication Methods', :js do
21
21
 
22
22
  click_link 'New Authentication Method'
23
23
  expect(page).to have_text /BACK TO AUTHENTICATION METHODS LIST/i
24
- select 'Test', from: 'authentication_method[environment]'
24
+ select2 'Test', from: 'Environment'
25
25
  select2 'Github', from: 'Social Provider'
26
- fill_in 'API Key', with: 'KEY123'
27
- fill_in 'API Secret', with: 'SEC123'
28
26
 
29
27
  click_button 'Create'
30
28
  expect(page).to have_text 'successfully created!'
31
29
  end
32
-
33
- scenario 'does not save with empty fields' do
34
- click_link 'New Authentication Method'
35
- click_button 'Create'
36
- expect(page).to have_text 'errors prohibited this record from being saved'
37
- end
38
30
  end
39
31
 
40
32
  context 'when auth method exists' do
@@ -58,20 +50,19 @@ RSpec.feature 'Admin Authentication Methods', :js do
58
50
  click_icon :edit
59
51
  end
60
52
 
61
- fill_in 'API Key', with: 'fake'
62
- fill_in 'API Secret', with: 'fake'
53
+ find('#authentication_method_active_false').click
63
54
 
64
55
  click_button 'Update'
65
56
  expect(page).to have_text 'successfully updated!'
66
57
  end
67
58
 
68
59
  scenario 'can be deleted' do
69
- within_row(1) do
70
- click_icon :trash
60
+ accept_alert do
61
+ within_row(1) do
62
+ click_icon :trash
63
+ end
71
64
  end
72
65
 
73
- page.driver.browser.switch_to.alert.accept unless Capybara.javascript_driver == :poltergeist
74
-
75
66
  expect(page).to have_text 'successfully removed!'
76
67
  expect(page).not_to have_text authentication_method.provider
77
68
  end
@@ -24,30 +24,27 @@ RSpec.feature 'signing in using Omniauth', :js do
24
24
  end
25
25
 
26
26
  scenario 'going to sign in' do
27
- visit spree.root_path
28
- click_link 'Login'
29
- find('a[title="Login with facebook"]').trigger('click')
27
+ visit spree.login_path
28
+ click_on 'Login with facebook'
30
29
  expect(page).to have_text 'You are now signed in with your facebook account.'
31
30
  click_link 'Logout'
32
31
  click_link 'Login'
33
- find('a[title="Login with facebook"]').trigger('click')
32
+ click_on 'Login with facebook'
34
33
  expect(page).to have_text 'You are now signed in with your facebook account.'
35
34
  end
36
35
 
37
36
  # Regression test for #91
38
37
  scenario "attempting to view 'My Account' works" do
39
- visit spree.root_path
40
- click_link 'Login'
41
- find('a[title="Login with facebook"]').trigger('click')
38
+ visit spree.login_path
39
+ click_on 'Login with facebook'
42
40
  expect(page).to have_text 'You are now signed in with your facebook account.'
43
41
  click_link 'My Account'
44
42
  expect(page).to have_text 'My Account'
45
43
  end
46
44
 
47
45
  scenario "view 'My Account'" do
48
- visit spree.root_path
49
- click_link 'Login'
50
- find('a[title="Login with facebook"]').trigger('click')
46
+ visit spree.login_path
47
+ click_on 'Login with facebook'
51
48
  expect(page).to have_text 'You are now signed in with your facebook account.'
52
49
  click_link 'My Account'
53
50
  expect(page).not_to have_selector 'div#social-signin-links'
@@ -78,9 +75,8 @@ RSpec.feature 'signing in using Omniauth', :js do
78
75
  end
79
76
 
80
77
  scenario 'going to sign in' do
81
- visit spree.root_path
82
- click_link 'Login'
83
- find('a[title="Login with twitter"]').trigger('click')
78
+ visit spree.login_path
79
+ click_on 'Login with twitter'
84
80
  expect(page).to have_text 'Please confirm your email address to continue'.upcase
85
81
  fill_in 'Email', with: 'user@example.com'
86
82
  click_button 'Create'
@@ -0,0 +1,9 @@
1
+ RSpec.describe Spree::SocialConfig do
2
+ it "changing a preference does not create a Spree::Preference" do
3
+ expect { subject.path_prefix = 'customer' }.not_to change(Spree::Preference, :count)
4
+ end
5
+
6
+ it "holds configuration for the five default providers" do
7
+ expect(subject.providers.keys).to match_array([:amazon, :facebook, :github, :google_oauth2, :twitter])
8
+ end
9
+ end
@@ -1,16 +1,23 @@
1
1
  RSpec.describe SolidusSocial do
2
- context 'constants' do
3
- it { is_expected.to be_const_defined(:OAUTH_PROVIDERS) }
2
+ describe '.configured_providers' do
3
+ subject { described_class.configured_providers }
4
4
 
5
- it 'contain all providers' do
6
- oauth_providers = [
7
- %w(Amazon amazon),
8
- %w(Facebook facebook),
9
- %w(Twitter twitter),
10
- %w(Github github),
11
- %w(Google google_oauth2)
12
- ]
13
- expect(described_class::OAUTH_PROVIDERS).to match_array oauth_providers
5
+ it { is_expected.to match_array(["amazon", "facebook", "github", "google_oauth2", "twitter"]) }
6
+ end
7
+
8
+ describe '.init_providers' do
9
+ subject { described_class.init_providers }
10
+
11
+ around do |example|
12
+ previous_providers = Spree::SocialConfig.providers
13
+ Spree::SocialConfig.providers = { facebook: { api_key: "secret_key", api_secret: "secret_secret" } }
14
+ example.run
15
+ Spree::SocialConfig.providers = previous_providers
16
+ end
17
+
18
+ it "sets up Devise for the given providers" do
19
+ expect(SolidusSocial).to receive(:setup_key_for).with(:facebook, "secret_key", "secret_secret")
20
+ subject
14
21
  end
15
22
  end
16
23
  end
@@ -0,0 +1,17 @@
1
+ RSpec.describe Spree::AuthenticationMethod do
2
+ describe '.provider_options' do
3
+ let(:expected_provider_options) do
4
+ [
5
+ %w(Amazon amazon),
6
+ %w(Facebook facebook),
7
+ %w(Twitter twitter),
8
+ %w(Github github),
9
+ %w(Google google_oauth2)
10
+ ]
11
+ end
12
+
13
+ subject { described_class.provider_options }
14
+
15
+ it { is_expected.to match_array(expected_provider_options) }
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ RSpec.describe Spree::SocialConfiguration do
2
+ it { is_expected.to respond_to(:path_prefix) }
3
+ it { is_expected.to respond_to(:providers) }
4
+ end
@@ -21,6 +21,27 @@ RSpec.describe Spree::User, type: :model do
21
21
  expect(user.email).to eq 'test@example.com'
22
22
  end
23
23
  end
24
+
25
+ context 'instance is valid' do
26
+ let(:user) { create(:user) { |user| user.email = nil } }
27
+ let(:omni_params) do
28
+ {
29
+ 'provider' => 'any_provider',
30
+ 'uid' => 12_345,
31
+ 'info' => { 'email' => 'test@example.com' }
32
+ }
33
+ end
34
+
35
+ before do
36
+ allow(auths).to receive(:build)
37
+ allow(auths).to receive(:empty?).and_return(false)
38
+ end
39
+
40
+ it 'builds a valid user' do
41
+ user.apply_omniauth(omni_params)
42
+ expect(user.valid?).to be_truthy
43
+ end
44
+ end
24
45
  end
25
46
 
26
47
  context '.password_required?' do
@@ -1,18 +1,11 @@
1
1
  require 'capybara/rspec'
2
2
  require 'capybara/rails'
3
3
  require 'capybara/poltergeist'
4
+ require 'capybara-screenshot/rspec'
5
+ require 'selenium-webdriver'
4
6
 
5
7
  RSpec.configure do |config|
6
8
  config.include Rack::Test::Methods, type: :requests
7
9
 
8
- Capybara.javascript_driver = :poltergeist
9
- Capybara.register_driver(:poltergeist) do |app|
10
- Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 60
11
- end
12
-
13
- config.before(:each, :js) do
14
- if Capybara.javascript_driver == :selenium
15
- page.driver.browser.manage.window.maximize
16
- end
17
- end
10
+ Capybara.javascript_driver = :selenium_chrome_headless
18
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Dyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2017-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: solidus_support
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: solidus_auth_devise
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +170,20 @@ dependencies:
156
170
  - - "~>"
157
171
  - !ruby/object:Gem::Version
158
172
  version: '2.4'
173
+ - !ruby/object:Gem::Dependency
174
+ name: capybara-screenshot
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
159
187
  - !ruby/object:Gem::Dependency
160
188
  name: database_cleaner
161
189
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +240,20 @@ dependencies:
212
240
  - - ">="
213
241
  - !ruby/object:Gem::Version
214
242
  version: 2.41.0
243
+ - !ruby/object:Gem::Dependency
244
+ name: chromedriver-helper
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
250
+ type: :development
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - ">="
255
+ - !ruby/object:Gem::Version
256
+ version: '0'
215
257
  - !ruby/object:Gem::Dependency
216
258
  name: poltergeist
217
259
  requirement: !ruby/object:Gem::Requirement
@@ -320,17 +362,16 @@ files:
320
362
  - app/views/spree/admin/authentication_methods/edit.html.erb
321
363
  - app/views/spree/admin/authentication_methods/index.html.erb
322
364
  - app/views/spree/admin/authentication_methods/new.html.erb
323
- - app/views/spree/admin/shared/_configurations_menu.html.erb
324
365
  - app/views/spree/shared/_social.html.erb
325
366
  - app/views/spree/shared/_user_form.html.erb
326
367
  - app/views/spree/users/_new-customer.html.erb
327
368
  - app/views/spree/users/_social.html.erb
328
369
  - bin/rails
329
- - config/initializers/devise.rb
330
370
  - config/locales/de.yml
331
371
  - config/locales/en.yml
332
372
  - config/locales/es-MX.yml
333
373
  - config/locales/fr.yml
374
+ - config/locales/it.yml
334
375
  - config/locales/nl.yml
335
376
  - config/locales/pt-BR.yml
336
377
  - config/locales/sv.yml
@@ -338,6 +379,7 @@ files:
338
379
  - db/migrate/20120120163432_create_user_authentications.rb
339
380
  - db/migrate/20120123163222_create_authentication_methods.rb
340
381
  - lib/generators/solidus_social/install/install_generator.rb
382
+ - lib/generators/solidus_social/install/templates/config/initializers/solidus_social.rb
341
383
  - lib/solidus_social.rb
342
384
  - lib/solidus_social/engine.rb
343
385
  - lib/solidus_social/version.rb
@@ -345,7 +387,10 @@ files:
345
387
  - spec/controllers/spree/omniauth_callbacks_controller_spec.rb
346
388
  - spec/features/spree/admin/authentication_methods_configuration_spec.rb
347
389
  - spec/features/spree/sign_in_spec.rb
390
+ - spec/lib/spree/social_config_spec.rb
348
391
  - spec/lib/spree_social/engine_spec.rb
392
+ - spec/models/spree/authentication_method_spec.rb
393
+ - spec/models/spree/social_configuration_spec.rb
349
394
  - spec/models/spree/user_decorator_spec.rb
350
395
  - spec/spec_helper.rb
351
396
  - spec/support/capybara.rb
@@ -374,7 +419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
374
419
  requirements:
375
420
  - none
376
421
  rubyforge_project:
377
- rubygems_version: 2.5.1
422
+ rubygems_version: 2.6.11
378
423
  signing_key:
379
424
  specification_version: 4
380
425
  summary: Adds social network login services (OAuth) to Spree
@@ -382,7 +427,10 @@ test_files:
382
427
  - spec/controllers/spree/omniauth_callbacks_controller_spec.rb
383
428
  - spec/features/spree/admin/authentication_methods_configuration_spec.rb
384
429
  - spec/features/spree/sign_in_spec.rb
430
+ - spec/lib/spree/social_config_spec.rb
385
431
  - spec/lib/spree_social/engine_spec.rb
432
+ - spec/models/spree/authentication_method_spec.rb
433
+ - spec/models/spree/social_configuration_spec.rb
386
434
  - spec/models/spree/user_decorator_spec.rb
387
435
  - spec/spec_helper.rb
388
436
  - spec/support/capybara.rb
@@ -1,4 +0,0 @@
1
- <tr>
2
- <td><%= link_to Spree.t(:social_authentication_methods), spree.admin_authentication_methods_path %></td>
3
- <td><%= Spree.t(:social_authentication_methods_description) %></td>
4
- </tr>
@@ -1,13 +0,0 @@
1
- SolidusSocial::OAUTH_PROVIDERS.each do |provider|
2
- SolidusSocial.init_provider(provider[1])
3
- end
4
-
5
- OmniAuth.config.logger = Logger.new(STDOUT)
6
- OmniAuth.logger.progname = 'omniauth'
7
-
8
- OmniAuth.config.on_failure = proc do |env|
9
- env['devise.mapping'] = Devise.mappings[Spree.user_class.table_name.singularize.to_sym]
10
- controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
11
- controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
12
- controller_klass.action(:failure).call(env)
13
- end