Skip to content

Commit

Permalink
don't error on the comm prefs page; refs #6914
Browse files Browse the repository at this point in the history
When a user's immediate messages start getting throttled (like when they've
received 50 in a day), we create a NotificationPolicy for that user with no
Notification. That's not an ideal design, but rather than fix that now, we're
just going to make sure those policies don't cause errors

test plan:
 * See specs.

Change-Id: Ib262b256a9d4fe5fe7fd882d6848883e7a40cb59
Reviewed-on: https://gerrit.instructure.com/8096
Reviewed-by: Cody Cutrer <[email protected]>
Tested-by: Hudson <[email protected]>
  • Loading branch information
zwily authored and codekitchen committed Jan 16, 2012
1 parent d3e6c6b commit 867c8db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/profile_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def communication
@active_tab = "communication-preferences"

# build placeholder notification policies for categories the user does not have policies for already
user_categories = @user.notification_policies.map {|np| np.notification.category }
# Note that currently a NotificationPolicy might not have a Notification attached to it.
# See the relevant spec in profile_controller_spec.rb for more details.
user_categories = @user.notification_policies.map {|np| np.notification.try(:category) }
@notification_categories.each do |category|
# category is actually a Notification
next if user_categories.include?(category.category)
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/profile_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@
@cc.reload.position.should == 2
end
end

describe "GET 'communication'" do
it "should not fail when a user has a notification policy with no notification" do
# A user might have a NotificationPolicy with no Notification if the policy was created
# as part of throttling a user's "immediate" messages. Eventually we should fix how that
# works, but for now we just make sure that that state does not cause an error for the
# user when they go to their notification preferences.
user_model
user_session(@user)
cc = @user.communication_channels.create!(:path => '[email protected]', :path_type => 'email') { |cc| cc.workflow_state = 'active' }
@user.notification_policies.create!(:notification => nil, :communication_channel => cc, :frequency => 'daily')

get 'communication'
response.should be_success
end
end
end

0 comments on commit 867c8db

Please sign in to comment.