Skip to content

Commit

Permalink
Merge pull request #3477 from betagouv/clean_code_naf
Browse files Browse the repository at this point in the history
Clean code_naf with point in match_filter
  • Loading branch information
LucienMLD authored Jun 5, 2024
2 parents 12f3af6 + f9233c8 commit b8ecd90
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/match_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def raw_accepted_legal_forms
end

def raw_accepted_naf_codes=(naf_codes)
updated_naf_codes = naf_codes.split(/[,\s]/).delete_if(&:empty?)
updated_naf_codes = naf_codes.delete('.').split(/[,\s]/).delete_if(&:empty?)
self.accepted_naf_codes = updated_naf_codes
end

def raw_excluded_naf_codes=(naf_codes)
updated_naf_codes = naf_codes.split(/[,\s]/).delete_if(&:empty?)
updated_naf_codes = naf_codes.delete('.').split(/[,\s]/).delete_if(&:empty?)
self.excluded_naf_codes = updated_naf_codes
end

Expand Down
42 changes: 42 additions & 0 deletions spec/models/match_filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe MatchFilter do
describe 'getter' do
subject { match_filter.raw_accepted_naf_codes }

let(:match_filter) { create :match_filter, accepted_naf_codes: accepted_naf_codes }

context 'with full accepted_naf_codes' do
let(:accepted_naf_codes) { ["9001Z", "9002Z"] }

it { is_expected.to eq "9001Z 9002Z" }
end

context 'with empty accepted_naf_codes' do
let(:accepted_naf_codes) { [] }

it { is_expected.to eq '' }
end
end

describe 'setter' do
subject { match_filter.accepted_naf_codes }

let(:match_filter) { create :match_filter, raw_accepted_naf_codes: raw_accepted_naf_codes }

context 'with empty data' do
let(:raw_accepted_naf_codes) { '' }

it { is_expected.to eq [] }
end

context 'with proper values' do
let(:raw_accepted_naf_codes) { '90.01Z 9002Z' }

it { is_expected.to eq ["9001Z", "9002Z"] }
end

end
end

0 comments on commit b8ecd90

Please sign in to comment.