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
|
|
|
|
2021-12-03 02:46:45 +01:00
|
|
|
subject { @controller.send(:last_four_months_serie, association, :updated_at) }
|
2017-05-26 17:29:31 +02:00
|
|
|
|
2018-01-15 18:54:57 +01:00
|
|
|
it do
|
2021-12-03 02:46:45 +01:00
|
|
|
expect(subject).to eq({
|
|
|
|
4.months.ago => 0,
|
|
|
|
3.months.ago => 0,
|
|
|
|
62.days.ago => 2,
|
|
|
|
31.days.ago => 1
|
|
|
|
}.transform_keys { |date| I18n.l(date, format: '%B %Y') })
|
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 }
|
|
|
|
|
2021-12-03 02:46:45 +01:00
|
|
|
subject { @controller.send(:last_four_months_serie, association, :updated_at) }
|
2017-06-22 12:10:03 +02:00
|
|
|
|
2018-01-15 18:54:57 +01:00
|
|
|
it do
|
2021-12-03 02:46:45 +01:00
|
|
|
expect(subject).to eq({
|
|
|
|
3.months.ago => 0,
|
|
|
|
45.days.ago => 1,
|
|
|
|
1.month.ago => 0,
|
|
|
|
1.day.ago => 2
|
|
|
|
}.transform_keys { |date| I18n.l(date, format: '%B %Y') })
|
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
|
|
|
|
2021-12-03 02:46:45 +01:00
|
|
|
subject { @controller.send(:cumulative_month_serie, association, :updated_at) }
|
2017-10-06 09:34:02 +02:00
|
|
|
|
2018-01-15 19:02:12 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to eq({
|
2021-12-03 02:46:45 +01:00
|
|
|
Date.new(2016, 8, 1) => 2,
|
|
|
|
Date.new(2016, 9, 1) => 4,
|
|
|
|
Date.new(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
|
|
|
|
2021-12-03 02:46:45 +01:00
|
|
|
subject { @controller.send(:cumulative_month_serie, association, :updated_at) }
|
2017-10-06 09:34:02 +02:00
|
|
|
|
2018-01-15 19:02:12 +01:00
|
|
|
it do
|
|
|
|
expect(subject).to eq({
|
2021-12-03 02:46:45 +01:00
|
|
|
Date.new(2016, 8, 1) => 2,
|
|
|
|
Date.new(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
|