diff --git a/app/views/users/_org_member.html.erb b/app/views/users/_org_member.html.erb index 72470063e..2ba781b24 100644 --- a/app/views/users/_org_member.html.erb +++ b/app/views/users/_org_member.html.erb @@ -7,7 +7,7 @@ <% end %>

Danger zone

-<%= form_tag "/users/leave_org", onsubmit: "return confirm('Are you sure you want to leave this organization?');" do %> +<%= form_tag users_leave_org_path(@organization), onsubmit: "return confirm('Are you sure you want to leave this organization?');" do %>
<%= submit_tag "Leave Organization", class: "danger-button" %>
diff --git a/config/routes.rb b/config/routes.rb index bb8bb0023..f7e407a17 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -245,7 +245,7 @@ Rails.application.routes.draw do post "users/update_language_settings" => "users#update_language_settings" post "users/update_twitch_username" => "users#update_twitch_username" post "users/join_org" => "users#join_org" - post "users/leave_org/:organization_id" => "users#leave_org" + post "users/leave_org/:organization_id" => "users#leave_org", as: :users_leave_org post "users/add_org_admin" => "users#add_org_admin" post "users/remove_org_admin" => "users#remove_org_admin" post "users/remove_from_org" => "users#remove_from_org" diff --git a/spec/system/organization/user_leaves_an_organization_spec.rb b/spec/system/organization/user_leaves_an_organization_spec.rb new file mode 100644 index 000000000..be908602e --- /dev/null +++ b/spec/system/organization/user_leaves_an_organization_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +RSpec.describe "User leaves an organization", type: :system do + let!(:org_user) { create(:user, :org_member) } + let(:organization) { org_user.organizations.first } + + before do + sign_in org_user + visit "/settings/organization/#{organization.id}" + end + + context "when user visits member organization settings" do + it "shows the leave oranization button" do + expect(page).to have_button("Leave Organization") + end + end + + context "when user leaves member organization" do + it "leaves organization and shows confirmation" do + click_button("Leave Organization") + expect(page).to have_content("You have left your organization.") + end + end +end