Browse files

Broke some tests.

  • Loading branch information...
1 parent 83b4cb8 commit 7e6cb6f877dc1702afcb7ec3ba555feb9edb557c @jasiek committed Jan 6, 2011
Showing with 46 additions and 8 deletions.
  1. +44 −8 spec/models/page_spec.rb
  2. +2 −0 user_pages_extension.rb
View
52 spec/models/page_spec.rb
@@ -7,16 +7,23 @@ def random_string
describe Page do
before :all do
@user = User.create!
- @page = Page.create!(:title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
+ @page_with_permission = Page.create!(:title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
+ @page_without_permission = Page.create(:title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
end
describe 'creation' do
before :each do
- @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page, :action => 'create')
+ @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page_with_permission, :action => 'create')
end
it "should allow the user to create a new page" do
- Page.create!(:parent => @page, :title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
+ Page.create!(:parent => @page_with_permission, :title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
+ end
+
+ it "should prevent the user from creating a new page" do
+ lambda do
+ Page.create!(:parent => @page_without_permission, :title => random_string(), :slug => random_string(), :breadcrumb => random_string(), :status => Status.find(1))
+ end.should raise_exception(UserPagesExtension::AccessDenied)
end
after :each do
@@ -26,11 +33,17 @@ def random_string
describe 'removal' do
before :each do
- @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page, :action => 'destroy')
+ @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page_with_permission, :action => 'destroy')
end
it "should allow the user to destroy the page" do
- @page.destroy
+ @page_with_permission.destroy
+ end
+
+ it "should prevent the user from destroying the page" do
+ lambda do
+ @page_without_permission.destroy
+ end.should raise_exception(UserPagesExtension::AccessDenied)
end
after :each do
@@ -40,12 +53,35 @@ def random_string
describe 'modification' do
before :each do
- @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page, :action => 'update')
+ @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page_with_permission, :action => 'update')
end
it "should allow the user to edit the page" do
- @page.title = 'hello'
- @page.save!
+ @page_with_permission.title = 'hello'
+ @page_with_permission.save!
+ end
+
+ it "should prevent the user from editing the page" do
+ lambda do
+ @page_without_permission.title = 'hello'
+ @page_without_permission.save!
+ end.should raise_exception(UserPagesExtension::AccessDenied)
+ end
+
+ after :each do
+ @user_page_permission.destroy
+ end
+ end
+
+ describe 'permission modification' do
+ before :each do
+ @user_page_permission = UserPagePermission.create!(:user_id => @user, :page_id => @page_with_permission, :action => 'permissions')
+ end
+
+ it "should allow the user to change permissions" do
+ end
+
+ it "should prevent the user from changing permissions" do
end
after :each do
View
2 user_pages_extension.rb
@@ -20,4 +20,6 @@ def activate
# add_item "User Pages", "/admin/user_pages", :after => "Pages"
# end
end
+
+ class AccessDenied < StandardError; end
end

0 comments on commit 7e6cb6f

Please sign in to comment.