Skip to content

Commit

Permalink
Merge pull request #45 from rhokbrisbane/more_abilities
Browse files Browse the repository at this point in the history
More abilities
  • Loading branch information
Rowan committed Dec 8, 2013
2 parents 6d3dd86 + 76892b1 commit 75b9921
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user!
before_filter :fetch_tags_by_category

before_filter do
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end

private

def fetch_tags_by_category
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CommentsController < ApplicationController
before_action :set_comment, only: [:show, :edit, :update, :destroy]
load_and_authorize_resource

def create
@comment = current_user.comments.new(comment_params)
Expand All @@ -21,10 +21,6 @@ def destroy

private

def set_comment
@comment = current_user.comments.find(params[:id])
end

def comment_params
params.require(:comment).permit(:content, :commentable_id, :commentable_type)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(user)
can :read, Address
can :read, Tag
can :read, Tagging
can :read, Comment

can :read, Note do |note|
note.group_shares.where(shared_group_id: user.group_ids).any? ||
Expand Down Expand Up @@ -48,6 +49,7 @@ def initialize(user)
can :manage, Tagging, user_id: user.id
can :manage, Address, user_id: user.id
can :manage, SavedSearch, user_id: user.id
can :manage, Comment, user_id: user.id
can :manage, Kid do |kid|
kid.guardianships.where(user_id: user.id).any?
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@
it "should be_able_to(:create, Kid)" do
should be_able_to(:create, Kid)
end

it "should be_able_to(:create, SavedSearch)" do
should be_able_to(:create, SavedSearch)
end

it "should be_able_to(:create, Comment)" do
should be_able_to(:create, Comment)
end
end
end
end
Expand Down

0 comments on commit 75b9921

Please sign in to comment.