Browse Source

feat: update tests

pull/1775/head
natdeanlewissoftwire 3 years ago
parent
commit
fd628eaf67
  1. 2
      app/models/log.rb
  2. 10
      spec/helpers/log_list_helper_spec.rb

2
app/models/log.rb

@ -38,7 +38,7 @@ class Log < ApplicationRecord
} }
scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :filter_by_id, ->(id) { where(id:) } scope :filter_by_id, ->(id) { where(id:) }
scope :filter_by_user, ->(selected_user, _user = nil) { where(created_by: selected_user) } scope :filter_by_user, ->(selected_user, _user = nil) { selected_user.present? ? where(created_by: selected_user) : all }
scope :filter_by_bulk_upload_id, lambda { |bulk_upload_id, user| scope :filter_by_bulk_upload_id, lambda { |bulk_upload_id, user|
joins(:bulk_upload) joins(:bulk_upload)
.where(bulk_upload: { id: bulk_upload_id, user: }) .where(bulk_upload: { id: bulk_upload_id, user: })

10
spec/helpers/log_list_helper_spec.rb

@ -16,22 +16,22 @@ RSpec.describe LogListHelper, type: :helper do
expect(result).to be false expect(result).to be false
end end
it "returns true if the user filter is set to 'yours'" do it "returns true if the assigned to filter is set to you" do
allow(self).to receive(:filter_selected?).with("user", "yours", filter_type).and_return true allow(self).to receive(:filter_selected?).with("assigned_to", "you", filter_type).and_return true
expect(result).to be true expect(result).to be true
end end
it "returns false if any filters other than the user filter are set" do it "returns false if any filters other than the user filter are set" do
allow(self).to receive(:filter_selected?).and_return true allow(self).to receive(:filter_selected?).and_return true
allow(self).to receive(:filter_selected?).with("user", "yours", filter_type).and_return false allow(self).to receive(:filter_selected?).with("assigned_to", "you", filter_type).and_return false
expect(result).to be false expect(result).to be false
end end
context "when there is a search term present" do context "when there is a search term present" do
let(:search_term) { "word" } let(:search_term) { "word" }
it "still returns false as long as the user filter is not set to yours" do it "still returns false as long as the assigned to filter is not set to you" do
allow(self).to receive(:filter_selected?).with("user", "yours", filter_type).and_return false allow(self).to receive(:filter_selected?).with("assigned_to", "you", filter_type).and_return false
expect(result).to be false expect(result).to be false
end end
end end

Loading…
Cancel
Save