From 65559e25c4972f2698bafd1ab98056cf2727fadd Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 13 Apr 2015 21:26:48 +0300 Subject: [PATCH] #465: Added specs for ProductBuildListPolicy --- .../product_build_list_policy_spec.rb | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 spec/policies/product_build_list_policy_spec.rb diff --git a/spec/policies/product_build_list_policy_spec.rb b/spec/policies/product_build_list_policy_spec.rb new file mode 100644 index 000000000..8d2f0b6a1 --- /dev/null +++ b/spec/policies/product_build_list_policy_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +RSpec.describe ProductBuildListPolicy, type: :policy do + let(:pbl) { FactoryGirl.build(:product_build_list) } + subject { described_class } + + permissions :index? do + it "grants access to anonymous user" do + expect(subject).to permit(User.new, pbl) + end + end + + %i(show? log? read?).each do |perm| + permissions perm do + it "denies access to user if user can not show a product" do + allow_any_instance_of(ProductPolicy).to receive(:show?).and_return(false) + expect(subject).not_to permit(User.new, pbl) + end + + it "grants access if user can show a product" do + allow_any_instance_of(ProductPolicy).to receive(:show?).and_return(true) + expect(subject).to permit(User.new, pbl) + end + + it "grants access for to global admin" do + expect(subject).to permit(FactoryGirl.build(:admin), pbl) + end + end + end + + %i(create? cancel?).each do |perm| + permissions perm do + it "denies access to user" do + expect(subject).not_to permit(User.new, pbl) + end + + it "grants access if user can write to project" do + allow_any_instance_of(ProjectPolicy).to receive(:write?).and_return(true) + expect(subject).to permit(User.new, pbl) + end + + it "grants access if user can update a product" do + allow_any_instance_of(ProductPolicy).to receive(:update?).and_return(true) + expect(subject).to permit(User.new, pbl) + end + + it "grants access for to global admin" do + expect(subject).to permit(FactoryGirl.build(:admin), pbl) + end + end + end + + permissions :update? do + it "denies access to user" do + expect(subject).not_to permit(User.new, pbl) + end + + it "grants access if user can update a product" do + allow_any_instance_of(ProductPolicy).to receive(:update?).and_return(true) + expect(subject).to permit(User.new, pbl) + end + + it "grants access for to global admin" do + expect(subject).to permit(FactoryGirl.build(:admin), pbl) + end + end + + permissions :destroy? do + it "denies access to user" do + expect(subject).not_to permit(User.new, pbl) + end + + it "grants access if user can destroy a product" do + allow_any_instance_of(ProductPolicy).to receive(:destroy?).and_return(true) + expect(subject).to permit(User.new, pbl) + end + + it "grants access for to global admin" do + expect(subject).to permit(FactoryGirl.build(:admin), pbl) + end + end + +end