Skip to content

Instantly share code, notes, and snippets.

@paulca
Created October 22, 2008 15:57
Show Gist options
  • Save paulca/18674 to your computer and use it in GitHub Desktop.
Save paulca/18674 to your computer and use it in GitHub Desktop.
describe Task, "notifications" do
before(:each) do
@company = mock_model(Company)
@first_user = mock_model(User, :login => 'first', :sms_for? => true, :company => @company )
@second_user = mock_model(User, :login => 'second', :sms_for? => true, :company => @company)
@third_user = mock_model(User, :login => 'third', :sms_for? => true, :company => @company)
@company.stub!(:users).and_return([@first_user, @second_user, @third_user])
@company.stub!(:users_who_are_not).and_return([@second_user, @third_user])
@first_user.stub!(:tasks_for).and_return([])
@task = Task.create(:created_by => @first_user, :description => 'do the dishes', :due_at => Date.today, :user => @first_user)
end
it "should notify the first user when the task is updated by someone else" do
@task.update_attributes(:updated_by => @second_user, :due_at => Date.today.tomorrow)
@task.notifications.first.user_id.should == @first_user.id
@task.notifications.size.should == 4
@task.notifications.collect { |n| n.service }.should == ['sms', 'email', 'sms', 'email']
@task.notifications.first.notification_type.should == :changed
end
it "should notify the team when the task is updated by the first user" do
@task.update_attributes(:updated_by => @first_user, :due_at => Date.today.tomorrow)
@task.notifications.collect { |n| [n.user.login, n.service] }.should == [['second', 'sms'], ['second', 'email'], ['third', 'sms'], ['third', 'email']]
end
it "should notify the team when the first user completes their task" do
@task.update_attributes(:updated_by => @first_user, :done => true)
@task.notifications.collect { |n| [n.user.login, n.service] }.should == [['second', 'sms'], ['second', 'email'], ['third', 'sms'], ['third', 'email']]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment