|
1 | 1 | require "rails_helper"
|
2 | 2 |
|
3 | 3 | RSpec.describe ApplicationHelper, type: :helper do
|
| 4 | + describe "dashboard_path_from_user" do |
| 5 | + before(:each) do |
| 6 | + allow(helper).to receive(:current_user).and_return(user) |
| 7 | + end |
| 8 | + |
| 9 | + context "As a super admin" do |
| 10 | + let(:user) { create :super_admin } |
| 11 | + |
| 12 | + it "links to the admin dashboard" do |
| 13 | + expect(helper.dashboard_path_from_user).to eq "/admin/dashboard" |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + context "As a user without super admin status" do |
| 18 | + let(:user) { create :organization_admin } |
| 19 | + |
| 20 | + it "links to the general dashboard" do |
| 21 | + pending("TODO - dashboard_path_from_user needs to receive user org to generate path") |
| 22 | + org_name = user.organization.short_name |
| 23 | + expect(helper.dashboard_path_from_user).to eq "/#{org_name}/dashboard" |
| 24 | + end |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + describe "default_title_content" do |
| 29 | + helper do |
| 30 | + def current_organization; end |
| 31 | + end |
| 32 | + |
| 33 | + before(:each) do |
| 34 | + allow(helper).to receive(:current_organization).and_return(organization) |
| 35 | + end |
| 36 | + |
| 37 | + context "Organization exists" do |
| 38 | + let(:organization) { create :organization } |
| 39 | + |
| 40 | + it "returns the organization's name" do |
| 41 | + expect(helper.default_title_content).to eq organization.name |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "Organization does not exist" do |
| 46 | + let(:organization) { nil } |
| 47 | + |
| 48 | + it "returns a default name" do |
| 49 | + expect(helper.default_title_content).to eq "DiaperBank" |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + describe "active_class" do |
| 55 | + it "Returns the controller name" do |
| 56 | + expect(helper.active_class("foo")).to eq "test" |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "can_administrate?" do |
| 61 | + let(:org_1) { @organization } |
| 62 | + let(:org_2) { create :organization } |
| 63 | + |
| 64 | + before(:each) do |
| 65 | + allow(helper).to receive(:current_user).and_return(user) |
| 66 | + end |
| 67 | + |
| 68 | + context "User is org admin and part of org" do |
| 69 | + let(:user) { create :user, organization_admin: true, organization: org_1 } |
| 70 | + |
| 71 | + it "can administrate" do |
| 72 | + expect(helper.can_administrate?).to be_truthy |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context "User is org admin and not part of org" do |
| 77 | + let(:user) { create :user, organization_admin: true, organization: org_2 } |
| 78 | + |
| 79 | + it "cannot administrate" do |
| 80 | + expect(helper.can_administrate?).to be_falsy |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + context "User is part of org but not org admin" do |
| 85 | + let(:user) { create :user, organization: org_1 } |
| 86 | + |
| 87 | + it "cannot administrate" do |
| 88 | + expect(helper.can_administrate?).to be_falsy |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + |
4 | 93 | describe "confirm_delete_msg" do
|
5 | 94 | let(:item) { "Adult Briefs (Medium/Large)" }
|
6 | 95 |
|
|
0 commit comments