acts_as_readable 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +8 -1
- data/lib/acts_as_readable/acts_as_readable.rb +9 -7
- data/spec/acts_as_readable_spec.rb +237 -222
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f1b10303846fe0f6adb4dd943ca37ba592463bfaf57b6dbf8f55008bca9d9f
|
4
|
+
data.tar.gz: c108f52d20a6b6e32f76b57486a87dffcea367b33e2b9d11845761cbde28bb76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdf040047e4f4985c51d2bd1a0b3f207f4f8d6ee7c17f3732c5c93a09f89c2a842ec670e970ff5c8cb0f00dc0bf02fdbff9fe04b3d154b3881f4d52db17f209
|
7
|
+
data.tar.gz: 335b0e36faf70e2385bc806a5900a4eddaf66ab0e8fdf18b9c2850a041329408c89b0c8d6107eb29a596bcee7c3217522fc5a2907d625b202fec5ce61d19f0f7
|
data/README.rdoc
CHANGED
@@ -32,6 +32,13 @@ TODO...
|
|
32
32
|
|
33
33
|
bob.readings # => [<Reading 1>]
|
34
34
|
|
35
|
+
=== Upgrading from 2.3.x to 2.4.0
|
36
|
+
|
37
|
+
Version 2.4.0 now supports reading and querying against STI subclasses, even when the read and queried subclass don't
|
38
|
+
match. This requires you to migrate the `readings.readable_type` column data to the base class name of the stored class
|
39
|
+
name, as in versions prior to 2.4.0 the column stored the class name of whatever instance was being read, event STI
|
40
|
+
subclasses.
|
41
|
+
|
35
42
|
=== Testing
|
36
43
|
|
37
44
|
There are multiple gemfiles available for testing against different Rails versions. Set `BUNDLE_GEMFILE` to target them, e.g.
|
@@ -40,4 +47,4 @@ There are multiple gemfiles available for testing against different Rails versio
|
|
40
47
|
BUNDLE_GEMFILE=gemfiles/rails7.gemfile bundle exec rspec
|
41
48
|
|
42
49
|
|
43
|
-
Copyright (c)
|
50
|
+
Copyright (c) 2024 Culture Code Software Consulting. Released under the MIT license
|
@@ -6,8 +6,6 @@ module ActsAsReadable
|
|
6
6
|
class_attribute :acts_as_readable_options
|
7
7
|
self.acts_as_readable_options = options
|
8
8
|
|
9
|
-
User.has_many :readings, :dependent => :delete_all
|
10
|
-
|
11
9
|
has_many :readings, :as => :readable, :dependent => :delete_all
|
12
10
|
has_many :readers, lambda { where :readings => {:state => 'read'} }, :through => :readings, :source => :user
|
13
11
|
|
@@ -46,7 +44,11 @@ module ActsAsReadable
|
|
46
44
|
end
|
47
45
|
|
48
46
|
def self.outer_join_readings(scope, user)
|
49
|
-
scope.joins("LEFT OUTER JOIN readings ON readings.readable_type = '#{scope.model
|
47
|
+
scope.joins("LEFT OUTER JOIN readings ON readings.readable_type = '#{readable_type(scope.model)}' AND readings.readable_id = #{scope.model.table_name}.id AND readings.user_id = #{user.id}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.readable_type(readable_class)
|
51
|
+
readable_class.base_class.name
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -54,7 +56,7 @@ module ActsAsReadable
|
|
54
56
|
# Find all the readings of the readables by the user in a single SQL query and cache them in the readables for use in the view.
|
55
57
|
def cache_readings_for(readables, user)
|
56
58
|
readings = []
|
57
|
-
Reading.where(:readable_type =>
|
59
|
+
Reading.where(:readable_type => HelperMethods.readable_type(self), :readable_id => readables.collect(&:id), :user_id => user.id).each do |reading|
|
58
60
|
readings[reading.readable_id] = reading
|
59
61
|
end
|
60
62
|
|
@@ -69,7 +71,7 @@ module ActsAsReadable
|
|
69
71
|
# If a :cache option has been set in acts_as_readable, a timestamp will be updated on the user instead of creating individual readings for each record
|
70
72
|
def read_by!(user)
|
71
73
|
if user.has_attribute?(acts_as_readable_options[:cache])
|
72
|
-
Reading.where(:user_id => user.id, :readable_type =>
|
74
|
+
Reading.where(:user_id => user.id, :readable_type => HelperMethods.readable_type(self)).delete_all
|
73
75
|
user.update_column(acts_as_readable_options[:cache], Time.now)
|
74
76
|
else
|
75
77
|
unread_by(user).find_each do |record|
|
@@ -88,7 +90,7 @@ module ActsAsReadable
|
|
88
90
|
|
89
91
|
def read_by!(user)
|
90
92
|
# Find an existing reading and update the record so we can know when the thing was first read, and the last time we read it
|
91
|
-
reading = Reading.find_or_initialize_by(:user_id => user.id, :readable_id => self.id, :readable_type => self.class
|
93
|
+
reading = Reading.find_or_initialize_by(:user_id => user.id, :readable_id => self.id, :readable_type => HelperMethods.readable_type(self.class))
|
92
94
|
reading.updated_at = Time.now # Explicitly set the read time to now in order to force a save in case we haven't changed anything else about the reading
|
93
95
|
reading.state = :read
|
94
96
|
reading.save!
|
@@ -98,7 +100,7 @@ module ActsAsReadable
|
|
98
100
|
end
|
99
101
|
|
100
102
|
def unread_by!(user)
|
101
|
-
reading = Reading.find_or_initialize_by(:user_id => user.id, :readable_id => self.id, :readable_type => self.class
|
103
|
+
reading = Reading.find_or_initialize_by(:user_id => user.id, :readable_id => self.id, :readable_type => HelperMethods.readable_type(self.class))
|
102
104
|
reading.state = :unread
|
103
105
|
reading.save!
|
104
106
|
end
|
@@ -2,235 +2,250 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'acts_as_readable' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
5
|
+
shared_examples_for 'a readable class' do |readable_class, queryable_class|
|
6
|
+
before(:each) do
|
7
|
+
@readable = readable_class.create
|
8
|
+
@queryable = @readable.becomes!(queryable_class)
|
9
|
+
@user = User.create
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "the unread scope" do
|
13
|
+
it "should not return records explicitly marked as read" do
|
14
|
+
@readable.read_by! @user
|
15
|
+
expect(queryable_class.unread_by(@user)).not_to include(@queryable)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return records without readings if the user hasn't 'read all'" do
|
19
|
+
expect(queryable_class.unread_by(@user)).to include(@queryable)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return records explicitly marked as unread if the user hasn't 'read all'" do
|
23
|
+
@readable.unread_by! @user
|
24
|
+
expect(queryable_class.unread_by(@user)).to include(@queryable)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return records explicitly marked as unread if the user has 'read all' before the record was marked unread" do
|
28
|
+
readable_class.read_by! @user
|
29
|
+
@readable.unread_by! @user
|
30
|
+
expect(queryable_class.unread_by(@user)).to include(@queryable)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return records explicitly marked as unread after the user 'read all'" do
|
34
|
+
@readable.read_by! @user
|
35
|
+
readable_class.read_by! @user
|
36
|
+
@readable.unread_by! @user
|
37
|
+
expect(queryable_class.unread_by(@user)).to include(@queryable)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
41
|
+
@readable.unread_by! @user
|
42
|
+
readable_class.read_by! @user
|
43
|
+
expect(queryable_class.unread_by(@user)).not_to include(@queryable)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not return records that have been updated since they were last read" do
|
47
|
+
@readable.read_by! @user
|
48
|
+
@readable.touch
|
49
|
+
expect(queryable_class.unread_by(@user)).not_to include(@queryable)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return records that have been updated since they were last unread" do
|
53
|
+
@readable.unread_by! @user
|
54
|
+
@readable.touch
|
55
|
+
expect(queryable_class.unread_by(@user)).to include(@queryable)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "the read scope" do
|
60
|
+
it "should not return records without readings if the user has not 'read all'" do
|
61
|
+
expect(queryable_class.read_by(@user)).not_to include(@queryable)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return records without readings if the user has 'read all' since the last time the record was updated" do
|
65
|
+
readable_class.read_by! @user
|
66
|
+
expect(queryable_class.read_by(@user)).to include(@queryable)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return records explicitly marked as read if the user hasn't 'read all'" do
|
70
|
+
@readable.read_by! @user
|
71
|
+
expect(queryable_class.read_by(@user)).to include(@queryable)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return records explicitly marked as read if the user has 'read all' before the record was marked read" do
|
75
|
+
readable_class.read_by! @user
|
76
|
+
@readable.read_by! @user
|
77
|
+
expect(queryable_class.read_by(@user)).to include(@queryable)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not return records explicitly marked as unread after the user 'read all'" do
|
81
|
+
@readable.read_by! @user
|
82
|
+
readable_class.read_by! @user
|
83
|
+
@readable.unread_by! @user
|
84
|
+
expect(queryable_class.read_by(@user)).not_to include(@queryable)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
88
|
+
@readable.unread_by! @user
|
89
|
+
readable_class.read_by! @user
|
90
|
+
expect(queryable_class.read_by(@user)).to include(@queryable)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return records that have been updated since they were last read" do
|
94
|
+
@readable.read_by! @user
|
95
|
+
@readable.touch
|
96
|
+
expect(queryable_class.read_by(@user)).to include(@queryable)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "the latest_update_read_by scope" do
|
101
|
+
it "should return records without readings if the user has 'read all' since the last time the record was updated" do
|
102
|
+
readable_class.read_by! @user
|
103
|
+
expect(queryable_class.latest_update_read_by(@user)).to include(@queryable)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return records explicitly marked as read if the user hasn't 'read all'" do
|
107
|
+
@readable.read_by! @user
|
108
|
+
expect(queryable_class.latest_update_read_by(@user)).to include(@queryable)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return records explicitly marked as read if the user has 'read all' before the record was marked unread" do
|
112
|
+
readable_class.read_by! @user
|
113
|
+
@readable.read_by! @user
|
114
|
+
expect(queryable_class.latest_update_read_by(@user)).to include(@queryable)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
118
|
+
@readable.unread_by! @user
|
119
|
+
readable_class.read_by! @user
|
120
|
+
expect(queryable_class.latest_update_read_by(@user)).to include(@queryable)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not return records that have been updated since they were last read" do
|
124
|
+
@readable.read_by! @user
|
125
|
+
@readable.touch
|
126
|
+
expect(queryable_class.latest_update_read_by(@user)).not_to include(@queryable)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return records updated after being read after a bulk read_by" do
|
130
|
+
@readable.read_by! @user
|
131
|
+
@readable.touch
|
132
|
+
readable_class.read_by! @user
|
133
|
+
expect(queryable_class.latest_update_read_by(@user)).to include(@queryable)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "the latest_update_unread_by scope" do
|
138
|
+
it "should not return records explicitly marked as read" do
|
139
|
+
@readable.read_by! @user
|
140
|
+
expect(queryable_class.latest_update_unread_by(@user)).not_to include(@queryable)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return records without readings if the user hasn't 'read all'" do
|
144
|
+
expect(queryable_class.latest_update_unread_by(@user)).to include(@queryable)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return records explicitly marked as unread if the user hasn't 'read all'" do
|
148
|
+
@readable.unread_by! @user
|
149
|
+
expect(queryable_class.latest_update_unread_by(@user)).to include(@queryable)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return records explicitly marked as unread if the user has 'read all' before the record was marked unread" do
|
153
|
+
readable_class.read_by! @user
|
154
|
+
@readable.unread_by! @user
|
155
|
+
expect(queryable_class.latest_update_unread_by(@user)).to include(@queryable)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should not return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
159
|
+
@readable.unread_by! @user
|
160
|
+
readable_class.read_by! @user
|
161
|
+
expect(queryable_class.latest_update_unread_by(@user)).not_to include(@queryable)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return records that have been updated since they were last read" do
|
165
|
+
@readable.read_by! @user
|
166
|
+
@readable.touch
|
167
|
+
expect(queryable_class.latest_update_unread_by(@user)).to include(@queryable)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "when checking a specific record for read_by?" do
|
172
|
+
it "should return true if the record hasn't explicitly been read, but the user has 'read all' since the record was created" do
|
173
|
+
readable_class.read_by! @user
|
174
|
+
expect(@queryable.read_by?(@user)).to be_truthy
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should return true if the record hasn't explicitly been read and the user has 'read all' since the record was created but not since it was updated" do
|
178
|
+
readable_class.read_by! @user
|
179
|
+
@readable.touch
|
180
|
+
expect(@queryable.read_by?(@user)).to be_truthy
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should return true if the record has been explicitly marked as read and the user hasn't 'read all'" do
|
184
|
+
@readable.read_by! @user
|
185
|
+
expect(@queryable.read_by?(@user)).to be_truthy
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return false if the user 'read all' before and then marked the record as unread" do
|
189
|
+
readable_class.read_by! @user
|
190
|
+
@readable.unread_by! @user
|
191
|
+
expect(@queryable.read_by?(@user)).to be_falsey
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should return true if the user has explicitly marked it as unread and then 'reads all'" do
|
195
|
+
@readable.unread_by! @user
|
196
|
+
readable_class.read_by! @user
|
197
|
+
expect(@queryable.read_by?(@user)).to be_truthy
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "when checking a specific record for latest_update_read_by?" do
|
202
|
+
it "should return true if the record hasn't explicitly been read, but the user has 'read all' since the record was updated" do
|
203
|
+
readable_class.read_by! @user
|
204
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_truthy
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return false if the record hasn't explicitly been read and the user has 'read all' since the record was created but not since it was updated" do
|
208
|
+
readable_class.read_by! @user
|
209
|
+
@readable.touch
|
210
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_falsey
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should return true if the record has been explicitly marked as read and the user hasn't 'read all'" do
|
214
|
+
@readable.read_by! @user
|
215
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_truthy
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should return false if the user 'read all' before and then marked the record as unread" do
|
219
|
+
readable_class.read_by! @user
|
220
|
+
@readable.unread_by! @user
|
221
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_falsey
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should return true if the user has explicitly marked it as unread and then 'reads all'" do
|
225
|
+
@readable.unread_by! @user
|
226
|
+
readable_class.read_by! @user
|
227
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_truthy
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should return false if the user 'read all' before and then marked the record as unread using cached readings" do
|
231
|
+
readable_class.read_by! @user
|
232
|
+
@readable.unread_by! @user
|
233
|
+
readable_class.cache_readings_for([@readable], @user)
|
234
|
+
expect(@queryable.latest_update_read_by?(@user)).to be_falsey
|
235
|
+
end
|
54
236
|
end
|
55
237
|
end
|
56
238
|
|
57
|
-
|
58
|
-
|
59
|
-
expect( Comment.read_by(@user) ).not_to include(@comment)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return records without readings if the user has 'read all' since the last time the record was updated" do
|
63
|
-
Comment.read_by! @user
|
64
|
-
expect( Comment.read_by(@user) ).to include(@comment)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return records explicitly marked as read if the user hasn't 'read all'" do
|
68
|
-
@comment.read_by! @user
|
69
|
-
expect( Comment.read_by(@user) ).to include(@comment)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return records explicitly marked as read if the user has 'read all' before the record was marked read" do
|
73
|
-
Comment.read_by! @user
|
74
|
-
@comment.read_by! @user
|
75
|
-
expect( Comment.read_by(@user) ).to include(@comment)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not return records explicitly marked as unread after the user 'read all'" do
|
79
|
-
@comment.read_by! @user
|
80
|
-
Comment.read_by! @user
|
81
|
-
@comment.unread_by! @user
|
82
|
-
expect( Comment.read_by(@user) ).not_to include(@comment)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
86
|
-
@comment.unread_by! @user
|
87
|
-
Comment.read_by! @user
|
88
|
-
expect( Comment.read_by(@user) ).to include(@comment)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should return records that have been updated since they were last read" do
|
92
|
-
@comment.read_by! @user
|
93
|
-
@comment.touch
|
94
|
-
expect( Comment.read_by(@user) ).to include(@comment)
|
95
|
-
end
|
239
|
+
context 'the readable is a base class' do
|
240
|
+
it_behaves_like 'a readable class', Comment, Comment
|
96
241
|
end
|
97
242
|
|
98
|
-
|
99
|
-
|
100
|
-
Comment.read_by! @user
|
101
|
-
expect( Comment.latest_update_read_by(@user) ).to include(@comment)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should return records explicitly marked as read if the user hasn't 'read all'" do
|
105
|
-
@comment.read_by! @user
|
106
|
-
expect( Comment.latest_update_read_by(@user) ).to include(@comment)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should return records explicitly marked as read if the user has 'read all' before the record was marked unread" do
|
110
|
-
Comment.read_by! @user
|
111
|
-
@comment.read_by! @user
|
112
|
-
expect( Comment.latest_update_read_by(@user) ).to include(@comment)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
116
|
-
@comment.unread_by! @user
|
117
|
-
Comment.read_by! @user
|
118
|
-
expect( Comment.latest_update_read_by(@user) ).to include(@comment)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should not return records that have been updated since they were last read" do
|
122
|
-
@comment.read_by! @user
|
123
|
-
@comment.touch
|
124
|
-
expect( Comment.latest_update_read_by(@user) ).not_to include(@comment)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should return records updated after being read after a bulk read_by" do
|
128
|
-
@comment.read_by! @user
|
129
|
-
@comment.touch
|
130
|
-
Comment.read_by! @user
|
131
|
-
expect( Comment.latest_update_read_by(@user) ).to include(@comment)
|
132
|
-
end
|
243
|
+
context 'when reading an STI record' do
|
244
|
+
it_behaves_like 'a readable class', PrivateComment, PrivateComment
|
133
245
|
end
|
134
246
|
|
135
|
-
|
136
|
-
|
137
|
-
@comment.read_by! @user
|
138
|
-
expect( Comment.latest_update_unread_by(@user) ).not_to include(@comment)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should return records without readings if the user hasn't 'read all'" do
|
142
|
-
expect( Comment.latest_update_unread_by(@user) ).to include(@comment)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should return records explicitly marked as unread if the user hasn't 'read all'" do
|
146
|
-
@comment.unread_by! @user
|
147
|
-
expect( Comment.latest_update_unread_by(@user) ).to include(@comment)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should return records explicitly marked as unread if the user has 'read all' before the record was marked unread" do
|
151
|
-
Comment.read_by! @user
|
152
|
-
@comment.unread_by! @user
|
153
|
-
expect( Comment.latest_update_unread_by(@user) ).to include(@comment)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should not return records explicitly marked as unread if the user has 'read all' after the record was marked unread" do
|
157
|
-
@comment.unread_by! @user
|
158
|
-
Comment.read_by! @user
|
159
|
-
expect( Comment.latest_update_unread_by(@user) ).not_to include(@comment)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should return records that have been updated since they were last read" do
|
163
|
-
@comment.read_by! @user
|
164
|
-
@comment.touch
|
165
|
-
expect( Comment.latest_update_unread_by(@user) ).to include(@comment)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "when checking a specific record for read_by?" do
|
170
|
-
it "should return true if the record hasn't explicitly been read, but the user has 'read all' since the record was created" do
|
171
|
-
Comment.read_by! @user
|
172
|
-
expect( @comment.read_by?(@user) ).to be_truthy
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should return true if the record hasn't explicitly been read and the user has 'read all' since the record was created but not since it was updated" do
|
176
|
-
Comment.read_by! @user
|
177
|
-
@comment.touch
|
178
|
-
expect( @comment.read_by?(@user) ).to be_truthy
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should return true if the record has been explicitly marked as read and the user hasn't 'read all'" do
|
182
|
-
@comment.read_by! @user
|
183
|
-
expect( @comment.read_by?(@user) ).to be_truthy
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should return false if the user 'read all' before and then marked the record as unread" do
|
187
|
-
Comment.read_by! @user
|
188
|
-
@comment.unread_by! @user
|
189
|
-
expect( @comment.read_by?(@user) ).to be_falsey
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should return true if the user has explicitly marked it as unread and then 'reads all'" do
|
193
|
-
@comment.unread_by! @user
|
194
|
-
Comment.read_by! @user
|
195
|
-
expect( @comment.read_by?(@user) ).to be_truthy
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "when checking a specific record for latest_update_read_by?" do
|
200
|
-
it "should return true if the record hasn't explicitly been read, but the user has 'read all' since the record was updated" do
|
201
|
-
Comment.read_by! @user
|
202
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_truthy
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should return false if the record hasn't explicitly been read and the user has 'read all' since the record was created but not since it was updated" do
|
206
|
-
Comment.read_by! @user
|
207
|
-
@comment.touch
|
208
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_falsey
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should return true if the record has been explicitly marked as read and the user hasn't 'read all'" do
|
212
|
-
@comment.read_by! @user
|
213
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_truthy
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should return false if the user 'read all' before and then marked the record as unread" do
|
217
|
-
Comment.read_by! @user
|
218
|
-
@comment.unread_by! @user
|
219
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_falsey
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should return true if the user has explicitly marked it as unread and then 'reads all'" do
|
223
|
-
@comment.unread_by! @user
|
224
|
-
Comment.read_by! @user
|
225
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_truthy
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should return false if the user 'read all' before and then marked the record as unread using cached readings" do
|
229
|
-
Comment.read_by! @user
|
230
|
-
@comment.unread_by! @user
|
231
|
-
Comment.cache_readings_for([@comment], @user)
|
232
|
-
expect( @comment.latest_update_read_by?(@user) ).to be_falsey
|
233
|
-
end
|
247
|
+
context 'when reading an STI record and querying against the base class record' do
|
248
|
+
it_behaves_like 'a readable class', PrivateComment, Comment
|
234
249
|
end
|
235
250
|
end
|
236
251
|
`dropdb acts_as_readable_test`
|
data/spec/spec_helper.rb
CHANGED
@@ -17,6 +17,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
create_table :comments, :force => true do |t|
|
20
|
+
t.string :type
|
20
21
|
t.timestamps
|
21
22
|
end
|
22
23
|
|
@@ -35,6 +36,9 @@ class Comment < ActiveRecord::Base
|
|
35
36
|
acts_as_readable :cache => :comments_read_at
|
36
37
|
end
|
37
38
|
|
39
|
+
class PrivateComment < Comment
|
40
|
+
end
|
41
|
+
|
38
42
|
|
39
43
|
def debug_queries
|
40
44
|
logger = ActiveRecord::Base.logger
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_readable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Jakobsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|