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

pulibrary / tigerdata-app / 1f9ee909-20b2-467d-b493-b5be4964430d

22 Oct 2025 04:57PM UTC coverage: 91.212%. Remained the same
1f9ee909-20b2-467d-b493-b5be4964430d

push

circleci

web-flow
Fixing flaky tests (#2080)

10 times out of 10 one of these tests would fail for me locally.

Really we just have to look at the page for something new so that we are
sure the controller action has finished before we check for something
that is not waiting.

2740 of 3004 relevant lines covered (91.21%)

755.12 hits per line

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

100.0
/app/services/xml_element_builder.rb
1
# frozen_string_literal: true
2
class XmlElementBuilder < XmlNodeBuilder
5✔
3
  attr_reader :presenter, :name, :attributes, :content
5✔
4
  alias entry content
5✔
5
  delegate :blank?, to: :content
5✔
6

7
  # @return [Nokogiri::XML::Element] the XML element node
8
  def element
5✔
9
    @element ||= begin
9,362✔
10
                   created = @document.create_element(name)
3,166✔
11
                   @document.root = created
3,166✔
12
                   created
3,166✔
13
                 end
14
  end
15

16
  # @return [Nokogiri::XML::Element] the XML element node
17
  def build_attributes
5✔
18
    attributes.each do |key, attr_entry|
3,260✔
19
      value = attr_entry
6,308✔
20
      if attr_entry.is_a?(Hash) && attr_entry.key?(:object_method)
6,308✔
21
        allow_empty_attr = attr_entry.fetch(:allow_empty, true)
1,094✔
22

23
        message = attr_entry[:object_method]
1,094✔
24
        method_args = attr_entry[:args] || []
1,094✔
25
        method_args = @default_method_args + method_args
1,094✔
26
        value = presenter.send(message, *method_args)
1,094✔
27

28
        raise ArgumentError, "Value for #{key} cannot be nil" if value.nil? && !allow_empty_attr
1,086✔
29
      end
30

31
      element[key] = value unless value.nil?
6,214✔
32
    end
33

34
    element
3,166✔
35
  end
36

37
  # @return [String] the content for the XML element
38
  def build_content!
5✔
39
    allow_empty_content = entry.fetch(:allow_empty, true)
1,994✔
40

41
    message = entry[:object_method]
1,994✔
42
    method_args = entry[:args] || []
1,994✔
43
    method_args = @default_method_args + method_args
1,994✔
44
    @content = presenter.send(message, *method_args)
1,994✔
45

46
    raise ArgumentError, "Content for #{name} cannot be nil" if content.nil? && !allow_empty_content
1,994✔
47
    content
1,908✔
48
  end
49

50
  # rubocop:disable Metrics/AbcSize
51
  # rubocop:disable Metrics/CyclomaticComplexity
52
  # rubocop:disable Metrics/MethodLength
53
  # rubocop:disable Metrics/PerceivedComplexity
54
  #
55
  # @return [Nokogiri::XML::Element]
56
  def build
5✔
57
    if entry.is_a?(Hash) && entry.key?(:object_method)
3,346✔
58
      build_content!
1,994✔
59
    end
60

61
    built = build_attributes
3,260✔
62
    built.content = content
3,166✔
63

64
    built
3,166✔
65
  rescue ArgumentError => arg_error
66
    Rails.logger.warn("Error building XML project metadata: #{arg_error.message}")
180✔
67
    nil
180✔
68
  end
69
  # rubocop:enable Metrics/PerceivedComplexity
70
  # rubocop:enable Metrics/MethodLength
71
  # rubocop:enable Metrics/CyclomaticComplexity
72
  # rubocop:enable Metrics/AbcSize
73

74
  # @return [Nokogiri::XML::Element] the XML element node
75
  def node
5✔
76
    @node ||= build
6,420✔
77
  end
78

79
  def add_child(child)
5✔
80
    return if child.nil?
3,254✔
81

82
    # @see https://nokogiri.org/rdoc/Nokogiri/XML/Node.html#method-i-clone
83
    level = 1
3,074✔
84
    cloned = child.clone(level, document)
3,074✔
85
    node.add_child(cloned)
3,074✔
86

87
    cloned
3,074✔
88
  end
89

90
  # @param [ProjectXmlPresenter] presenter
91
  # @param [String] name
92
  # @param [Hash] attributes
93
  # @param [String] content
94
  # @param [Integer] index the index for the element (when there are multiple sibling nodes)
95
  # @param [Hash] options
96
  def initialize(presenter:, name:, attributes: {}, content: nil, index: nil, **options)
5✔
97
    super(**options)
3,346✔
98

99
    @presenter = presenter
3,346✔
100
    @name = name
3,346✔
101

102
    @attributes = attributes
3,346✔
103
    @content = content
3,346✔
104

105
    @index = index
3,346✔
106

107
    @default_method_args = []
3,346✔
108
    @default_method_args << @index unless @index.nil?
3,346✔
109
  end
110
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

© 2025 Coveralls, Inc