spec/canner_spec.rb in canner-0.3.0 vs spec/canner_spec.rb in canner-0.4.0
- old
+ new
@@ -2,27 +2,35 @@
require "canner"
class Sample
end
-class SamplePolicy
+class SamplePolicy < Canner::Policy
def initialize(current_user, method, current_branch)
@current_user = current_user
@current_branch = current_branch
@method = method.to_sym
@roles = fetch_roles
end
def fetch_roles
- # ['admin']
+ ['admin']
end
def canner_scope
- # [Sample.new]
+ [Sample.new]
end
+ def can?
+ case @method
+ when :index, :show
+ has_role?(:admin)
+ else
+ false
+ end
+ end
end
class AppController
include Canner
@@ -53,10 +61,10 @@
it "should return true if the policy allows access to the instance" do
expect(app_controller).to receive(:canner_policy).and_return(sample_policy)
expect(sample_policy).to receive(:instance_can?).and_return true
- app_controller.instance_can?('test', 'sample', Sample.new).should be_truthy
+ expect(app_controller.instance_can?('test', 'sample', Sample.new)).to be true
end
end
describe "can?" do