2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2014-07-05 12:59:42 +00:00
|
|
|
|
|
|
|
describe UserPolicy do
|
|
|
|
|
|
|
|
subject { described_class }
|
|
|
|
|
2015-04-28 13:11:19 +00:00
|
|
|
describe '#permitted_attributes' do
|
|
|
|
subject { Pundit.policy(user, user).permitted_attributes }
|
|
|
|
|
|
|
|
let(:user) { User.new }
|
|
|
|
|
|
|
|
it "includes basic form fields" do
|
2015-05-10 16:40:39 +00:00
|
|
|
expect(subject).to eq([:username, :name, :email, :theme_name, :asciicasts_private_by_default])
|
2015-04-28 13:11:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-05 12:59:42 +00:00
|
|
|
permissions :update? do
|
|
|
|
it "grants access if edited user is current user" do
|
|
|
|
user = User.new
|
|
|
|
expect(subject).to permit(user, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "denies access if edited user is not current user" do
|
|
|
|
expect(subject).not_to permit(User.new, User.new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|