Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Feb 21, 2024
2 parents bfd2ea0 + 4222a64 commit 2b69680
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
16 changes: 8 additions & 8 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ def passthru
end

def twitter
logger.info("Callback Linked")
logger.info("Callback Twitter")
# logger.info(session.to_json)
callback
callback_handler
end

def instagram
logger.info("Callback Instagr")
logger.info("Callback Instagram")
# logger.info(session.to_json)
callback
callback_handler
end

def soundcloud
logger.info("Callback SoundCloud")
# logger.info(session.to_json)
callback
callback_handler
end

def zoom
Expand All @@ -63,19 +63,19 @@ def zoom
end

def stripe_connect
logger.info("Callback stripe")
logger.info("Callback Stripe")
# logger.info(session.to_json)
callback_handler
end

def discord
logger.info("Callback stripe")
logger.info("Callback Discord")
# logger.info(session.to_json)
callback_handler
end

def twitch
logger.info("Callback twitch")
logger.info("Callback Twitch")
# logger.info(session.to_json)
callback_handler
end
Expand Down
2 changes: 0 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

config.action_mailer.default_url_options = {host: "localhost", port: 3000}

Rails.application.routes.default_url_options = {host: "localhost", port: 3000}

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

Expand Down
4 changes: 4 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

require "sidekiq/testing"

Dir[Rails.root.join("spec", "support", "**", "*.rb")].each { |f| require f }

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = Rails.root.join("spec/fixtures")
Expand Down Expand Up @@ -73,4 +75,6 @@
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")

config.include TestHelpers
end
36 changes: 34 additions & 2 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
require "rails_helper"

RSpec.describe "Users", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
describe "omniauth" do
before(:each) do
OmniAuth.config.test_mode = true
end

after(:each) do
OmniAuth.config.test_mode = false
OmniAuth.config.mock_auth[:twitter] = nil
OmniAuth.config.mock_auth[:discord] = nil
end

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

it "should sign in with twitter" do
omni_params = oauth2_mock(:twitter)
user.oauth_credentials.create(provider: omni_params.provider, uid: omni_params.uid)

expect {
post user_twitter_omniauth_callback_url, env: {"omniauth.auth": omni_params}
}.to change(User, :count).by(0)
expect(response).to redirect_to(new_user_session_path)
expect(flash[:notice]).to include("We are synchronizing your twitter data")
end

it "should sign in with discord" do
omni_params = oauth2_mock(:discord)
user.oauth_credentials.create(provider: omni_params.provider, uid: omni_params.uid)

expect {
post user_discord_omniauth_callback_url, env: {"omniauth.auth": omni_params}
}.to change(User, :count).by(0)
expect(response).to redirect_to(new_user_session_path)
expect(flash[:notice]).to include("We are synchronizing your discord data")
end
end
end
10 changes: 10 additions & 0 deletions spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module TestHelpers
def oauth2_mock(provider, name: nil, email: nil)
name = Faker::Movies::Ghostbusters.character if name.blank?
email = Faker::Internet.email if email.blank?
OmniAuth.config.add_mock(provider,
uid: "12345",
info: {name: name, email: email},
credentials: {token: "1a2b3c", secret: "4d5e6f"})
end
end

0 comments on commit 2b69680

Please sign in to comment.