introspective_admin 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +75 -0
- data/.ruby-version +1 -1
- data/Gemfile +20 -11
- data/Gemfile.lock +190 -135
- data/Rakefile +3 -5
- data/introspective_admin.gemspec +16 -21
- data/lib/introspective_admin/base.rb +64 -47
- data/lib/introspective_admin/version.rb +3 -1
- data/lib/introspective_admin.rb +2 -0
- data/lib/tasks/introspective_admin_tasks.rake +2 -0
- data/spec/admin/company_admin_spec.rb +24 -23
- data/spec/admin/job_admin_spec.rb +21 -19
- data/spec/admin/location_admin_spec.rb +27 -23
- data/spec/admin/location_beacon_admin_spec.rb +26 -24
- data/spec/admin/project__admin_spec.rb +26 -24
- data/spec/admin/user_admin_spec.rb +25 -24
- data/spec/dummy/Gemfile +6 -4
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/admin/admin_users.rb +2 -1
- data/spec/dummy/app/admin/company_admin.rb +4 -3
- data/spec/dummy/app/admin/dashboard.rb +10 -8
- data/spec/dummy/app/admin/job_admin.rb +3 -2
- data/spec/dummy/app/admin/location_admin.rb +3 -2
- data/spec/dummy/app/admin/location_beacon_admin.rb +2 -0
- data/spec/dummy/app/admin/project_admin.rb +3 -4
- data/spec/dummy/app/admin/role_admin.rb +3 -3
- data/spec/dummy/app/admin/user_admin.rb +5 -5
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -1
- data/spec/dummy/app/models/abstract_adapter.rb +10 -8
- data/spec/dummy/app/models/admin_user.rb +4 -2
- data/spec/dummy/app/models/company.rb +3 -2
- data/spec/dummy/app/models/job.rb +3 -3
- data/spec/dummy/app/models/locatable.rb +3 -1
- data/spec/dummy/app/models/location.rb +4 -3
- data/spec/dummy/app/models/location_beacon.rb +5 -5
- data/spec/dummy/app/models/location_gps.rb +2 -2
- data/spec/dummy/app/models/project.rb +6 -6
- data/spec/dummy/app/models/project_job.rb +2 -1
- data/spec/dummy/app/models/role.rb +8 -7
- data/spec/dummy/app/models/team.rb +2 -1
- data/spec/dummy/app/models/team_user.rb +5 -4
- data/spec/dummy/app/models/user.rb +22 -18
- data/spec/dummy/app/models/user_location.rb +14 -14
- data/spec/dummy/app/models/user_project_job.rb +4 -3
- data/spec/dummy/bin/bundle +3 -1
- data/spec/dummy/bin/rails +3 -1
- data/spec/dummy/bin/rake +2 -0
- data/spec/dummy/bin/setup +10 -8
- data/spec/dummy/config/application.rb +12 -11
- data/spec/dummy/config/boot.rb +4 -2
- data/spec/dummy/config/environment.rb +6 -5
- data/spec/dummy/config/environments/development.rb +3 -1
- data/spec/dummy/config/environments/production.rb +4 -3
- data/spec/dummy/config/environments/test.rb +5 -5
- data/spec/dummy/config/initializers/active_admin.rb +5 -4
- data/spec/dummy/config/initializers/assets.rb +3 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/devise.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/initializers/zeitwerk.rb +6 -4
- data/spec/dummy/config/routes.rb +5 -3
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141002205024_devise_create_users.rb +4 -3
- data/spec/dummy/db/migrate/20141002211055_devise_create_admin_users.rb +4 -3
- data/spec/dummy/db/migrate/20141002211057_create_active_admin_comments.rb +4 -2
- data/spec/dummy/db/migrate/20141002220722_add_lockable_to_users.rb +2 -0
- data/spec/dummy/db/migrate/20150406213646_create_companies.rb +2 -0
- data/spec/dummy/db/migrate/20150414213154_add_user_authentication_token.rb +4 -2
- data/spec/dummy/db/migrate/20150415222005_create_roles.rb +3 -2
- data/spec/dummy/db/migrate/20150505181635_create_chats.rb +2 -0
- data/spec/dummy/db/migrate/20150505181636_create_chat_users.rb +2 -0
- data/spec/dummy/db/migrate/20150505181640_create_chat_messages.rb +2 -0
- data/spec/dummy/db/migrate/20150507191529_create_chat_message_users.rb +2 -0
- data/spec/dummy/db/migrate/20150601200526_create_locations.rb +3 -1
- data/spec/dummy/db/migrate/20150601200533_create_locatables.rb +2 -0
- data/spec/dummy/db/migrate/20150601212924_create_location_beacons.rb +4 -2
- data/spec/dummy/db/migrate/20150601213542_create_location_gps.rb +2 -0
- data/spec/dummy/db/migrate/20150609201823_create_user_locations.rb +2 -0
- data/spec/dummy/db/migrate/20150617232519_create_projects.rb +2 -0
- data/spec/dummy/db/migrate/20150617232521_create_jobs.rb +2 -0
- data/spec/dummy/db/migrate/20150617232522_create_project_jobs.rb +3 -1
- data/spec/dummy/db/migrate/20150623170133_create_user_project_jobs.rb +3 -1
- data/spec/dummy/db/migrate/20150701234929_create_teams.rb +2 -0
- data/spec/dummy/db/migrate/20150701234930_create_team_users.rb +3 -1
- data/spec/dummy/db/migrate/20150727214950_add_confirmable_to_devise.rb +4 -2
- data/spec/dummy/db/migrate/20150820190524_add_user_names.rb +4 -2
- data/spec/dummy/db/migrate/20150909225019_add_password_to_project.rb +2 -0
- data/spec/dummy/db/migrate/20220806003731_add_devise_to_admin_users.rb +2 -3
- data/spec/dummy/db/schema.rb +197 -198
- data/spec/rails_helper.rb +17 -11
- data/spec/support/blueprints.rb +50 -49
- data/spec/support/location_helper.rb +28 -29
- metadata +13 -153
- data/spec/dummy/db/development.sqlite3-shm +0 -0
- data/spec/dummy/db/development.sqlite3-wal +0 -0
- data/spec/dummy/introspective_admin.gemspec +0 -34
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails_helper'
|
|
2
4
|
|
|
3
|
-
RSpec.describe Admin::LocationBeaconsController, :
|
|
5
|
+
RSpec.describe Admin::LocationBeaconsController, type: :controller do
|
|
4
6
|
render_views
|
|
5
7
|
|
|
6
8
|
before :each do # Why can't I do this shit in a helper like I do for requests?
|
|
@@ -9,44 +11,44 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
|
|
|
9
11
|
allow(controller).to receive(:current_user) { user }
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
describe
|
|
13
|
-
it
|
|
14
|
+
describe 'GET index' do
|
|
15
|
+
it 'finds all location beacons' do
|
|
14
16
|
c = LocationBeacon.make!(last_known_battery_level: 50)
|
|
15
17
|
d = LocationBeacon.make!(last_known_battery_level: 4)
|
|
16
18
|
get :index
|
|
17
|
-
response.status.should
|
|
18
|
-
assigns(:location_beacons).include?(c).should
|
|
19
|
+
response.status.should
|
|
20
|
+
assigns(:location_beacons).include?(c).should
|
|
19
21
|
assigns(:location_beacons).include?(d).should == true
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
it
|
|
24
|
+
it 'scopes location beacons by low battery level' do
|
|
23
25
|
c = LocationBeacon.make!(last_known_battery_level: 50)
|
|
24
26
|
d = LocationBeacon.make!(last_known_battery_level: 4)
|
|
25
|
-
get :index, params: { scope: 'low_battery' }
|
|
26
|
-
response.status.should
|
|
27
|
-
assigns(:location_beacons).include?(c).should
|
|
27
|
+
get :index, params: { scope: 'low_battery' }
|
|
28
|
+
response.status.should
|
|
29
|
+
assigns(:location_beacons).include?(c).should
|
|
28
30
|
assigns(:location_beacons).include?(d).should == true
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
describe
|
|
33
|
-
it
|
|
34
|
+
describe 'SHOW record' do
|
|
35
|
+
it 'finds the record' do
|
|
34
36
|
c = LocationBeacon.make!
|
|
35
37
|
get :show, params: { id: c.id }
|
|
36
|
-
response.status.should == 200
|
|
38
|
+
response.status.should == 200
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
|
-
|
|
40
|
-
describe
|
|
41
|
+
|
|
42
|
+
describe 'NEW record' do
|
|
41
43
|
# will fail until https://github.com/activeadmin/activeadmin/pull/4010 is merged
|
|
42
|
-
it
|
|
44
|
+
it 'renders the form for a new record' do
|
|
43
45
|
get :new
|
|
44
|
-
response.status.should == 200
|
|
46
|
+
response.status.should == 200
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
describe
|
|
49
|
-
it
|
|
50
|
+
describe 'CREATE record' do
|
|
51
|
+
it 'creates the record' do
|
|
50
52
|
c = LocationBeacon.make
|
|
51
53
|
post :create, params: { location_beacon: c.attributes }
|
|
52
54
|
response.should redirect_to action: :show, id: LocationBeacon.last.id
|
|
@@ -54,18 +56,18 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
|
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
describe
|
|
58
|
-
it
|
|
59
|
+
describe 'EDIT record' do
|
|
60
|
+
it 'renders the edit form for an existing record' do
|
|
59
61
|
r = LocationBeacon.make!
|
|
60
62
|
get :edit, params: { id: r.id }
|
|
61
|
-
response.status.should == 200
|
|
63
|
+
response.status.should == 200
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
describe
|
|
66
|
-
it
|
|
67
|
+
describe 'UPDATE record' do
|
|
68
|
+
it 'updates the record' do
|
|
67
69
|
r = LocationBeacon.make!
|
|
68
|
-
put :update, params: { id: r.id, location_beacon: { last_known_battery_level: 30 }
|
|
70
|
+
put :update, params: { id: r.id, location_beacon: { last_known_battery_level: 30 } }
|
|
69
71
|
response.should redirect_to action: :show, id: r.id
|
|
70
72
|
LocationBeacon.find(r.id).last_known_battery_level.should == 30
|
|
71
73
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails_helper'
|
|
2
|
-
RSpec.describe Admin::ProjectsController, :
|
|
4
|
+
RSpec.describe Admin::ProjectsController, type: :controller do
|
|
3
5
|
render_views
|
|
4
6
|
|
|
5
7
|
before :each do # Why can't I do this shit in a helper like I do for requests?
|
|
@@ -8,64 +10,64 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
|
|
|
8
10
|
allow(controller).to receive(:current_user) { user }
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
describe
|
|
12
|
-
it
|
|
13
|
+
describe 'GET index' do
|
|
14
|
+
it 'finds all projects' do
|
|
13
15
|
r = Project.make!
|
|
14
16
|
get :index
|
|
15
|
-
response.status.should
|
|
17
|
+
response.status.should
|
|
16
18
|
assigns(:projects).include?(r).should == true
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
describe
|
|
21
|
-
it
|
|
22
|
+
describe 'SHOW record' do
|
|
23
|
+
it 'finds the record' do
|
|
22
24
|
r = Project.make!
|
|
23
25
|
get :show, params: { id: r.id }
|
|
24
|
-
response.status.should == 200
|
|
26
|
+
response.status.should == 200
|
|
25
27
|
end
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
describe
|
|
29
|
-
it
|
|
30
|
+
describe 'NEW record' do
|
|
31
|
+
it 'renders the form for a new record' do
|
|
30
32
|
get :new
|
|
31
|
-
response.status.should == 200
|
|
33
|
+
response.status.should == 200
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
describe
|
|
36
|
-
it
|
|
37
|
+
describe 'CREATE record' do
|
|
38
|
+
it 'creates the record' do
|
|
37
39
|
r = Project.make
|
|
38
40
|
post :create, params: { project: r.attributes }
|
|
39
41
|
response.should redirect_to action: :show, id: Project.last.id
|
|
40
42
|
Project.last.name.should == r.name
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
it
|
|
45
|
+
it 'the inverse_of declaration allows a new project to be created with a project_job' do
|
|
44
46
|
j = Job.make!
|
|
45
47
|
r = Project.make
|
|
46
|
-
post :create, params: { project: r.attributes.merge({project_jobs_attributes:{'0'=>{job_id: j.id}}})
|
|
48
|
+
post :create, params: { project: r.attributes.merge({ project_jobs_attributes: { '0'=>{ job_id: j.id } } }) }
|
|
47
49
|
p = Project.last
|
|
48
|
-
p.name.should
|
|
49
|
-
|
|
50
|
+
p.name.should
|
|
51
|
+
r.name
|
|
52
|
+
p.project_jobs.size.should
|
|
50
53
|
p.project_jobs.first.job.should == j
|
|
51
54
|
end
|
|
52
|
-
|
|
53
55
|
end
|
|
54
56
|
|
|
55
|
-
describe
|
|
56
|
-
it
|
|
57
|
+
describe 'EDIT record' do
|
|
58
|
+
it 'renders the edit form for an existing record' do
|
|
57
59
|
r = Project.make!
|
|
58
60
|
get :edit, params: { id: r.id }
|
|
59
|
-
response.status.should == 200
|
|
61
|
+
response.status.should == 200
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
|
|
63
|
-
describe
|
|
64
|
-
it
|
|
65
|
+
describe 'UPDATE record' do
|
|
66
|
+
it 'updates the record' do
|
|
65
67
|
r = Project.make!
|
|
66
|
-
put :update, params: { id: r.id, project: { name:
|
|
68
|
+
put :update, params: { id: r.id, project: { name: 'New Name' } }
|
|
67
69
|
response.should redirect_to action: :show, id: r.id
|
|
68
|
-
Project.find(r.id).name.should ==
|
|
70
|
+
Project.find(r.id).name.should == 'New Name'
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
end
|
|
@@ -1,64 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails_helper'
|
|
2
4
|
|
|
3
|
-
RSpec.describe Admin::UsersController, :
|
|
5
|
+
RSpec.describe Admin::UsersController, type: :controller do
|
|
4
6
|
render_views
|
|
5
7
|
|
|
6
|
-
before :each do
|
|
8
|
+
before :each do
|
|
7
9
|
user = double('user')
|
|
8
10
|
allow(request.env['warden']).to receive(:authenticate!) { user }
|
|
9
11
|
allow(controller).to receive(:current_user) { user }
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
describe
|
|
13
|
-
it
|
|
14
|
+
describe 'GET index' do
|
|
15
|
+
it 'finds all users' do
|
|
14
16
|
u = User.make!
|
|
15
17
|
get :index
|
|
16
|
-
response.status.should
|
|
18
|
+
response.status.should
|
|
17
19
|
assigns(:users).include?(u).should == true
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
describe
|
|
22
|
-
it
|
|
23
|
+
describe 'SHOW record' do
|
|
24
|
+
it 'finds the record' do
|
|
23
25
|
u = User.make!
|
|
24
26
|
get :show, params: { id: u.id }
|
|
25
|
-
response.status.should == 200
|
|
27
|
+
response.status.should == 200
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
describe
|
|
30
|
-
it
|
|
31
|
+
describe 'NEW record' do
|
|
32
|
+
it 'renders the form for a new record' do
|
|
31
33
|
get :new
|
|
32
|
-
response.status.should == 200
|
|
34
|
+
response.status.should == 200
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
describe
|
|
37
|
-
it
|
|
38
|
-
post :create, params: { user: { first_name: 'first', last_name: 'last', email: 'test@blah.com', password:
|
|
38
|
+
describe 'CREATE record' do
|
|
39
|
+
it 'creates the record' do
|
|
40
|
+
post :create, params: { user: { first_name: 'first', last_name: 'last', email: 'test@blah.com', password: 'abcd1234' } }
|
|
39
41
|
response.should redirect_to action: :show, id: User.last.id
|
|
40
42
|
u = User.last
|
|
41
|
-
u.first_name.should
|
|
42
|
-
u.last_name.should
|
|
43
|
+
u.first_name.should
|
|
44
|
+
u.last_name.should
|
|
43
45
|
u.email.should == 'test@blah.com'
|
|
44
46
|
end
|
|
45
|
-
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
describe
|
|
49
|
-
it
|
|
49
|
+
describe 'EDIT record' do
|
|
50
|
+
it 'renders the edit form for an existing record' do
|
|
50
51
|
r = User.make!
|
|
51
52
|
get :edit, params: { id: r.id }
|
|
52
|
-
response.status.should == 200
|
|
53
|
+
response.status.should == 200
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
56
|
|
|
56
|
-
describe
|
|
57
|
-
it
|
|
57
|
+
describe 'UPDATE record' do
|
|
58
|
+
it 'updates the record' do
|
|
58
59
|
u = User.make!
|
|
59
|
-
put :update, params: { id: u.id, user: { first_name:
|
|
60
|
+
put :update, params: { id: u.id, user: { first_name: 'New Name' } }
|
|
60
61
|
response.should redirect_to action: :show, id: u.id
|
|
61
|
-
User.find(u.id).first_name.should ==
|
|
62
|
+
User.find(u.id).first_name.should == 'New Name'
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
65
|
end
|
data/spec/dummy/Gemfile
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# A sample Gemfile
|
|
2
|
-
source
|
|
4
|
+
source 'https://rubygems.org'
|
|
3
5
|
|
|
4
6
|
gemspec
|
|
5
7
|
gem 'coveralls', require: false
|
|
6
8
|
gem 'devise'
|
|
7
9
|
gem 'devise-async'
|
|
8
10
|
gem 'machinist_redux'
|
|
11
|
+
gem 'rails', '~> 8'
|
|
9
12
|
gem 'rails-controller-testing'
|
|
10
|
-
gem
|
|
13
|
+
gem 'rspec-rails'
|
|
11
14
|
gem 'rufus-mnemo'
|
|
12
15
|
gem 'simplecov'
|
|
13
16
|
gem 'sprockets-rails'
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
gem 'sqlite3'
|
data/spec/dummy/Rakefile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
4
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
5
|
|
|
4
|
-
require File.expand_path('
|
|
6
|
+
require File.expand_path('config/application', __dir__)
|
|
5
7
|
|
|
6
8
|
Rails.application.load_tasks
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
ActiveAdmin.register_page 'Dashboard' do
|
|
4
|
+
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
|
|
5
|
+
|
|
6
|
+
content title: proc { I18n.t('active_admin.dashboard') } do
|
|
7
|
+
div class: 'blank_slate_container', id: 'dashboard_default_message' do
|
|
8
|
+
span class: 'blank_slate' do
|
|
9
|
+
span I18n.t('active_admin.dashboard_welcome.welcome')
|
|
10
|
+
small I18n.t('active_admin.dashboard_welcome.call_to_action')
|
|
9
11
|
end
|
|
10
12
|
end
|
|
11
13
|
|
|
@@ -28,5 +30,5 @@ ActiveAdmin.register_page "Dashboard" do
|
|
|
28
30
|
# end
|
|
29
31
|
# end
|
|
30
32
|
# end
|
|
31
|
-
end
|
|
33
|
+
end
|
|
32
34
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class UserAdmin < IntrospectiveAdmin::Base
|
|
2
4
|
def self.include_virtual_attributes
|
|
3
|
-
%w
|
|
5
|
+
%w[password]
|
|
4
6
|
end
|
|
5
7
|
|
|
6
8
|
def self.exclude_params
|
|
7
|
-
%w
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
register User do
|
|
9
|
+
%w[reset_password_at current_sign_in_at current_sign_in_ip remember_created_at sign_in_count encrypted_password reset_password_sent_at reset_password_token password authentication_token unlock_token failed_attempts last_sign_in_at locked_at last_sign_in_ip]
|
|
11
10
|
end
|
|
12
11
|
|
|
12
|
+
register User
|
|
13
13
|
end
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class AbstractAdapter < ActiveRecord::Base
|
|
2
4
|
self.abstract_class = true
|
|
3
5
|
|
|
4
6
|
class << self
|
|
5
7
|
def human_attribute_name(attr, options = {})
|
|
6
8
|
# The default formatting of validation errors sucks, this helps a little syntatically:
|
|
7
|
-
super.titleize
|
|
9
|
+
"#{super.titleize}:"
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
def ransackable_attributes(_auth_object = nil)
|
|
13
|
+
@ransackable_attributes ||= column_names + _ransackers.keys
|
|
14
|
+
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
def ransackable_associations(_auth_object = nil)
|
|
17
|
+
@ransackable_associations ||= reflect_on_all_associations.map { |a| a.name.to_s } + _ransackers.keys
|
|
18
|
+
end
|
|
19
|
+
end
|
|
18
20
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class AdminUser < ActiveRecord::Base
|
|
2
4
|
# Include default devise modules. Others available are:
|
|
3
5
|
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
|
4
|
-
devise :database_authenticatable,
|
|
6
|
+
devise :database_authenticatable,
|
|
5
7
|
:recoverable, :rememberable, :validatable
|
|
6
8
|
# Include default devise modules. Others available are:
|
|
7
9
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
|
8
|
-
devise :database_authenticatable,
|
|
10
|
+
devise :database_authenticatable,
|
|
9
11
|
:recoverable, :rememberable, :trackable, :validatable
|
|
10
12
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Company < AbstractAdapter
|
|
2
4
|
has_many :roles, as: :ownable
|
|
3
5
|
has_many :admins, through: :roles, source: :user
|
|
4
6
|
accepts_nested_attributes_for :roles, allow_destroy: true
|
|
5
|
-
|
|
7
|
+
|
|
6
8
|
has_many :beacons, class_name: 'LocationBeacon', dependent: :destroy
|
|
7
9
|
has_many :locatables
|
|
8
10
|
has_many :locations, through: :locatables, source: :locatable, source_type: 'Company'
|
|
9
11
|
|
|
10
12
|
has_many :projects, foreign_key: :owner_id, dependent: :destroy, inverse_of: :owner
|
|
11
|
-
|
|
12
13
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class Job < AbstractAdapter
|
|
4
|
+
has_many :project_jobs, dependent: :destroy
|
|
4
5
|
accepts_nested_attributes_for :project_jobs, allow_destroy: true
|
|
5
6
|
|
|
6
7
|
has_many :user_project_jobs, dependent: :destroy
|
|
7
8
|
has_many :users, through: :user_project_jobs
|
|
8
9
|
has_many :projects, through: :user_project_jobs
|
|
9
|
-
|
|
10
10
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Location < AbstractAdapter
|
|
2
4
|
has_many :locatables, dependent: :destroy
|
|
3
5
|
has_many :companies, through: :locatables, source: :locatable, source_type: 'Company'
|
|
4
6
|
|
|
5
7
|
has_many :beacons, class_name: 'LocationBeacon', dependent: :destroy
|
|
6
8
|
has_one :gps, class_name: 'LocationGps', dependent: :destroy
|
|
7
|
-
delegate :lat
|
|
9
|
+
delegate :lat, :lng, :alt, to: :gps
|
|
8
10
|
|
|
9
11
|
belongs_to :parent_location, foreign_key: :parent_location_id, class_name: 'Location', inverse_of: :child_locations
|
|
10
12
|
has_many :child_locations, foreign_key: :parent_location_id, class_name: 'Location', dependent: :destroy, inverse_of: :parent_location
|
|
@@ -13,7 +15,7 @@ class Location < AbstractAdapter
|
|
|
13
15
|
|
|
14
16
|
# isn't this list going to be kinda long? are there any reasonable constraints to put
|
|
15
17
|
# on this random bit of metadata?
|
|
16
|
-
validates_inclusion_of :kind, in: %w
|
|
18
|
+
validates_inclusion_of :kind, in: %w[airport terminal gate plane]
|
|
17
19
|
|
|
18
20
|
accepts_nested_attributes_for :child_locations, allow_destroy: true
|
|
19
21
|
accepts_nested_attributes_for :gps, allow_destroy: true
|
|
@@ -22,5 +24,4 @@ class Location < AbstractAdapter
|
|
|
22
24
|
def coords
|
|
23
25
|
[gps.lat, gps.lng, gps.alt]
|
|
24
26
|
end
|
|
25
|
-
|
|
26
27
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class LocationBeacon < AbstractAdapter
|
|
2
4
|
belongs_to :location
|
|
3
5
|
has_many :gps, through: :location
|
|
@@ -9,11 +11,9 @@ class LocationBeacon < AbstractAdapter
|
|
|
9
11
|
|
|
10
12
|
before_validation :massage_ids
|
|
11
13
|
def massage_ids
|
|
12
|
-
self.uuid = (uuid||'').gsub(/[^0-9a-fA-F]+/,'').upcase
|
|
13
|
-
self.mac_address = (mac_address||'').gsub(/[^0-9a-fA-F]+/,'').upcase
|
|
14
|
+
self.uuid = (uuid || '').gsub(/[^0-9a-fA-F]+/, '').upcase
|
|
15
|
+
self.mac_address = (mac_address || '').gsub(/[^0-9a-fA-F]+/, '').upcase
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
scope :low_battery, -> { where(
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
scope :low_battery, -> { where('last_known_battery_level < 20') }
|
|
19
19
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class LocationGps < AbstractAdapter
|
|
2
4
|
belongs_to :location
|
|
3
5
|
has_many :beacons, through: :location
|
|
@@ -6,6 +8,4 @@ class LocationGps < AbstractAdapter
|
|
|
6
8
|
validates_numericality_of :lat, greater_than_or_equal_to: -90.0, less_than_or_equal_to: 90.0
|
|
7
9
|
validates_numericality_of :lng, greater_than_or_equal_to: -180.0, less_than_or_equal_to: 180.0
|
|
8
10
|
validates_numericality_of :alt
|
|
9
|
-
|
|
10
|
-
|
|
11
11
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Project < AbstractAdapter
|
|
2
4
|
belongs_to :owner, foreign_key: :owner_id, class_name: 'Company'
|
|
3
5
|
|
|
@@ -5,16 +7,14 @@ class Project < AbstractAdapter
|
|
|
5
7
|
has_many :admins, through: :roles, source: :user
|
|
6
8
|
accepts_nested_attributes_for :roles, allow_destroy: true
|
|
7
9
|
|
|
8
|
-
has_many :project_jobs,
|
|
9
|
-
has_many :jobs,
|
|
10
|
+
has_many :project_jobs, dependent: :destroy, inverse_of: :project
|
|
11
|
+
has_many :jobs, through: :project_jobs
|
|
10
12
|
accepts_nested_attributes_for :project_jobs, allow_destroy: true
|
|
11
|
-
|
|
13
|
+
|
|
12
14
|
has_many :user_project_jobs, dependent: :destroy, inverse_of: :project
|
|
13
|
-
has_many :users,
|
|
15
|
+
has_many :users, through: :user_project_jobs, inverse_of: :projects
|
|
14
16
|
accepts_nested_attributes_for :user_project_jobs, allow_destroy: true
|
|
15
17
|
|
|
16
18
|
has_many :teams, dependent: :destroy, inverse_of: :project
|
|
17
19
|
accepts_nested_attributes_for :teams, allow_destroy: true
|
|
18
|
-
|
|
19
|
-
|
|
20
20
|
end
|