Skip to content

Commit

Permalink
Added beginnings of cancan authorization to Contents controller
Browse files Browse the repository at this point in the history
  • Loading branch information
August committed Apr 23, 2012
1 parent 22957ce commit 3a22dfb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/controllers/contents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
class ContentsController < ApplicationController
before_filter :get_content_const, :only => [:new, :create]
before_filter { |controller| check_permissions(controller.action_name) }

#takes the action name being run as an argument an runs cancan's authorization routine
#TODO: Account for index and show actions - may need more definited Abilities
def check_permissions(action_name)
if action_name == "new" || action_name == "create"
authorize! :create, Content
elsif action_name == "edit" || action_name == "destroy" || action_name == "update"
authorize! [:update, :delete], Content
end
end

# Grab the constent object for the type of
# content we're working with. Probably needs
Expand Down
6 changes: 5 additions & 1 deletion test/functional/contents_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ def setup
end

test "should get generic new" do
sign_in users(:katie)
get :new
assert_response :success
end

test "should get new graphic" do
sign_in users(:katie)
get(:new, {:type => "graphic"})
assert_response :success
assert_select(HTML::Selector.new "input[type=file]")
end

test "should get new ticker" do
sign_in users(:katie)
get(:new, {:type => "ticker"})
assert_response :success
assert_select("textarea")
Expand All @@ -30,6 +33,7 @@ def setup
end

test "should demoderate submissions on edit" do
sign_in users(:admin)
put :update, :id => contents(:sample_ticker).id, :duration => "7"
related_submissions = contents(:sample_ticker).submissions
related_submissions.each do |submission|
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
include Devise::TestHelpers

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
Expand Down

0 comments on commit 3a22dfb

Please sign in to comment.