• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

foodcoops / foodsoft / 14591407989

22 Apr 2025 09:20AM UTC coverage: 43.167% (-25.0%) from 68.144%
14591407989

push

github

robwa
style: fix rubocop complexity error

Extracts article building to separate method.

1 of 9 new or added lines in 1 file covered. (11.11%)

1718 existing lines in 103 files now uncovered.

2982 of 6908 relevant lines covered (43.17%)

13.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.56
/app/controllers/article_units_controller.rb
1
class ArticleUnitsController < ApplicationController
1✔
2
  before_action :authenticate_article_meta
1✔
3
  before_action :load_available_units, only: %i[search create destroy]
1✔
4

5
  def index; end
1✔
6

7
  def search
1✔
UNCOV
8
    @query = article_unit_params[:q].blank? ? nil : article_unit_params[:q].downcase
×
9

UNCOV
10
    existing_article_units = ArticleUnit.all.to_a
×
UNCOV
11
    @article_units = @available_units
×
12
                     .to_h do |key, value|
UNCOV
13
      [key, value.merge({ code: key, record: existing_article_units.find do |existing_unit|
×
UNCOV
14
                                               existing_unit.unit == key
×
15
                                             end })]
16
    end
17

UNCOV
18
    unless @query.nil?
×
UNCOV
19
      @article_units = @article_units.select do |_key, value|
×
UNCOV
20
        (value[:name].downcase.include?(@query) || value[:symbol]&.downcase&.include?(@query)) &&
×
UNCOV
21
          (params[:only_recommended] == '0' || !value[:untranslated])
×
22
      end
23
    end
24

UNCOV
25
    @article_units = @article_units
×
UNCOV
26
                     .sort { |a, b| sort_by_unit_name(@query, a, b) }
×
UNCOV
27
                     .map { |_key, value| value }
×
28

UNCOV
29
    @article_units = @article_units.take(100) unless @query.nil?
×
UNCOV
30
    @article_units = @article_units.reject { |unit| unit[:record].nil? } if @query.nil?
×
31
  end
32

33
  def create
1✔
UNCOV
34
    @article_unit = ArticleUnit.create(unit: params[:unit])
×
35
  end
36

37
  def destroy
1✔
UNCOV
38
    @article_unit = ArticleUnit.find(params[:id])
×
UNCOV
39
    @article_unit.destroy
×
40
  end
41

42
  private
1✔
43

44
  def load_available_units
1✔
UNCOV
45
    @available_units = ArticleUnitsLib.units
×
46
  end
47

48
  def article_unit_params
1✔
UNCOV
49
    params.permit(:q)
×
50
  end
51

52
  def sort_by_unit_name(query, a_unit, b_unit)
1✔
UNCOV
53
    a_name = a_unit[1][:name].downcase
×
UNCOV
54
    b_name = b_unit[1][:name].downcase
×
55

UNCOV
56
    unless query.nil?
×
UNCOV
57
      return -1 if a_name.starts_with?(query) && !b_name.starts_with?(query)
×
UNCOV
58
      return 1 if !a_name.starts_with?(query) && b_name.starts_with?(query)
×
59
    end
60

UNCOV
61
    a_name <=> b_name
×
62
  end
63
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc