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

foodcoops / foodsoft / 14290630730

06 Apr 2025 08:19AM UTC coverage: 44.865% (-23.3%) from 68.13%
14290630730

Pull #1078

github

web-flow
Merge c89532609 into 02853a526
Pull Request #1078: order balancing add group to article: sort ordergroup names alphabetically

3097 of 6903 relevant lines covered (44.86%)

14.96 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✔
8
    @query = article_unit_params[:q].blank? ? nil : article_unit_params[:q].downcase
×
9

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

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

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

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

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

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

42
  private
1✔
43

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

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

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

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

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