Skip to content

Commit

Permalink
Increases the test coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Aug 20, 2024
1 parent f8ec016 commit 61490ab
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/models/employee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def self.solr_index(opts = {})
Sunspot.index! includes(options[:include]).select(&:indexable?)
end

# perform a final commit if not committing in batches
Sunspot.commit unless options[:batch_commit]
end

Expand Down
24 changes: 24 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,28 @@
end
end
end

describe "#roles" do
let(:account) { FactoryBot.create(:regular_user) }

it "generates the role for a given user" do
expect(account.roles).to eq([described_class::AUTHENTICATED_ROLE])
end

context "when the user is an admin. user" do
let(:account) { FactoryBot.create(:admin_user) }

it "includes the admin role" do
expect(account.roles).to include(described_class::ADMIN_ROLE)
end
end

context "when no user is specified" do
let(:account) { described_class.new(netid: nil) }

it "only includes the anonymous role" do
expect(account.roles).to include(described_class::ANONYMOUS_ROLE)
end
end
end
end
29 changes: 29 additions & 0 deletions spec/models/employee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,33 @@
expect(search).to be_a(Sunspot::Search::StandardSearch)
end
end

describe ".reindex" do
let(:employee) { FactoryBot.create(:employee_faked) }

before do
employee
allow(Sunspot).to receive(:index)
allow(Sunspot).to receive(:commit)
end

it "indexes models to Solr using the Sunspot API" do
described_class.reindex
expect(Sunspot).to have_received(:index)
expect(Sunspot).to have_received(:commit)
end

context "when the batch size option is negative" do
before do
allow(Sunspot).to receive(:index!)
allow(Sunspot.config.indexing).to receive(:default_batch_size).and_return(-1)
end

it "indexes models to Solr using the Sunspot API" do
described_class.reindex
expect(Sunspot).to have_received(:index!)
expect(Sunspot).not_to have_received(:commit)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/models/waiver_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@
expect(waiver_infos).not_to be_empty
end
end

describe ".all_with_words" do
let(:waiver_info) { FactoryBot.create(:waiver_info) }

it "searches for WaiverInfo models using the :all_word_fields" do
waiver_info
waiver_infos = described_class.all_with_words("Some Title")
expect(waiver_infos).to be_a(Sunspot::Search::StandardSearch)
end
end
end

0 comments on commit 61490ab

Please sign in to comment.