introspective_admin 0.0.8 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.DS_Store +0 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +9 -11
  5. data/CHANGELOG.md +22 -0
  6. data/Gemfile +10 -1
  7. data/Gemfile.lock +308 -208
  8. data/README.md +34 -8
  9. data/introspective_admin.gemspec +4 -11
  10. data/lib/introspective_admin/base.rb +17 -17
  11. data/lib/introspective_admin/version.rb +1 -1
  12. data/spec/admin/company_admin_spec.rb +6 -6
  13. data/spec/admin/job_admin_spec.rb +4 -4
  14. data/spec/admin/location_admin_spec.rb +4 -4
  15. data/spec/admin/location_beacon_admin_spec.rb +5 -5
  16. data/spec/admin/project__admin_spec.rb +5 -5
  17. data/spec/admin/user_admin_spec.rb +4 -4
  18. data/spec/dummy/Gemfile +15 -0
  19. data/spec/dummy/app/admin/admin_users.rb +28 -0
  20. data/spec/dummy/app/admin/dashboard.rb +32 -0
  21. data/spec/dummy/app/assets/config/manifest.js +3 -0
  22. data/spec/dummy/app/assets/javascripts/active_admin.js +1 -0
  23. data/spec/dummy/app/assets/stylesheets/active_admin.scss +17 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  26. data/spec/dummy/app/models/abstract_adapter.rb +8 -2
  27. data/spec/dummy/app/models/admin_user.rb +4 -0
  28. data/spec/dummy/app/models/role.rb +1 -1
  29. data/spec/dummy/app/models/user.rb +2 -2
  30. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  31. data/spec/dummy/config/application.rb +4 -2
  32. data/spec/dummy/config/environment.rb +1 -1
  33. data/spec/dummy/config/environments/development.rb +5 -1
  34. data/spec/dummy/config/environments/production.rb +6 -3
  35. data/spec/dummy/config/environments/test.rb +9 -2
  36. data/spec/dummy/config/initializers/assets.rb +3 -1
  37. data/spec/dummy/config/initializers/zeitwerk.rb +8 -0
  38. data/spec/dummy/config/routes.rb +1 -0
  39. data/spec/dummy/db/development.sqlite3 +0 -0
  40. data/spec/dummy/db/development.sqlite3-shm +0 -0
  41. data/spec/dummy/db/development.sqlite3-wal +0 -0
  42. data/spec/dummy/db/migrate/20220806003731_add_devise_to_admin_users.rb +51 -0
  43. data/spec/dummy/introspective_admin.gemspec +34 -0
  44. data/spec/rails_helper.rb +5 -2
  45. metadata +39 -58
data/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  IntrospectiveAdmin is a Rails Plugin for DRYing up ActiveAdmin configurations by
20
20
  laying out simple defaults and including nested relations according to the models'
21
- accepts_nested_attributes_for :relation declarations.
21
+ accepts_nested_attributes_for :relation declarations.
22
22
 
23
23
  ## Documentation
24
24
 
@@ -28,7 +28,9 @@ In your Gemfile:
28
28
  gem 'introspective_admin'
29
29
  ```
30
30
 
31
- And bundle install. In app/admin/my_admin.rb:
31
+ And bundle install.
32
+
33
+ In app/admin/my_admin.rb:
32
34
 
33
35
  ```
34
36
  class MyAdmin < IntrospectiveAdmin::Base
@@ -39,7 +41,7 @@ class MyAdmin < IntrospectiveAdmin::Base
39
41
  def self.exclude_params
40
42
  %w(fields to exclude from the admin screen)
41
43
  end
42
-
44
+
43
45
  register MyModel do
44
46
  # It yields the ActiveAdmin DSL context back, allowing further configuration to
45
47
  # be added here, just as you would normally, to the Admin::MyModelController
@@ -48,29 +50,32 @@ class MyAdmin < IntrospectiveAdmin::Base
48
50
  end
49
51
  ```
50
52
 
51
- Registering MyModel will set up the index, show, and form configurations for every attribute, virtual attribute listed in MyAdmin.include_virtual_attributes (e.g. a password field for a Devise model), and nested association on the model excluding those in MyAdmin.exclude_params. It will link to associated records (if they have ActiveAdmin screens), perform eager loading of nested associations, and permit parameters for every non-excluded attribute on the model.
53
+ Registering MyModel will set up the index, show, and form configurations for every attribute, virtual attribute listed in MyAdmin.include_virtual_attributes (e.g. a password field for a Devise model), and nested association on the model excluding those in MyAdmin.exclude_params. It will link to associated records (if they have ActiveAdmin screens), perform eager loading of nested associations, and permit parameters for every non-excluded attribute on the model.
52
54
 
53
- Customizing select box options for associations is done by adding an
55
+ Customizing select box options for associations is done by adding an
54
56
  "options_for_X" class method on the administrated model:
55
57
 
56
58
  ```
59
+ app/models/my_model.rb
57
60
  class MyModel < ActiveRecord::Base
58
61
  belongs_to :parent
59
62
  has_many :other_models
60
63
  accepts_nested_attributes_for :other_models, :allow_destroy => true
61
64
 
62
65
  def self.options_for_parent(instance_of_my_model)
63
- Parent.order(:appelation).map.{|p| ["#{p.appelation}", p.id] }
66
+ Parent.order(:appelation).map.{|p| ["#{p.appelation}", p.id] }
64
67
  end
65
68
  end
66
69
  ```
67
70
 
68
71
  IntrospectiveAdmin will detect nested polymorphic relations and attempt to handle
69
- them using virutal attributes that you must add to the model instance, plus a class
72
+ them using virutal attributes that you must add to the model instance, plus a class
70
73
  method for the select box options, using a shared delimiter string for the compound ID.
71
- E.g. here we use a hyphen:
74
+
75
+ E.g. here we use a hyphen:
72
76
 
73
77
  ```
78
+ app/models/my_model.rb
74
79
  class MyModel < ActiveRecord::Base
75
80
  belongs_to :poly_model, polymorphic: true
76
81
  accepts_nested_attributes_for :poly_model, :allow_destroy => true
@@ -90,6 +95,27 @@ class MyModel < ActiveRecord::Base
90
95
  end
91
96
  ```
92
97
 
98
+ ActiveAdmin relies on [Ransack](https://github.com/activerecord-hackery/ransack) to power its searches. You will need
99
+ to explicitly declare attributes and associations to be accessible to ActiveAdmin. You can defeat the purpose by declaring everything accessible via your models' abstract base class, but be sure to exclude sensitive data:
100
+
101
+ ```
102
+ app/models/application_record.rb
103
+ def ApplicationRecord < ActiveRecord::Base
104
+ self.abstract_class = true
105
+
106
+ class << self
107
+ def ransackable_attributes(auth_object = nil)
108
+ @ransackable_attributes ||= column_names + _ransackers.keys - %w(password)
109
+ end
110
+
111
+ def ransackable_associations(auth_object = nil)
112
+ @ransackable_associations ||= reflect_on_all_associations.map { |a| a.name.to_s } + _ransackers.keys
113
+ end
114
+ end
115
+ end
116
+ ```
117
+
118
+
93
119
  ## Dependencies
94
120
 
95
121
  Tool | Description
@@ -18,24 +18,17 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files`.split("\n").sort
19
19
  s.test_files = `git ls-files -- spec/*`.split("\n")
20
20
 
21
- s.required_ruby_version = '>= 1.9.3'
21
+ s.required_ruby_version = '>= 2.7.0'
22
22
 
23
+ s.add_dependency 'rails'
24
+ s.add_dependency 'activeadmin'
23
25
  s.add_dependency 'sass-rails'
26
+ s.add_dependency 'sass'
24
27
 
25
28
  if RUBY_PLATFORM == 'java'
26
29
  s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
27
30
  else
28
31
  s.add_development_dependency "sqlite3"
29
- if RUBY_VERSION > '2.0.0'
30
- #s.add_development_dependency 'byebug'
31
- end
32
32
  end
33
- s.add_development_dependency "rspec-rails", '>= 3.0'
34
- s.add_development_dependency 'devise'
35
- s.add_development_dependency 'devise-async'
36
- s.add_development_dependency 'machinist'
37
- s.add_development_dependency 'simplecov'
38
- s.add_development_dependency 'rufus-mnemo'
39
-
40
33
  end
41
34
 
@@ -1,5 +1,5 @@
1
1
  module IntrospectiveAdmin
2
- class Base
2
+ class Base
3
3
  # Generate an active admin interface by introspecting on the models.
4
4
 
5
5
  # For polymorphic associations set up virtual 'assign' attributes on the model like so:
@@ -20,11 +20,11 @@ module IntrospectiveAdmin
20
20
 
21
21
  class << self
22
22
 
23
- def exclude_params
23
+ def exclude_params
24
24
  [] # do not display the field in the index page and forms.
25
25
  end
26
26
 
27
- def include_virtual_attributes
27
+ def include_virtual_attributes
28
28
  [] #
29
29
  end
30
30
 
@@ -42,7 +42,7 @@ module IntrospectiveAdmin
42
42
  def params_list(model, extras=[])
43
43
  model.columns.map {|c|
44
44
  polymorphic?(model,c.name) ? c.name.sub(/_id$/,'')+"_assign" : c.name
45
- }+extras
45
+ }+extras
46
46
  end
47
47
 
48
48
  def link_record(dsl, record)
@@ -59,7 +59,7 @@ module IntrospectiveAdmin
59
59
 
60
60
  def register(model, &block)
61
61
  # Defining activeadmin pages will break pending migrations:
62
- begin ActiveRecord::Migration.check_pending! rescue return end
62
+ begin ActiveRecord::Migration.check_all_pending! rescue return end
63
63
 
64
64
  klass = self
65
65
  model_name = model.to_s.underscore
@@ -68,7 +68,7 @@ module IntrospectiveAdmin
68
68
  }.map {|assoc,options|
69
69
  reflection = model.reflections[assoc.to_s]
70
70
  reflection_class = reflection.class_name.constantize
71
- # merge the options of the nested attribute and relationship declarations
71
+ # merge the options of the nested attribute and relationship declarations
72
72
  options = options.merge(reflection_class.reflections[assoc.to_s].try(:options) || {})
73
73
  options[:class] = reflection_class
74
74
  options[:columns] = klass.column_list(reflection_class)
@@ -78,7 +78,7 @@ module IntrospectiveAdmin
78
78
  [assoc, options]
79
79
  }]
80
80
 
81
- ActiveAdmin.register model do
81
+ ActiveAdmin.register model do
82
82
  instance_eval &block if block_given? # Evalutate the passed black for overrides to the defaults
83
83
 
84
84
  controller do
@@ -87,14 +87,14 @@ module IntrospectiveAdmin
87
87
  end
88
88
  end
89
89
 
90
- index do
90
+ index do
91
91
  selectable_column
92
92
  cols = model.columns.map(&:name)-klass.exclude_params
93
93
  cols.each_with_index do |c,i|
94
94
  reflection = model.reflections.detect {|k,v| v.foreign_key == c }
95
95
  if reflection
96
96
  column c do |o|
97
- klass.link_record(self,o.send(reflection.first))
97
+ klass.link_record(self,o.send(reflection.first))
98
98
  end
99
99
  else
100
100
  column c
@@ -103,7 +103,7 @@ module IntrospectiveAdmin
103
103
  actions
104
104
  end
105
105
 
106
- show do
106
+ show do
107
107
  instance = self.send(model_name)
108
108
 
109
109
  attributes_table do
@@ -112,7 +112,7 @@ module IntrospectiveAdmin
112
112
  reflection = model.reflections.detect {|k,v| v.foreign_key == c.name }
113
113
  if reflection
114
114
  row c.name do |o|
115
- klass.link_record(self,instance.send(reflection.first))
115
+ klass.link_record(self,instance.send(reflection.first))
116
116
  end
117
117
  else
118
118
  row c.name
@@ -122,13 +122,13 @@ module IntrospectiveAdmin
122
122
 
123
123
  nested_config.each do |assoc,options|
124
124
  panel assoc.capitalize do
125
- table_for instance.send(assoc) do
125
+ table_for instance.send(assoc) do
126
126
  options[:columns].each do |c|
127
127
  if options[:class].reflections[c]
128
128
  column( c ) do |r|
129
129
  klass.link_record(self,r.send(c)) if r
130
130
  end
131
- else
131
+ else
132
132
  column c
133
133
  end
134
134
  end
@@ -152,7 +152,7 @@ module IntrospectiveAdmin
152
152
  }]]
153
153
 
154
154
  form do |f|
155
- f.semantic_errors *f.object.errors.keys
155
+ f.semantic_errors *f.object.errors.messages.keys
156
156
  f.actions
157
157
 
158
158
  klass.column_list(model, klass.include_virtual_attributes).each do |column|
@@ -166,7 +166,7 @@ module IntrospectiveAdmin
166
166
  end
167
167
  end
168
168
 
169
- div { '&nbsp'.html_safe }
169
+ div { '&nbsp'.html_safe }
170
170
 
171
171
  nested_config.each do |assoc,options|
172
172
  aclass = options[:class]
@@ -176,7 +176,7 @@ module IntrospectiveAdmin
176
176
  columns.each do |c|
177
177
  if c == model_name || c == options[:polymorphic_reference]
178
178
  # the join to the parent is implicit
179
- elsif klass.polymorphic?(aclass,c)
179
+ elsif klass.polymorphic?(aclass,c)
180
180
  r.input "#{c}_assign", collection: aclass.send("#{c}_assign_options")
181
181
  elsif aclass.reflections[c] && aclass.respond_to?("options_for_#{c}")
182
182
  # If the class has an options_for_<column> method defined use that
@@ -184,7 +184,7 @@ module IntrospectiveAdmin
184
184
  # e.g. UserProjectJob.options_for_job is scoped by the Project's
185
185
  # jobs:
186
186
  r.input c, collection: aclass.send("options_for_#{c}",f.object)
187
- else
187
+ else
188
188
  r.input c
189
189
  end
190
190
  end
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveAdmin
2
- VERSION = "0.0.8"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -21,7 +21,7 @@ RSpec.describe Admin::CompaniesController, :type => :controller do
21
21
  describe "SHOW record" do
22
22
  it "finds the record" do
23
23
  c = Company.make!
24
- get :show, id: c.id
24
+ get :show, params: { id: c.id }
25
25
  response.status.should == 200
26
26
  end
27
27
  end
@@ -36,7 +36,7 @@ RSpec.describe Admin::CompaniesController, :type => :controller do
36
36
  describe "CREATE record" do
37
37
  it "creates the record" do
38
38
  c = Company.make
39
- post :create, company: c.attributes
39
+ post :create, params: { company: c.attributes }
40
40
  response.should redirect_to action: :show, id: Company.last.id
41
41
  Company.last.name.should == c.name
42
42
  end
@@ -44,9 +44,9 @@ RSpec.describe Admin::CompaniesController, :type => :controller do
44
44
  it "creates a record with an admin" do
45
45
  u = User.make!
46
46
  c = Company.make
47
- post :create, company: c.attributes.merge({
47
+ post :create, params: { company: c.attributes.merge({
48
48
  roles_attributes: {'0'=>{ user_id: u.id }}
49
- })
49
+ }) }
50
50
  response.should redirect_to action: :show, id: Company.last.id
51
51
  Company.last.admins.include?(u).should be_truthy
52
52
  end
@@ -56,7 +56,7 @@ RSpec.describe Admin::CompaniesController, :type => :controller do
56
56
  describe "EDIT record" do
57
57
  it "renders the edit form for an existing record" do
58
58
  r = Company.make!
59
- get :edit, id: r.id
59
+ get :edit, params: { id: r.id }
60
60
  response.status.should == 200
61
61
  end
62
62
  end
@@ -64,7 +64,7 @@ RSpec.describe Admin::CompaniesController, :type => :controller do
64
64
  describe "UPDATE record" do
65
65
  it "updates the record" do
66
66
  c = Company.make!
67
- put :update, id: c.id, company: { name: "New Name" }
67
+ put :update, params: { id: c.id, company: { name: "New Name" } }
68
68
  response.should redirect_to action: :show, id: c.id
69
69
  Company.find(c.id).name.should == "New Name"
70
70
  end
@@ -21,7 +21,7 @@ RSpec.describe Admin::JobsController, :type => :controller do
21
21
  describe "SHOW record" do
22
22
  it "finds the record" do
23
23
  r = Job.make!
24
- get :show, id: r.id
24
+ get :show, params: { id: r.id }
25
25
  response.status.should == 200
26
26
  end
27
27
  end
@@ -36,7 +36,7 @@ RSpec.describe Admin::JobsController, :type => :controller do
36
36
  describe "CREATE record" do
37
37
  it "creates the record" do
38
38
  r = Job.make
39
- post :create, job: r.attributes
39
+ post :create, params: { job: r.attributes }
40
40
  response.should redirect_to action: :show, id: Job.last.id
41
41
  Job.last.title.should == r.title
42
42
  end
@@ -45,7 +45,7 @@ RSpec.describe Admin::JobsController, :type => :controller do
45
45
  describe "EDIT record" do
46
46
  it "renders the edit form for an existing record" do
47
47
  r = Job.make!
48
- get :edit, id: r.id
48
+ get :edit, params: { id: r.id }
49
49
  response.status.should == 200
50
50
  end
51
51
  end
@@ -53,7 +53,7 @@ RSpec.describe Admin::JobsController, :type => :controller do
53
53
  describe "UPDATE record" do
54
54
  it "updates the record" do
55
55
  r = Job.make!
56
- put :update, id: r.id, job: { title: "New Name" }
56
+ put :update, params: { id: r.id, job: { title: "New Name" } }
57
57
  response.should redirect_to action: :show, id: r.id
58
58
  Job.find(r.id).title.should == "New Name"
59
59
  end
@@ -21,7 +21,7 @@ RSpec.describe Admin::LocationsController, :type => :controller do
21
21
  describe "SHOW record" do
22
22
  it "finds the record" do
23
23
  c = Location.make!
24
- get :show, id: c.id
24
+ get :show, params: { id: c.id }
25
25
  response.status.should == 200
26
26
  end
27
27
  end
@@ -39,7 +39,7 @@ RSpec.describe Admin::LocationsController, :type => :controller do
39
39
  it "creates the record" do
40
40
  c = Location.make
41
41
  gps = LocationGps.make
42
- post :create, location: c.attributes.merge(gps_attributes: gps.attributes)
42
+ post :create, params: { location: c.attributes.merge(gps_attributes: gps.attributes) }
43
43
  response.should redirect_to action: :show, id: Location.last.id
44
44
  Location.last.name.should == c.name
45
45
  Location.last.gps.lat.round(10).should == gps.lat.round(10)
@@ -50,7 +50,7 @@ RSpec.describe Admin::LocationsController, :type => :controller do
50
50
  describe "EDIT record" do
51
51
  it "renders the edit form for an existing record" do
52
52
  r = Location.make!
53
- get :edit, id: r.id
53
+ get :edit, params: { id: r.id }
54
54
  response.status.should == 200
55
55
  end
56
56
  end
@@ -58,7 +58,7 @@ RSpec.describe Admin::LocationsController, :type => :controller do
58
58
  describe "UPDATE record" do
59
59
  it "updates the record" do
60
60
  r = Location.make!
61
- put :update, id: r.id, location: { name: "New Name" }
61
+ put :update, params: { id: r.id, location: { name: "New Name" } }
62
62
  response.should redirect_to action: :show, id: r.id
63
63
  Location.find(r.id).name.should == "New Name"
64
64
  end
@@ -22,7 +22,7 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
22
22
  it "scopes location beacons by low battery level" do
23
23
  c = LocationBeacon.make!(last_known_battery_level: 50)
24
24
  d = LocationBeacon.make!(last_known_battery_level: 4)
25
- get :index, { scope: 'low_battery' }
25
+ get :index, params: { scope: 'low_battery' }
26
26
  response.status.should == 200
27
27
  assigns(:location_beacons).include?(c).should == false
28
28
  assigns(:location_beacons).include?(d).should == true
@@ -32,7 +32,7 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
32
32
  describe "SHOW record" do
33
33
  it "finds the record" do
34
34
  c = LocationBeacon.make!
35
- get :show, id: c.id
35
+ get :show, params: { id: c.id }
36
36
  response.status.should == 200
37
37
  end
38
38
  end
@@ -48,7 +48,7 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
48
48
  describe "CREATE record" do
49
49
  it "creates the record" do
50
50
  c = LocationBeacon.make
51
- post :create, location_beacon: c.attributes
51
+ post :create, params: { location_beacon: c.attributes }
52
52
  response.should redirect_to action: :show, id: LocationBeacon.last.id
53
53
  LocationBeacon.last.mac_address.should =~ /#{c.mac_address}/i
54
54
  end
@@ -57,7 +57,7 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
57
57
  describe "EDIT record" do
58
58
  it "renders the edit form for an existing record" do
59
59
  r = LocationBeacon.make!
60
- get :edit, id: r.id
60
+ get :edit, params: { id: r.id }
61
61
  response.status.should == 200
62
62
  end
63
63
  end
@@ -65,7 +65,7 @@ RSpec.describe Admin::LocationBeaconsController, :type => :controller do
65
65
  describe "UPDATE record" do
66
66
  it "updates the record" do
67
67
  r = LocationBeacon.make!
68
- put :update, id: r.id, location_beacon: { last_known_battery_level: 30 }
68
+ put :update, params: { id: r.id, location_beacon: { last_known_battery_level: 30 } }
69
69
  response.should redirect_to action: :show, id: r.id
70
70
  LocationBeacon.find(r.id).last_known_battery_level.should == 30
71
71
  end
@@ -20,7 +20,7 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
20
20
  describe "SHOW record" do
21
21
  it "finds the record" do
22
22
  r = Project.make!
23
- get :show, id: r.id
23
+ get :show, params: { id: r.id }
24
24
  response.status.should == 200
25
25
  end
26
26
  end
@@ -35,7 +35,7 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
35
35
  describe "CREATE record" do
36
36
  it "creates the record" do
37
37
  r = Project.make
38
- post :create, project: r.attributes
38
+ post :create, params: { project: r.attributes }
39
39
  response.should redirect_to action: :show, id: Project.last.id
40
40
  Project.last.name.should == r.name
41
41
  end
@@ -43,7 +43,7 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
43
43
  it "the inverse_of declaration allows a new project to be created with a project_job" do
44
44
  j = Job.make!
45
45
  r = Project.make
46
- post :create, project: r.attributes.merge({project_jobs_attributes:{'0'=>{job_id: j.id}}})
46
+ post :create, params: { project: r.attributes.merge({project_jobs_attributes:{'0'=>{job_id: j.id}}}) }
47
47
  p = Project.last
48
48
  p.name.should == r.name
49
49
  p.project_jobs.size.should == 1
@@ -55,7 +55,7 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
55
55
  describe "EDIT record" do
56
56
  it "renders the edit form for an existing record" do
57
57
  r = Project.make!
58
- get :edit, id: r.id
58
+ get :edit, params: { id: r.id }
59
59
  response.status.should == 200
60
60
  end
61
61
  end
@@ -63,7 +63,7 @@ RSpec.describe Admin::ProjectsController, :type => :controller do
63
63
  describe "UPDATE record" do
64
64
  it "updates the record" do
65
65
  r = Project.make!
66
- put :update, id: r.id, project: { name: "New Name" }
66
+ put :update, params: { id: r.id, project: { name: "New Name" } }
67
67
  response.should redirect_to action: :show, id: r.id
68
68
  Project.find(r.id).name.should == "New Name"
69
69
  end
@@ -21,7 +21,7 @@ RSpec.describe Admin::UsersController, :type => :controller do
21
21
  describe "SHOW record" do
22
22
  it "finds the record" do
23
23
  u = User.make!
24
- get :show, id: u.id
24
+ get :show, params: { id: u.id }
25
25
  response.status.should == 200
26
26
  end
27
27
  end
@@ -35,7 +35,7 @@ RSpec.describe Admin::UsersController, :type => :controller do
35
35
 
36
36
  describe "CREATE record" do
37
37
  it "creates the record" do
38
- post :create, user: { first_name: 'first', last_name: 'last', email: 'test@blah.com', password: "abcd1234" }
38
+ post :create, params: { user: { first_name: 'first', last_name: 'last', email: 'test@blah.com', password: "abcd1234" } }
39
39
  response.should redirect_to action: :show, id: User.last.id
40
40
  u = User.last
41
41
  u.first_name.should == 'first'
@@ -48,7 +48,7 @@ RSpec.describe Admin::UsersController, :type => :controller do
48
48
  describe "EDIT record" do
49
49
  it "renders the edit form for an existing record" do
50
50
  r = User.make!
51
- get :edit, id: r.id
51
+ get :edit, params: { id: r.id }
52
52
  response.status.should == 200
53
53
  end
54
54
  end
@@ -56,7 +56,7 @@ RSpec.describe Admin::UsersController, :type => :controller do
56
56
  describe "UPDATE record" do
57
57
  it "updates the record" do
58
58
  u = User.make!
59
- put :update, id: u.id, user: { first_name: "New Name" }
59
+ put :update, params: { id: u.id, user: { first_name: "New Name" } }
60
60
  response.should redirect_to action: :show, id: u.id
61
61
  User.find(u.id).first_name.should == "New Name"
62
62
  end
@@ -0,0 +1,15 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+ gem 'coveralls', require: false
6
+ gem 'devise'
7
+ gem 'devise-async'
8
+ gem 'machinist_redux'
9
+ gem 'rails-controller-testing'
10
+ gem "rspec-rails"
11
+ gem 'rufus-mnemo'
12
+ gem 'simplecov'
13
+ gem 'sprockets-rails'
14
+
15
+
@@ -0,0 +1,28 @@
1
+ ActiveAdmin.register AdminUser do
2
+ permit_params :email, :password, :password_confirmation
3
+
4
+ index do
5
+ selectable_column
6
+ id_column
7
+ column :email
8
+ column :current_sign_in_at
9
+ column :sign_in_count
10
+ column :created_at
11
+ actions
12
+ end
13
+
14
+ filter :email
15
+ filter :current_sign_in_at
16
+ filter :sign_in_count
17
+ filter :created_at
18
+
19
+ form do |f|
20
+ f.inputs do
21
+ f.input :email
22
+ f.input :password
23
+ f.input :password_confirmation
24
+ end
25
+ f.actions
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ ActiveAdmin.register_page "Dashboard" do
2
+ menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
3
+
4
+ content title: proc { I18n.t("active_admin.dashboard") } do
5
+ div class: "blank_slate_container", id: "dashboard_default_message" do
6
+ span class: "blank_slate" do
7
+ span I18n.t("active_admin.dashboard_welcome.welcome")
8
+ small I18n.t("active_admin.dashboard_welcome.call_to_action")
9
+ end
10
+ end
11
+
12
+ # Here is an example of a simple dashboard with columns and panels.
13
+ #
14
+ # columns do
15
+ # column do
16
+ # panel "Recent Posts" do
17
+ # ul do
18
+ # Post.recent(5).map do |post|
19
+ # li link_to(post.title, admin_post_path(post))
20
+ # end
21
+ # end
22
+ # end
23
+ # end
24
+
25
+ # column do
26
+ # panel "Info" do
27
+ # para "Welcome to ActiveAdmin."
28
+ # end
29
+ # end
30
+ # end
31
+ end # content
32
+ end
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -0,0 +1 @@
1
+ //= require active_admin/base
@@ -0,0 +1,17 @@
1
+ // Sass variable overrides must be declared before loading up Active Admin's styles.
2
+ //
3
+ // To view the variables that Active Admin provides, take a look at
4
+ // `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
5
+ // Active Admin source.
6
+ //
7
+ // For example, to change the sidebar width:
8
+ // $sidebar-width: 242px;
9
+
10
+ // Active Admin's got SASS!
11
+ @import "active_admin/mixins";
12
+ @import "active_admin/base";
13
+
14
+ // Overriding any non-variable Sass must be done after the fact.
15
+ // For example, to change the default status-tag color:
16
+ //
17
+ // .status_tag { background: #6090DB; }
@@ -2,4 +2,7 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
+
6
+ # Load the test database schema into memory on startup
7
+ load "#{Rails.root}/db/schema.rb"
5
8
  end
@@ -1,2 +1,3 @@
1
1
  module ApplicationHelper
2
+
2
3
  end
@@ -6,7 +6,13 @@ class AbstractAdapter < ActiveRecord::Base
6
6
  # The default formatting of validation errors sucks, this helps a little syntatically:
7
7
  super.titleize+":"
8
8
  end
9
- end
10
9
 
11
- end
10
+ def ransackable_attributes(auth_object = nil)
11
+ @ransackable_attributes ||= column_names + _ransackers.keys
12
+ end
12
13
 
14
+ def ransackable_associations(auth_object = nil)
15
+ @ransackable_associations ||= reflect_on_all_associations.map { |a| a.name.to_s } + _ransackers.keys
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,9 @@
1
1
  class AdminUser < ActiveRecord::Base
2
2
  # Include default devise modules. Others available are:
3
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4
+ devise :database_authenticatable,
5
+ :recoverable, :rememberable, :validatable
6
+ # Include default devise modules. Others available are:
3
7
  # :confirmable, :lockable, :timeoutable and :omniauthable
4
8
  devise :database_authenticatable,
5
9
  :recoverable, :rememberable, :trackable, :validatable
@@ -2,7 +2,7 @@ class Role < AbstractAdapter
2
2
  belongs_to :user
3
3
  belongs_to :ownable, polymorphic: true
4
4
 
5
- validates_uniqueness_of :user_id, scope: [:ownable_type,:ownable_id], unless: "user_id.nil?", message: "user has already been assigned that role"
5
+ validates_uniqueness_of :user_id, scope: [:ownable_type,:ownable_id], unless: Proc.new {|u| u.user_id.nil? }, message: "user has already been assigned that role"
6
6
  validates_inclusion_of :ownable_type, in: ['Company', 'Project']
7
7
 
8
8
  delegate :email, to: :user, allow_nil: true