• 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

25.81
/app/controllers/api/v1/articles_controller.rb
1
class Api::V1::ArticlesController < Api::V1::BaseController
1✔
2
  skip_before_action :authenticate
1✔
3

4
  def index
1✔
5
    supplier = Supplier.find_by_external_uuid!(index_params.fetch(:shared_supplier_uuid))
×
6

7
    @articles = Article.with_latest_versions_and_categories.undeleted.where(supplier_id: supplier, type: nil)
×
8
    @articles = @articles.where('article_versions.updated_at > ?', index_params[:updated_after].to_datetime) if index_params.include?(:updated_after)
×
9
    @articles = @articles.where('article_versions.name LIKE ?', "%#{index_params[:name]}%") if index_params.include?(:name)
×
10
    @articles = @articles.where(article_versions: { origin: index_params[:origin] }) if index_params.include?(:origin)
×
11
    @articles = @articles.page(index_params[:page]).per(index_params.fetch(:per_page)) if index_params.include?(:page)
×
12

13
    data = @articles.map { |article| get_article_version_data(article) }
×
14

15
    render json: { articles: data, pagination: pagination_response, latest_update: get_latest_article_update(supplier) }
×
16
  end
17

18
  protected
1✔
19

20
  def index_params
1✔
21
    params.permit(:shared_supplier_uuid, :updated_after, :name, :origin, :page, :per_page)
×
22
  end
23

24
  def get_article_version_data(article)
1✔
25
    version_attributes = article.latest_article_version.attributes
×
26
    version_attributes.delete_if { |key| key == 'id' || key.end_with?('_id') }
×
27

28
    version_attributes['article_unit_ratios'] = article.latest_article_version.article_unit_ratios.map do |ratio|
×
29
      ratio_attributes = ratio.attributes
×
30
      ratio_attributes.delete_if { |key| key == 'id' || key.end_with?('_id') }
×
31
    end
32

33
    version_attributes
×
34
  end
35

36
  def get_latest_article_update(supplier)
1✔
37
    latest_update = Article
×
38
                    .with_latest_versions
39
                    .undeleted
40
                    .where(supplier_id: supplier, type: nil)
41
                    .order('article_versions.updated_at DESC')
42
                    .limit(1)
43
                    .first&.updated_at
44
    latest_update&.utc
×
45
  end
46

47
  def pagination_response
1✔
48
    return nil unless index_params.include?(:page)
×
49

50
    current = @articles.current_page
×
51
    total = @articles.total_pages
×
52
    {
53
      current_page: current,
×
54
      previous_page: (current > 1 ? (current - 1) : nil),
×
55
      next_page: (current == total ? nil : (current + 1)),
×
56
      per_page: @articles.limit_value,
57
      total_pages: total,
58
      number: @articles.total_count
59
    }
60
  end
61
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