Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def create
@user.updated_by = current_user

if @user.save
# @user.notifications.create(notification_type: 0)
redirect_to @user, notice: "User was successfully created."
else
set_form_variables
Expand Down
7 changes: 1 addition & 6 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Report < ApplicationRecord
belongs_to :workshop
has_one :form, as: :owner
has_many :bookmarks, as: :bookmarkable, dependent: :destroy
has_many :notifications, as: :noticeable, dependent: :destroy
has_many :notifications, as: :noticeable, dependent: :destroy, autosave: false
has_many :quotable_item_quotes, as: :quotable, dependent: :nullify, inverse_of: :quotable
has_many :report_form_field_answers,
foreign_key: :report_id, inverse_of: :report,
Expand Down Expand Up @@ -51,7 +51,6 @@ class Report < ApplicationRecord

before_save :set_has_attachment # TODO verify set_has_attachment works as expected once this feature is enabled in the UI
after_create :set_windows_type
after_save :create_notification

# Scopes
scope :in_month, ->(date) { where(created_at: date.beginning_of_month..date.end_of_month) }
Expand Down Expand Up @@ -174,8 +173,4 @@ def set_windows_type
return unless organization && windows_type.nil?
update(windows_type_id: organization.windows_type.id)
end

def create_notification
notifications.create(notification_type: 0)
end
end
23 changes: 20 additions & 3 deletions spec/models/workshop_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,25 @@
end
end

# Add tests for specific methods like #num_ongoing, #num_first_time, callbacks
describe 'callbacks' do
# Test after_save :update_workshop_log_count
describe 'updating does not fail due to notifications' do
it 'saves successfully even when associated notifications exist' do
workshop_log = create(:workshop_log)
create(:notification,
noticeable: workshop_log,
kind: :workshop_log_submitted_fyi,
recipient_role: :admin,
recipient_email: "test@example.com",
notification_type: 0)

workshop_log.reload
workshop_log.children_ongoing = 5
expect(workshop_log.save).to be true
end

it 'does not create a notification on save' do
workshop_log = create(:workshop_log)
expect { workshop_log.update!(children_ongoing: 3) }
.not_to change { Notification.count }
end
end
end