Skip to content

Commit

Permalink
Make unsubscribed calendars show properly for users without any subsc…
Browse files Browse the repository at this point in the history
…riptions [#12].
  • Loading branch information
marnen committed Dec 29, 2008
1 parent 69c79ee commit e456939
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/permissions_controller.rb
Expand Up @@ -10,7 +10,11 @@ class PermissionsController < ApplicationController
response_for :index do
@page_title = _('Subscriptions')
@permissions = User.current_user.permissions.find(:all, :include => [:calendar, :role])
@unsubscribed = Calendar.find(:all, :conditions => ['id NOT IN (:permissions)', {:permissions => @permissions.collect{|p| p.calendar.id}}])
if @permissions.empty?
@unsubscribed = Calendar.find(:all)
else
@unsubscribed = Calendar.find(:all, :conditions => ['id NOT IN (:permissions)', {:permissions => @permissions.collect{|p| p.calendar.id}}])
end
end

response_for :update do
Expand Down
22 changes: 22 additions & 0 deletions spec/controllers/permissions_controller_spec.rb
Expand Up @@ -84,6 +84,28 @@
end
end
end

describe PermissionsController, 'index (no subscribed calendars)' do
integrate_views

before(:each) do
controller.stub!(:login_required).and_return(true)
end

it 'should show all available calendars under "unsubscribed"' do
@blank = []
@blank.should_receive(:find).and_return([])
@current_user = mock_model(User, :id => 20, :email => 'no_permissions@gmail.com', :admin? => false)
@current_user.should_receive(:permissions).and_return(@blank)
@calendars = [mock_model(Calendar, :id => 1), mock_model(Calendar, :id => 2)]
Calendar.should_receive(:find).with(:all).and_return(@calendars)
User.stub!(:current_user).and_return(@current_user)
get :index
assigns[:permissions].should == @blank

response.should have_tag('table.unsubscribed')
end
end

describe PermissionsController, 'index (no unsubscribed calendars)' do
it 'should not show the list of unsubscribed calendars if there are none' do
Expand Down

0 comments on commit e456939

Please sign in to comment.