From 4a5610983d7e1b0aeaa9f521924e9315748f9c3b Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 14 Apr 2015 00:17:37 +0300 Subject: [PATCH] #465: Added specs for SubscribePolicy --- spec/policies/subscribe_policy_spec.rb | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/policies/subscribe_policy_spec.rb diff --git a/spec/policies/subscribe_policy_spec.rb b/spec/policies/subscribe_policy_spec.rb new file mode 100644 index 000000000..4fcff1167 --- /dev/null +++ b/spec/policies/subscribe_policy_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +RSpec.describe SubscribePolicy, type: :policy do + let(:subscribe) { FactoryGirl.create(:subscribe) } + subject { described_class } + + permissions :create? do + it "denies access to anonymous user" do + expect(subject).to_not permit(User.new, subscribe) + end + + it "grants access to user" do + expect(subject).to permit(FactoryGirl.create(:user), subscribe) + end + + it "denies access if user already subscribed" do + expect(subject).to_not permit(subscribe.user, subscribe) + end + end + + permissions :destroy? do + it "denies access to anonymous user" do + expect(subject).to_not permit(User.new, subscribe) + end + + it "denies access to user" do + expect(subject).to_not permit(FactoryGirl.create(:user), subscribe) + end + + it "grants access if user already subscribed" do + expect(subject).to permit(subscribe.user, subscribe) + end + end + +end