|
|
@ -480,7 +480,7 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
context "when there is a log with nil values for purchid" do |
|
|
|
context "when there is a log with nil values for purchid" do |
|
|
|
let!(:purchid_not_given) { create(:sales_log, :duplicate, purchid: nil, owning_organisation: organisation) } |
|
|
|
let!(:purchid_not_given) { create(:sales_log, :duplicate, purchid: nil, owning_organisation: organisation) } |
|
|
|
|
|
|
|
|
|
|
|
it "returns the log as a duplicate if tenancy code is nil" do |
|
|
|
it "returns the log as a duplicate if purchaser code is nil" do |
|
|
|
log.update!(purchid: nil) |
|
|
|
log.update!(purchid: nil) |
|
|
|
expect(duplicate_sets.count).to eq(1) |
|
|
|
expect(duplicate_sets.count).to eq(1) |
|
|
|
expect(duplicate_sets.first).to contain_exactly(log.id, purchid_not_given.id) |
|
|
|
expect(duplicate_sets.first).to contain_exactly(log.id, purchid_not_given.id) |
|
|
@ -1142,5 +1142,97 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when searching logs" do |
|
|
|
|
|
|
|
let!(:sales_log_to_search) { create(:sales_log, :completed, purchid: "to search", postcode_full: "ME0 0WW") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
create_list(:sales_log, 5, :completed) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#filter_by_id" do |
|
|
|
|
|
|
|
it "allows searching by a log ID" do |
|
|
|
|
|
|
|
result = described_class.filter_by_id(sales_log_to_search.id.to_s) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#filter_by_purchaser_code" do |
|
|
|
|
|
|
|
it "allows searching by a purchaser_code" do |
|
|
|
|
|
|
|
result = described_class.filter_by_purchaser_code(sales_log_to_search.purchid) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when purchaser_code has lower case letters" do |
|
|
|
|
|
|
|
let(:matching_purchaser_code_lower_case) { sales_log_to_search.purchid.downcase } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "allows searching by a purchaser_code" do |
|
|
|
|
|
|
|
result = described_class.filter_by_purchaser_code(matching_purchaser_code_lower_case) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#filter_by_postcode" do |
|
|
|
|
|
|
|
it "allows searching by a Property Postcode" do |
|
|
|
|
|
|
|
result = described_class.filter_by_postcode(sales_log_to_search.postcode_full) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#search_by" do |
|
|
|
|
|
|
|
it "allows searching using ID" do |
|
|
|
|
|
|
|
result = described_class.search_by(sales_log_to_search.id.to_s) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "allows searching using purchaser code" do |
|
|
|
|
|
|
|
result = described_class.search_by(sales_log_to_search.purchid) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "allows searching by a Property Postcode" do |
|
|
|
|
|
|
|
result = described_class.search_by(sales_log_to_search.postcode_full) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when postcode has spaces and lower case letters" do |
|
|
|
|
|
|
|
let(:matching_postcode_lower_case_with_spaces) { sales_log_to_search.postcode_full.downcase.chars.insert(3, " ").join } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "allows searching by a Property Postcode" do |
|
|
|
|
|
|
|
result = described_class.search_by(matching_postcode_lower_case_with_spaces) |
|
|
|
|
|
|
|
expect(result.count).to eq(1) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when matching multiple records on different fields" do |
|
|
|
|
|
|
|
let!(:sales_log_with_purchid) { create(:sales_log, purchid: sales_log_to_search.id) } |
|
|
|
|
|
|
|
let!(:sales_log_with_postcode) { create(:sales_log, postcode_full: "C1 1AC") } |
|
|
|
|
|
|
|
let!(:sales_log_with_postcode_purchid) { create(:sales_log, purchid: "C1 1AC") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns all matching records in correct order with matching IDs" do |
|
|
|
|
|
|
|
result = described_class.search_by(sales_log_to_search.id.to_s) |
|
|
|
|
|
|
|
expect(result.count).to eq(2) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_to_search.id |
|
|
|
|
|
|
|
expect(result.second.id).to eq sales_log_with_purchid.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns all matching records in correct order with matching postcode" do |
|
|
|
|
|
|
|
result = described_class.search_by("C1 1AC") |
|
|
|
|
|
|
|
expect(result.count).to eq(2) |
|
|
|
|
|
|
|
expect(result.first.id).to eq sales_log_with_postcode_purchid.id |
|
|
|
|
|
|
|
expect(result.second.id).to eq sales_log_with_postcode.id |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
# rubocop:enable RSpec/MessageChain |
|
|
|
# rubocop:enable RSpec/MessageChain |
|
|
|