Skip to content

Commit

Permalink
Update simplecov config, increase coverage (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
holytoastr authored and armahillo committed Jul 26, 2019
1 parent e5203fe commit ec12be8
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SimpleCov.start 'rails' do
# any custom configs like groups and filters can be here at a central place
end
89 changes: 89 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,95 @@
require "rails_helper"

RSpec.describe ApplicationHelper, type: :helper do
describe "dashboard_path_from_user" do
before(:each) do
allow(helper).to receive(:current_user).and_return(user)
end

context "As a super admin" do
let(:user) { create :super_admin }

it "links to the admin dashboard" do
expect(helper.dashboard_path_from_user).to eq "/admin/dashboard"
end
end

context "As a user without super admin status" do
let(:user) { create :organization_admin }

it "links to the general dashboard" do
pending("TODO - dashboard_path_from_user needs to receive user org to generate path")
org_name = user.organization.short_name
expect(helper.dashboard_path_from_user).to eq "/#{org_name}/dashboard"
end
end
end

describe "default_title_content" do
helper do
def current_organization; end
end

before(:each) do
allow(helper).to receive(:current_organization).and_return(organization)
end

context "Organization exists" do
let(:organization) { create :organization }

it "returns the organization's name" do
expect(helper.default_title_content).to eq organization.name
end
end

context "Organization does not exist" do
let(:organization) { nil }

it "returns a default name" do
expect(helper.default_title_content).to eq "DiaperBank"
end
end
end

describe "active_class" do
it "Returns the controller name" do
expect(helper.active_class("foo")).to eq "test"
end
end

describe "can_administrate?" do
let(:org_1) { @organization }
let(:org_2) { create :organization }

before(:each) do
allow(helper).to receive(:current_user).and_return(user)
end

context "User is org admin and part of org" do
let(:user) { create :user, organization_admin: true, organization: org_1 }

it "can administrate" do
expect(helper.can_administrate?).to be_truthy
end
end

context "User is org admin and not part of org" do
let(:user) { create :user, organization_admin: true, organization: org_2 }

it "cannot administrate" do
expect(helper.can_administrate?).to be_falsy
end
end

context "User is part of org but not org admin" do
let(:user) { create :user, organization: org_1 }

it "cannot administrate" do
expect(helper.can_administrate?).to be_falsy
end
end
end

describe "confirm_delete_msg" do
let(:item) { "Adult Briefs (Medium/Large)" }

Expand Down
18 changes: 18 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,32 @@
# super_admin :boolean default(FALSE)
# last_request_at :datetime
#
require "rails_helper"

RSpec.describe User, type: :model do
it "has a valid factory" do
expect(build(:user)).to be_valid
end

context "Associations" do
it {
expect(described_class.reflect_on_association(:organization).macro)
.to eq(:belongs_to)
}
it {
expect(described_class.reflect_on_association(:feedback_messages).macro)
.to eq(:has_many)
}
end

context "Validations >" do
it "requires a name" do
expect(build(:user, name: nil)).not_to be_valid
expect(build(:user, name: "foo")).to be_valid
end
it "requires an email" do
expect(build(:user, email: nil)).not_to be_valid
expect(build(:user, email: "[email protected]")).to be_valid
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= "test"
require 'simplecov'
require File.expand_path("../config/environment", __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
Expand Down Expand Up @@ -100,6 +101,7 @@ def stub_addresses
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::ControllerHelpers, type: :helper
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::IntegrationHelpers, type: :system

Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'simplecov'
require 'active_support/testing/time_helpers'
SimpleCov.start 'rails'

RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
Expand Down

0 comments on commit ec12be8

Please sign in to comment.