mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
base_spec_helper now defines configs that are universal, whereas spec_helper is for configs that are using DatabaseCleaner and Selenium. This means we can include the base_spec_helper in both the system test setup and the regular setup but separate the other configurations for each type.
55 lines
1.5 KiB
Ruby
55 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
describe TermsOfServiceFile do
|
|
let(:pdf) { File.open(Rails.root.join("public/Terms-of-service.pdf")) }
|
|
|
|
describe ".current" do
|
|
it "returns nil" do
|
|
expect(TermsOfServiceFile.current).to be_nil
|
|
end
|
|
|
|
it "returns the last one" do
|
|
existing = [
|
|
TermsOfServiceFile.create!(attachment: pdf),
|
|
TermsOfServiceFile.create!(attachment: pdf),
|
|
]
|
|
|
|
expect(TermsOfServiceFile.current).to eq existing.last
|
|
end
|
|
end
|
|
|
|
describe ".current_url" do
|
|
let(:subject) { TermsOfServiceFile.current_url }
|
|
|
|
it "points to the old default" do
|
|
expect(subject).to eq "/Terms-of-service.pdf"
|
|
end
|
|
|
|
it "points to the last uploaded file with timestamp parameter" do
|
|
file = TermsOfServiceFile.create!(attachment: pdf)
|
|
|
|
expect(subject).to match %r{^/system/terms_of_service_files/attachments.*Terms-of-service\.pdf\?\d+$}
|
|
end
|
|
end
|
|
|
|
describe ".updated_at" do
|
|
let(:subject) { TermsOfServiceFile.updated_at }
|
|
|
|
it "gives the most conservative time if not known" do
|
|
Timecop.freeze do
|
|
expect(subject).to eq Time.zone.now
|
|
end
|
|
end
|
|
|
|
it "returns the time when the terms were last updated" do
|
|
update_time = 1.day.ago
|
|
file = TermsOfServiceFile.create!(attachment: pdf, updated_at: update_time)
|
|
|
|
# The database isn't as precise as Ruby's time and rounds.
|
|
expect(subject).to be_within(0.001).of(update_time)
|
|
end
|
|
end
|
|
end
|