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

MushroomObserver / mushroom-observer / 14145714091

29 Mar 2025 12:39PM UTC coverage: 84.27% (-9.7%) from 93.985%
14145714091

Pull #2808

github

web-flow
Merge 0843c72fa into 6655216a6
Pull Request #2808: Convert Query to AR scopes

472 of 2300 new or added lines in 78 files covered. (20.52%)

1381 existing lines in 27 files now uncovered.

26557 of 31514 relevant lines covered (84.27%)

537.23 hits per line

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

0.0
/app/classes/query/scope_classes/comments.rb
1
# frozen_string_literal: true
2

NEW
3
class Query::ScopeClasses::Comments < Query::BaseAR
×
NEW
4
  def model
×
NEW
5
    Comment
×
NEW
6
  end
×
7

NEW
8
  def self.parameter_declarations
×
NEW
9
    super.merge(
×
NEW
10
      created_at: [:time],
×
NEW
11
      updated_at: [:time],
×
NEW
12
      id_in_set: [Comment],
×
NEW
13
      target: { id: AbstractModel, type: :string },
×
NEW
14
      types: [{ string: Comment::ALL_TYPE_TAGS }],
×
NEW
15
      summary_has: :string,
×
NEW
16
      content_has: :string,
×
NEW
17
      by_users: [User],
×
NEW
18
      for_user: User,
×
NEW
19
      pattern: :string
×
NEW
20
    )
×
NEW
21
  end
×
22

NEW
23
  def initialize_flavor
×
NEW
24
    add_sort_order_to_title
×
NEW
25
    add_owner_and_time_stamp_conditions
×
NEW
26
    add_id_in_set_condition
×
NEW
27
    add_for_user_condition
×
NEW
28
    add_for_target_condition
×
NEW
29
    add_pattern_condition
×
NEW
30
    add_string_enum_condition(Comment[:target_type], params[:types],
×
NEW
31
                              Comment::ALL_TYPE_TAGS)
×
NEW
32
    add_simple_search_condition(:summary)
×
NEW
33
    add_search_condition(:comment)
×
NEW
34
    super
×
NEW
35
  end
×
36

NEW
37
  def add_for_user_condition
×
NEW
38
    return if params[:for_user].blank?
×
39

NEW
40
    user = find_cached_parameter_instance(User, :for_user)
×
NEW
41
    @title_tag = :query_title_for_user
×
NEW
42
    @title_args[:user] = user.legal_name
×
43
    # where << "observations.user_id = '#{params[:for_user]}'"
NEW
44
    add_association_condition(Observation[:user_id], params[:for_user])
×
NEW
45
    @scopes = @scopes.joins(:observation)
×
NEW
46
  end
×
47

NEW
48
  def add_for_target_condition
×
NEW
49
    return if params[:target].blank?
×
50

NEW
51
    target = target_instance
×
NEW
52
    @title_tag = :query_title_for_target
×
NEW
53
    @title_args[:object] = target.unique_format_name
×
NEW
54
    @scopes = @scopes.for_target(target.id)
×
NEW
55
  end
×
56

NEW
57
  def target_instance
×
NEW
58
    type_param = params.dig(:target, :type)
×
NEW
59
    unless (type = Comment.safe_model_from_name(type_param))
×
NEW
60
      raise("The model #{type_param.inspect} does not support comments!")
×
NEW
61
    end
×
62

NEW
63
    type.safe_find(params.dig(:target, :id))
×
NEW
64
  end
×
65

NEW
66
  def search_fields
×
NEW
67
    (Comment[:summary] + Comment[:comment].coalesce(""))
×
NEW
68
  end
×
69

NEW
70
  def self.default_order
×
NEW
71
    :created_at
×
NEW
72
  end
×
NEW
73
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