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

ledermann / unread / #713

05 Oct 2024 01:41PM UTC coverage: 97.357%. Remained the same
#713

push

ledermann
Bump 0.14.0

221 of 227 relevant lines covered (97.36%)

45.86 hits per line

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

95.65
/lib/unread/readable_scopes.rb
1
module Unread
1✔
2
  module Readable
1✔
3
    module Scopes
1✔
4
      def join_read_marks(reader)
1✔
5
        assert_reader(reader)
100✔
6

7
        joins "LEFT JOIN #{ReadMark.quoted_table_name}
69✔
8
                ON #{ReadMark.quoted_table_name}.readable_type  = '#{readable_parent.name}'
9
               AND #{ReadMark.quoted_table_name}.readable_id    = #{quoted_table_name}.#{quoted_primary_key}
10
               AND #{ReadMark.quoted_table_name}.reader_id      = #{quoted(reader.id)}
11
               AND #{ReadMark.quoted_table_name}.reader_type    = #{quoted(reader.class.base_class.name)}
12
               AND #{ReadMark.quoted_table_name}.timestamp     >= #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])}"
13
      end
14

15
      def unread_by(reader)
1✔
16
        result = join_read_marks(reader)
67✔
17

18
        if global_time_stamp = reader.read_mark_global(self).try(:timestamp)
54✔
19
          result.where("#{ReadMark.quoted_table_name}.id IS NULL
48✔
20
                        AND #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} > ?", global_time_stamp)
21
        else
22
          result.where("#{ReadMark.quoted_table_name}.id IS NULL")
6✔
23
        end
24
      end
25

26
      def read_by(reader)
1✔
27
        result = join_read_marks(reader)
22✔
28

29
        if global_time_stamp = reader.read_mark_global(self).try(:timestamp)
10✔
30
          result.where("#{ReadMark.quoted_table_name}.id IS NOT NULL
6✔
31
                        OR #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} <= ?", global_time_stamp)
32
        else
33
          result.where("#{ReadMark.quoted_table_name}.id IS NOT NULL")
4✔
34
        end
35
      end
36

37
      def with_read_marks_for(reader)
1✔
38
        postgresql_string_cast = using_postgresql? ? '::varchar' : ''
11✔
39

40
        join_read_marks(reader).select("#{quoted_table_name}.*,
11✔
41
                                        #{ReadMark.quoted_table_name}.id AS read_mark_id,
42
                                        #{quoted(reader.class.base_class.name)}#{postgresql_string_cast} AS read_mark_reader_type,
43
                                        #{quoted(reader.id)} AS read_mark_reader_id")
44
      end
45

46
      def quoted(value)
1✔
47
        if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.2')
148✔
48
          quote_bound_value(connection, value)
148✔
49
        else
50
          quote_bound_value(value)
×
51
        end
52
      end
53
    end
54
  end
55
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