Skip to content

Commit e7b3a44

Browse files
authored
Merge pull request #31 from ruby/coverage
test: test coverage should be at least 50%
2 parents 85e4e2c + 00bc8f2 commit e7b3a44

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ group :test do
6868
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
6969
gem "capybara"
7070
gem "selenium-webdriver"
71+
gem 'simplecov'
7172
end
7273

7374
group :production do
7475
gem 'pg'
7576
end
7677

77-
gem 'aws-sdk-s3', '~> 1'
78+
gem 'aws-sdk-s3', '~> 1'

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ GEM
121121
debug (1.9.2)
122122
irb (~> 1.10)
123123
reline (>= 0.3.8)
124+
docile (1.4.1)
124125
drb (2.2.1)
125126
erubi (1.13.0)
126127
globalid (1.2.1)
@@ -256,6 +257,12 @@ GEM
256257
rexml (~> 3.2, >= 3.2.5)
257258
rubyzip (>= 1.2.2, < 3.0)
258259
websocket (~> 1.0)
260+
simplecov (0.22.0)
261+
docile (~> 1.1)
262+
simplecov-html (~> 0.11)
263+
simplecov_json_formatter (~> 0.1)
264+
simplecov-html (0.13.1)
265+
simplecov_json_formatter (0.1.4)
259266
sprockets (4.2.1)
260267
concurrent-ruby (~> 1.0)
261268
rack (>= 2.2.4, < 4)
@@ -318,6 +325,7 @@ DEPENDENCIES
318325
rails (~> 7.1.3, >= 7.1.3.4)
319326
rubocop
320327
selenium-webdriver
328+
simplecov
321329
sprockets-rails
322330
sqlite3 (~> 1.4)
323331
stimulus-rails

app/models/message.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ class Message < ApplicationRecord
1010
# https://blade.ruby-lang.org/ruby-talk/410000 is not.
1111
self.skip_time_zone_conversion_for_attributes = [:published_at]
1212

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

1716
m = self.from_string(obj.body.read)
1817
m.list_id = List.find_by_name(list_name).id

test/models/list_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ class ListTest < ActiveSupport::TestCase
44
test 'name' do
55
assert_equal 'ruby-list', List::find_by_name('ruby-list').name
66
end
7+
8+
test 'find_by_id' do
9+
assert_equal 'ruby-list', List.find_by_id(1).name
10+
end
711
end

test/models/message_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ class MessageTest < ActiveSupport::TestCase
1414

1515
assert_equal DateTime.parse('2005-12-15T19:32:40+09:00'), m.published_at
1616
end
17+
18+
test 'from_s3' do
19+
s3_client = Aws::S3::Client.new(stub_responses: true)
20+
s3_client.stub_responses(:get_object, body: <<END_OF_BODY)
21+
Subject: [ruby-list:1] Hello
22+
From: alice@...
23+
Date: 2005-12-15T19:32:40+09:00
24+
25+
Hello, world!
26+
END_OF_BODY
27+
Message.from_s3('ruby-list', 1234, s3_client)
28+
end
1729
end

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
require 'simplecov'
2+
SimpleCov.start 'rails'
3+
SimpleCov.minimum_coverage 50
4+
15
ENV["RAILS_ENV"] ||= "test"
26
require_relative "../config/environment"
37
require "rails/test_help"
48

9+
510
module ActiveSupport
611
class TestCase
712
# Run tests in parallel with specified workers

0 commit comments

Comments
 (0)