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

gregschmit / rails-rest-framework / 24615084524

18 Apr 2026 10:14PM UTC coverage: 87.679% (-0.5%) from 88.164%
24615084524

push

github

gregschmit
Fix rubocop and tests.

2 of 2 new or added lines in 1 file covered. (100.0%)

74 existing lines in 7 files now uncovered.

1103 of 1258 relevant lines covered (87.68%)

205.64 hits per line

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

95.77
/lib/rest_framework.rb
1
# frozen_string_literal: true
2

3
module RESTFramework
2✔
4
  BUILTIN_FORM_ACTIONS = [ :new, :edit ].freeze
2✔
5
  BUILTIN_ACTIONS = {
2✔
6
    index: :get,
7
    new: :get,
8
    create: :post,
9
  }.freeze
10
  BUILTIN_MEMBER_ACTIONS = {
11
    show: :get,
2✔
12
    edit: :get,
13
    update: [ :put, :patch ].freeze,
14
    destroy: :delete,
15
  }.freeze
16
  RRF_BUILTIN_ACTIONS = {
2✔
17
    options: :options,
18
  }.freeze
19
  RRF_BUILTIN_BULK_ACTIONS = {
20
    update_all: [ :put, :patch ].freeze,
2✔
21
    destroy_all: :delete,
22
  }.freeze
23

24
  # Storage for extra routes and associated metadata.
25
  EXTRA_ACTION_ROUTES = Set.new
2✔
26
  ROUTE_METADATA = {}
2✔
27

28
  # We put most vendored external assets into these files to make precompilation and serving faster.
29
  EXTERNAL_CSS_NAME = "rest_framework/external.min.css"
2✔
30
  EXTERNAL_JS_NAME = "rest_framework/external.min.js"
2✔
31

32
  # We should always add the `.min` extension prefix even if the assets are not minified, to avoid
33
  # sprockets minifying the assets. We target propshaft, so we want these assets to just be passed
34
  # through.
35
  # rubocop:disable Layout/LineLength
36
  EXTERNAL_ASSETS = {
37
    # Bootstrap
38
    "bootstrap.min.css" => {
2✔
39
      url: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css",
40
      sri: "sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr",
41
    },
42
    "bootstrap.min.js" => {
43
      url: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js",
44
      sri: "sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q",
45
    },
46

47
    # Bootstrap Icons
48
    "bootstrap-icons.min.css" => {
49
      url: "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css",
50
      inline_fonts: true,
51
    },
52

53
    # Highlight.js
54
    "highlight.min.js" => {
55
      url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/highlight.min.js",
56
      sri: "sha512-6QBAC6Sxc4IF04SvIg0k78l5rP5YgVjmHX2NeArelbxM3JGj4imMqfNzEta3n+mi7iG3nupdLnl3QrbfjdXyTg==",
57
    },
58
    "highlight-json.min.js" => {
59
      url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/languages/json.min.js",
60
      sri: "sha512-8JO7/pRnd1Ce8OBXWQg85e5wNPJdBaQdN8w4oDa+HelMXaLwCxTdbzdWHmJtWR9AmcI6dOln4FS5/KrzpxqqfQ==",
61
    },
62
    "highlight-xml.min.js" => {
63
      url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/languages/xml.min.js",
64
      sri: "sha512-/vq6wbS2Qkv8Hj4mP3Jd/m6MbnIrquzZiUt9tIluQfe332IQeFDrSIK7j2cjAyn6/9Ntb2WMPbo1CAxu26NViA==",
65
    },
66
    "highlight-a11y-dark.min.css" => {
67
      url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-dark.min.css",
68
      sri: "sha512-Vj6gPCk8EZlqnoveEyuGyYaWZ1+jyjMPg8g4shwyyNlRQl6d3L9At02ZHQr5K6s5duZl/+YKMnM3/8pDhoUphg==",
69
      extra_tag_attrs: { class: "rrf-dark-mode" },
70
    },
71
    "highlight-a11y-light.min.css" => {
72
      url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-light.min.css",
73
      sri: "sha512-WDk6RzwygsN9KecRHAfm9HTN87LQjqdygDmkHSJxVkVI7ErCZ8ZWxP6T8RvBujY1n2/E4Ac+bn2ChXnp5rnnHA==",
74
      extra_tag_attrs: { class: "rrf-light-mode" },
75
    },
76

77
    # NeatJSON
78
    "neatjson.min.js" => {
79
      url: "https://cdn.jsdelivr.net/npm/neatjson@0.10.6/javascript/neatjson.min.js",
80
      exclude_from_docs: true,
81
    },
82

83
    # Trix
84
    "trix.min.css" => {
85
      url: "https://unpkg.com/trix@2.0.8/dist/trix.css",
86
      exclude_from_docs: true,
87
    },
88
    "trix.min.js" => {
89
      url: "https://unpkg.com/trix@2.0.8/dist/trix.umd.min.js",
90
      exclude_from_docs: true,
91
    },
92
  }.map { |name, cfg|
93
    ext = File.extname(name)
22✔
94
    if ext == ".js"
22✔
95
      cfg[:place] = "javascripts"
12✔
96
      cfg[:extra_tag_attrs] ||= {}
12✔
97
      cfg[:tag_attrs] = {
12✔
98
        src: cfg[:url],
99
        integrity: cfg[:sri],
100
        crossorigin: "anonymous",
101
        referrerpolicy: "no-referrer",
102
        defer: true,
103
        **cfg[:extra_tag_attrs],
104
      }
105
      cfg[:tag] = ActionController::Base.helpers.tag.script(**cfg[:tag_attrs])
12✔
106
    elsif ext == ".css"
10✔
107
      cfg[:place] = "stylesheets"
10✔
108
      cfg[:extra_tag_attrs] ||= {}
10✔
109
      cfg[:tag_attrs] = {
10✔
110
        rel: "stylesheet",
111
        href: cfg[:url],
112
        integrity: cfg[:sri],
113
        crossorigin: "anonymous",
114
        **cfg[:extra_tag_attrs],
115
      }
116
      cfg[:tag] = ActionController::Base.helpers.tag.link(**cfg[:tag_attrs])
10✔
117
    else
118
      raise "Unknown asset extension: #{ext}."
×
119
    end
120

121
    [ name, cfg ]
22✔
122
  }.to_h.freeze
123
  # rubocop:enable Layout/LineLength
124

125
  EXTERNAL_UNSUMMARIZED_ASSETS = EXTERNAL_ASSETS.select { |_, cfg| cfg[:extra_tag_attrs].present? }
24✔
126

127
  # Global configuration should be kept minimal, as controller-level configurations allows multiple
128
  # APIs to be defined to behave differently.
129
  class Config
2✔
130
    DEFAULT_LABEL_FIELDS = %w[name label login title email username url].freeze
2✔
131
    DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w[description note].freeze
2✔
132
    DEFAULT_READ_ONLY_FIELDS = %w[
2✔
133
      created_at
134
      created_by
135
      created_by_id
136
      updated_at
137
      updated_by
138
      updated_by_id
139
      _method
140
      utf8
141
      authenticity_token
142
    ].freeze
143
    DEFAULT_WRITE_ONLY_FIELDS = %w[
2✔
144
      password
145
      password_confirmation
146
    ].freeze
147
    DEFAULT_INFLECT_ACRONYMS = [ "ID", "IDs", "REST", "API", "APIs" ].freeze
2✔
148

149
    # Permits use of `render(api: obj)` syntax over `render_api(obj)`; `true` by default.
150
    attr_accessor :register_api_renderer
2✔
151

152
    # Run `rrf_finalize` on controllers automatically using a `TracePoint` hook. This is `true` by
153
    # default, and can be disabled for performance, and must be global because we have to determine
154
    # this before any controller-specific configuration is set. If this is set to `false`, then you
155
    # must manually call `rrf_finalize` after any configuration on each controller that needs to
156
    # participate in:
157
    #  - Model delegation, for the helper methods to be defined dynamically.
158
    #  - Websockets, for `::Channel` class to be defined dynamically.
159
    #  - Controller configuration freezing.
160
    attr_accessor :auto_finalize
2✔
161

162
    # Freeze configuration attributes during finalization to prevent accidental mutation.
163
    attr_accessor :freeze_config
2✔
164

165
    # Specify reverse association tables that are typically very large, and therefore should not be
166
    # added to fields by default.
167
    attr_accessor :large_reverse_association_tables
2✔
168

169
    # Whether the backtrace should be shown in rescued errors.
170
    attr_accessor :show_backtrace
2✔
171

172
    # Disable `rescue_from` on the controller.
173
    attr_accessor :disable_rescue_from
2✔
174

175
    # The default label fields to use when generating labels for `has_many` associations.
176
    attr_accessor :label_fields
2✔
177

178
    # The default search columns to use when generating search filters.
179
    attr_accessor :search_columns
2✔
180

181
    # Helper to set global read/write only fields.
182
    attr_accessor :read_only_fields
2✔
183
    attr_accessor :write_only_fields
2✔
184

185
    # List of acronyms to be inflected in controller titles and field labels.
186
    attr_accessor :inflect_acronyms
2✔
187

188
    # Option to use vendored assets (requires sprockets or propshaft) rather than linking to
189
    # external assets (the default).
190
    attr_accessor :use_vendored_assets
2✔
191

192
    def initialize
2✔
193
      self.register_api_renderer = true
2✔
194
      self.auto_finalize = true
2✔
195
      self.freeze_config = true
2✔
196

197
      self.show_backtrace = Rails.env.development?
2✔
198

199
      self.label_fields = DEFAULT_LABEL_FIELDS
2✔
200
      self.search_columns = DEFAULT_SEARCH_COLUMNS
2✔
201
      self.read_only_fields = DEFAULT_READ_ONLY_FIELDS
2✔
202
      self.write_only_fields = DEFAULT_WRITE_ONLY_FIELDS
2✔
203
      self.inflect_acronyms = DEFAULT_INFLECT_ACRONYMS
2✔
204
    end
205
  end
206

207
  def self.config
2✔
208
    @config ||= Config.new
1,596✔
209
  end
210

211
  def self.configure
2✔
UNCOV
212
    yield(self.config)
×
213
  end
214

215
  def self.features
2✔
UNCOV
216
    @features ||= {}
×
217
  end
218

219
  def self.deprecator
2✔
220
    @deprecator ||= ActiveSupport::Deprecation.new("2.0", "REST Framework")
16✔
221
  end
222
end
223

224
require_relative "rest_framework/engine"
2✔
225
require_relative "rest_framework/errors"
2✔
226
require_relative "rest_framework/filters"
2✔
227
require_relative "rest_framework/mixins"
2✔
228
require_relative "rest_framework/paginators"
2✔
229
require_relative "rest_framework/routers"
2✔
230
require_relative "rest_framework/serializers"
2✔
231
require_relative "rest_framework/utils"
2✔
232
require_relative "rest_framework/version"
2✔
233

234
require_relative "rest_framework/controller"
2✔
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