rails_admin 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rails_admin might be problematic. Click here for more details.
- data/README.md +8 -57
- data/app/assets/stylesheets/rails_admin/base/{README → README.txt} +1 -1
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +4 -2
- data/app/assets/stylesheets/rails_admin/themes/cerulean/theming.css.scss +2 -2
- data/app/helpers/rails_admin/application_helper.rb +22 -28
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +1 -1
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +1 -1
- data/lib/generators/rails_admin/install_generator.rb +4 -3
- data/lib/rails_admin/adapters/mongoid.rb +2 -1
- data/lib/rails_admin/engine.rb +1 -0
- data/lib/rails_admin/version.rb +1 -1
- data/spec/controllers/application_controller_spec.rb +4 -4
- data/spec/controllers/main_controller_spec.rb +26 -26
- data/spec/dummy_app/config/routes.rb +1 -1
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +161818 -0
- data/spec/helpers/application_helper_spec.rb +46 -46
- data/spec/helpers/form_builder_spec.rb +2 -2
- data/spec/integration/authorization/cancan_spec.rb +22 -22
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +6 -6
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +16 -16
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +1 -1
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +6 -6
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +8 -8
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +10 -10
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +16 -16
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +3 -3
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +2 -2
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +1 -2
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +27 -27
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +45 -45
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +35 -38
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
- data/spec/integration/history/rails_admin_history_spec.rb +9 -9
- data/spec/integration/rails_admin_spec.rb +4 -4
- data/spec/integration/relation_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/abstract_model_spec.rb +10 -10
- data/spec/unit/active_record_extension_spec.rb +1 -1
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +24 -24
- data/spec/unit/adapters/active_record_spec.rb +131 -132
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +5 -5
- data/spec/unit/adapters/mongoid_spec.rb +180 -180
- data/spec/unit/config/actions/base_spec.rb +6 -6
- data/spec/unit/config/actions_spec.rb +31 -32
- data/spec/unit/config/fields/base_spec.rb +69 -70
- data/spec/unit/config/fields/date_spec.rb +5 -5
- data/spec/unit/config/fields/datetime_spec.rb +4 -4
- data/spec/unit/config/fields/time_spec.rb +3 -3
- data/spec/unit/config/fields/timestamp_spec.rb +1 -1
- data/spec/unit/config/model_spec.rb +12 -12
- data/spec/unit/config/sections_spec.rb +17 -17
- data/spec/unit/config_spec.rb +23 -24
- data/spec/unit/support/csv_converter_spec.rb +2 -2
- metadata +19 -3
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
# RailsAdmin [![Build Status](https://secure.travis-ci.org/sferik/rails_admin.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/sferik/rails_admin.png?travis)][gemnasium] [![Click here to lend your support to: RailsAdmin and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/15917.png)][pledgie]
|
1
|
+
# RailsAdmin [![Build Status](https://secure.travis-ci.org/sferik/rails_admin.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/sferik/rails_admin.png?travis)][gemnasium] [![Code Climate](https://codeclimate.com/badge.png)][codeclimate] [![Click here to lend your support to: RailsAdmin and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/15917.png)][pledgie]
|
2
2
|
RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.
|
3
3
|
|
4
4
|
[travis]: http://travis-ci.org/sferik/rails_admin
|
5
5
|
[gemnasium]: https://gemnasium.com/sferik/rails_admin
|
6
|
+
[codeclimate]: https://codeclimate.com/github/sferik/rails_admin
|
6
7
|
[pledgie]: http://www.pledgie.com/campaigns/15917
|
7
8
|
|
8
9
|
It started as a port of [MerbAdmin][merb-admin] to Rails 3 and was implemented
|
@@ -23,7 +24,7 @@ Hoeven][plukevdh], and [Rein Henrichs][reinh].
|
|
23
24
|
* for those with `rake db:migrate` errors, update to master and check that you see the line: "[RailsAdmin] RailsAdmin initialization disabled by default." when you launch the task. If not (or if migrations still don't work), open a ticket with an application on Github that can reproduce the issue.
|
24
25
|
|
25
26
|
* `config.models do ... end` is deprecated (note the 's' to models, `config.model(MyModel) do .. end` is fine), for performance reasons (forces early loading of all application's models). Duplicate to each model instead, before next release. If you really need the old behavior:
|
26
|
-
|
27
|
+
|
27
28
|
```ruby
|
28
29
|
config.models.each do |m|
|
29
30
|
config.model m do
|
@@ -73,8 +74,8 @@ And then run:
|
|
73
74
|
|
74
75
|
This generator will install RailsAdmin and [Devise](https://github.com/plataformatec/devise) if you
|
75
76
|
don't already have it installed. [Devise](https://github.com/plataformatec/devise) is strongly
|
76
|
-
recommended to protect your data from anonymous users. Note: If you do not already have [Devise](https://github.com/plataformatec/devise)
|
77
|
-
installed, make sure you remove the registerable module from the generated user model.
|
77
|
+
recommended to protect your data from anonymous users. Note: If you do not already have [Devise](https://github.com/plataformatec/devise)
|
78
|
+
installed, make sure you remove the registerable module from the generated user model.
|
78
79
|
|
79
80
|
|
80
81
|
It will modify your `config/routes.rb`, adding:
|
@@ -83,19 +84,18 @@ It will modify your `config/routes.rb`, adding:
|
|
83
84
|
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin' # Feel free to change '/admin' to any namespace you need.
|
84
85
|
```
|
85
86
|
|
86
|
-
Note:
|
87
|
-
The following will generate infinite redirects.
|
87
|
+
Note: The `devise_for` route must be placed before the mounted engine. The following will generate infinite redirects.
|
88
88
|
|
89
89
|
```ruby
|
90
90
|
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
|
91
91
|
devise_for :admins
|
92
92
|
```
|
93
93
|
|
94
|
-
|
94
|
+
This will resolve the infinite redirect error:
|
95
95
|
|
96
96
|
```ruby
|
97
|
-
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
|
98
97
|
devise_for :admins
|
98
|
+
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
|
99
99
|
```
|
100
100
|
|
101
101
|
See [#715](https://github.com/sferik/rails_admin/issues/715) for more details.
|
@@ -147,55 +147,6 @@ list][list].
|
|
147
147
|
|
148
148
|
If you think you found a bug in RailsAdmin, you can [submit an issue][issues].
|
149
149
|
|
150
|
-
## Contributing
|
151
|
-
|
152
|
-
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
153
|
-
improve this project.
|
154
|
-
|
155
|
-
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
156
|
-
|
157
|
-
Here are some ways *you* can contribute:
|
158
|
-
|
159
|
-
* by using alpha, beta, and prerelease versions
|
160
|
-
* by reporting bugs
|
161
|
-
* by suggesting new features
|
162
|
-
* by writing or editing documentation
|
163
|
-
* by writing specifications
|
164
|
-
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
165
|
-
inconsistent whitespace)
|
166
|
-
* by refactoring code
|
167
|
-
* by fixing [issues][]
|
168
|
-
* by reviewing patches
|
169
|
-
* [financially][pledgie]
|
170
|
-
|
171
|
-
[issues]: https://github.com/sferik/rails_admin/issues
|
172
|
-
|
173
|
-
## Submitting an Issue
|
174
|
-
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
175
|
-
submitting a bug report or feature request, check to make sure it hasn't
|
176
|
-
already been submitted. When submitting a bug report, please include a [Gist][]
|
177
|
-
that includes a stack trace and any details that may be necessary to reproduce
|
178
|
-
the bug, including your gem version, Ruby version, and operating system.
|
179
|
-
Ideally, a bug report should include a pull request with failing specs.
|
180
|
-
|
181
|
-
[gist]: https://gist.github.com/
|
182
|
-
|
183
|
-
## Submitting a Pull Request
|
184
|
-
1. [Fork the repository.][fork]
|
185
|
-
2. [Create a topic branch.][branch]
|
186
|
-
3. Add specs for your unimplemented feature or bug fix.
|
187
|
-
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
188
|
-
5. Implement your feature or bug fix.
|
189
|
-
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
190
|
-
7. Run `open coverage/index.html`. If your changes are not completely covered
|
191
|
-
by your tests, return to step 3.
|
192
|
-
8. Add, commit, and push your changes.
|
193
|
-
9. [Submit a pull request.][pr]
|
194
|
-
|
195
|
-
[fork]: http://help.github.com/fork-a-repo/
|
196
|
-
[branch]: http://learn.github.com/p/branching.html
|
197
|
-
[pr]: http://help.github.com/send-pull-requests/
|
198
|
-
|
199
150
|
## Supported Ruby Versions
|
200
151
|
This library aims to support and is [tested against][travis] the following Ruby implementations:
|
201
152
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
For RailsAdmin
|
1
|
+
For RailsAdmin developers:
|
2
2
|
We should use sass variables & mixins as much as possible so that themers/users can override them cleanly
|
@@ -20,7 +20,6 @@
|
|
20
20
|
|
21
21
|
/*** Reset ***/
|
22
22
|
@import "bootstrap/reset";
|
23
|
-
|
24
23
|
/*** Libraries ***/
|
25
24
|
|
26
25
|
@import "rails_admin/aristo/jquery-ui-1.8.7.custom";
|
@@ -31,6 +30,10 @@
|
|
31
30
|
@import "rails_admin/jquery.colorpicker";
|
32
31
|
|
33
32
|
|
33
|
+
/*** Font-awesome ***/
|
34
|
+
|
35
|
+
@import 'font-awesome';
|
36
|
+
|
34
37
|
/*** Bootstrap Theming ***/
|
35
38
|
|
36
39
|
@import "bootstrap/scaffolding";
|
@@ -39,7 +42,6 @@
|
|
39
42
|
@import "bootstrap/type";
|
40
43
|
@import "bootstrap/forms";
|
41
44
|
@import "bootstrap/tables";
|
42
|
-
@import "bootstrap/sprites";
|
43
45
|
@import "bootstrap/dropdowns";
|
44
46
|
@import "bootstrap/wells";
|
45
47
|
@import "bootstrap/component-animations";
|
@@ -16,7 +16,7 @@
|
|
16
16
|
// -----------------------------------------------------
|
17
17
|
|
18
18
|
.navbar-inner {
|
19
|
-
@include gradient-vertical-three-colors($navbarBackground, $navbarBackground,
|
19
|
+
@include gradient-vertical-three-colors($navbarBackground, $navbarBackground, 0.9, $navbarBackgroundHighlight);
|
20
20
|
}
|
21
21
|
|
22
22
|
.navbar .nav .active > a,
|
@@ -55,7 +55,7 @@
|
|
55
55
|
// -----------------------------------------------------
|
56
56
|
|
57
57
|
.btn {
|
58
|
-
@include gradient-vertical-three-colors($white, $white,
|
58
|
+
@include gradient-vertical-three-colors($white, $white, 0.05, darken($white, 0%));
|
59
59
|
$shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.05);
|
60
60
|
@include box-shadow($shadow);
|
61
61
|
|
@@ -44,46 +44,39 @@ module RailsAdmin
|
|
44
44
|
|
45
45
|
def main_navigation
|
46
46
|
nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
|
47
|
+
node_model_names = nodes_stack.map{ |c| c.abstract_model.model_name }
|
48
|
+
|
47
49
|
nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
<li data-model="#{node.abstract_model.to_param}">
|
52
|
-
<a class="pjax" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => node.abstract_model.to_param)}">#{node.label_plural}</a>
|
53
|
-
</li>
|
54
|
-
#{navigation(nodes_stack, nodes_stack.select{|n| n.parent.to_s == node.abstract_model.model_name}, 1)}
|
55
|
-
}.html_safe
|
56
|
-
end.join.html_safe
|
57
|
-
|
58
|
-
if li_stack.present?
|
59
|
-
li_stack = %{<li class='nav-header'>#{navigation_label || t('admin.misc.navigation')}</li>}.html_safe + li_stack
|
60
|
-
end
|
51
|
+
nodes = nodes.select{ |n| n.parent.nil? || !n.parent.to_s.in?(node_model_names) }
|
52
|
+
li_stack = navigation nodes_stack, nodes
|
61
53
|
|
62
|
-
|
54
|
+
label = navigation_label || t('admin.misc.navigation')
|
55
|
+
%{<li class='nav-header'>#{label}</li>#{li_stack}} if li_stack.present?
|
63
56
|
end.join.html_safe
|
64
57
|
end
|
65
58
|
|
66
59
|
def static_navigation
|
67
60
|
li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
|
68
|
-
content_tag(:li, link_to(title.to_s, url, :target => '_blank'))
|
69
|
-
end.join
|
70
|
-
|
71
|
-
if li_stack.present?
|
72
|
-
li_stack = %{<li class='nav-header'>#{RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')}</li>}.html_safe + li_stack
|
73
|
-
end
|
61
|
+
content_tag(:li, link_to(title.to_s, url, :target => '_blank'))
|
62
|
+
end.join
|
74
63
|
|
64
|
+
label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
|
65
|
+
li_stack = %{<li class='nav-header'>#{label}</li>#{li_stack}}.html_safe if li_stack.present?
|
75
66
|
li_stack
|
76
67
|
end
|
77
68
|
|
78
|
-
def navigation nodes_stack, nodes, level
|
69
|
+
def navigation nodes_stack, nodes, level=0
|
79
70
|
nodes.map do |node|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
71
|
+
model_param = node.abstract_model.to_param
|
72
|
+
url = url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)
|
73
|
+
level_class = "nav-level-#{level}" if level > 0
|
74
|
+
|
75
|
+
li = content_tag :li, "data-model"=>model_param do
|
76
|
+
link_to node.label_plural, url, :class => "pjax#{level_class}"
|
77
|
+
end
|
78
|
+
li + navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level+1)
|
79
|
+
end.join.html_safe
|
87
80
|
end
|
88
81
|
|
89
82
|
def breadcrumb action = @action, acc = []
|
@@ -134,8 +127,9 @@ module RailsAdmin
|
|
134
127
|
end
|
135
128
|
end.join.html_safe
|
136
129
|
end
|
137
|
-
end
|
130
|
+
end.html_safe
|
138
131
|
end
|
132
|
+
|
139
133
|
end
|
140
134
|
end
|
141
135
|
|
@@ -43,5 +43,5 @@
|
|
43
43
|
= form.select field.method_name, collection, { :selected => selected_ids, :object => form.object }, field.html_attributes.reverse_merge({:data => { :filteringmultiselect => true, :options => js_data.to_json }, :multiple => true})
|
44
44
|
- if authorized? :new, config.abstract_model
|
45
45
|
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
|
46
|
-
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.id
|
46
|
+
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
|
47
47
|
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "create btn btn-info", :style => 'margin-left:10px'
|
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
- if authorized? :new, config.abstract_model
|
32
32
|
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
|
33
|
-
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.id
|
33
|
+
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
|
34
34
|
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "btn btn-info create", :style => 'float:left; margin-left:10px'
|
35
35
|
|
36
36
|
- if edit_url.present?
|
@@ -37,6 +37,10 @@ module RailsAdmin
|
|
37
37
|
display "Looks like you've already installed it, good!"
|
38
38
|
end
|
39
39
|
|
40
|
+
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
|
41
|
+
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
|
42
|
+
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
|
43
|
+
|
40
44
|
unless routes.index("devise_for")
|
41
45
|
model_name = ask_for("What would you like the user model to be called?", "user", _model_name)
|
42
46
|
display "Now setting up devise with user model name '#{model_name}':"
|
@@ -75,9 +79,6 @@ module RailsAdmin
|
|
75
79
|
end
|
76
80
|
display "Adding a migration..."
|
77
81
|
migration_template 'migration.rb', 'db/migrate/create_rails_admin_histories_table.rb' rescue display $!.message
|
78
|
-
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
|
79
|
-
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
|
80
|
-
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
|
81
82
|
display "Job's done: migrate, start your server and visit '/#{namespace}'!", :blue
|
82
83
|
end
|
83
84
|
end
|
@@ -251,6 +251,7 @@ module RailsAdmin
|
|
251
251
|
"DateTime" => { :type => :datetime },
|
252
252
|
"Float" => { :type => :float },
|
253
253
|
"Hash" => { :type => :serialized },
|
254
|
+
"Money" => { :type => :serialized },
|
254
255
|
"Integer" => { :type => :integer },
|
255
256
|
"Object" => (
|
256
257
|
if associations.find{|a| a[:type] == :belongs_to && a[:foreign_key] == name.to_sym}
|
@@ -270,7 +271,7 @@ module RailsAdmin
|
|
270
271
|
),
|
271
272
|
"Symbol" => { :type => :string, :length => 255 },
|
272
273
|
"Time" => { :type => :datetime },
|
273
|
-
}[field.type.to_s] or raise "
|
274
|
+
}[field.type.to_s] or raise "Type #{field.type.to_s} for field :#{name} in #{model.inspect} not supported"
|
274
275
|
end
|
275
276
|
|
276
277
|
def association_model_proc_lookup(association)
|
data/lib/rails_admin/engine.rb
CHANGED
data/lib/rails_admin/version.rb
CHANGED
@@ -3,20 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe RailsAdmin::ApplicationController do
|
4
4
|
describe "#to_model_name" do
|
5
5
|
it "works with modules" do
|
6
|
-
controller.to_model_name("conversations~conversation").
|
6
|
+
expect(controller.to_model_name("conversations~conversation")).to eq("Conversations::Conversation")
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "helper method _get_plugin_name" do
|
11
11
|
it "works by default" do
|
12
|
-
controller.send(:_get_plugin_name).
|
12
|
+
expect(controller.send(:_get_plugin_name)).to eq(['Dummy App', 'Admin'])
|
13
13
|
end
|
14
14
|
|
15
15
|
it "works for static names" do
|
16
16
|
RailsAdmin.config do |config|
|
17
17
|
config.main_app_name = ['static','value']
|
18
18
|
end
|
19
|
-
controller.send(:_get_plugin_name).
|
19
|
+
expect(controller.send(:_get_plugin_name)).to eq(['static', 'value'])
|
20
20
|
end
|
21
21
|
|
22
22
|
it "works for dynamic names in the controller context" do
|
@@ -24,7 +24,7 @@ describe RailsAdmin::ApplicationController do
|
|
24
24
|
config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.try(:titleize), controller.params[:action].titleize] }
|
25
25
|
end
|
26
26
|
controller.params[:action] = "dashboard"
|
27
|
-
controller.send(:_get_plugin_name).
|
27
|
+
expect(controller.send(:_get_plugin_name)).to eq(["Dummy App Application", "Dashboard"])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -3,17 +3,17 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe RailsAdmin::MainController do
|
6
|
-
|
6
|
+
|
7
7
|
describe "#dashboard" do
|
8
8
|
before do
|
9
9
|
controller.stub(:render).and_return(true) # no rendering
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "should show statistics by default" do
|
13
13
|
RailsAdmin.config(Player).abstract_model.should_receive(:count).and_return(0)
|
14
14
|
controller.dashboard
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should not show statistics if turned off" do
|
18
18
|
RailsAdmin.config do |c|
|
19
19
|
c.actions do
|
@@ -22,14 +22,14 @@ describe RailsAdmin::MainController do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
RailsAdmin.config(Player).abstract_model.should_not_receive(:count)
|
27
27
|
controller.dashboard
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
describe "#check_for_cancel" do
|
32
|
-
|
32
|
+
|
33
33
|
it "should redirect to back if params[:bulk_ids] is nil when params[:bulk_action] is present" do
|
34
34
|
controller.stub(:back_or_index) { raise StandardError.new('redirected back') }
|
35
35
|
expect { get :bulk_delete, { :model_name => "player", :bulk_action =>"bulk_delete" } }.to raise_error('redirected back')
|
@@ -40,12 +40,12 @@ describe RailsAdmin::MainController do
|
|
40
40
|
describe "#get_sort_hash" do
|
41
41
|
it 'should work with belongs_to associations with label method virtual' do
|
42
42
|
controller.params = { :sort => "parent_category", :model_name =>"categories" }
|
43
|
-
controller.send(:get_sort_hash, RailsAdmin.config(Category)).
|
43
|
+
expect(controller.send(:get_sort_hash, RailsAdmin.config(Category))).to eq({:sort=>"categories.parent_category_id", :sort_reverse=>true})
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should work with belongs_to associations with label method real column' do
|
47
47
|
controller.params = { :sort => "team", :model_name =>"players" }
|
48
|
-
controller.send(:get_sort_hash, RailsAdmin.config(Player)).
|
48
|
+
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq({:sort=>"teams.name", :sort_reverse=>true})
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -56,8 +56,8 @@ describe RailsAdmin::MainController do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should paginate" do
|
59
|
-
controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length.
|
60
|
-
controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length.
|
59
|
+
expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length).to eq(21)
|
60
|
+
expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length).to eq(20)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -68,7 +68,7 @@ describe RailsAdmin::MainController do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should not paginate" do
|
71
|
-
controller.list_entries(RailsAdmin.config(Team), :bulk_delete).to_a.length.
|
71
|
+
expect(controller.list_entries(RailsAdmin.config(Team), :bulk_delete).to_a.length).to eq(21)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -90,7 +90,7 @@ describe RailsAdmin::MainController do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
controller.list_entries.to_a.length.
|
93
|
+
expect(controller.list_entries.to_a.length).to eq(@players.size)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "scopes associated collection records according to associated_collection_scope" do
|
@@ -106,7 +106,7 @@ describe RailsAdmin::MainController do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
controller.list_entries.to_a.length.
|
109
|
+
expect(controller.list_entries.to_a.length).to eq(3)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "scopes associated collection records according to bindings" do
|
@@ -128,7 +128,7 @@ describe RailsAdmin::MainController do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
controller.list_entries.to_a.length.
|
131
|
+
expect(controller.list_entries.to_a.length).to eq(@team.revenue.to_i)
|
132
132
|
end
|
133
133
|
|
134
134
|
|
@@ -142,14 +142,14 @@ describe RailsAdmin::MainController do
|
|
142
142
|
associated_collection_cache_all false
|
143
143
|
end
|
144
144
|
end
|
145
|
-
controller.list_entries.to_a.length.
|
145
|
+
expect(controller.list_entries.to_a.length).to eq(30)
|
146
146
|
|
147
147
|
RailsAdmin.config Team do
|
148
148
|
field :players do
|
149
149
|
associated_collection_cache_all true
|
150
150
|
end
|
151
151
|
end
|
152
|
-
controller.list_entries.length.
|
152
|
+
expect(controller.list_entries.length).to eq(@players.size)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "orders associated collection records by desc" do
|
@@ -157,7 +157,7 @@ describe RailsAdmin::MainController do
|
|
157
157
|
FactoryGirl.create :player
|
158
158
|
end
|
159
159
|
|
160
|
-
controller.list_entries.to_a.first.
|
160
|
+
expect(controller.list_entries.to_a.first).to eq(@players.last)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -169,10 +169,10 @@ describe RailsAdmin::MainController do
|
|
169
169
|
FactoryGirl.create :team
|
170
170
|
TeamWithNumberedPlayers.first.numbered_players = [FactoryGirl.create(:player, :number => 123)]
|
171
171
|
returned = get :index, {:model_name => 'player', :source_object_id => Team.first.id, :source_abstract_model => 'team_with_numbered_players', :associated_collection => 'numbered_players', :current_action => :create, :compact => true, :format => :json}
|
172
|
-
returned.body.
|
172
|
+
expect(returned.body).to match /\"id\"\:123/
|
173
173
|
end
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
describe "sanitize_params_for!" do
|
177
177
|
it 'sanitize params recursively in nested forms' do
|
178
178
|
RailsAdmin.config Comment do
|
@@ -190,7 +190,7 @@ describe RailsAdmin::MainController do
|
|
190
190
|
I18n.locale = :fr
|
191
191
|
controller.params = {
|
192
192
|
"field_test"=>{
|
193
|
-
:"datetime_field"=>"1 août 2010",
|
193
|
+
:"datetime_field"=>"1 août 2010",
|
194
194
|
"nested_field_tests_attributes"=>{
|
195
195
|
"new_1330520162002"=>{
|
196
196
|
"comment_attributes"=>{
|
@@ -198,7 +198,7 @@ describe RailsAdmin::MainController do
|
|
198
198
|
},
|
199
199
|
:"created_at"=>"3 août 2010"
|
200
200
|
}
|
201
|
-
},
|
201
|
+
},
|
202
202
|
"comment_attributes"=>{
|
203
203
|
:"created_at"=>"4 août 2010"
|
204
204
|
}
|
@@ -207,22 +207,22 @@ describe RailsAdmin::MainController do
|
|
207
207
|
|
208
208
|
controller.send(:sanitize_params_for!, :create, RailsAdmin.config(FieldTest), controller.params['field_test'])
|
209
209
|
|
210
|
-
controller.params.
|
210
|
+
expect(controller.params).to eq({
|
211
211
|
"field_test"=>{
|
212
|
-
:datetime_field=>'Sun, 01 Aug 2010 00:00:00 UTC +00:00',
|
212
|
+
:datetime_field=>'Sun, 01 Aug 2010 00:00:00 UTC +00:00',
|
213
213
|
"nested_field_tests_attributes"=>{
|
214
214
|
"new_1330520162002"=>{
|
215
215
|
"comment_attributes"=>{
|
216
216
|
:created_at=>'Mon, 02 Aug 2010 00:00:00 UTC +00:00'
|
217
|
-
},
|
217
|
+
},
|
218
218
|
:created_at=>'Tue, 03 Aug 2010 00:00:00 UTC +00:00'
|
219
219
|
}
|
220
|
-
},
|
220
|
+
},
|
221
221
|
"comment_attributes"=>{
|
222
222
|
:created_at=>'Wed, 04 Aug 2010 00:00:00 UTC +00:00'
|
223
223
|
}
|
224
224
|
}
|
225
|
-
}
|
225
|
+
})
|
226
226
|
I18n.locale = :en
|
227
227
|
end
|
228
228
|
end
|