Sha256: 4ab18bcd65d3ae565547bdc4ccb4b9f284a5592a939ac45af0c8f1533234d470

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

describe UserPolicy do
  subject { UserPolicy }

  let (:current_user) { FactoryGirl.build_stubbed :user }
  let (:other_user) { FactoryGirl.build_stubbed :user }
  let (:admin) { FactoryGirl.build_stubbed :user, :admin }

  permissions :index? do
    it "denies access if not an admin" do
      expect(UserPolicy).not_to permit(current_user)
    end
    it "allows access for an admin" do
      expect(UserPolicy).to permit(admin)
    end
  end

  permissions :show? do
    it "prevents other users from seeing your profile" do
      expect(subject).not_to permit(current_user, other_user)
    end
    it "allows you to see your own profile" do
      expect(subject).to permit(current_user, current_user)
    end
    it "allows an admin to see any profile" do
      expect(subject).to permit(admin)
    end
  end

  permissions :update? do
    it "prevents updates if not an admin" do
      expect(subject).not_to permit(current_user)
    end
    it "allows an admin to make updates" do
      expect(subject).to permit(admin)
    end
  end

  permissions :destroy? do
    it "prevents deleting yourself" do
      expect(subject).not_to permit(current_user, current_user)
    end
    it "allows an admin to delete any user" do
      expect(subject).to permit(admin, other_user)
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_apps_testing-0.3.12 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.11 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.10 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.9 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.8 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.7 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.6 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.5 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb
rails_apps_testing-0.3.4 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb