-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed field name, modified the User model, added unit tests.
- Loading branch information
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class User < ActiveRecord::Base | ||
def can?(action, page) | ||
UserPagePermission.count(:conditions => ['user_id = ? AND page_id = ? AND action = ?', self.id, page.id, action.to_s]) > 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe User, 'permissions' do | ||
before(:each) do | ||
User.delete_observers | ||
@user = User.create! | ||
@page = Page.create!(:title => 'sample_title', :slug => 'sample_title', :breadcrumb => '...', :status => Status.find(1)) | ||
@user_page_permission = UserPagePermission.create!(:user_id => @user.id, :page_id => @page.id, :action => 'create') | ||
end | ||
|
||
it "should allow the user to create a page under the given page by a given user" do | ||
@user.can?(:create, @page).should be_true | ||
@user.can?(:destroy, @page).should be_false | ||
end | ||
end |