• 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

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

13
  def create_all!
2✔
14
    pk = self.class.model.primary_key
4✔
15
    data = self.get_create_params(bulk_mode: true)[:_json]
4✔
16

17
    unless data&.is_a?(Array) && data.all? { |r| r.is_a?(ActionController::Parameters) }
12✔
UNCOV
18
      raise RESTFramework::InvalidBulkParametersError.new("Expected an array of objects.")
×
19
    end
20

21
    unless first_keys = data.first&.keys&.sort
4✔
UNCOV
22
      raise RESTFramework::InvalidBulkParametersError.new("Expected objects with attrs.")
×
23
    end
24
    unless data.all? { |r| r.keys.sort == first_keys }
12✔
UNCOV
25
      raise RESTFramework::InvalidBulkParametersError.new("All objects must have the same attrs.")
×
26
    end
27

28
    self.create_from.insert_all(data, unique_by: pk)
4✔
29
  end
30

31
  def update_all
2✔
32
    result = self.update_all!
4✔
33
    render(api: { result: result })
2✔
34
  end
35

36
  def update_all!
2✔
37
    pk = self.class.model.primary_key
4✔
38
    data = self.get_update_params(bulk_mode: :update)[:_json]
4✔
39

40
    unless data&.is_a?(Array) && data.all? { |r| r.is_a?(ActionController::Parameters) }
12✔
UNCOV
41
      raise RESTFramework::InvalidBulkParametersError.new("Expected an array of objects.")
×
42
    end
43

44
    data_ids = data.map { |r| r[pk] }.uniq
12✔
45
    if self.get_recordset.where(pk => data_ids).count != data_ids.length
4✔
UNCOV
46
      raise RESTFramework::InvalidBulkParametersError.new("Some objects not found.")
×
47
    end
48

49
    unless first_keys = data.first&.keys&.sort
4✔
UNCOV
50
      raise RESTFramework::InvalidBulkParametersError.new("Expected objects with attrs.")
×
51
    end
52
    unless data.all? { |r| r.keys.sort == first_keys }
12✔
53
      raise RESTFramework::InvalidBulkParametersError.new("All objects must have the same attrs.")
2✔
54
    end
55

56
    self.get_recordset.upsert_all(data, unique_by: pk)
2✔
57
  end
58

59
  def destroy_all
2✔
60
    deleted = self.destroy_all!
2✔
61
    render(api: { result: deleted })
2✔
62
  end
63

64
  def destroy_all!
2✔
65
    pk = self.class.model.primary_key
2✔
66
    data = self.get_destroy_params(bulk_mode: :destroy)[:_json]
2✔
67

68
    unless data&.is_a?(Array) && data.all? { |r| r.is_a?(String) || r.is_a?(Numeric) }
6✔
UNCOV
69
      raise RESTFramework::InvalidBulkParametersError.new("Expected an array of primary keys.")
×
70
    end
71

72
    self.get_recordset.where(pk => data).delete_all
2✔
73
  end
74
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