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

foodcoops / foodsoft / 16526107939

25 Jul 2025 03:49PM UTC coverage: 42.064% (-24.5%) from 66.58%
16526107939

push

github

robwa
feat(order): add tests for custom remote order method and FTP upload

Introduce tests for registered custom remote order methods.
Verify FTP upload functionality and integration with the new system.

2971 of 7063 relevant lines covered (42.06%)

12.1 hits per line

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

50.0
/app/controllers/api/v1/base_controller.rb
1
class Api::V1::BaseController < ApplicationController
1✔
2
  include Concerns::AuthApi
1✔
3

4
  protect_from_forgery with: :null_session
1✔
5

6
  before_action :skip_session
1✔
7
  before_action :authenticate
1✔
8

9
  rescue_from ActiveRecord::RecordNotFound, with: :not_found_handler
1✔
10
  rescue_from ActiveRecord::RecordNotSaved, with: :not_acceptable_handler
1✔
11
  rescue_from ActiveRecord::RecordInvalid, with: :not_acceptable_handler
1✔
12
  rescue_from Api::Errors::PermissionRequired, with: :permission_required_handler
1✔
13

14
  private
1✔
15

16
  # @return [Ordergroup] Current user's ordergroup, or +nil+ if no valid token or user has no ordergroup.
17
  def current_ordergroup
1✔
18
    current_user.try(:ordergroup)
×
19
  end
20

21
  def require_ordergroup
1✔
22
    authenticate
×
23
    return if current_ordergroup.present?
×
24

25
    raise Api::Errors::PermissionRequired, 'Forbidden, must be in an ordergroup'
×
26
  end
27

28
  def require_minimum_balance
1✔
29
    minimum_balance = FoodsoftConfig[:minimum_balance] or return
×
30
    return unless current_ordergroup.account_balance < minimum_balance
×
31

32
    raise Api::Errors::PermissionRequired, t('application.controller.error_minimum_balance', min: minimum_balance)
×
33
  end
34

35
  def require_enough_apples
1✔
36
    return unless current_ordergroup.not_enough_apples?
×
37

38
    s = t('group_orders.messages.not_enough_apples', apples: current_ordergroup.apples,
×
39
                                                     stop_ordering_under: FoodsoftConfig[:stop_ordering_under])
40
    raise Api::Errors::PermissionRequired, s
×
41
  end
42

43
  def require_config_enabled(config)
1✔
44
    return if FoodsoftConfig[config]
×
45

46
    raise Api::Errors::PermissionRequired, t('application.controller.error_not_enabled', config: config)
×
47
  end
48

49
  def skip_session
1✔
50
    request.session_options[:skip] = true
×
51
  end
52

53
  def not_found_handler(e)
1✔
54
    # remove where-clauses from error message (not suitable for end-users)
55
    msg = e.message.try { |m| m.sub(/\s*\[.*?\]\s*$/, '') } || 'Not found'
×
56
    render status: :not_found, json: { error: 'not_found', error_description: msg }
×
57
  end
58

59
  def not_acceptable_handler(e)
1✔
60
    msg = e.message || 'Data not acceptable'
×
61
    render status: :unprocessable_entity, json: { error: 'not_acceptable', error_description: msg }
×
62
  end
63

64
  def doorkeeper_unauthorized_render_options(error:)
1✔
65
    { json: { error: error.name, error_description: error.description } }
×
66
  end
67

68
  def doorkeeper_forbidden_render_options(error:)
1✔
69
    { json: { error: error.name, error_description: error.description } }
×
70
  end
71

72
  def permission_required_handler(e)
1✔
73
    msg = e.message || 'Forbidden, user has no access'
×
74
    render status: :forbidden, json: { error: 'forbidden', error_description: msg }
×
75
  end
76

77
  # @todo something with ApplicationHelper#show_user
78
  def show_user(user = current_user, **_options)
1✔
79
    user.display
×
80
  end
81
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