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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +75 -0
  5. data/.ruby-version +1 -1
  6. data/Gemfile +20 -11
  7. data/Gemfile.lock +190 -135
  8. data/Rakefile +3 -5
  9. data/introspective_admin.gemspec +16 -21
  10. data/lib/introspective_admin/base.rb +64 -47
  11. data/lib/introspective_admin/version.rb +3 -1
  12. data/lib/introspective_admin.rb +2 -0
  13. data/lib/tasks/introspective_admin_tasks.rake +2 -0
  14. data/spec/admin/company_admin_spec.rb +24 -23
  15. data/spec/admin/job_admin_spec.rb +21 -19
  16. data/spec/admin/location_admin_spec.rb +27 -23
  17. data/spec/admin/location_beacon_admin_spec.rb +26 -24
  18. data/spec/admin/project__admin_spec.rb +26 -24
  19. data/spec/admin/user_admin_spec.rb +25 -24
  20. data/spec/dummy/Gemfile +6 -4
  21. data/spec/dummy/Rakefile +3 -1
  22. data/spec/dummy/app/admin/admin_users.rb +2 -1
  23. data/spec/dummy/app/admin/company_admin.rb +4 -3
  24. data/spec/dummy/app/admin/dashboard.rb +10 -8
  25. data/spec/dummy/app/admin/job_admin.rb +3 -2
  26. data/spec/dummy/app/admin/location_admin.rb +3 -2
  27. data/spec/dummy/app/admin/location_beacon_admin.rb +2 -0
  28. data/spec/dummy/app/admin/project_admin.rb +3 -4
  29. data/spec/dummy/app/admin/role_admin.rb +3 -3
  30. data/spec/dummy/app/admin/user_admin.rb +5 -5
  31. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -1
  33. data/spec/dummy/app/models/abstract_adapter.rb +10 -8
  34. data/spec/dummy/app/models/admin_user.rb +4 -2
  35. data/spec/dummy/app/models/company.rb +3 -2
  36. data/spec/dummy/app/models/job.rb +3 -3
  37. data/spec/dummy/app/models/locatable.rb +3 -1
  38. data/spec/dummy/app/models/location.rb +4 -3
  39. data/spec/dummy/app/models/location_beacon.rb +5 -5
  40. data/spec/dummy/app/models/location_gps.rb +2 -2
  41. data/spec/dummy/app/models/project.rb +6 -6
  42. data/spec/dummy/app/models/project_job.rb +2 -1
  43. data/spec/dummy/app/models/role.rb +8 -7
  44. data/spec/dummy/app/models/team.rb +2 -1
  45. data/spec/dummy/app/models/team_user.rb +5 -4
  46. data/spec/dummy/app/models/user.rb +22 -18
  47. data/spec/dummy/app/models/user_location.rb +14 -14
  48. data/spec/dummy/app/models/user_project_job.rb +4 -3
  49. data/spec/dummy/bin/bundle +3 -1
  50. data/spec/dummy/bin/rails +3 -1
  51. data/spec/dummy/bin/rake +2 -0
  52. data/spec/dummy/bin/setup +10 -8
  53. data/spec/dummy/config/application.rb +12 -11
  54. data/spec/dummy/config/boot.rb +4 -2
  55. data/spec/dummy/config/environment.rb +6 -5
  56. data/spec/dummy/config/environments/development.rb +3 -1
  57. data/spec/dummy/config/environments/production.rb +4 -3
  58. data/spec/dummy/config/environments/test.rb +5 -5
  59. data/spec/dummy/config/initializers/active_admin.rb +5 -4
  60. data/spec/dummy/config/initializers/assets.rb +3 -1
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  63. data/spec/dummy/config/initializers/devise.rb +2 -0
  64. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  65. data/spec/dummy/config/initializers/inflections.rb +2 -0
  66. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  67. data/spec/dummy/config/initializers/session_store.rb +2 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  69. data/spec/dummy/config/initializers/zeitwerk.rb +6 -4
  70. data/spec/dummy/config/routes.rb +5 -3
  71. data/spec/dummy/config.ru +3 -1
  72. data/spec/dummy/db/development.sqlite3 +0 -0
  73. data/spec/dummy/db/migrate/20141002205024_devise_create_users.rb +4 -3
  74. data/spec/dummy/db/migrate/20141002211055_devise_create_admin_users.rb +4 -3
  75. data/spec/dummy/db/migrate/20141002211057_create_active_admin_comments.rb +4 -2
  76. data/spec/dummy/db/migrate/20141002220722_add_lockable_to_users.rb +2 -0
  77. data/spec/dummy/db/migrate/20150406213646_create_companies.rb +2 -0
  78. data/spec/dummy/db/migrate/20150414213154_add_user_authentication_token.rb +4 -2
  79. data/spec/dummy/db/migrate/20150415222005_create_roles.rb +3 -2
  80. data/spec/dummy/db/migrate/20150505181635_create_chats.rb +2 -0
  81. data/spec/dummy/db/migrate/20150505181636_create_chat_users.rb +2 -0
  82. data/spec/dummy/db/migrate/20150505181640_create_chat_messages.rb +2 -0
  83. data/spec/dummy/db/migrate/20150507191529_create_chat_message_users.rb +2 -0
  84. data/spec/dummy/db/migrate/20150601200526_create_locations.rb +3 -1
  85. data/spec/dummy/db/migrate/20150601200533_create_locatables.rb +2 -0
  86. data/spec/dummy/db/migrate/20150601212924_create_location_beacons.rb +4 -2
  87. data/spec/dummy/db/migrate/20150601213542_create_location_gps.rb +2 -0
  88. data/spec/dummy/db/migrate/20150609201823_create_user_locations.rb +2 -0
  89. data/spec/dummy/db/migrate/20150617232519_create_projects.rb +2 -0
  90. data/spec/dummy/db/migrate/20150617232521_create_jobs.rb +2 -0
  91. data/spec/dummy/db/migrate/20150617232522_create_project_jobs.rb +3 -1
  92. data/spec/dummy/db/migrate/20150623170133_create_user_project_jobs.rb +3 -1
  93. data/spec/dummy/db/migrate/20150701234929_create_teams.rb +2 -0
  94. data/spec/dummy/db/migrate/20150701234930_create_team_users.rb +3 -1
  95. data/spec/dummy/db/migrate/20150727214950_add_confirmable_to_devise.rb +4 -2
  96. data/spec/dummy/db/migrate/20150820190524_add_user_names.rb +4 -2
  97. data/spec/dummy/db/migrate/20150909225019_add_password_to_project.rb +2 -0
  98. data/spec/dummy/db/migrate/20220806003731_add_devise_to_admin_users.rb +2 -3
  99. data/spec/dummy/db/schema.rb +197 -198
  100. data/spec/rails_helper.rb +17 -11
  101. data/spec/support/blueprints.rb +50 -49
  102. data/spec/support/location_helper.rb +28 -29
  103. metadata +13 -153
  104. data/spec/dummy/db/development.sqlite3-shm +0 -0
  105. data/spec/dummy/db/development.sqlite3-wal +0 -0
  106. data/spec/dummy/introspective_admin.gemspec +0 -34
@@ -1,34 +1,29 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
2
4
 
3
5
  # Maintain your gem's version:
4
- require "introspective_admin/version"
5
- require "introspective_admin/base"
6
+ require 'introspective_admin/version'
7
+ require 'introspective_admin/base'
6
8
 
7
9
  # Describe your gem and declare its dependencies:
8
10
  Gem::Specification.new do |s|
9
- s.name = "introspective_admin"
11
+ s.name = 'introspective_admin'
10
12
  s.version = IntrospectiveAdmin::VERSION
11
- s.authors = ["Josh Buermann"]
12
- s.email = ["buermann@gmail.com"]
13
- s.homepage = "https://github.com/buermann/introspective_admin"
14
- s.summary = "Set up basic ActiveAdmin screens for an ActiveRecord model."
15
- s.description = "Set up basic ActiveAdmin screens for an ActiveRecord model."
16
- s.license = "MIT"
13
+ s.authors = ['Josh Buermann']
14
+ s.email = ['buermann@gmail.com']
15
+ s.homepage = 'https://github.com/buermann/introspective_admin'
16
+ s.summary = 'Set up basic ActiveAdmin screens for an ActiveRecord model.'
17
+ s.description = 'Set up basic ActiveAdmin screens for an ActiveRecord model.'
18
+ s.license = 'MIT'
17
19
 
18
- s.files = `git ls-files`.split("\n").sort
19
- s.test_files = `git ls-files -- spec/*`.split("\n")
20
+ s.files = `git ls-files`.split("\n").sort
20
21
 
21
- s.required_ruby_version = '>= 2.7.0'
22
+ s.required_ruby_version = '>= 3.0', '< 4'
22
23
 
23
- s.add_dependency 'rails'
24
24
  s.add_dependency 'activeadmin'
25
- s.add_dependency 'sass-rails'
26
25
  s.add_dependency 'sass'
26
+ s.add_dependency 'sass-rails'
27
27
 
28
- if RUBY_PLATFORM == 'java'
29
- s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
30
- else
31
- s.add_development_dependency "sqlite3"
32
- end
28
+ s.metadata['rubygems_mfa_required'] = 'true'
33
29
  end
34
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IntrospectiveAdmin
2
4
  class Base
3
5
  # Generate an active admin interface by introspecting on the models.
@@ -19,35 +21,39 @@ module IntrospectiveAdmin
19
21
  # end
20
22
 
21
23
  class << self
22
-
23
24
  def exclude_params
24
25
  [] # do not display the field in the index page and forms.
25
26
  end
26
27
 
27
28
  def include_virtual_attributes
28
- [] #
29
+ []
29
30
  end
30
31
 
31
- def polymorphic?(model,column)
32
- (model.reflections[column.sub(/_id$/,'')].try(:options)||{})[:polymorphic]
32
+ def polymorphic?(model, column)
33
+ (model.reflections[column.sub(/_id$/, '')].try(:options) || {})[:polymorphic]
33
34
  end
34
35
 
35
- def column_list(model, extras=[])
36
- model.columns.map {|c|
37
- ref_name = c.name.sub(/(_type|_id)$/,'')
36
+ def column_list(model, extras = [])
37
+ model.columns.map { |c|
38
+ ref_name = c.name.sub(/(_type|_id)$/, '')
38
39
  model.reflections[ref_name] ? ref_name : c.name
39
- }.uniq-['created_at','updated_at']-exclude_params+extras
40
+ }.uniq - %w[created_at updated_at] - exclude_params + extras
40
41
  end
41
42
 
42
- def params_list(model, extras=[])
43
- model.columns.map {|c|
44
- polymorphic?(model,c.name) ? c.name.sub(/_id$/,'')+"_assign" : c.name
45
- }+extras
43
+ def params_list(model, extras = [])
44
+ model.columns.map { |c|
45
+ polymorphic?(model, c.name) ? "#{c.name.sub(/_id$/, '')}_assign" : c.name
46
+ } + extras
46
47
  end
47
48
 
48
49
  def link_record(dsl, record)
49
50
  link_text = record.try(:name) || record.try(:title) || record.class.to_s
50
- link_href = begin dsl.send("admin_#{record.class.name.underscore}_path", record.id) rescue false end
51
+ link_href = begin begin
52
+ dsl.send("admin_#{record.class.name.underscore}_path", record.id)
53
+ rescue StandardError
54
+ false
55
+ end
56
+ end
51
57
  if link_href
52
58
  dsl.link_to link_text, link_href
53
59
  elsif link_text
@@ -59,13 +65,18 @@ module IntrospectiveAdmin
59
65
 
60
66
  def register(model, &block)
61
67
  # Defining activeadmin pages will break pending migrations:
62
- begin ActiveRecord::Migration.check_all_pending! rescue return end
68
+ begin begin
69
+ ActiveRecord::Migration.check_all_pending!
70
+ rescue StandardError
71
+ return
72
+ end
73
+ end
63
74
 
64
75
  klass = self
65
76
  model_name = model.to_s.underscore
66
- nested_config = Hash[model.nested_attributes_options.reject {|name,o|
77
+ nested_config = model.nested_attributes_options.reject { |name, _o|
67
78
  klass.exclude_params.include?("#{name}_attributes")
68
- }.map {|assoc,options|
79
+ }.to_h do |assoc, options|
69
80
  reflection = model.reflections[assoc.to_s]
70
81
  reflection_class = reflection.class_name.constantize
71
82
  # merge the options of the nested attribute and relationship declarations
@@ -76,10 +87,10 @@ module IntrospectiveAdmin
76
87
  options[:reflection] = reflection
77
88
  options[:polymorphic_reference] = reflection.options[:as].to_s
78
89
  [assoc, options]
79
- }]
90
+ end
80
91
 
81
92
  ActiveAdmin.register model do
82
- instance_eval &block if block_given? # Evalutate the passed black for overrides to the defaults
93
+ instance_eval(&block) if block_given? # Evalutate the passed black for overrides to the defaults
83
94
 
84
95
  controller do
85
96
  def scoped_collection
@@ -89,12 +100,12 @@ module IntrospectiveAdmin
89
100
 
90
101
  index do
91
102
  selectable_column
92
- cols = model.columns.map(&:name)-klass.exclude_params
93
- cols.each_with_index do |c,i|
94
- reflection = model.reflections.detect {|k,v| v.foreign_key == c }
103
+ cols = model.columns.map(&:name) - klass.exclude_params
104
+ cols.each_with_index do |c, _i|
105
+ reflection = model.reflections.detect { |_k, v| v.foreign_key == c }
95
106
  if reflection
96
107
  column c do |o|
97
- klass.link_record(self,o.send(reflection.first))
108
+ klass.link_record(self, o.send(reflection.first))
98
109
  end
99
110
  else
100
111
  column c
@@ -104,41 +115,46 @@ module IntrospectiveAdmin
104
115
  end
105
116
 
106
117
  show do
107
- instance = self.send(model_name)
118
+ instance = send(model_name)
108
119
 
109
120
  attributes_table do
110
121
  model.columns.each do |c|
111
- next if (c.name =~ /password/)
112
- reflection = model.reflections.detect {|k,v| v.foreign_key == c.name }
122
+ next if c.name =~ /password/
123
+
124
+ reflection = model.reflections.detect { |_k, v| v.foreign_key == c.name }
113
125
  if reflection
114
- row c.name do |o|
115
- klass.link_record(self,instance.send(reflection.first))
126
+ row c.name do |_o|
127
+ klass.link_record(self, instance.send(reflection.first))
116
128
  end
117
129
  else
118
130
  row c.name
119
131
  end
120
-
121
132
  end
122
133
 
123
- nested_config.each do |assoc,options|
134
+ nested_config.each do |assoc, options|
124
135
  panel assoc.capitalize do
125
136
  table_for instance.send(assoc) do
126
137
  options[:columns].each do |c|
127
138
  if options[:class].reflections[c]
128
- column( c ) do |r|
129
- klass.link_record(self,r.send(c)) if r
139
+ column(c) do |r|
140
+ klass.link_record(self, r.send(c)) if r
130
141
  end
131
142
  else
132
143
  column c
133
144
  end
134
145
  end
135
146
 
136
- admin_route = begin url_for(['admin', options[:class].name.underscore]) rescue false end
147
+ admin_route = begin begin
148
+ url_for(['admin', options[:class].name.underscore])
149
+ rescue StandardError
150
+ false
151
+ end
152
+ end
137
153
  if admin_route
138
154
  column 'actions' do |child|
139
- span link_to "View", url_for(['admin', child])
140
- span link_to "Edit", url_for(['edit','admin',child])
141
- span link_to "Delete", url_for(['admin',child]), method: :delete, confirm: "Are you sure you want to delete this?"
155
+ span link_to 'View', url_for(['admin', child])
156
+ span link_to 'Edit', url_for(['edit', 'admin', child])
157
+ span link_to 'Delete', url_for(['admin', child]), method: :delete, confirm: 'Are you sure you want to delete this?'
142
158
  end
143
159
  end
144
160
  end
@@ -147,18 +163,20 @@ module IntrospectiveAdmin
147
163
  end
148
164
  end
149
165
 
150
- permit_params klass.params_list(model, klass.include_virtual_attributes) + [Hash[nested_config.map{|assoc,o|
151
- ["#{assoc}_attributes", o[:params]+[(o[:allow_destroy] ? :_destroy : '')] ]
152
- }]]
166
+ permitted_params = klass.params_list(model, klass.include_virtual_attributes) + [nested_config.to_h do |assoc, o|
167
+ ["#{assoc}_attributes", o[:params] + [(o[:allow_destroy] ? :_destroy : '')]]
168
+ end]
169
+ permit_params(*permitted_params)
153
170
 
154
171
  form do |f|
155
- f.semantic_errors *f.object.errors.messages.keys
172
+ f.semantic_errors(*f.object.errors.messages.keys)
156
173
  f.actions
157
174
 
158
175
  klass.column_list(model, klass.include_virtual_attributes).each do |column|
159
- if column == model.primary_key
160
- elsif klass.polymorphic?(model,column)
161
- f.input column+"_assign", collection: model.send("#{column}_assign_options")
176
+ next if column == model.primary_key
177
+
178
+ if klass.polymorphic?(model, column)
179
+ f.input "#{column}_assign", collection: model.send("#{column}_assign_options")
162
180
  elsif model.respond_to?("options_for_#{column}")
163
181
  f.input column, collection: model.send("options_for_#{column}", f.object)
164
182
  else
@@ -168,22 +186,22 @@ module IntrospectiveAdmin
168
186
 
169
187
  div { '&nbsp'.html_safe }
170
188
 
171
- nested_config.each do |assoc,options|
189
+ nested_config.each do |assoc, options|
172
190
  aclass = options[:class]
173
- columns = options[:columns]-[aclass.primary_key]
191
+ columns = options[:columns] - [aclass.primary_key]
174
192
  f.inputs do
175
193
  f.has_many assoc, allow_destroy: options[:allow_destroy] do |r|
176
194
  columns.each do |c|
177
195
  if c == model_name || c == options[:polymorphic_reference]
178
196
  # the join to the parent is implicit
179
- elsif klass.polymorphic?(aclass,c)
197
+ elsif klass.polymorphic?(aclass, c)
180
198
  r.input "#{c}_assign", collection: aclass.send("#{c}_assign_options")
181
199
  elsif aclass.reflections[c] && aclass.respond_to?("options_for_#{c}")
182
200
  # If the class has an options_for_<column> method defined use that
183
201
  # rather than the default behavior, pass the instance for scoping,
184
202
  # e.g. UserProjectJob.options_for_job is scoped by the Project's
185
203
  # jobs:
186
- r.input c, collection: aclass.send("options_for_#{c}",f.object)
204
+ r.input c, collection: aclass.send("options_for_#{c}", f.object)
187
205
  else
188
206
  r.input c
189
207
  end
@@ -192,7 +210,6 @@ module IntrospectiveAdmin
192
210
  end
193
211
  end
194
212
  end
195
-
196
213
  end
197
214
  end
198
215
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IntrospectiveAdmin
2
- VERSION = "0.9.0"
4
+ VERSION = '1.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'activeadmin'
2
4
  module IntrospectiveAdmin
3
5
  autoload :Base, 'introspective_admin/base'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :introspective_admin do
3
5
  # # Task goes here
@@ -1,72 +1,73 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
- RSpec.describe Admin::CompaniesController, :type => :controller do
5
+ RSpec.describe Admin::CompaniesController, 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 "GET index" do
13
- it "finds all companies" do
14
+ describe 'GET index' do
15
+ it 'finds all companies' do
14
16
  c = Company.make!
15
17
  get :index
16
- response.status.should == 200
18
+ response.status.should
17
19
  assigns(:companies).include?(c).should == true
18
20
  end
19
21
  end
20
22
 
21
- describe "SHOW record" do
22
- it "finds the record" do
23
+ describe 'SHOW record' do
24
+ it 'finds the record' do
23
25
  c = Company.make!
24
26
  get :show, params: { id: c.id }
25
- response.status.should == 200
27
+ response.status.should == 200
26
28
  end
27
29
  end
28
30
 
29
- describe "NEW record" do
30
- it "renders the form for a new record" do
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 "CREATE record" do
37
- it "creates the record" do
38
+ describe 'CREATE record' do
39
+ it 'creates the record' do
38
40
  c = Company.make
39
41
  post :create, params: { company: c.attributes }
40
42
  response.should redirect_to action: :show, id: Company.last.id
41
43
  Company.last.name.should == c.name
42
44
  end
43
45
 
44
- it "creates a record with an admin" do
46
+ it 'creates a record with an admin' do
45
47
  u = User.make!
46
48
  c = Company.make
47
49
  post :create, params: { company: c.attributes.merge({
48
- roles_attributes: {'0'=>{ user_id: u.id }}
50
+ roles_attributes: { '0'=>{ user_id: u.id } }
49
51
  }) }
50
52
  response.should redirect_to action: :show, id: Company.last.id
51
53
  Company.last.admins.include?(u).should be_truthy
52
54
  end
53
-
54
55
  end
55
56
 
56
- describe "EDIT record" do
57
- it "renders the edit form for an existing record" do
57
+ describe 'EDIT record' do
58
+ it 'renders the edit form for an existing record' do
58
59
  r = Company.make!
59
60
  get :edit, params: { id: r.id }
60
- response.status.should == 200
61
+ response.status.should == 200
61
62
  end
62
63
  end
63
64
 
64
- describe "UPDATE record" do
65
- it "updates the record" do
65
+ describe 'UPDATE record' do
66
+ it 'updates the record' do
66
67
  c = Company.make!
67
- put :update, params: { id: c.id, company: { name: "New Name" } }
68
+ put :update, params: { id: c.id, company: { name: 'New Name' } }
68
69
  response.should redirect_to action: :show, id: c.id
69
- Company.find(c.id).name.should == "New Name"
70
+ Company.find(c.id).name.should == 'New Name'
70
71
  end
71
72
  end
72
73
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
- RSpec.describe Admin::JobsController, :type => :controller do
5
+ RSpec.describe Admin::JobsController, 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,32 +11,32 @@ RSpec.describe Admin::JobsController, :type => :controller do
9
11
  allow(controller).to receive(:current_user) { user }
10
12
  end
11
13
 
12
- describe "GET index" do
13
- it "finds all Jobs" do
14
+ describe 'GET index' do
15
+ it 'finds all Jobs' do
14
16
  r = Job.make!
15
17
  get :index
16
- response.status.should == 200
18
+ response.status.should
17
19
  assigns(:jobs).include?(r).should == true
18
20
  end
19
21
  end
20
22
 
21
- describe "SHOW record" do
22
- it "finds the record" do
23
+ describe 'SHOW record' do
24
+ it 'finds the record' do
23
25
  r = Job.make!
24
26
  get :show, params: { id: r.id }
25
- response.status.should == 200
27
+ response.status.should == 200
26
28
  end
27
29
  end
28
30
 
29
- describe "NEW record" do
30
- it "renders the form for a new record" do
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 "CREATE record" do
37
- it "creates the record" do
38
+ describe 'CREATE record' do
39
+ it 'creates the record' do
38
40
  r = Job.make
39
41
  post :create, params: { job: r.attributes }
40
42
  response.should redirect_to action: :show, id: Job.last.id
@@ -42,20 +44,20 @@ RSpec.describe Admin::JobsController, :type => :controller do
42
44
  end
43
45
  end
44
46
 
45
- describe "EDIT record" do
46
- it "renders the edit form for an existing record" do
47
+ describe 'EDIT record' do
48
+ it 'renders the edit form for an existing record' do
47
49
  r = Job.make!
48
50
  get :edit, params: { id: r.id }
49
- response.status.should == 200
51
+ response.status.should == 200
50
52
  end
51
53
  end
52
54
 
53
- describe "UPDATE record" do
54
- it "updates the record" do
55
+ describe 'UPDATE record' do
56
+ it 'updates the record' do
55
57
  r = Job.make!
56
- put :update, params: { id: r.id, job: { title: "New Name" } }
58
+ put :update, params: { id: r.id, job: { title: 'New Name' } }
57
59
  response.should redirect_to action: :show, id: r.id
58
- Job.find(r.id).title.should == "New Name"
60
+ Job.find(r.id).title.should == 'New Name'
59
61
  end
60
62
  end
61
63
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
- RSpec.describe Admin::LocationsController, :type => :controller do
5
+ RSpec.describe Admin::LocationsController, 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,58 +11,60 @@ RSpec.describe Admin::LocationsController, :type => :controller do
9
11
  allow(controller).to receive(:current_user) { user }
10
12
  end
11
13
 
12
- describe "GET index" do
13
- it "finds all locations" do
14
+ describe 'GET index' do
15
+ it 'finds all locations' do
14
16
  c = Location.make!
15
17
  get :index
16
- response.status.should == 200
18
+ response.status.should
17
19
  assigns(:locations).include?(c).should == true
18
20
  end
19
21
  end
20
22
 
21
- describe "SHOW record" do
22
- it "finds the record" do
23
+ describe 'SHOW record' do
24
+ it 'finds the record' do
23
25
  c = Location.make!
24
26
  get :show, params: { id: c.id }
25
- response.status.should == 200
27
+ response.status.should == 200
26
28
  end
27
29
  end
28
-
29
- describe "NEW record" do
30
+
31
+ describe 'NEW record' do
30
32
  # will fail until https://github.com/activeadmin/activeadmin/pull/4010 is merged
31
- it "renders the form for a new record" do
33
+ it 'renders the form for a new record' do
32
34
  get :new
33
35
  response.body.should =~ /location\[unreflected_id\]/
34
- response.status.should == 200
36
+ response.status.should == 200
35
37
  end
36
38
  end
37
39
 
38
- describe "CREATE record" do
39
- it "creates the record" do
40
+ describe 'CREATE record' do
41
+ it 'creates the record' do
40
42
  c = Location.make
41
43
  gps = LocationGps.make
42
- post :create, params: { location: c.attributes.merge(gps_attributes: gps.attributes) }
44
+ post :create, params: { location: c.attributes.merge(gps_attributes: gps.attributes) }
43
45
  response.should redirect_to action: :show, id: Location.last.id
44
- Location.last.name.should == c.name
45
- Location.last.gps.lat.round(10).should == gps.lat.round(10)
46
+ Location.last.name.should
47
+ c.name
48
+ Location.last.gps.lat.round(10).should
49
+ gps.lat.round(10)
46
50
  Location.last.gps.lng.round(10).should == gps.lng.round(10)
47
51
  end
48
52
  end
49
53
 
50
- describe "EDIT record" do
51
- it "renders the edit form for an existing record" do
54
+ describe 'EDIT record' do
55
+ it 'renders the edit form for an existing record' do
52
56
  r = Location.make!
53
57
  get :edit, params: { id: r.id }
54
- response.status.should == 200
58
+ response.status.should == 200
55
59
  end
56
60
  end
57
61
 
58
- describe "UPDATE record" do
59
- it "updates the record" do
62
+ describe 'UPDATE record' do
63
+ it 'updates the record' do
60
64
  r = Location.make!
61
- put :update, params: { id: r.id, location: { name: "New Name" } }
65
+ put :update, params: { id: r.id, location: { name: 'New Name' } }
62
66
  response.should redirect_to action: :show, id: r.id
63
- Location.find(r.id).name.should == "New Name"
67
+ Location.find(r.id).name.should == 'New Name'
64
68
  end
65
69
  end
66
70
  end