mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Rails 4.1 added time helpers but we never bothered using them. But now I'm getting rid of the Timecop dependency and use standard helpers. Beware though that the new helpers always freeze time. When you travel to a certain date then the clock stops ticking while Timecop maintained the passing of time. The freezing of time could cause problems if you are trying to enforce a timeout. But all current specs don't seem affected. In most cases, the freezing will make it easier to avoid flaky specs.
61 lines
2.0 KiB
Ruby
61 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "system_helper"
|
|
|
|
RSpec.describe "Uploading Terms and Conditions PDF" do
|
|
include AuthenticationHelper
|
|
include FileHelper
|
|
|
|
context "as an Enterprise user" do
|
|
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
|
|
let(:distributor) { create(:distributor_enterprise, name: "First Distributor") }
|
|
|
|
before do
|
|
enterprise_user.enterprise_roles.build(enterprise: distributor).save!
|
|
|
|
login_as enterprise_user
|
|
visit edit_admin_enterprise_path(distributor)
|
|
end
|
|
|
|
describe "with terms and conditions to upload" do
|
|
def go_to_business_details
|
|
within(".side_menu") do
|
|
click_link "Business Details"
|
|
end
|
|
end
|
|
|
|
let(:original_terms) { Rails.public_path.join('Terms-of-service.pdf') }
|
|
let(:updated_terms) { Rails.public_path.join('Terms-of-ServiceUK.pdf') }
|
|
|
|
it "uploading terms and conditions" do
|
|
go_to_business_details
|
|
|
|
# Add PDF
|
|
attach_file "enterprise[terms_and_conditions]", original_terms, make_visible: true
|
|
|
|
time = Time.zone.local(2002, 4, 13, 0, 0, 0)
|
|
travel_to(run_time = time) do
|
|
click_button "Update"
|
|
expect(distributor.reload.terms_and_conditions_blob.created_at).to eq run_time
|
|
end
|
|
expect(page).
|
|
to have_content "Enterprise \"#{distributor.name}\" has been successfully updated!"
|
|
|
|
go_to_business_details
|
|
expect(page).to have_selector "a[href*='Terms-of-service.pdf'][target=\"_blank\"]"
|
|
expect(page).to have_content time.strftime("%F %T")
|
|
|
|
# Replace PDF
|
|
attach_file "enterprise[terms_and_conditions]", updated_terms, make_visible: true
|
|
click_button "Update"
|
|
expect(page).
|
|
to have_content "Enterprise \"#{distributor.name}\" has been successfully updated!"
|
|
expect(distributor.reload.terms_and_conditions_blob.created_at).not_to eq run_time
|
|
|
|
go_to_business_details
|
|
expect(page).to have_selector "a[href*='Terms-of-ServiceUK.pdf']"
|
|
end
|
|
end
|
|
end
|
|
end
|