63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
require "test_helper"
|
|
|
|
class AccountTest < ActiveSupport::TestCase
|
|
test "create" do
|
|
assert_difference "Account::JoinCode.count", +1 do
|
|
Account.create!(name: "ACME corp")
|
|
end
|
|
end
|
|
|
|
test "slug" do
|
|
account = accounts("37s")
|
|
assert_equal "/#{account.external_account_id}", account.slug
|
|
end
|
|
|
|
test ".create_with_admin_user creates a new local account" do
|
|
Current.without_account do
|
|
identity = identities(:david)
|
|
account = nil
|
|
|
|
assert_changes -> { Account.count }, +1 do
|
|
assert_changes -> { User.count }, +2 do
|
|
account = Account.create_with_admin_user(
|
|
account: {
|
|
external_account_id: ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"),
|
|
name: "Account Create With Admin"
|
|
},
|
|
owner: {
|
|
name: "David",
|
|
identity: identity
|
|
}
|
|
)
|
|
end
|
|
end
|
|
|
|
assert_not_nil account
|
|
assert account.persisted?
|
|
assert_equal ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"), account.external_account_id
|
|
assert_equal "Account Create With Admin", account.name
|
|
|
|
admin = account.users.find_by(role: "admin")
|
|
assert_equal "David", admin.name
|
|
assert_equal "david@37signals.com", admin.identity.email_address
|
|
assert_equal "admin", admin.role
|
|
|
|
assert_predicate account.system_user, :present?
|
|
end
|
|
end
|
|
|
|
test "#system_user returns the system user of the account" do
|
|
system_user = User.find_by!(account: accounts("37s"), role: :system)
|
|
|
|
assert_equal system_user, accounts("37s").system_user
|
|
end
|
|
|
|
test "#system_user raises if there is no system user" do
|
|
account = Account.create!(name: "No System User Account")
|
|
|
|
assert_raises ActiveRecord::RecordNotFound do
|
|
account.system_user
|
|
end
|
|
end
|
|
end
|