Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiedeziel committed Mar 24, 2017
1 parent ccd2b24 commit bbfd1dc
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 87 deletions.
121 changes: 62 additions & 59 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]

# GET /resource/sign_up
# def new
# super
# end

# POST /resource
def create
super
SlackInvitationSendingService.new(@user).call if @user.persisted?
end
# frozen_string_literal: true
module Users
class RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]

# GET /resource/sign_up
# def new
# super
# end

# POST /resource
def create
super
SlackInvitationSendingService.new(@user).call if @user.persisted?
end

# GET /resource/edit
# def edit
# super
# end

# PUT /resource
# def update
# super
# end

# DELETE /resource
# def destroy
# super
# end

# GET /resource/edit
# def edit
# super
# end

# PUT /resource
# def update
# super
# end

# DELETE /resource
# def destroy
# super
# end

# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end

# protected

# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end

# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end

# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end

# protected

# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end

# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end

# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
end
2 changes: 0 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# frozen_string_literal: true
require "open-uri"

module ApplicationHelper
def full_title(page_title = "")
base_title = "Montreal.rb"
Expand Down
22 changes: 10 additions & 12 deletions app/services/slack_invitation_sending_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class SlackInvitationSendingService
def initialize(user, token = ENV['SLACK_TOKEN'])
def initialize(user, token = ENV["SLACK_TOKEN"])
@user = user
@token = token
end
Expand All @@ -20,7 +20,7 @@ def call
def send_invite
response = JSON.parse Faraday.get(url).body

if response['ok']
if response["ok"]
Rails.logger.info("slack invitation sent to: #{@user.email}".colorize(:green))
@success = true
else
Expand All @@ -31,15 +31,13 @@ def send_invite
end

def url
URI::HTTPS.build({
host: 'slack.com',
path: '/api/users.admin.invite',
query: {
set_active: true,
_attempts: 1,
token: @token,
email: URI.escape(@user.email)
}.to_param
})
URI::HTTPS.build(host: "slack.com",
path: "/api/users.admin.invite",
query: {
set_active: true,
_attempts: 1,
token: @token,
email: URI.escape(@user.email)
}.to_param)
end
end
11 changes: 6 additions & 5 deletions spec/controllers/users/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
require 'rails_helper'
# frozen_string_literal: true
require "rails_helper"

RSpec.describe Users::RegistrationsController do
before do
@request.env['devise.mapping'] = Devise.mappings[:user]
@request.env["devise.mapping"] = Devise.mappings[:user]
end

describe '#create' do
let(:attributes) { { email: 'stranger@things.com', password: 'superseekret' } }
describe "#create" do
let(:attributes) { { email: "stranger@things.com", password: "superseekret" } }
let(:service) { double(:service, call: true) }

before do
allow(SlackInvitationSendingService).to receive(:new).and_return service
end

it 'sends the slack invitation' do
it "sends the slack invitation" do
post :create, user: attributes
expect(service).to have_received(:call)
end
Expand Down
19 changes: 10 additions & 9 deletions spec/services/slack_invitation_sending_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
require 'rails_helper'
# frozen_string_literal: true
require "rails_helper"

RSpec.describe SlackInvitationSendingService do
let(:user) { build :user, email: 'courrier+new@sophiedeziel.com' }
let(:user) { build :user, email: "courrier+new@sophiedeziel.com" }

subject { described_class.new(user) }

describe '#call', skip: ENV['SLACK_TOKEN'].nil? do
it 'is success', record: true do
describe "#call", skip: ENV["SLACK_TOKEN"].nil? do
it "is success", record: true do
expect(subject.call).to be_success
end

it 'logs it', record: true do
it "logs it", record: true do
expect(Rails.logger).to receive(:info)
subject.call
end

context 'when there is an error' do
subject { described_class.new(user, 'sadfasdfsdf') }
context "when there is an error" do
subject { described_class.new(user, "sadfasdfsdf") }

it 'is not success', record: true do
it "is not success", record: true do
expect(subject.call).to_not be_success
end

it 'logs it', record: true do
it "logs it", record: true do
expect(Rails.logger).to receive(:info).twice
subject.call
end
Expand Down

0 comments on commit bbfd1dc

Please sign in to comment.