mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Fix tests
This commit is contained in:
parent
8389cd85a3
commit
f898f3aab0
9 changed files with 61 additions and 32 deletions
1
app/assets/svg/icons/lucide/outline/chevron-left.svg
Normal file
1
app/assets/svg/icons/lucide/outline/chevron-left.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-left-icon lucide-chevron-left"><path d="m15 18-6-6 6-6"/></svg>
|
||||||
|
After Width: | Height: | Size: 274 B |
1
app/assets/svg/icons/lucide/outline/chevron-right.svg
Normal file
1
app/assets/svg/icons/lucide/outline/chevron-right.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right-icon lucide-chevron-right"><path d="m9 18 6-6-6-6"/></svg>
|
||||||
|
After Width: | Height: | Size: 275 B |
|
|
@ -78,17 +78,19 @@ class FamilyInvitationsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
authorize @family, :manage_invitations?
|
authorize @family, :manage_invitations?
|
||||||
|
|
||||||
if @invitation.update(status: :cancelled)
|
begin
|
||||||
|
if @invitation.update(status: :cancelled)
|
||||||
|
redirect_to family_path(@family),
|
||||||
|
notice: 'Invitation cancelled'
|
||||||
|
else
|
||||||
|
redirect_to family_path(@family),
|
||||||
|
alert: 'Failed to cancel invitation. Please try again'
|
||||||
|
end
|
||||||
|
rescue StandardError => e
|
||||||
|
Rails.logger.error "Error cancelling family invitation: #{e.message}"
|
||||||
redirect_to family_path(@family),
|
redirect_to family_path(@family),
|
||||||
notice: 'Invitation cancelled'
|
alert: 'An unexpected error occurred while cancelling the invitation'
|
||||||
else
|
|
||||||
redirect_to family_path(@family),
|
|
||||||
alert: 'Failed to cancel invitation. Please try again'
|
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
|
||||||
Rails.logger.error "Error cancelling family invitation: #{e.message}"
|
|
||||||
redirect_to family_path(@family),
|
|
||||||
alert: 'An unexpected error occurred while cancelling the invitation'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,14 @@ module Families
|
||||||
def call
|
def call
|
||||||
return false unless validate_can_leave
|
return false unless validate_can_leave
|
||||||
|
|
||||||
|
# Store family info before removing membership
|
||||||
|
@family_name = user.family.name
|
||||||
|
@family_owner = user.family.owner
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
handle_ownership_transfer if user.family_owner?
|
handle_ownership_transfer if user.family_owner?
|
||||||
remove_membership
|
remove_membership
|
||||||
send_notification
|
send_notifications
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
@ -68,18 +72,26 @@ module Families
|
||||||
user.family_membership.destroy!
|
user.family_membership.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_notification
|
def send_notifications
|
||||||
return unless defined?(Notification)
|
return unless defined?(Notification)
|
||||||
|
|
||||||
|
# Notify the user who left
|
||||||
Notification.create!(
|
Notification.create!(
|
||||||
user: user,
|
user: user,
|
||||||
kind: :info,
|
kind: :info,
|
||||||
title: 'Left Family',
|
title: 'Left Family',
|
||||||
content: "You've left the family"
|
content: "You've left the family \"#{@family_name}\""
|
||||||
|
)
|
||||||
|
|
||||||
|
# Notify the family owner
|
||||||
|
return unless @family_owner&.persisted?
|
||||||
|
|
||||||
|
Notification.create!(
|
||||||
|
user: @family_owner,
|
||||||
|
kind: :info,
|
||||||
|
title: 'Family Member Left',
|
||||||
|
content: "#{user.email} has left the family \"#{@family_name}\""
|
||||||
)
|
)
|
||||||
rescue StandardError => e
|
|
||||||
# Don't fail the entire operation if notification fails
|
|
||||||
Rails.logger.warn "Failed to send family leave notification: #{e.message}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_record_invalid_error(error)
|
def handle_record_invalid_error(error)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
method: :delete,
|
method: :delete,
|
||||||
data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' },
|
data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' },
|
||||||
class: "btn btn-outline btn-error" do %>
|
class: "btn btn-outline btn-error" do %>
|
||||||
<%= icon 'trash-2', class: "inline-block w-4 h-4 mr-2 -mt-1" %>
|
<%= icon 'trash-2', class: "inline-block w-4" %>
|
||||||
Delete Family
|
Delete Family
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@
|
||||||
<% if policy(@family).update? %>
|
<% if policy(@family).update? %>
|
||||||
<%= link_to edit_family_path(@family),
|
<%= link_to edit_family_path(@family),
|
||||||
class: "btn btn-outline btn-info" do %>
|
class: "btn btn-outline btn-info" do %>
|
||||||
<%= icon 'square-pen', class: "inline-block w-4 h-4 mr-2 -mt-1" %>
|
<%= icon 'square-pen', class: "inline-block w-4" %><%= t('families.show.edit', default: 'Edit') %>
|
||||||
<%= t('families.show.edit', default: 'Edit') %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@
|
||||||
method: :delete,
|
method: :delete,
|
||||||
data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' },
|
data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' },
|
||||||
class: "btn btn-outline btn-error" do %>
|
class: "btn btn-outline btn-error" do %>
|
||||||
<%= icon 'trash-2', class: "inline-block w-4 h-4 mr-2 -mt-1" %>
|
<%= icon 'trash-2', class: "inline-block w-4" %>
|
||||||
Delete
|
Delete
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<span class="tooltip" data-tip="<%= human_date(@start_at - 1.day) %>">
|
<span class="tooltip" data-tip="<%= human_date(@start_at - 1.day) %>">
|
||||||
<%= link_to map_path(start_at: @start_at - 1.day, end_at: @end_at - 1.day, import_id: params[:import_id]), class: "btn border border-base-300 hover:btn-ghost w-full" do %>
|
<%= link_to map_path(start_at: @start_at - 1.day, end_at: @end_at - 1.day, import_id: params[:import_id]), class: "btn border border-base-300 hover:btn-ghost w-full" do %>
|
||||||
◀️
|
<%= icon 'chevron-left' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<span class="tooltip" data-tip="<%= human_date(@start_at + 1.day) %>">
|
<span class="tooltip" data-tip="<%= human_date(@start_at + 1.day) %>">
|
||||||
<%= link_to map_path(start_at: @start_at + 1.day, end_at: @end_at + 1.day, import_id: params[:import_id]), class: "btn border border-base-300 hover:btn-ghost w-full" do %>
|
<%= link_to map_path(start_at: @start_at + 1.day, end_at: @end_at + 1.day, import_id: params[:import_id]), class: "btn border border-base-300 hover:btn-ghost w-full" do %>
|
||||||
▶️
|
<%= icon 'chevron-right' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,21 @@ RSpec.describe 'Users', type: :request do
|
||||||
describe 'GET /users/sign_up' do
|
describe 'GET /users/sign_up' do
|
||||||
context 'when self-hosted' do
|
context 'when self-hosted' do
|
||||||
before do
|
before do
|
||||||
stub_const('SELF_HOSTED', true)
|
allow(ENV).to receive(:[]).and_call_original
|
||||||
|
allow(ENV).to receive(:[]).with('SELF_HOSTED').and_return('true')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'redirects to root path' do
|
||||||
get '/users/sign_up'
|
get '/users/sign_up'
|
||||||
expect(response).to have_http_status(:not_found)
|
expect(response).to redirect_to(root_path)
|
||||||
|
expect(flash[:alert]).to include('Registration is not available')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not self-hosted' do
|
context 'when not self-hosted' do
|
||||||
before do
|
before do
|
||||||
stub_const('SELF_HOSTED', false)
|
allow(ENV).to receive(:[]).and_call_original
|
||||||
Rails.application.reload_routes!
|
allow(ENV).to receive(:[]).with('SELF_HOSTED').and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,32 @@ RSpec.describe Families::Leave do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
context 'when user is a member (not owner)' do
|
context 'when user is a member (not owner)' do
|
||||||
let(:member) { create(:user) }
|
let(:member) { create(:user) }
|
||||||
let!(:membership) { create(:family_membership, user: member, family: family, role: :member) }
|
let!(:owner_membership) { create(:family_membership, user: user, family: family, role: :owner) }
|
||||||
|
let!(:member_membership) { create(:family_membership, user: member, family: family, role: :member) }
|
||||||
let(:service) { described_class.new(user: member) }
|
let(:service) { described_class.new(user: member) }
|
||||||
|
|
||||||
it 'removes the membership' do
|
it 'removes the membership' do
|
||||||
expect { service.call }.to change(FamilyMembership, :count).by(-1)
|
result = service.call
|
||||||
|
expect(result).to be_truthy, "Expected service to succeed but got error: #{service.error_message}"
|
||||||
|
expect(FamilyMembership.count).to eq(1) # Only owner should remain
|
||||||
expect(member.reload.family_membership).to be_nil
|
expect(member.reload.family_membership).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends notification' do
|
it 'sends notification to member who left' do
|
||||||
expect { service.call }.to change(Notification, :count).by(1)
|
expect { service.call }.to change(Notification, :count).by(2)
|
||||||
|
|
||||||
notification = member.notifications.last
|
member_notification = member.notifications.last
|
||||||
|
expect(member_notification.title).to eq('Left Family')
|
||||||
|
expect(member_notification.content).to include(family.name)
|
||||||
|
end
|
||||||
|
|
||||||
expect(notification.title).to eq('Left Family')
|
it 'sends notification to family owner' do
|
||||||
|
service.call
|
||||||
|
|
||||||
|
owner_notification = user.notifications.last
|
||||||
|
expect(owner_notification.title).to eq('Family Member Left')
|
||||||
|
expect(owner_notification.content).to include(member.email)
|
||||||
|
expect(owner_notification.content).to include(family.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue