Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/models/concerns/issued_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def issued_at_cannot_be_before_2000
end

def issued_at_cannot_be_further_than_1_year
if issued_at.present? && issued_at > DateTime.now.next_year
if issued_at.present? && issued_at > DateTime.current.next_year
errors.add(:issued_at, "cannot be more than 1 year in the future")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/donations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
source { Donation::SOURCES[:misc] }
storage_location
organization { Organization.try(:first) || create(:organization) }
issued_at { Time.current }
issued_at { DateTime.current }

factory :manufacturer_donation do
manufacturer
Expand Down
31 changes: 16 additions & 15 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@

describe 'users' do
subject { organization.users }
let(:organization) { create(:organization) }

context 'when a organizaton has a user that has two roles' do
let(:user) { create(:user) }
Expand Down Expand Up @@ -361,7 +360,6 @@
end

context 'with invisible items' do
let!(:organization) { create(:organization) }
let!(:item1) { create(:item, organization: organization, active: true, visible_to_partners: true) }
let!(:item2) { create(:item, organization: organization, active: true, visible_to_partners: false) }
let!(:item3) { create(:item, organization: organization, active: false, visible_to_partners: true) }
Expand Down Expand Up @@ -401,21 +399,24 @@
describe 'earliest reporting year' do
# re 2813 update annual report -- allowing an earliest reporting year will let us do system testing and staging for annual reports
it 'is the organization created year if no associated data' do
org = create(:organization)
expect(org.earliest_reporting_year).to eq(org.created_at.year)
expect(organization.earliest_reporting_year).to eq(organization.created_at.year)
end

it 'is the year of the earliest of donation, purchase, or distribution if they are earlier ' do
org = create(:organization)
create(:donation, organization: org, issued_at: 364.days.from_now)
create(:purchase, organization: org, issued_at: 364.days.from_now)
create(:distribution, organization: org, issued_at: 364.days.from_now)
expect(org.earliest_reporting_year).to eq(org.created_at.year)
create(:donation, organization: org, issued_at: 5.years.ago)
expect(org.earliest_reporting_year).to eq(5.years.ago.year)
create(:purchase, organization: org, issued_at: 6.years.ago)
expect(org.earliest_reporting_year).to eq(6.years.ago.year)
create(:purchase, organization: org, issued_at: 7.years.ago)
expect(org.earliest_reporting_year).to eq(7.years.ago.year)
freeze_time do
create(:donation, organization: organization, issued_at: DateTime.current.next_year - 1.day)
create(:purchase, organization: organization, issued_at: DateTime.current.next_year - 1.day)
create(:distribution, organization: organization, issued_at: DateTime.current.next_year - 1.day)
expect(organization.earliest_reporting_year).to eq(organization.created_at.year)
create(:donation, organization: organization, issued_at: 5.years.ago)
expect(organization.earliest_reporting_year).to eq(5.years.ago.year)
create(:purchase, organization: organization, issued_at: 6.years.ago)
expect(organization.earliest_reporting_year).to eq(6.years.ago.year)
create(:purchase, organization: organization, issued_at: 7.years.ago)
expect(organization.earliest_reporting_year).to eq(7.years.ago.year)
ensure
travel_back
end
end
end

Expand Down
15 changes: 8 additions & 7 deletions spec/requests/reports/donations_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
end

describe "time display" do
let!(:donation) { create(:donation, :with_items, issued_at: 1.day.ago) }
it "uses issued_at for the relative time display, not created_at" do
freeze_time do
create(:donation, :with_items, issued_at: DateTime.current - 1.day)

before do
freeze_time
get reports_donations_summary_path
end
get reports_donations_summary_path

it "uses issued_at for the relative time display, not created_at" do
expect(response.body).to include("1 day ago")
expect(response.body).to include("1 day ago")
ensure
travel_back
end
end
end

Expand Down
Loading