Skip to content

Commit 847e25d

Browse files
committed
fix: fix and test reload_from_s3
1 parent e7b3a44 commit 847e25d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

app/models/message.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,21 @@ def self.from_string(str)
3737
published_at = DateTime.strptime(headers['Date'], '%Y-%m-%dT%H:%M:%S%:z')
3838

3939
self.new(
40-
body: body,
40+
body: Kconv.toutf8(body),
4141
subject: headers['Subject'],
4242
from: headers['From'],
4343
published_at: published_at,
4444
)
4545
end
4646

47-
def reload_from_s3
48-
m = self.from_s3(List.find_by_id(self.list_id).name, self.list_seq)
47+
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
48+
m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client)
4949

5050
self.body = m.body
5151
self.subject = m.subject
5252
self.from = from
5353
self.published_at = m.published_at
54+
55+
m
5456
end
5557
end

test/models/message_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@ class MessageTest < ActiveSupport::TestCase
2626
END_OF_BODY
2727
Message.from_s3('ruby-list', 1234, s3_client)
2828
end
29+
30+
test 'reload_from_s3' do
31+
s3_client = Aws::S3::Client.new(stub_responses: true)
32+
s3_client.stub_responses(:get_object, body: <<END_OF_BODY)
33+
Subject: [ruby-list:1] Hello
34+
From: alice@...
35+
Date: 2005-12-15T19:32:40+09:00
36+
37+
Hello, world!
38+
END_OF_BODY
39+
40+
m = Message.new
41+
m.list_id = 1
42+
m.list_seq = 1
43+
m.reload_from_s3(s3_client)
44+
assert_equal '[ruby-list:1] Hello', m.subject
45+
end
2946
end

0 commit comments

Comments
 (0)