Move user db creation to service
This commit is contained in:
@@ -53,8 +53,11 @@ RSpec.describe "Signup", type: :feature do
|
||||
expect(page).to have_content("Choose a password")
|
||||
|
||||
expect(CreateAccount).to receive(:call)
|
||||
.with(username: "tony", email: "tony@example.com", password: "a-valid-password")
|
||||
.and_return(true)
|
||||
.with(
|
||||
username: "tony", domain: "kosmos.org",
|
||||
email: "tony@example.com", password: "a-valid-password",
|
||||
invitation: Invitation.last
|
||||
).and_return(true)
|
||||
|
||||
fill_in "user_password", with: "a-valid-password"
|
||||
click_button "Create account"
|
||||
@@ -62,7 +65,6 @@ RSpec.describe "Signup", type: :feature do
|
||||
expect(page).to have_content("confirm your address")
|
||||
end
|
||||
expect(page).to have_content("close this window or tab now")
|
||||
expect(User.last.confirmed_at).to be_nil
|
||||
end
|
||||
|
||||
scenario "Validation errors" do
|
||||
@@ -89,15 +91,17 @@ RSpec.describe "Signup", type: :feature do
|
||||
expect(page).to have_content("Password is too short")
|
||||
|
||||
expect(CreateAccount).to receive(:call)
|
||||
.with(username: "tony", email: "tony@example.com", password: "a-valid-password")
|
||||
.and_return(true)
|
||||
.with(
|
||||
username: "tony", domain: "kosmos.org",
|
||||
email: "tony@example.com", password: "a-valid-password",
|
||||
invitation: Invitation.last
|
||||
).and_return(true)
|
||||
|
||||
fill_in "user_password", with: "a-valid-password"
|
||||
click_button "Create account"
|
||||
within ".flash-msg.notice" do
|
||||
expect(page).to have_content("confirm your address")
|
||||
end
|
||||
expect(User.last.cn).to eq("tony")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,22 @@ RSpec.describe CreateAccount, type: :model do
|
||||
allow(service).to receive(:ldap_client).and_return(ldap_client_mock)
|
||||
end
|
||||
|
||||
describe "#create_user_in_database" do
|
||||
let(:service) { CreateAccount.new(
|
||||
username: 'isaacnewton',
|
||||
email: 'isaacnewton@example.com',
|
||||
password: 'bright-ideas-in-autumn'
|
||||
)}
|
||||
|
||||
it "creates a new user record in the akkounts database" do
|
||||
expect(User.count).to eq(0)
|
||||
service.send(:create_user_in_database)
|
||||
expect(User.count).to eq(1)
|
||||
expect(User.last.cn).to eq("isaacnewton")
|
||||
expect(User.last.email).to eq("isaacnewton@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_ldap_document" do
|
||||
let(:service) { CreateAccount.new(
|
||||
username: 'halfinney',
|
||||
|
||||
Reference in New Issue
Block a user