Sha256: 62481a76b292fb00ba080382d27dbd9fe3470c999334202f98d05aeef561027f

Contents?: true

Size: 1.61 KB

Versions: 10

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

describe Storytime::CommentPolicy do
  subject { Storytime::CommentPolicy.new(user, comment) }
  let(:post) { FactoryGirl.create(:post) }

  context "as a normal user" do
    let(:user) { FactoryGirl.create(:user) }

    context "a comment owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, user: user, post: post) }

      it { should permit!(:create)  }
      it { should permit!(:destroy)  }
    end

    context "a comment not owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, post: post) }

      it { should_not permit!(:create)  }
      it { should_not permit!(:destroy)  }
    end
  end

  context "as an editor" do
    let(:user){ FactoryGirl.create(:editor) }

    context "a comment owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, user: user, post: post) }

      it { should permit!(:create)  }
      it { should permit!(:destroy)  }
    end

    context "a comment not owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, post: post) }

      it { should_not permit!(:create)  }
      it { should permit!(:destroy)  }
    end
  end

  context "as an admin" do
    let(:user){ FactoryGirl.create(:admin) }

    context "a comment owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, user: user, post: post) }

      it { should permit!(:create)  }
      it { should permit!(:destroy)  }
    end

    context "a comment not owned by the user" do
      let(:comment) { FactoryGirl.build(:comment, post: post) }

      it { should_not permit!(:create)  }
      it { should permit!(:destroy)  }
    end
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
storytime-1.2.0 spec/policies/comment_policy_spec.rb
storytime-1.1.1 spec/policies/comment_policy_spec.rb
storytime-1.0.7 spec/policies/comment_policy_spec.rb
storytime-1.0.6 spec/policies/comment_policy_spec.rb
storytime-1.0.5 spec/policies/comment_policy_spec.rb
storytime-1.0.2 spec/policies/comment_policy_spec.rb
storytime-1.0.1 spec/policies/comment_policy_spec.rb
storytime-1.0.0 spec/policies/comment_policy_spec.rb
storytime-0.0.4 spec/policies/comment_policy_spec.rb
storytime-0.0.2 spec/policies/comment_policy_spec.rb