panda_pal 4.1.0.beta3 → 5.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +81 -71
- data/app/models/panda_pal/organization.rb +46 -17
- data/app/views/panda_pal/lti/iframe_cookie_authorize.html.erb +19 -0
- data/db/618eef7c0380ba654ad16f867a919e72.sqlite3 +0 -0
- data/db/9ff93d4f7e0e9dc80a43f68997caf4a1.sqlite3 +0 -0
- data/db/a3fda4044a7215bc2c9eb01a4b9e517a.sqlite3 +0 -0
- data/db/daa0e6378a5ec76fcce83b7070dad219.sqlite3 +0 -0
- data/lib/panda_pal/helpers/controller_helper.rb +60 -15
- data/lib/panda_pal/version.rb +1 -1
- data/panda_pal.gemspec +0 -3
- data/spec/dummy/config/application.rb +1 -7
- data/spec/dummy/config/environments/development.rb +14 -0
- data/spec/dummy/config/environments/production.rb +11 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +15058 -0
- data/spec/dummy/log/test.log +0 -0
- data/spec/models/panda_pal/organization_spec.rb +89 -0
- data/spec/spec_helper.rb +0 -4
- metadata +18 -38
- data/app/models/panda_pal/organization/settings_validation.rb +0 -111
- data/app/models/panda_pal/organization/task_scheduling.rb +0 -172
- data/spec/models/panda_pal/organization/settings_validation_spec.rb +0 -175
- data/spec/models/panda_pal/organization/task_scheduling_spec.rb +0 -144
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module PandaPal
|
4
|
-
PandaPal::Organization
|
5
|
-
|
6
|
-
RSpec.describe OrganizationConcerns::TaskScheduling, type: :model do
|
7
|
-
let!(:organization) { create(:panda_pal_organization) }
|
8
|
-
let(:schedules) { {} }
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
Organization.instance_variable_set(:@_schedule_descriptors, nil)
|
12
|
-
Organization.scheduled_task('0 0 0 * * *', :ident) { }
|
13
|
-
|
14
|
-
allow(Sidekiq).to receive(:remove_schedule)
|
15
|
-
allow(Sidekiq).to receive(:get_schedule) { schedules }
|
16
|
-
end
|
17
|
-
|
18
|
-
def descriptors
|
19
|
-
Organization.instance_variable_get(:@_schedule_descriptors)
|
20
|
-
end
|
21
|
-
|
22
|
-
def descriptor
|
23
|
-
descriptors[descriptors.keys[0]]
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.scheduled_task' do
|
27
|
-
it 'adds to the set of descriptors' do
|
28
|
-
expect(descriptors).to match(
|
29
|
-
'ident' => {
|
30
|
-
:key=>"ident",
|
31
|
-
:schedule=>"0 0 0 * * *",
|
32
|
-
:worker=>Proc,
|
33
|
-
:queue=>"default",
|
34
|
-
}
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '.sync_schedules' do
|
40
|
-
it 'adds new schedules' do
|
41
|
-
expect(Sidekiq).to receive(:set_schedule).with(/org:\w+-ident/, anything)
|
42
|
-
Organization.sync_schedules
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'removes schedules for deleted Orgs' do
|
46
|
-
schedules['org:deleted_org-schedule'] = {}
|
47
|
-
expect(Sidekiq).to receive(:remove_schedule).with('org:deleted_org-schedule')
|
48
|
-
Organization.sync_schedules
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'keeps schedules created from other sources' do
|
52
|
-
schedules['other-schedule'] = {}
|
53
|
-
expect(Sidekiq).not_to receive(:remove_schedule).with('other-schedule')
|
54
|
-
Organization.sync_schedules
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#generate_schedule' do
|
59
|
-
it 'generates the expected schedule' do
|
60
|
-
expect(organization.generate_schedule).to eq({
|
61
|
-
"org:#{organization.name}-ident" => {
|
62
|
-
"cron"=>"0 0 0 * * *",
|
63
|
-
"queue"=>"default",
|
64
|
-
"class"=>"PandaPal::OrganizationConcerns::TaskScheduling::ScheduledTaskExecutor",
|
65
|
-
"args"=>[organization.name, "ident"],
|
66
|
-
}
|
67
|
-
})
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#schedule_task_cron_time' do
|
72
|
-
before :each do
|
73
|
-
organization.settings = { timezone: 'America/Denver' }
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'includes timezone if in settings' do
|
77
|
-
expect(organization.send(:schedule_task_cron_time, descriptor)).to eq '0 0 0 * * * America/Denver'
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'does not re-append timezone if already present' do
|
81
|
-
descriptor[:schedule] = '1 1 1 * * * America/Chicago'
|
82
|
-
expect(organization.send(:schedule_task_cron_time, descriptor)).to eq '1 1 1 * * * America/Chicago'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#sync_schedule' do
|
87
|
-
it 'adds new schedules' do
|
88
|
-
expect(Sidekiq).to receive(:set_schedule).with(/org:\w+-ident/, anything)
|
89
|
-
organization.sync_schedule
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'removes old jobs' do
|
93
|
-
schedules["org:#{organization.name}-old_schedule"] = {}
|
94
|
-
expect(Sidekiq).to receive(:remove_schedule).with("org:#{organization.name}-old_schedule")
|
95
|
-
organization.sync_schedule
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'SettingsValidation' do
|
100
|
-
before :each do
|
101
|
-
organization.settings = {}
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'passes a valid timezone' do
|
105
|
-
organization.settings[:timezone] = 'America/Denver'
|
106
|
-
expect(organization).to be_valid
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'fails an invalid timezone' do
|
110
|
-
organization.settings[:timezone] = 'Timezone/Blorg'
|
111
|
-
expect(organization).not_to be_valid
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'allows [:task_schedules] entry to be missing' do
|
115
|
-
expect(organization).to be_valid
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'does not require [:task_schedules] sub-entries' do
|
119
|
-
organization.settings[:task_schedules] = {}
|
120
|
-
expect(organization).to be_valid
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'allows task entry to be false' do
|
124
|
-
organization.settings[:task_schedules] = { ident: false }
|
125
|
-
expect(organization).to be_valid
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'allows task entry to be a valid cron string' do
|
129
|
-
organization.settings[:task_schedules] = { ident: '0 0 0 * * * America/Denver' }
|
130
|
-
expect(organization).to be_valid
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'does not allow task entry to be an invalid cron string' do
|
134
|
-
organization.settings[:task_schedules] = { ident: 'blort' }
|
135
|
-
expect(organization).not_to be_valid
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'does not allow sub-entries for unknown tasks' do
|
139
|
-
organization.settings[:task_schedules] = { missing_ident: '0 0 0 * * * America/Denver' }
|
140
|
-
expect(organization).not_to be_valid
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|