Skip to content

Commit

Permalink
Remove default values from foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
marlena-b committed Oct 23, 2023
1 parent c6def53 commit db490b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/controllers/organizations/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Organizations::InvitationsController < Devise::InvitationsController
include OrganizationScopable
# TODO: remove next line once we fix links in the invitation emails
skip_before_action :set_tenant, except: [:new, :create]
before_action :require_organization_admin, only: [:new, :create]
layout "dashboard", only: [:new, :create]

Expand Down
2 changes: 1 addition & 1 deletion app/models/adopter_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint default(0), not null
# user_id :bigint not null
#
# Indexes
#
Expand Down
5 changes: 3 additions & 2 deletions app/models/staff_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Table name: staff_accounts
#
# id :bigint not null, primary key
# deactivated_at :datetime
# verified :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# organization_id :bigint default(1), not null
# user_id :bigint default(0), not null
# organization_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20231023113924_remove_default_values.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveDefaultValues < ActiveRecord::Migration[7.0]
def change
change_column_default(:adopter_accounts, :user_id, nil)
change_column_default(:staff_accounts, :organization_id, nil)
change_column_default(:staff_accounts, :user_id, nil)
end
end
8 changes: 4 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions test/integration/organizations/invite_staff_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Organizations::InviteStaffTest < ActionDispatch::IntegrationTest
end

test "staff admin can invite other staffs to the organization" do
sign_in create(:user, :staff_admin)
admin = create(:user, :staff_admin)
sign_in admin
set_organization(admin.organization)

post(
user_invitation_path,
Expand All @@ -32,7 +34,9 @@ class Organizations::InviteStaffTest < ActionDispatch::IntegrationTest
end

test "staff admin can not invite existing user to the organization" do
sign_in create(:user, :staff_admin)
admin = create(:user, :staff_admin)
sign_in admin
set_organization(admin.organization)
_existing_user = create(:user, email: "[email protected]")

post(
Expand Down

0 comments on commit db490b3

Please sign in to comment.