Skip to content

Commit

Permalink
Adding an S3File factory to clean up tests (#977)
Browse files Browse the repository at this point in the history
Co-authored-by: Bess Sadler <bess.sadler@princeton.edu>
  • Loading branch information
carolyncole and bess authored Feb 10, 2023
1 parent ca29a4a commit 03da34c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 65 deletions.
73 changes: 8 additions & 65 deletions spec/controllers/works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,7 @@
"https://example-bucket.s3.amazonaws.com/"
end

let(:file1) do
S3File.new(
filename: "anyfile.txt",
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file1) { FactoryBot.build :s3_file, filename: "anyfile.txt", last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:fake_s3_service) { stub_s3 }

before do
Expand Down Expand Up @@ -269,22 +262,8 @@
end

let(:fake_s3_service) { stub_s3 }
let(:file1) do
S3File.new(
filename: uploaded_file1.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file2) do
S3File.new(
filename: uploaded_file2.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file1) { FactoryBot.build :s3_file, filename: uploaded_file1.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:file2) { FactoryBot.build :s3_file, filename: uploaded_file2.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }

before do
# This is utilized for active record to send the file to S3
Expand Down Expand Up @@ -372,47 +351,11 @@
end

let(:fake_s3_service) { stub_s3 }
let(:file1) do
S3File.new(
filename: temp_file1.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file2) do
S3File.new(
filename: temp_file2.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file3) do
S3File.new(
filename: temp_file3.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end

let(:replaced_file1) do
S3File.new(
filename: uploaded_file1.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:replaced_file3) do
S3File.new(
filename: uploaded_file2.path,
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file1) { FactoryBot.build :s3_file, filename: temp_file1.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:file2) { FactoryBot.build :s3_file, filename: temp_file2.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:file3) { FactoryBot.build :s3_file, filename: temp_file3.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:replaced_file1) { FactoryBot.build :s3_file, filename: uploaded_file1.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }
let(:replaced_file3) { FactoryBot.build :s3_file, filename: uploaded_file2.path, last_modified: Time.parse("2022-04-21T18:29:40.000Z") }

before do
# This is utilized for active record to send the file to S3
Expand Down
15 changes: 15 additions & 0 deletions spec/factories/s3_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

FactoryBot.define do
factory :s3_file, class: "S3File" do
filename { "anyfile.txt" }
last_modified { Time.zone.now }
size { 10_759 }
checksum { "abc123" }
query_service { nil }
initialize_with do
new(filename: filename, last_modified: last_modified, size: size,
checksum: checksum, query_service: query_service)
end
end
end

0 comments on commit 03da34c

Please sign in to comment.