-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2725 from mkllnk/2699-email-confirm-jobs
2699 email confirm jobs
- Loading branch information
Showing
18 changed files
with
159 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Our error logging API currently wraps Bugsnag. | ||
# It makes us more flexible if we wanted to replace Bugsnag or change logging | ||
# behaviour. | ||
module OpenFoodNetwork | ||
module ErrorLogger | ||
# Tries to escalate the error to a developer. | ||
# If Bugsnag is configured, it will notify it. It would be nice to implement | ||
# some kind of fallback. | ||
def self.notify(error) | ||
Bugsnag.notify(error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,14 @@ module Admin | |
|
||
context "signing up a new user" do | ||
before do | ||
create(:mail_method) | ||
controller.stub spree_current_user: admin | ||
end | ||
|
||
it "creates a new user, sends an invitation email, and returns the user id" do | ||
expect do | ||
spree_post :create, {email: '[email protected]', enterprise_id: enterprise.id} | ||
end.to enqueue_job Delayed::PerformableMethod | ||
end.to send_confirmation_instructions | ||
|
||
new_user = Spree::User.find_by_email('[email protected]') | ||
|
||
|
@@ -45,6 +46,7 @@ module Admin | |
describe "with enterprise permissions" do | ||
context "as user with proper enterprise permissions" do | ||
before do | ||
create(:mail_method) | ||
controller.stub spree_current_user: enterprise_owner | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,66 @@ | |
|
||
describe UserRegistrationsController, type: :controller do | ||
|
||
before(:all) do | ||
create(:mail_method) | ||
end | ||
|
||
before do | ||
@request.env["devise.mapping"] = Devise.mappings[:spree_user] | ||
end | ||
|
||
describe "via ajax" do | ||
render_views | ||
it "returns errors when registration fails" do | ||
|
||
let(:user_params) do | ||
{ | ||
email: "[email protected]", | ||
password: "testy123", | ||
password_confirmation: "testy123" | ||
} | ||
end | ||
|
||
it "returns validation errors" do | ||
xhr :post, :create, spree_user: {}, :use_route => :spree | ||
response.status.should == 401 | ||
expect(response.status).to eq(401) | ||
json = JSON.parse(response.body) | ||
expect(json).to eq({"email" => ["can't be blank"], "password" => ["can't be blank"]}) | ||
end | ||
|
||
it "returns error when emailing fails" do | ||
allow(Spree::UserMailer).to receive(:confirmation_instructions).and_raise("Some error") | ||
expect(OpenFoodNetwork::ErrorLogger).to receive(:notify) | ||
|
||
xhr :post, :create, spree_user: user_params, use_route: :spree | ||
|
||
expect(response.status).to eq(401) | ||
json = JSON.parse(response.body) | ||
json.should == {"email" => ["can't be blank"], "password" => ["can't be blank"]} | ||
expect(json).to eq({"message" => I18n.t('devise.user_registrations.spree_user.unknown_error')}) | ||
end | ||
|
||
it "returns 200 when registration succeeds" do | ||
xhr :post, :create, spree_user: {email: "[email protected]", password: "testy123", password_confirmation: "testy123"}, :use_route => :spree | ||
response.status.should == 200 | ||
xhr :post, :create, spree_user: user_params, use_route: :spree | ||
expect(response.status).to eq(200) | ||
json = JSON.parse(response.body) | ||
json.should == {"email" => "[email protected]"} | ||
expect(json).to eq({"email" => "[email protected]"}) | ||
expect(controller.spree_current_user).to be_nil | ||
end | ||
end | ||
|
||
context "when registration fails" do | ||
it "renders new" do | ||
spree_post :create, spree_user: {} | ||
response.status.should == 200 | ||
response.should render_template "spree/user_registrations/new" | ||
expect(response.status).to eq(200) | ||
expect(response).to render_template "spree/user_registrations/new" | ||
end | ||
end | ||
|
||
context "when registration succeeds" do | ||
context "when referer is not '/checkout'" do | ||
it "redirects to root" do | ||
spree_post :create, spree_user: {email: "[email protected]", password: "testy123", password_confirmation: "testy123"}, :use_route => :spree | ||
response.should redirect_to root_path | ||
assigns[:user].email.should == "[email protected]" | ||
expect(response).to redirect_to root_path | ||
expect(assigns[:user].email).to eq("[email protected]") | ||
end | ||
end | ||
|
||
|
@@ -47,8 +71,8 @@ | |
|
||
it "redirects to checkout" do | ||
spree_post :create, spree_user: {email: "[email protected]", password: "testy123", password_confirmation: "testy123"}, :use_route => :spree | ||
response.should redirect_to checkout_path | ||
assigns[:user].email.should == "[email protected]" | ||
expect(response).to redirect_to checkout_path | ||
expect(assigns[:user].email).to eq("[email protected]") | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
let(:user) { create(:user, email: '[email protected]') } | ||
|
||
before do | ||
create(:mail_method) | ||
quick_login_as user | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,16 +75,15 @@ | |
end | ||
|
||
scenario "Signing up successfully" do | ||
create(:mail_method) | ||
fill_in "Email", with: "[email protected]" | ||
fill_in "Choose a password", with: "test12345" | ||
fill_in "Confirm password", with: "test12345" | ||
|
||
expect do | ||
click_signup_button | ||
expect(page).to have_content I18n.t('devise.user_registrations.spree_user.signed_up_but_unconfirmed') | ||
end.to enqueue_job Delayed::PerformableMethod | ||
|
||
expect(Delayed::Job.last.payload_object.method_name).to eq(:send_on_create_confirmation_instructions_without_delay) | ||
end.to send_confirmation_instructions | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'spec_helper' | ||
require 'open_food_network/error_logger' | ||
|
||
module OpenFoodNetwork | ||
describe ErrorLogger do | ||
let(:error) { StandardError.new("Test") } | ||
|
||
it "notifies Bugsnag" do | ||
expect(Bugsnag).to receive(:notify).with(error) | ||
|
||
ErrorLogger.notify(error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.