Browse Source

Unit test filter module

pull/607/head
baarkerlounger 3 years ago
parent
commit
b0db321b25
  1. 6
      app/views/users/index.html.erb
  2. 30
      spec/controllers/modules/users_filter_spec.rb

6
app/views/users/index.html.erb

@ -1,4 +1,8 @@
<% title = "Your organisation (Users)" %>
<% if @searched.present? %>
<% search_title = " (search results for ‘#{@searched})’" %>
<% end %>
<% title = "Your organisation (Users)#{search_title}" %>
<% content_for :title, title %>
<% content_for :tab_title do %>

30
spec/controllers/modules/users_filter_spec.rb

@ -0,0 +1,30 @@
require "rails_helper"
RSpec.describe Modules::UsersFilter do
describe "filtered_users" do
before do
FactoryBot.create_list(:user, 5)
FactoryBot.create(:user, name: "Joe Blogg")
FactoryBot.create(:user, name: "Tom Blogg", active: false)
end
subject(:instance) { Class.new.include(described_class).new }
let(:user_list) { User.all }
context "when given a search term" do
let(:search_term) { "Blogg" }
it "filters the collection on search term and active users" do
expect(instance.filtered_users(user_list, search_term).count).to eq(1)
end
end
context "when not given a search term" do
let(:search_term) { nil }
it "filters the collection on active users" do
expect(instance.filtered_users(user_list, search_term).count).to eq(6)
end
end
end
end
Loading…
Cancel
Save