Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed May 28, 2024
1 parent 9573683 commit 50d7af1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/helpers/models_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ModelsHelper
def group(files)
return {} if files.empty?
sections = {}
min_section_size = 2
min_prefix_length = 3
Expand All @@ -16,7 +17,7 @@ def group(files)
end
end
# Sort and include empty set
{ nil => files }.merge sections.sort_by {|k, v| k }.to_h
{nil => files}.merge sections.sort_by { |k, v| k }.to_h
end

def status_badges(model)
Expand Down
14 changes: 7 additions & 7 deletions spec/helpers/models_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
describe "string concat" do
let(:files) do
%w[
foo
bar
foobar
foo_bar
bar_foo
armleft
arm_right
head_1
leg_l
leg_r
].map { |x| build(:model_file, filename: "#{x}.stl") }
end

it "groups strings together with similar prefixes" do # rubocop:todo RSpec/MultipleExpectations
groups = helper.group(files)
expect(groups["foo"].count).to eq(2)
expect(groups["bar"].count).to eq(2)
expect(groups["leg_"].count).to eq(2)
expect(groups["arm"].count).to eq(2)
expect(groups[nil].count).to eq(1)
end
end
Expand Down

0 comments on commit 50d7af1

Please sign in to comment.