2017-04-03 16:26:05 +02:00
|
|
|
describe StatsController, type: :controller do
|
2017-05-26 17:29:31 +02:00
|
|
|
describe "#last_four_months_hash" do
|
2017-07-17 15:12:05 +02:00
|
|
|
context "while a regular user is logged in" do
|
2017-05-26 17:29:31 +02:00
|
|
|
before do
|
2020-08-27 19:56:48 +02:00
|
|
|
create(:procedure, created_at: 6.months.ago, updated_at: 6.months.ago)
|
|
|
|
create(:procedure, created_at: 2.months.ago, updated_at: 62.days.ago)
|
|
|
|
create(:procedure, created_at: 2.months.ago, updated_at: 62.days.ago)
|
|
|
|
create(:procedure, created_at: 2.months.ago, updated_at: 31.days.ago)
|
|
|
|
create(:procedure, created_at: 2.months.ago, updated_at: Time.zone.now)
|
2017-06-22 12:10:03 +02:00
|
|
|
@controller = StatsController.new
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
allow(@controller).to receive(:super_admin_signed_in?).and_return(false)
|
2017-05-26 17:29:31 +02:00
|
|
|
end
|
|
|
|
|
2020-08-27 19:56:48 +02:00
|
|
|
let(:association) { Procedure.all }
|
2017-05-26 17:29:31 +02:00
|
|
|
|
2017-06-22 12:10:03 +02:00
|
|
|
subject { @controller.send(:last_four_months_hash, association, :updated_at) }
|
2017-05-26 17:29:31 +02:00
|
|
|
|
2018-01-15 18:54:57 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to match_array([
|
|
|
|
[I18n.l(62.days.ago.beginning_of_month, format: "%B %Y"), 2],
|
|
|
|
[I18n.l(31.days.ago.beginning_of_month, format: "%B %Y"), 1]
|
2017-06-22 12:10:03 +02:00
|
|
|
])
|
2018-01-15 18:54:57 +01:00
|
|
|
end
|
2017-06-22 12:10:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "while a super admin is logged in" do
|
|
|
|
before do
|
2020-08-27 19:56:48 +02:00
|
|
|
create(:procedure, updated_at: 6.months.ago)
|
|
|
|
create(:procedure, updated_at: 45.days.ago)
|
|
|
|
create(:procedure, updated_at: 1.day.ago)
|
|
|
|
create(:procedure, updated_at: 1.day.ago)
|
2017-06-22 12:10:03 +02:00
|
|
|
|
|
|
|
@controller = StatsController.new
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
allow(@controller).to receive(:super_admin_signed_in?).and_return(true)
|
2017-06-22 12:10:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let (:association) { Procedure.all }
|
|
|
|
|
2017-07-17 15:12:05 +02:00
|
|
|
subject { @controller.send(:last_four_months_hash, association, :updated_at) }
|
2017-06-22 12:10:03 +02:00
|
|
|
|
2018-01-15 18:54:57 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to eq([
|
|
|
|
[I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1],
|
2018-03-06 13:44:29 +01:00
|
|
|
[I18n.l(1.day.ago.beginning_of_month, format: "%B %Y"), 2]
|
2017-06-12 14:10:49 +02:00
|
|
|
])
|
2018-01-15 18:54:57 +01:00
|
|
|
end
|
2017-05-26 17:29:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-28 15:42:48 +02:00
|
|
|
describe '#cumulative_hash' do
|
2017-07-17 15:12:05 +02:00
|
|
|
before do
|
2018-10-25 15:21:06 +02:00
|
|
|
Timecop.freeze(Time.zone.local(2016, 10, 2))
|
2020-08-27 19:56:48 +02:00
|
|
|
create(:procedure, created_at: 55.days.ago, updated_at: 43.days.ago)
|
|
|
|
create(:procedure, created_at: 45.days.ago, updated_at: 40.days.ago)
|
|
|
|
create(:procedure, created_at: 45.days.ago, updated_at: 20.days.ago)
|
|
|
|
create(:procedure, created_at: 15.days.ago, updated_at: 20.days.ago)
|
|
|
|
create(:procedure, created_at: 15.days.ago, updated_at: 1.hour.ago)
|
2017-04-26 14:28:39 +02:00
|
|
|
end
|
|
|
|
|
2017-11-29 16:07:39 +01:00
|
|
|
after { Timecop.return }
|
|
|
|
|
2017-07-17 15:12:05 +02:00
|
|
|
let (:association) { Procedure.all }
|
2017-03-28 15:42:48 +02:00
|
|
|
|
2017-10-06 09:34:02 +02:00
|
|
|
context "while a super admin is logged in" do
|
2020-11-05 15:09:11 +01:00
|
|
|
before { allow(@controller).to receive(:super_admin_signed_in?).and_return(true) }
|
2017-10-06 09:34:02 +02:00
|
|
|
|
|
|
|
subject { @controller.send(:cumulative_hash, association, :updated_at) }
|
|
|
|
|
2018-01-15 19:02:12 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to eq({
|
2018-10-26 11:02:14 +02:00
|
|
|
Time.utc(2016, 8, 1) => 2,
|
|
|
|
Time.utc(2016, 9, 1) => 4,
|
|
|
|
Time.utc(2016, 10, 1) => 5
|
2017-10-06 09:34:02 +02:00
|
|
|
})
|
2018-01-15 19:02:12 +01:00
|
|
|
end
|
2017-10-06 09:34:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "while a super admin is not logged in" do
|
2020-11-05 15:09:11 +01:00
|
|
|
before { allow(@controller).to receive(:super_admin_signed_in?).and_return(false) }
|
2017-10-06 09:34:02 +02:00
|
|
|
|
|
|
|
subject { @controller.send(:cumulative_hash, association, :updated_at) }
|
|
|
|
|
2018-01-15 19:02:12 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to eq({
|
2018-10-26 11:02:14 +02:00
|
|
|
Time.utc(2016, 8, 1) => 2,
|
|
|
|
Time.utc(2016, 9, 1) => 4
|
2017-10-06 09:34:02 +02:00
|
|
|
})
|
2018-01-15 19:02:12 +01:00
|
|
|
end
|
2017-10-06 09:34:02 +02:00
|
|
|
end
|
2017-03-28 15:42:48 +02:00
|
|
|
end
|
2017-04-03 16:26:05 +02:00
|
|
|
end
|