rails_admin 0.3.0 → 0.4.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.
- data/Gemfile +2 -2
- data/README.md +13 -6
- data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/images/rails_admin/bullet_white.png +0 -0
- data/app/assets/images/rails_admin/calendar.png +0 -0
- data/app/assets/images/rails_admin/clock.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
- data/app/assets/images/rails_admin/logo.png +0 -0
- data/app/assets/images/rails_admin/magnifier.png +0 -0
- data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +1 -0
- data/app/controllers/rails_admin/main_controller.rb +1 -1
- data/app/helpers/rails_admin/application_helper.rb +3 -2
- data/app/views/rails_admin/main/index.html.haml +1 -1
- data/lib/generators/rails_admin/install_generator.rb +1 -1
- data/lib/rails_admin/abstract_model.rb +4 -0
- data/lib/rails_admin/adapters/active_record.rb +4 -0
- data/lib/rails_admin/adapters/mongoid.rb +6 -0
- data/lib/rails_admin/adapters/mongoid/abstract_object.rb +3 -3
- data/lib/rails_admin/config.rb +9 -12
- data/lib/rails_admin/config/actions/base.rb +4 -3
- data/lib/rails_admin/config/fields/association.rb +1 -1
- data/lib/rails_admin/config/fields/base.rb +1 -1
- data/lib/rails_admin/config/fields/factories/association.rb +1 -1
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +1 -1
- data/lib/rails_admin/config/fields/types/boolean.rb +2 -2
- data/lib/rails_admin/config/fields/types/datetime.rb +1 -1
- data/lib/rails_admin/config/has_fields.rb +3 -2
- data/lib/rails_admin/config/lazy_model.rb +21 -0
- data/lib/rails_admin/extensions/history/history.rb +5 -5
- data/lib/rails_admin/support/csv_converter.rb +2 -6
- data/lib/rails_admin/version.rb +1 -1
- data/spec/controllers/{application_controller_spec.rb → rails_admin/application_controller_spec.rb} +0 -0
- data/spec/controllers/{main_controller_spec.rb → rails_admin/main_controller_spec.rb} +36 -4
- data/spec/dummy_app/Gemfile +2 -2
- data/spec/dummy_app/app/active_record/comment.rb +1 -1
- data/spec/dummy_app/app/active_record/team.rb +1 -1
- data/spec/dummy_app/app/mongoid/field_test.rb +2 -1
- data/spec/dummy_app/app/mongoid/team.rb +1 -1
- data/spec/dummy_app/db/seeds.rb +4 -4
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +156160 -0
- data/spec/helpers/rails_admin/application_helper_spec.rb +353 -0
- data/spec/helpers/{form_builder_spec.rb → rails_admin/form_builder_spec.rb} +0 -0
- data/spec/integration/authorization/cancan_spec.rb +13 -13
- data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +2 -2
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +13 -2
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +8 -9
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -1
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +4 -4
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +2 -2
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +2 -2
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +51 -21
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +15 -15
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +13 -14
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +7 -6
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +1 -1
- data/spec/integration/rails_admin_spec.rb +2 -0
- data/spec/{unit → rails_admin}/abstract_model_spec.rb +7 -0
- data/spec/{unit → rails_admin}/active_record_extension_spec.rb +0 -0
- data/spec/{unit → rails_admin}/adapters/active_record/abstract_object_spec.rb +0 -0
- data/spec/{unit → rails_admin}/adapters/active_record_spec.rb +0 -0
- data/spec/{unit → rails_admin}/adapters/mongoid/abstract_object_spec.rb +0 -0
- data/spec/{unit → rails_admin}/adapters/mongoid_spec.rb +7 -1
- data/spec/{unit → rails_admin}/config/actions/base_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/actions_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/base_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/date_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/datetime_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/file_upload_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/time_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/fields/timestamp_spec.rb +0 -0
- data/spec/rails_admin/config/fields/types/datetime_spec.rb +18 -0
- data/spec/{unit → rails_admin}/config/fields_spec.rb +0 -0
- data/spec/rails_admin/config/has_fields_spec.rb +30 -0
- data/spec/rails_admin/config/lazy_model_spec.rb +29 -0
- data/spec/{unit → rails_admin}/config/model_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config/sections_spec.rb +0 -0
- data/spec/{unit → rails_admin}/config_spec.rb +0 -0
- data/spec/{unit → rails_admin}/support/csv_converter_spec.rb +0 -0
- data/spec/spec_helper.rb +2 -0
- metadata +65 -60
- data/spec/helpers/application_helper_spec.rb +0 -328
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'cancan'
|
|
3
|
+
|
|
4
|
+
class TestAbility
|
|
5
|
+
include CanCan::Ability
|
|
6
|
+
def initialize(user)
|
|
7
|
+
can :access, :rails_admin
|
|
8
|
+
can :edit, FieldTest
|
|
9
|
+
cannot :edit, FieldTest, string_field: 'dangerous'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe RailsAdmin::ApplicationHelper do
|
|
14
|
+
describe '#authorized?' do
|
|
15
|
+
before do
|
|
16
|
+
RailsAdmin.config.stub(_current_user: FactoryGirl.create(:user))
|
|
17
|
+
helper.instance_variable_set('@authorization_adapter', RailsAdmin::AUTHORIZATION_ADAPTERS[:cancan].new(RailsAdmin.config, TestAbility))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'doesn\'t test unpersisted objects' do
|
|
21
|
+
am = RailsAdmin.config(FieldTest).abstract_model
|
|
22
|
+
expect(helper.authorized?(:edit, am, FactoryGirl.create(:field_test, string_field: 'dangerous'))).to be_false
|
|
23
|
+
expect(helper.authorized?(:edit, am, FactoryGirl.create(:field_test, string_field: 'not-dangerous'))).to be_true
|
|
24
|
+
expect(helper.authorized?(:edit, am, FactoryGirl.build(:field_test, string_field: 'dangerous'))).to be_true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'with #authorized? stubbed' do
|
|
29
|
+
before do
|
|
30
|
+
controller.stub(:authorized?).and_return(true)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "#current_action?" do
|
|
34
|
+
it "returns true if current_action, false otherwise" do
|
|
35
|
+
@action = RailsAdmin::Config::Actions.find(:index)
|
|
36
|
+
|
|
37
|
+
expect(helper.current_action?(RailsAdmin::Config::Actions.find(:index))).to be_true
|
|
38
|
+
expect(helper.current_action?(RailsAdmin::Config::Actions.find(:show))).not_to be_true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#action" do
|
|
43
|
+
it "returns action by :custom_key" do
|
|
44
|
+
RailsAdmin.config do |config|
|
|
45
|
+
config.actions do
|
|
46
|
+
dashboard do
|
|
47
|
+
custom_key :my_custom_dashboard_key
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
expect(helper.action(:my_custom_dashboard_key)).to be
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "returns only visible actions" do
|
|
55
|
+
RailsAdmin.config do |config|
|
|
56
|
+
config.actions do
|
|
57
|
+
dashboard do
|
|
58
|
+
visible false
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
expect(helper.action(:dashboard)).to be_nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "returns only visible actions, passing all bindings" do
|
|
67
|
+
RailsAdmin.config do |config|
|
|
68
|
+
config.actions do
|
|
69
|
+
member :test_bindings do
|
|
70
|
+
visible do
|
|
71
|
+
bindings[:controller].is_a?(ActionView::TestCase::TestController) and
|
|
72
|
+
bindings[:abstract_model].model == Team and
|
|
73
|
+
bindings[:object].is_a? Team
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
expect(helper.action(:test_bindings, RailsAdmin::AbstractModel.new(Team), Team.new)).to be
|
|
79
|
+
expect(helper.action(:test_bindings, RailsAdmin::AbstractModel.new(Team), Player.new)).to be_nil
|
|
80
|
+
expect(helper.action(:test_bindings, RailsAdmin::AbstractModel.new(Player), Team.new)).to be_nil
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "#actions" do
|
|
85
|
+
it "returns actions by type" do
|
|
86
|
+
abstract_model = RailsAdmin::AbstractModel.new(Player)
|
|
87
|
+
object = FactoryGirl.create :player
|
|
88
|
+
expect(helper.actions(:all, abstract_model, object).map(&:custom_key)).to eq([:dashboard, :index, :show, :new, :edit, :export, :delete, :bulk_delete, :history_show, :history_index, :show_in_app])
|
|
89
|
+
expect(helper.actions(:root, abstract_model, object).map(&:custom_key)).to eq([:dashboard])
|
|
90
|
+
expect(helper.actions(:collection, abstract_model, object).map(&:custom_key)).to eq([:index, :new, :export, :bulk_delete, :history_index])
|
|
91
|
+
expect(helper.actions(:member, abstract_model, object).map(&:custom_key)).to eq([:show, :edit, :delete, :history_show, :show_in_app])
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "only returns visible actions, passing bindings correctly" do
|
|
95
|
+
RailsAdmin.config do |config|
|
|
96
|
+
config.actions do
|
|
97
|
+
member :test_bindings do
|
|
98
|
+
visible do
|
|
99
|
+
bindings[:controller].is_a?(ActionView::TestCase::TestController) and
|
|
100
|
+
bindings[:abstract_model].model == Team and
|
|
101
|
+
bindings[:object].is_a? Team
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
expect(helper.actions(:all, RailsAdmin::AbstractModel.new(Team), Team.new).map(&:custom_key)).to eq([:test_bindings])
|
|
108
|
+
expect(helper.actions(:all, RailsAdmin::AbstractModel.new(Team), Player.new).map(&:custom_key)).to eq([])
|
|
109
|
+
expect(helper.actions(:all, RailsAdmin::AbstractModel.new(Player), Team.new).map(&:custom_key)).to eq([])
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "#wording_for" do
|
|
114
|
+
it "gives correct wording even if action is not visible" do
|
|
115
|
+
RailsAdmin.config do |config|
|
|
116
|
+
config.actions do
|
|
117
|
+
index do
|
|
118
|
+
visible false
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
expect(helper.wording_for(:menu, :index)).to eq("List")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "passes correct bindings" do
|
|
127
|
+
expect(helper.wording_for(:title, :edit, RailsAdmin::AbstractModel.new(Team), Team.new(:name => 'the avengers'))).to eq("Edit Team 'the avengers'")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "defaults correct bindings" do
|
|
131
|
+
@action = RailsAdmin::Config::Actions.find :edit
|
|
132
|
+
@abstract_model = RailsAdmin::AbstractModel.new(Team)
|
|
133
|
+
@object = Team.new(:name => 'the avengers')
|
|
134
|
+
expect(helper.wording_for(:title)).to eq("Edit Team 'the avengers'")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "does not try to use the wrong :label_metod" do
|
|
138
|
+
@abstract_model = RailsAdmin::AbstractModel.new(Draft)
|
|
139
|
+
@object = Draft.new
|
|
140
|
+
|
|
141
|
+
expect(helper.wording_for(:link, :new, RailsAdmin::AbstractModel.new(Team))).to eq("Add a new Team")
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe "#breadcrumb" do
|
|
147
|
+
it "gives us a breadcrumb" do
|
|
148
|
+
@action = RailsAdmin::Config::Actions.find(:edit, {:abstract_model => RailsAdmin::AbstractModel.new(Team), :object => Team.new(:name => 'the avengers')})
|
|
149
|
+
bc = helper.breadcrumb
|
|
150
|
+
expect(bc).to match /Dashboard/ # dashboard
|
|
151
|
+
expect(bc).to match /Teams/ # list
|
|
152
|
+
expect(bc).to match /the avengers/ # show
|
|
153
|
+
expect(bc).to match /Edit/ # current (edit)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe "#menu_for" do
|
|
158
|
+
it "passes model and object as bindings and generates a menu, excluding non-get actions" do
|
|
159
|
+
RailsAdmin.config do |config|
|
|
160
|
+
config.actions do
|
|
161
|
+
dashboard
|
|
162
|
+
index do
|
|
163
|
+
visible do
|
|
164
|
+
bindings[:abstract_model].model == Team
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
show do
|
|
168
|
+
visible do
|
|
169
|
+
bindings[:object].class == Team
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
delete do
|
|
173
|
+
http_methods [:post, :put, :delete]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
@action = RailsAdmin::Config::Actions.find :show
|
|
179
|
+
@abstract_model = RailsAdmin::AbstractModel.new(Team)
|
|
180
|
+
@object = Team.new(:name => 'the avengers')
|
|
181
|
+
|
|
182
|
+
expect(helper.menu_for(:root)).to match /Dashboard/
|
|
183
|
+
expect(helper.menu_for(:collection, @abstract_model)).to match /List/
|
|
184
|
+
expect(helper.menu_for(:member, @abstract_model, @object)).to match /Show/
|
|
185
|
+
|
|
186
|
+
@abstract_model = RailsAdmin::AbstractModel.new(Player)
|
|
187
|
+
@object = Player.new
|
|
188
|
+
expect(helper.menu_for(:collection, @abstract_model)).not_to match /List/
|
|
189
|
+
expect(helper.menu_for(:member, @abstract_model, @object)).not_to match /Show/
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "excludes non-get actions" do
|
|
193
|
+
RailsAdmin.config do |config|
|
|
194
|
+
config.actions do
|
|
195
|
+
dashboard do
|
|
196
|
+
http_methods [:post, :put, :delete]
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
@action = RailsAdmin::Config::Actions.find :dashboard
|
|
202
|
+
expect(helper.menu_for(:root)).not_to match /Dashboard/
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe "#main_navigation" do
|
|
207
|
+
it "shows included models" do
|
|
208
|
+
RailsAdmin.config do |config|
|
|
209
|
+
config.included_models = [Ball, Comment]
|
|
210
|
+
end
|
|
211
|
+
expect(helper.main_navigation).to match /(nav\-header).*(Navigation).*(Balls).*(Comments)/m
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "does not draw empty navigation labels" do
|
|
215
|
+
RailsAdmin.config do |config|
|
|
216
|
+
config.included_models = [Ball, Comment, Comment::Confirmed]
|
|
217
|
+
config.model Comment do
|
|
218
|
+
navigation_label 'Commentz'
|
|
219
|
+
end
|
|
220
|
+
config.model Comment::Confirmed do
|
|
221
|
+
label_plural 'Confirmed'
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
expect(helper.main_navigation).to match /(nav\-header).*(Navigation).*(Balls).*(Commentz).*(Confirmed)/m
|
|
225
|
+
expect(helper.main_navigation).not_to match /(nav\-header).*(Navigation).*(Balls).*(Commentz).*(Confirmed).*(Comment)/m
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "does not show unvisible models" do
|
|
229
|
+
RailsAdmin.config do |config|
|
|
230
|
+
config.included_models = [Ball, Comment]
|
|
231
|
+
config.model Comment do
|
|
232
|
+
hide
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
result = helper.main_navigation
|
|
236
|
+
expect(result).to match /(nav\-header).*(Navigation).*(Balls)/m
|
|
237
|
+
expect(result).not_to match "Comments"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "shows children of hidden models" do # https://github.com/sferik/rails_admin/issues/978
|
|
241
|
+
RailsAdmin.config do |config|
|
|
242
|
+
config.included_models = [Ball, Hardball]
|
|
243
|
+
config.model Ball do
|
|
244
|
+
hide
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
expect(helper.main_navigation).to match /(nav\-header).*(Navigation).*(Hardballs)/m
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it "shows children of excluded models" do
|
|
251
|
+
RailsAdmin.config do |config|
|
|
252
|
+
config.included_models = [Hardball]
|
|
253
|
+
end
|
|
254
|
+
expect(helper.main_navigation).to match /(nav\-header).*(Navigation).*(Hardballs)/m
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it "nests in navigation label" do
|
|
258
|
+
RailsAdmin.config do |config|
|
|
259
|
+
config.included_models = [Comment]
|
|
260
|
+
config.model Comment do
|
|
261
|
+
navigation_label 'commentable'
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
expect(helper.main_navigation).to match /(nav\-header).*(commentable).*(Comments)/m
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "nests in parent model" do
|
|
268
|
+
RailsAdmin.config do |config|
|
|
269
|
+
config.included_models = [Player, Comment]
|
|
270
|
+
config.model Comment do
|
|
271
|
+
parent Player
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
expect(helper.main_navigation).to match /(Players).* (nav\-level\-1).*(Comments)/m
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it "orders" do
|
|
278
|
+
RailsAdmin.config do |config|
|
|
279
|
+
config.included_models = [Player, Comment]
|
|
280
|
+
end
|
|
281
|
+
expect(helper.main_navigation).to match /(Comments).*(Players)/m
|
|
282
|
+
|
|
283
|
+
RailsAdmin.config(Comment) do
|
|
284
|
+
weight 1
|
|
285
|
+
end
|
|
286
|
+
expect(helper.main_navigation).to match /(Players).*(Comments)/m
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
describe "#static_navigation" do
|
|
291
|
+
it "shows not show static nav if no static links defined" do
|
|
292
|
+
RailsAdmin.config do |config|
|
|
293
|
+
config.navigation_static_links = {}
|
|
294
|
+
end
|
|
295
|
+
expect(helper.static_navigation).to be_empty
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it "shows links if defined" do
|
|
299
|
+
RailsAdmin.config do |config|
|
|
300
|
+
config.navigation_static_links = {
|
|
301
|
+
'Test Link' => 'http://www.google.com'
|
|
302
|
+
}
|
|
303
|
+
end
|
|
304
|
+
expect(helper.static_navigation).to match /Test Link/
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
it "shows default header if navigation_static_label not defined in config" do
|
|
308
|
+
RailsAdmin.config do |config|
|
|
309
|
+
config.navigation_static_links = {
|
|
310
|
+
'Test Link' => 'http://www.google.com'
|
|
311
|
+
}
|
|
312
|
+
end
|
|
313
|
+
expect(helper.static_navigation).to match I18n.t('admin.misc.navigation_static_label')
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
it "shows custom header if defined" do
|
|
317
|
+
RailsAdmin.config do |config|
|
|
318
|
+
config.navigation_static_label = "Test Header"
|
|
319
|
+
config.navigation_static_links = {
|
|
320
|
+
'Test Link' => 'http://www.google.com'
|
|
321
|
+
}
|
|
322
|
+
end
|
|
323
|
+
expect(helper.static_navigation).to match /Test Header/
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
describe "#bulk_menu" do
|
|
328
|
+
it "includes all visible bulkable actions" do
|
|
329
|
+
RailsAdmin.config do |config|
|
|
330
|
+
config.actions do
|
|
331
|
+
index
|
|
332
|
+
collection :zorg do
|
|
333
|
+
bulkable true
|
|
334
|
+
action_name :zorg_action
|
|
335
|
+
end
|
|
336
|
+
collection :blub do
|
|
337
|
+
bulkable true
|
|
338
|
+
visible do
|
|
339
|
+
bindings[:abstract_model].model == Team
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
@action = RailsAdmin::Config::Actions.find :index
|
|
345
|
+
result = helper.bulk_menu(RailsAdmin::AbstractModel.new(Team))
|
|
346
|
+
expect(result).to match "zorg_action"
|
|
347
|
+
expect(result).to match "blub"
|
|
348
|
+
|
|
349
|
+
expect(helper.bulk_menu(RailsAdmin::AbstractModel.new(Player))).not_to match "blub"
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
end
|
|
File without changes
|
|
@@ -76,9 +76,9 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
76
76
|
|
|
77
77
|
it "GET /admin should show Player but not League" do
|
|
78
78
|
visit dashboard_path
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
should have_content("Player")
|
|
80
|
+
should_not have_content("League")
|
|
81
|
+
should_not have_content("Add new")
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it "GET /admin/player should render successfully but not list retired players and not show new, edit, or delete actions" do
|
|
@@ -132,7 +132,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
132
132
|
fill_in "player[name]", :with => "Jackie Robinson"
|
|
133
133
|
fill_in "player[number]", :with => "42"
|
|
134
134
|
fill_in "player[position]", :with => "Second baseman"
|
|
135
|
-
click_button "Save"
|
|
135
|
+
click_button "Save" # first(:button, "Save").click
|
|
136
136
|
should_not have_content("Edit")
|
|
137
137
|
|
|
138
138
|
@player = RailsAdmin::AbstractModel.new("Player").first
|
|
@@ -165,7 +165,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
165
165
|
should_not have_content("History")
|
|
166
166
|
should_not have_content("Show in app")
|
|
167
167
|
fill_in "player[name]", :with => "Jackie Robinson"
|
|
168
|
-
click_button "Save"
|
|
168
|
+
click_button "Save" # click_button "Save" # first(:button, "Save").click
|
|
169
169
|
@player.reload
|
|
170
170
|
expect(@player.name).to eq("Jackie Robinson")
|
|
171
171
|
end
|
|
@@ -276,17 +276,17 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
276
276
|
active_player = FactoryGirl.create :player, :retired => false
|
|
277
277
|
retired_player = FactoryGirl.create :player, :retired => true
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
post bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => [active_player, retired_player].map(&:id))
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
expect(response.body).to include(active_player.name)
|
|
282
|
+
expect(response.body).not_to include(retired_player.name)
|
|
283
283
|
end
|
|
284
284
|
|
|
285
285
|
it "POST /admin/player/bulk_destroy should destroy records which are authorized to" do
|
|
286
286
|
active_player = FactoryGirl.create :player, :retired => false
|
|
287
287
|
retired_player = FactoryGirl.create :player, :retired => true
|
|
288
288
|
|
|
289
|
-
|
|
289
|
+
delete bulk_delete_path(:model_name => "player", :bulk_ids => [active_player, retired_player].map(&:id))
|
|
290
290
|
expect(@player_model.get(active_player.id)).to be_nil
|
|
291
291
|
expect(@player_model.get(retired_player.id)).not_to be_nil
|
|
292
292
|
end
|
|
@@ -298,10 +298,10 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
298
298
|
active_player = FactoryGirl.create :player, :retired => false
|
|
299
299
|
retired_player = FactoryGirl.create :player, :retired => true
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
post bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => [active_player, retired_player].map(&:id))
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
expect(response.body).to include(active_player.name)
|
|
304
|
+
expect(response.body).not_to include(retired_player.name)
|
|
305
305
|
end
|
|
306
306
|
|
|
307
307
|
it "POST /admin/player/bulk_destroy should destroy records which are authorized to" do
|
|
@@ -309,7 +309,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
|
309
309
|
active_player = FactoryGirl.create :player, :retired => false
|
|
310
310
|
retired_player = FactoryGirl.create :player, :retired => true
|
|
311
311
|
|
|
312
|
-
|
|
312
|
+
delete bulk_delete_path(:model_name => "player", :bulk_ids => [active_player, retired_player].map(&:id))
|
|
313
313
|
expect(@player_model.get(active_player.id)).to be_nil
|
|
314
314
|
expect(@player_model.get(retired_player.id)).not_to be_nil
|
|
315
315
|
end
|
|
@@ -10,8 +10,8 @@ describe "RailsAdmin Basic Bulk Action" do
|
|
|
10
10
|
|
|
11
11
|
describe "bulk_delete" do
|
|
12
12
|
it "shows names of to-be-deleted players" do
|
|
13
|
-
|
|
14
|
-
@players.each { |player|
|
|
13
|
+
post(bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => @players.map(&:id)))
|
|
14
|
+
@players.each { |player| expect(response.body).to include(player.name) }
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -9,8 +9,13 @@ describe "RailsAdmin Basic Bulk Destroy" do
|
|
|
9
9
|
RailsAdmin.config { |c| c.audit_with :history }
|
|
10
10
|
@players = 3.times.map { FactoryGirl.create(:player) }
|
|
11
11
|
@delete_ids = @players[0..1].map(&:id)
|
|
12
|
-
page.driver.post(bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => @delete_ids))
|
|
13
12
|
|
|
13
|
+
# NOTE: This uses an internal, unsupported capybara API which could break at any moment. We
|
|
14
|
+
# should refactor this test so that it either A) uses capybara's supported API (only GET
|
|
15
|
+
# requests via visit) or B) just uses Rack::Test (and doesn't use capybara for browser
|
|
16
|
+
# interaction like click_button).
|
|
17
|
+
page.driver.browser.reset_host!
|
|
18
|
+
page.driver.browser.process :post, bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => @delete_ids, '_method' => 'post')
|
|
14
19
|
click_button "Yes, I'm sure"
|
|
15
20
|
end
|
|
16
21
|
|
|
@@ -31,7 +36,13 @@ describe "RailsAdmin Basic Bulk Destroy" do
|
|
|
31
36
|
before do
|
|
32
37
|
@players = 3.times.map { FactoryGirl.create(:player) }
|
|
33
38
|
@delete_ids = @players[0..1].map(&:id)
|
|
34
|
-
|
|
39
|
+
|
|
40
|
+
# NOTE: This uses an internal, unsupported capybara API which could break at any moment. We
|
|
41
|
+
# should refactor this test so that it either A) uses capybara's supported API (only GET
|
|
42
|
+
# requests via visit) or B) just uses Rack::Test (and doesn't use capybara for browser
|
|
43
|
+
# interaction like click_button).
|
|
44
|
+
page.driver.browser.reset_host!
|
|
45
|
+
page.driver.browser.process :post, bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => @delete_ids, '_method' => 'post')
|
|
35
46
|
click_button "Cancel"
|
|
36
47
|
end
|
|
37
48
|
|