Created
July 27, 2020 22:06
-
-
Save staycreativedesign/ad5622cb29152805742aadc538d2daf7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
RSpec.describe "Account", :type => :system do | |
it "creates an account" do | |
name = Faker::Name.name | |
email = Faker::Internet.email | |
password = Faker::Alphanumeric.alphanumeric(number: 10) | |
visit sign_up_path | |
within("#new_account") do | |
fill_in 'Organization Name:', with: 'Pdg Creative' | |
fill_in 'Your Name:', with: name | |
fill_in 'Email:', with: email | |
fill_in 'Subdomain:', with: 'loremipsum' | |
fill_in 'Password:', with: password | |
fill_in 'Password Confirmation:', with: password | |
click_button 'Submit' | |
end | |
#macros.rb | |
login(email, password) | |
expect(page).to have_content('Organizations') | |
expect(Organization.count).to eq(1) | |
end | |
end | |
# Failure/Error: expect(Organization.count).to eq(1) | |
# | |
# expected: 1 | |
# got: 0 | |
# it logs in correctly and the organiation is there but why cant I check for t? | |
This file contains hidden or 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
def new | |
@account = Account.new | |
@account.organizations.build(account_id: @account.id) | |
owner = @account.build_owner() | |
end | |
def create | |
@account = Account.new(account_params) | |
if @account.valid? | |
subdomain = @account.subdomain | |
Apartment::Tenant.create(@account.subdomain) | |
Apartment::Tenant.switch!(@account.subdomain) | |
@account.save | |
org = @account.organizations.first | |
org.users << @account.owner | |
client = org.clients.create(name: org.name) | |
session[:current_user_id] = @account.owner.id | |
cookies.signed[:current_user_id] = @account.owner.id | |
@current_user = @account.owner | |
current_user.update(organization_id: org.id, client_id: client.id) | |
redirect_to organization_client_url( | |
subdomain: subdomain, | |
organization_id: org.slug, | |
id: client.slug | |
) | |
#send email to staff and account created | |
else | |
render :new | |
flash[:danger] = @account.errors.full_messages | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment