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

gregschmit / rails-rest-framework / 24538335705

16 Apr 2026 10:51PM UTC coverage: 88.164% (-2.7%) from 90.879%
24538335705

push

github

gregschmit
Refactor mixins into single Controller include.

Makes overloading builtin actions simpler.
Keep mixins backwards compatible, but replace with `model`, `bulk`, and
`excluded_actions` config attributes.
Remove UnknownModelError; no more auto model detection.
Update README.md.
Update test/demo APIs to use the new style, keep plain API on old mixin
style.
Ensure usage of old mixins triggers deprecation notices.
Update dependencies.
Update GH actions checkout to v6.

445 of 548 new or added lines in 13 files covered. (81.2%)

1095 of 1242 relevant lines covered (88.16%)

214.01 hits per line

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

89.66
/lib/rest_framework/controller/bulk.rb
1
module RESTFramework::Controller
2✔
2
  # Serialize the records, but also include any errors that might exist. This is used for bulk
3
  # actions, however we include it here so the helper is available everywhere.
4
  def bulk_serialize(records)
2✔
5
    # This is kinda slow, so perhaps we should eventually integrate `errors` serialization into
6
    # the serializer directly. This would fail for active model serializers, but maybe we don't
7
    # care?
8
    s = RESTFramework::Utils.wrap_ams(self.get_serializer_class)
12✔
9
    records.map do |record|
12✔
10
      s.new(record, controller: self).serialize.merge!({ errors: record.errors.presence }.compact)
24✔
11
    end
12
  end
13

14
  # Perform the `create` call, and return the collection of (possibly) created records.
15
  def create_all!
2✔
16
    create_data = self.get_create_params(bulk_mode: true)[:_json]
4✔
17

18
    # Perform bulk create in a transaction.
19
    ActiveRecord::Base.transaction { self.create_from.create(create_data) }
8✔
20
  end
21

22
  def update_all
2✔
23
    records = self.update_all!
4✔
24
    serialized_records = self.bulk_serialize(records)
4✔
25
    render(api: serialized_records)
4✔
26
  end
27

28
  # Perform the `update` call and return the collection of (possibly) updated records.
29
  def update_all!
2✔
30
    pk = self.class.model.primary_key
4✔
31
    data = if params[:_json].is_a?(Array)
4✔
32
      self.get_create_params(bulk_mode: :update)[:_json].index_by { |r| r[pk] }
12✔
33
    else
NEW
34
      create_params = self.get_create_params
×
NEW
35
      { create_params[pk] => create_params }
×
36
    end
37

38
    # Perform bulk update in a transaction.
39
    ActiveRecord::Base.transaction { self.get_recordset.update(data.keys, data.values) }
8✔
40
  end
41

42
  def destroy_all
2✔
43
    if params[:_json].is_a?(Array)
4✔
44
      records = self.destroy_all!
4✔
45
      serialized_records = self.bulk_serialize(records)
4✔
46
      return render(api: serialized_records)
4✔
47
    end
48

NEW
49
    render(
×
50
      api: { message: "Bulk destroy requires an array of primary keys as input." }, status: 400,
51
    )
52
  end
53

54
  # Perform the `destroy!` call and return the destroyed (and frozen) record.
55
  def destroy_all!
2✔
56
    pk = self.class.model.primary_key
4✔
57
    destroy_data = self.request.request_parameters[:_json]
4✔
58

59
    # Perform bulk destroy in a transaction.
60
    ActiveRecord::Base.transaction { self.get_recordset.where(pk => destroy_data).destroy_all }
8✔
61
  end
62
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