Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem 'simplecov'
end

group :production do
gem 'pg'
end

gem 'aws-sdk-s3', '~> 1'
gem 'aws-sdk-s3', '~> 1'
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ GEM
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
docile (1.4.1)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
Expand Down Expand Up @@ -256,6 +257,12 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -318,6 +325,7 @@ DEPENDENCIES
rails (~> 7.1.3, >= 7.1.3.4)
rubocop
selenium-webdriver
simplecov
sprockets-rails
sqlite3 (~> 1.4)
stimulus-rails
Expand Down
5 changes: 2 additions & 3 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class Message < ApplicationRecord
# https://blade.ruby-lang.org/ruby-talk/410000 is not.
self.skip_time_zone_conversion_for_attributes = [:published_at]

def self.from_s3(list_name, list_seq)
client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION)
obj = client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list_name}/#{list_seq}")
def self.from_s3(list_name, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list_name}/#{list_seq}")

m = self.from_string(obj.body.read)
m.list_id = List.find_by_name(list_name).id
Expand Down
4 changes: 4 additions & 0 deletions test/models/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class ListTest < ActiveSupport::TestCase
test 'name' do
assert_equal 'ruby-list', List::find_by_name('ruby-list').name
end

test 'find_by_id' do
assert_equal 'ruby-list', List.find_by_id(1).name
end
end
12 changes: 12 additions & 0 deletions test/models/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ class MessageTest < ActiveSupport::TestCase

assert_equal DateTime.parse('2005-12-15T19:32:40+09:00'), m.published_at
end

test 'from_s3' do
s3_client = Aws::S3::Client.new(stub_responses: true)
s3_client.stub_responses(:get_object, body: <<END_OF_BODY)
Subject: [ruby-list:1] Hello
From: alice@...
Date: 2005-12-15T19:32:40+09:00

Hello, world!
END_OF_BODY
Message.from_s3('ruby-list', 1234, s3_client)
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require 'simplecov'
SimpleCov.start 'rails'
SimpleCov.minimum_coverage 50

ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"


module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
Expand Down