2021-08-06 11:49:47 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
2022-01-16 04:47:40 -08:00
|
|
|
describe ApplicationHelper, type: :helper do
|
|
|
|
describe "#privileged" do
|
|
|
|
context "current user and checked user do not match" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
let(:priv_user) { FactoryBot.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not return true" do
|
|
|
|
expect(helper.privileged?(priv_user)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "current user and checked user match" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true" do
|
|
|
|
expect(helper.privileged?(user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "current user is moderator" do
|
|
|
|
let(:user) { FactoryBot.create(:user, roles: [:moderator]) }
|
|
|
|
let(:priv_user) { FactoryBot.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true" do
|
|
|
|
expect(helper.privileged?(priv_user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-06 13:33:02 -07:00
|
|
|
describe "#rails_admin_path_for_resource" do
|
|
|
|
context "user resource" do
|
|
|
|
let(:resource) { FactoryBot.create(:user) }
|
|
|
|
subject { rails_admin_path_for_resource(resource) }
|
|
|
|
|
|
|
|
it "should return a URL to the given resource within rails admin" do
|
|
|
|
expect(subject).to eq("/justask_admin/user/#{resource.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-06 13:20:55 -07:00
|
|
|
end
|