solidus_social 1.0.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.gitignore +6 -8
  5. data/.rspec +3 -3
  6. data/.rubocop.yml +3 -7
  7. data/.rubocop_todo.yml +42 -0
  8. data/CHANGELOG.md +34 -4
  9. data/Gemfile +23 -0
  10. data/{LICENSE.md → LICENSE} +2 -2
  11. data/README.md +133 -78
  12. data/Rakefile +4 -13
  13. data/app/controllers/spree/admin/authentication_methods_controller.rb +2 -12
  14. data/app/controllers/spree/omniauth_callbacks_controller.rb +46 -42
  15. data/app/controllers/spree/user_authentications_controller.rb +3 -1
  16. data/app/core/spree/permission_sets/authentication_method_display.rb +11 -0
  17. data/app/core/spree/permission_sets/authentication_method_management.rb +11 -0
  18. data/app/decorators/controllers/solidus_social/spree/user_registrations_controller_decorator.rb +27 -0
  19. data/app/decorators/models/solidus_social/spree/user_decorator.rb +28 -0
  20. data/app/helpers/spree/omniauth_callbacks_helper.rb +2 -0
  21. data/app/models/spree/authentication_method.rb +8 -2
  22. data/app/models/spree/social_configuration.rb +3 -0
  23. data/app/models/spree/user_authentication.rb +3 -1
  24. data/app/overrides/add_authentications_to_account_summary.rb +2 -0
  25. data/app/overrides/admin_configuration_decorator.rb +9 -2
  26. data/app/overrides/user_registrations_decorator.rb +2 -0
  27. data/app/views/spree/admin/authentication_methods/_form.html.erb +6 -22
  28. data/app/views/spree/admin/authentication_methods/edit.html.erb +5 -3
  29. data/app/views/spree/admin/authentication_methods/index.html.erb +22 -18
  30. data/app/views/spree/admin/authentication_methods/new.html.erb +5 -3
  31. data/app/views/spree/shared/_social.html.erb +5 -5
  32. data/app/views/spree/shared/_user_form.html.erb +3 -3
  33. data/app/views/spree/users/_new-customer.html.erb +2 -2
  34. data/app/views/spree/users/_social.html.erb +24 -22
  35. data/bin/console +17 -0
  36. data/bin/rails +15 -4
  37. data/bin/rake +7 -0
  38. data/bin/sandbox +72 -0
  39. data/bin/setup +8 -0
  40. data/config/locales/en.yml +1 -0
  41. data/config/locales/es-MX.yml +8 -4
  42. data/config/locales/es.yml +30 -0
  43. data/config/locales/it.yml +26 -0
  44. data/config/routes.rb +7 -5
  45. data/db/migrate/20120120163432_create_user_authentications.rb +3 -1
  46. data/db/migrate/20120123163222_create_authentication_methods.rb +3 -1
  47. data/lib/generators/solidus_social/install/install_generator.rb +13 -5
  48. data/lib/generators/solidus_social/install/templates/config/initializers/solidus_social.rb +50 -0
  49. data/lib/solidus_social.rb +24 -8
  50. data/lib/solidus_social/engine.rb +29 -55
  51. data/lib/solidus_social/facebook_omniauth_strategy_ext.rb +25 -0
  52. data/lib/solidus_social/factories.rb +4 -0
  53. data/lib/solidus_social/version.rb +3 -16
  54. data/solidus_social.gemspec +43 -46
  55. data/spec/controllers/spree/omniauth_callbacks_controller_spec.rb +42 -9
  56. data/spec/features/spree/admin/authentication_methods_configuration_spec.rb +21 -27
  57. data/spec/features/spree/sign_in_spec.rb +27 -19
  58. data/spec/lib/solidus_social/engine_spec.rb +9 -0
  59. data/spec/lib/solidus_social_speec.rb +25 -0
  60. data/spec/lib/spree/social_config_spec.rb +11 -0
  61. data/spec/models/spree/authentication_method_spec.rb +19 -0
  62. data/spec/models/spree/social_configuration_spec.rb +6 -0
  63. data/spec/models/spree/user_decorator_spec.rb +25 -2
  64. data/spec/spec_helper.rb +17 -29
  65. data/spec/support/omniauth.rb +4 -0
  66. metadata +71 -198
  67. data/.hound.yml +0 -26
  68. data/.travis.yml +0 -19
  69. data/Guardfile +0 -10
  70. data/app/assets/javascripts/spree/backend/solidus_social.js +0 -1
  71. data/app/assets/javascripts/spree/frontend/solidus_social.js +0 -1
  72. data/app/assets/stylesheets/spree/backend/solidus_social.css +0 -3
  73. data/app/controllers/spree/user_registrations_controller_decorator.rb +0 -15
  74. data/app/models/spree/user_decorator.rb +0 -16
  75. data/app/views/spree/admin/shared/_configurations_menu.html.erb +0 -4
  76. data/config/initializers/devise.rb +0 -13
  77. data/spec/lib/spree_social/engine_spec.rb +0 -16
  78. data/spec/support/capybara.rb +0 -18
  79. data/spec/support/database_cleaner.rb +0 -24
  80. data/spec/support/devise.rb +0 -3
  81. data/spec/support/factory_girl.rb +0 -7
  82. data/spec/support/spree.rb +0 -8
@@ -1,10 +1,26 @@
1
- require 'spree_core'
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_core'
4
+ require 'solidus_support'
2
5
  require 'solidus_auth_devise'
3
- require 'omniauth-twitter'
4
- require 'omniauth-facebook'
5
- require 'omniauth-github'
6
- require 'omniauth-google-oauth2'
7
- require 'omniauth-amazon'
8
- require 'solidus_social/engine'
6
+
9
7
  require 'solidus_social/version'
10
- require 'coffee_script'
8
+ require 'solidus_social/engine'
9
+
10
+ module SolidusSocial
11
+ def self.configured_providers
12
+ ::Spree::SocialConfig.providers.keys.map(&:to_s)
13
+ end
14
+
15
+ def self.init_providers
16
+ ::Spree::SocialConfig.providers.each do |provider, credentials|
17
+ setup_key_for(provider, credentials[:api_key], credentials[:api_secret])
18
+ end
19
+ end
20
+
21
+ def self.setup_key_for(provider, key, secret)
22
+ Devise.setup do |config|
23
+ config.omniauth provider, key, secret, setup: true
24
+ end
25
+ end
26
+ end
@@ -1,69 +1,43 @@
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
- ]
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-twitter'
4
+ require 'omniauth-facebook'
5
+ require 'omniauth-github'
6
+ require 'omniauth-google-oauth2'
7
+ require 'omniauth-amazon'
8
+ require 'deface'
9
+ require 'coffee_script'
10
+ require 'spree/core'
11
+ require 'solidus_social/facebook_omniauth_strategy_ext'
9
12
 
13
+ module SolidusSocial
10
14
  class Engine < Rails::Engine
11
- engine_name 'solidus_social'
15
+ include SolidusSupport::EngineExtensions
12
16
 
13
- config.autoload_paths += %W(#{config.root}/lib)
17
+ isolate_namespace ::Spree
14
18
 
15
- initializer 'solidus_social.environment', before: 'spree.environment' do
16
- Spree::SocialConfig = Spree::SocialConfiguration.new
17
- end
19
+ engine_name 'solidus_social'
18
20
 
19
- def self.activate
20
- Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
21
- Rails.configuration.cache_classes ? require(c) : load(c)
22
- end
21
+ # use rspec for tests
22
+ config.generators do |g|
23
+ g.test_framework :rspec
23
24
  end
24
25
 
25
- config.to_prepare(&method(:activate).to_proc)
26
- end
26
+ USER_DECORATOR_PATH = root.join(
27
+ "app/decorators/models/solidus_social/spree/user_decorator.rb"
28
+ ).to_s
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
+ initializer 'solidus_social.environment', before: 'spree.environment' do
31
+ ::Spree::SocialConfig = ::Spree::SocialConfiguration.new
37
32
  end
38
- setup_key_for(provider.to_sym, key, secret)
39
- end
40
33
 
41
- def self.setup_key_for(provider, key, secret)
42
- Devise.setup do |config|
43
- config.omniauth provider, key, secret, setup: true
44
- end
45
- end
46
- end
47
-
48
- module OmniAuth
49
- module Strategies
50
- class Facebook < OAuth2
51
- MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' \
52
- 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' \
53
- 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' \
54
- 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' \
55
- 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' \
56
- 'mobile'
57
- def request_phase
58
- options[:scope] ||= 'email'
59
- options[:info_fields] ||= 'email'
60
- options[:display] = mobile_request? ? 'touch' : 'page'
61
- super
62
- end
34
+ initializer 'solidus_social.decorate_spree_user' do |app|
35
+ next unless app.respond_to?(:reloader)
63
36
 
64
- def mobile_request?
65
- ua = Rack::Request.new(@env).user_agent.to_s
66
- ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS)
37
+ app.reloader.after_class_unload do
38
+ # Reload and decorate the spree user class immediately after it is
39
+ # unloaded so that it is available to devise when loading routes
40
+ load USER_DECORATOR_PATH
67
41
  end
68
42
  end
69
43
  end
@@ -0,0 +1,25 @@
1
+ module SolidusSocial
2
+ # Patch the Facebook strategy discriminating between mobile and desktop.
3
+ module FacebookOmniauthStrategyExt
4
+ MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' \
5
+ 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' \
6
+ 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' \
7
+ 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' \
8
+ 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' \
9
+ 'mobile'
10
+
11
+ def request_phase
12
+ options[:scope] ||= 'email'
13
+ options[:info_fields] ||= 'email'
14
+ options[:display] = mobile_request? ? 'touch' : 'page'
15
+ super
16
+ end
17
+
18
+ def mobile_request?
19
+ ua = Rack::Request.new(@env).user_agent.to_s
20
+ ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS)
21
+ end
22
+
23
+ OmniAuth::Strategies::Facebook.prepend self
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ end
@@ -1,18 +1,5 @@
1
- module SolidusSocial
2
- module_function
3
-
4
- # Returns the version of the currently loaded SolidusSocial as a
5
- # <tt>Gem::Version</tt>.
6
- def version
7
- Gem::Version.new VERSION::STRING
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- module VERSION
11
- MAJOR = 1
12
- MINOR = 0
13
- TINY = 0
14
- PRE = nil
15
-
16
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
17
- end
3
+ module SolidusSocial
4
+ VERSION = '1.4.0'
18
5
  end
@@ -1,47 +1,44 @@
1
- lib = File.expand_path('../lib/', __FILE__)
2
- $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
-
4
- require 'solidus_social/version'
5
-
6
- Gem::Specification.new do |s|
7
- s.platform = Gem::Platform::RUBY
8
- s.name = 'solidus_social'
9
- s.version = SolidusSocial.version
10
- s.summary = 'Adds social network login services (OAuth) to Spree'
11
- s.description = s.summary
12
- s.required_ruby_version = '>= 1.9.3'
13
-
14
- s.author = 'John Dyer'
15
- s.email = 'jdyer@spreecommerce.com'
16
- s.homepage = 'http://www.spreecommerce.com'
17
- s.license = 'BSD-3'
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- spec/*`.split("\n")
21
- s.require_path = 'lib'
22
- s.requirements << 'none'
23
-
24
- s.add_runtime_dependency 'solidus_core', ["~> 1.0"]
25
- s.add_runtime_dependency 'omniauth'
26
- s.add_runtime_dependency 'oa-core'
27
- s.add_runtime_dependency 'omniauth-twitter'
28
- s.add_runtime_dependency 'omniauth-facebook'
29
- s.add_runtime_dependency 'omniauth-github'
30
- s.add_runtime_dependency 'omniauth-google-oauth2'
31
- s.add_runtime_dependency 'omniauth-amazon'
32
-
33
- s.add_development_dependency 'capybara', '~> 2.4.1'
34
- s.add_development_dependency 'database_cleaner', '1.3.0'
35
- s.add_development_dependency 'rspec-rails', '~> 3.1.0'
36
- s.add_development_dependency 'factory_girl', '~> 4.4'
37
- s.add_development_dependency 'pry-rails'
38
- s.add_development_dependency 'selenium-webdriver', '>= 2.41.0'
39
- s.add_development_dependency 'poltergeist', '~> 1.5.0'
40
- s.add_development_dependency 'simplecov', '~> 0.9.0'
41
- s.add_development_dependency 'sqlite3', '~> 1.3.10'
42
- s.add_development_dependency 'coffee-rails'
43
- s.add_development_dependency 'sass-rails'
44
- s.add_development_dependency 'guard-rspec'
45
- s.add_development_dependency 'rubocop', '>= 0.24.1'
46
- s.add_development_dependency 'rake', '< 11'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/solidus_social/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'solidus_social'
7
+ spec.version = SolidusSocial::VERSION
8
+ spec.authors = ['John Dyer']
9
+ spec.email = 'jdyer@spreecommerce.com'
10
+
11
+ spec.summary = 'Adds social network login services (OAuth) to Solidus'
12
+ spec.homepage = 'https://github.com/solidusio-contrib/solidus_social#readme'
13
+ spec.license = 'BSD-3-Clause'
14
+
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_social'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_social/blob/master/CHANGELOG.md'
19
+
20
+ spec.required_ruby_version = '>= 2.4'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
25
+ spec.files = files.grep_v(%r{^(test|spec|features)/})
26
+ spec.test_files = files.grep(%r{^(test|spec|features)/})
27
+ spec.bindir = "exe"
28
+ spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency 'deface'
32
+ spec.add_dependency 'oa-core'
33
+ spec.add_dependency 'omniauth'
34
+ spec.add_dependency 'omniauth-amazon'
35
+ spec.add_dependency 'omniauth-facebook'
36
+ spec.add_dependency 'omniauth-github'
37
+ spec.add_dependency 'omniauth-google-oauth2'
38
+ spec.add_dependency 'omniauth-twitter'
39
+ spec.add_dependency 'solidus_auth_devise'
40
+ spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
41
+ spec.add_dependency 'solidus_support', '~> 0.5'
42
+
43
+ spec.add_development_dependency 'solidus_dev_support'
47
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
2
4
  let(:user) { create(:user) }
3
5
  let(:omni_params) { double('omni', :[] => nil).as_null_object }
@@ -45,18 +47,19 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
45
47
  end
46
48
  end
47
49
 
48
- context '#callback' do
50
+ describe '#callback' do
49
51
  context 'when user is authenticated' do
50
52
  before do
51
53
  allow(controller).to receive(:spree_current_user).and_return(user)
52
54
  end
53
55
 
54
- it_should_behave_like 'denied_permissions'
56
+ it_behaves_like 'denied_permissions'
55
57
 
56
58
  context 'when existing user_authentication' do
57
59
  let(:user_authentication) { double('user_authentication', user: user) }
60
+
58
61
  before do
59
- allow(Spree::UserAuthentication).to receive(:find_by_provider_and_uid).and_return(user_authentication)
62
+ allow(Spree::UserAuthentication).to receive(:find_by).and_return(user_authentication)
60
63
  end
61
64
 
62
65
  it 'does not need to create the user_authentication' do
@@ -77,7 +80,7 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
77
80
 
78
81
  context 'when no existing user_authentication' do
79
82
  before do
80
- allow(Spree::UserAuthentication).to receive(:find_by_provider_and_uid).and_return(nil)
83
+ allow(Spree::UserAuthentication).to receive(:find_by).and_return(nil)
81
84
  end
82
85
 
83
86
  it 'creates a new user_authentication' do
@@ -96,7 +99,7 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
96
99
  controller.twitter
97
100
  end
98
101
 
99
- it_should_behave_like 'associate_order'
102
+ it_behaves_like 'associate_order'
100
103
  end
101
104
  end
102
105
 
@@ -105,12 +108,13 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
105
108
  allow(controller).to receive(:spree_current_user).and_return(nil)
106
109
  end
107
110
 
108
- it_should_behave_like 'denied_permissions'
111
+ it_behaves_like 'denied_permissions'
109
112
 
110
113
  context 'when existing user_authentication' do
111
114
  let(:user_authentication) { double('user_authentication', user: user) }
115
+
112
116
  before do
113
- allow(Spree::UserAuthentication).to receive(:find_by_provider_and_uid).and_return(user_authentication)
117
+ allow(Spree::UserAuthentication).to receive(:find_by).and_return(user_authentication)
114
118
  end
115
119
 
116
120
  it 'does not need to create the user_authentication' do
@@ -131,8 +135,9 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
131
135
 
132
136
  context 'when no existing user_authentication' do
133
137
  let(:user) { Spree::User.new }
138
+
134
139
  before do
135
- allow(Spree::UserAuthentication).to receive(:find_by_provider_and_uid).and_return(nil)
140
+ allow(Spree::UserAuthentication).to receive(:find_by).and_return(nil)
136
141
  allow(controller).to receive(:auth_hash).and_return('provider' => 'facebook', 'info' => { 'email' => 'spree@gmail.com' }, 'uid' => '123')
137
142
  end
138
143
 
@@ -141,13 +146,41 @@ RSpec.describe Spree::OmniauthCallbacksController, type: :controller do
141
146
  expect(controller).to receive(:sign_in_and_redirect)
142
147
  expect { controller.twitter }.to change(Spree::User, :count).by(1)
143
148
  end
149
+
150
+ context 'when `Spree.user_class` has changed' do
151
+ before do
152
+ @previous_user_class = Spree.user_class.to_s
153
+ Spree.user_class = Spree::LegacyUser.to_s
154
+
155
+ # the application was initialized with Spree::User, so some
156
+ # some methods do not exist on LegacyUser. In practice, this will
157
+ # not happen as Spree.user_class will not change on the fly like
158
+ # this.
159
+ # this statement simply stubs the required missing method
160
+ allow_any_instance_of(Spree::LegacyUser)
161
+ .to receive(:apply_omniauth)
162
+ end
163
+
164
+ after do
165
+ # in order to not affect other tests, restore the original class
166
+ Spree.user_class = @previous_user_class
167
+ end
168
+
169
+ it 'creates a new user' do
170
+ expect(Spree::User).not_to receive :new
171
+ expect_any_instance_of(Spree::User).not_to receive :save
172
+
173
+ expect { controller.twitter }
174
+ .to change(Spree::LegacyUser, :count).by(1)
175
+ end
176
+ end
144
177
  end
145
178
 
146
179
  context 'email belongs to existing user' do
147
180
  before { @user = create(:user, email: 'spree@gmail.com') }
148
181
 
149
182
  it 'does not create new user' do
150
- expect { controller.twitter }.to_not change(Spree::User, :count)
183
+ expect { controller.twitter }.not_to change(Spree::User, :count)
151
184
  end
152
185
 
153
186
  it 'assigns authentication to existing user' do
@@ -1,77 +1,71 @@
1
- RSpec.feature 'Admin Authentication Methods', :js do
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Admin Authentication Methods', :js do
2
4
  stub_authorization!
3
5
 
4
6
  context 'elements' do
5
- scenario 'has configuration tab' do
7
+ it 'has configuration tab' do
6
8
  visit spree.admin_path
7
9
  click_link 'Settings'
8
- expect(page).to have_text 'SOCIAL AUTHENTICATION METHODS'
10
+ expect(page).to have_text(/Social Authentication Methods/i)
9
11
  end
10
12
  end
11
13
 
12
14
  context 'when no auth methods exists' do
13
- background do
15
+ before do
14
16
  visit spree.admin_path
15
17
  click_link 'Settings'
16
18
  click_link 'Social Authentication Methods'
17
19
  end
18
20
 
19
- scenario 'can create new' do
20
- expect(page).to have_text 'NO AUTHENTICATION METHODS FOUND, ADD ONE!'
21
+ it 'can create new' do
22
+ expect(page).to have_text /NO AUTHENTICATION METHODS FOUND, ADD ONE!/i
21
23
 
22
24
  click_link 'New Authentication Method'
23
- expect(page).to have_text 'BACK TO AUTHENTICATION METHODS LIST'
24
- select 'Test', from: 'authentication_method[environment]'
25
+ expect(page).to have_text /BACK TO AUTHENTICATION METHODS LIST/i
26
+ select2 'Test', from: 'Environment'
25
27
  select2 'Github', from: 'Social Provider'
26
- fill_in 'API Key', with: 'KEY123'
27
- fill_in 'API Secret', with: 'SEC123'
28
28
 
29
29
  click_button 'Create'
30
30
  expect(page).to have_text 'successfully created!'
31
31
  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
32
  end
39
33
 
40
34
  context 'when auth method exists' do
41
- given!(:authentication_method) do
35
+ let!(:authentication_method) do
42
36
  Spree::AuthenticationMethod.create!(
43
37
  provider: 'facebook',
44
38
  api_key: 'fake',
45
39
  api_secret: 'fake',
46
40
  environment: Rails.env,
47
- active: true)
41
+ active: true
42
+ )
48
43
  end
49
44
 
50
- background do
45
+ before do
51
46
  visit spree.admin_path
52
47
  click_link 'Settings'
53
48
  click_link 'Social Authentication Methods'
54
49
  end
55
50
 
56
- scenario 'can be updated' do
51
+ it 'can be updated' do
57
52
  within_row(1) do
58
53
  click_icon :edit
59
54
  end
60
55
 
61
- fill_in 'API Key', with: 'fake'
62
- fill_in 'API Secret', with: 'fake'
56
+ find('#authentication_method_active_false').click
63
57
 
64
58
  click_button 'Update'
65
59
  expect(page).to have_text 'successfully updated!'
66
60
  end
67
61
 
68
- scenario 'can be deleted' do
69
- within_row(1) do
70
- click_icon :trash
62
+ it 'can be deleted' do
63
+ accept_confirm do
64
+ within_row(1) do
65
+ click_icon :trash
66
+ end
71
67
  end
72
68
 
73
- page.driver.browser.switch_to.alert.accept unless Capybara.javascript_driver == :poltergeist
74
-
75
69
  expect(page).to have_text 'successfully removed!'
76
70
  expect(page).not_to have_text authentication_method.provider
77
71
  end