rails_admin 0.0.5 → 0.1.0
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/Gemfile +5 -30
- data/README.md +20 -2
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +2 -2
- data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +1 -1
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +1 -1
- data/app/assets/javascripts/rails_admin/ra.widgets.coffee +43 -3
- data/app/assets/javascripts/rails_admin/ui.js.coffee +2 -0
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +3 -0
- data/app/assets/stylesheets/rails_admin/ra.widgets.css.scss +8 -0
- data/app/controllers/rails_admin/main_controller.rb +3 -3
- data/app/helpers/rails_admin/application_helper.rb +15 -4
- data/app/helpers/rails_admin/form_builder.rb +35 -35
- data/app/views/layouts/rails_admin/application.html.haml +2 -1
- data/app/views/rails_admin/main/_delete_notice.html.haml +9 -8
- data/app/views/rails_admin/main/_form_datetime.html.haml +1 -1
- data/app/views/rails_admin/main/_form_enumeration.html.haml +18 -1
- data/app/views/rails_admin/main/_form_file_upload.html.haml +2 -2
- data/app/views/rails_admin/main/_form_text.html.haml +7 -1
- data/app/views/rails_admin/main/dashboard.html.haml +26 -25
- data/app/views/rails_admin/main/index.html.haml +1 -1
- data/config/initializers/active_record_extensions.rb +2 -2
- data/config/locales/rails_admin.en.yml +1 -0
- data/lib/generators/rails_admin/install_generator.rb +1 -1
- data/lib/generators/rails_admin/templates/initializer.erb +66 -67
- data/lib/rails_admin/abstract_model.rb +7 -7
- data/lib/rails_admin/adapters/active_record.rb +17 -8
- data/lib/rails_admin/adapters/mongoid.rb +38 -42
- data/lib/rails_admin/adapters/mongoid/extension.rb +1 -1
- data/lib/rails_admin/config.rb +15 -1
- data/lib/rails_admin/config/actions/base.rb +16 -2
- data/lib/rails_admin/config/actions/dashboard.rb +17 -11
- data/lib/rails_admin/config/fields.rb +0 -1
- data/lib/rails_admin/config/fields/association.rb +2 -3
- data/lib/rails_admin/config/fields/base.rb +18 -6
- data/lib/rails_admin/config/fields/types/enum.rb +4 -0
- data/lib/rails_admin/config/fields/types/string.rb +6 -4
- data/lib/rails_admin/config/fields/types/text.rb +19 -2
- data/lib/rails_admin/config/model.rb +17 -0
- data/lib/rails_admin/config/sections/base.rb +17 -0
- data/lib/rails_admin/engine.rb +4 -0
- data/lib/rails_admin/extensions/history/auditing_adapter.rb +1 -1
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +4 -4
- data/lib/rails_admin/support/csv_converter.rb +3 -3
- data/lib/rails_admin/version.rb +2 -2
- data/lib/tasks/rails_admin.rake +36 -6
- data/spec/controllers/main_controller_spec.rb +52 -9
- data/spec/dummy_app/Gemfile +7 -16
- data/spec/dummy_app/app/active_record/another_field_test.rb +4 -0
- data/spec/dummy_app/app/active_record/ball.rb +1 -1
- data/spec/dummy_app/app/active_record/nested_field_test.rb +2 -1
- data/spec/dummy_app/app/active_record/team.rb +3 -2
- data/spec/dummy_app/app/active_record/user.rb +6 -2
- data/spec/dummy_app/app/mongoid/another_field_test.rb +6 -0
- data/spec/dummy_app/app/mongoid/ball.rb +1 -1
- data/spec/dummy_app/app/mongoid/nested_field_test.rb +2 -1
- data/spec/dummy_app/app/mongoid/team.rb +1 -1
- data/spec/dummy_app/config/environments/development.rb +2 -2
- data/spec/dummy_app/db/migrate/20120720075608_create_another_field_tests.rb +8 -0
- data/spec/dummy_app/db/seeds.rb +3 -3
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +53792 -0
- data/spec/helpers/application_helper_spec.rb +37 -0
- data/spec/helpers/form_builder_spec.rb +17 -0
- data/spec/integration/authorization/cancan_spec.rb +21 -13
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -8
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +15 -4
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +9 -12
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +2 -10
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +6 -0
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +241 -300
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +3 -81
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/active_record_extension_spec.rb +16 -0
- data/spec/unit/adapters/active_record_spec.rb +11 -9
- data/spec/unit/adapters/mongoid_spec.rb +4 -4
- data/spec/unit/config/actions/base_spec.rb +32 -0
- data/spec/unit/config/fields/base_spec.rb +56 -0
- data/spec/unit/config/fields/date_spec.rb +53 -0
- data/spec/unit/config/fields/datetime_spec.rb +55 -0
- data/spec/unit/config/fields/time_spec.rb +39 -0
- data/spec/unit/config/fields/timestamp_spec.rb +20 -0
- data/spec/unit/config_spec.rb +1 -1
- data/spec/unit/support/csv_converter_spec.rb +16 -0
- metadata +44 -35
- data/lib/rails_admin/config/fields/factories/serialized.rb +0 -17
- data/lib/tasks/prepare_ci_env.rake +0 -27
@@ -263,6 +263,43 @@ describe RailsAdmin::ApplicationHelper do
|
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
|
+
describe '#static_navigation' do
|
267
|
+
it 'should show not show static nav if no static links defined' do
|
268
|
+
RailsAdmin.config do |config|
|
269
|
+
config.navigation_static_links = {}
|
270
|
+
end
|
271
|
+
helper.static_navigation.should be_empty
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should show links if defined' do
|
275
|
+
RailsAdmin.config do |config|
|
276
|
+
config.navigation_static_links = {
|
277
|
+
'Test Link' => 'http://www.google.com'
|
278
|
+
}
|
279
|
+
end
|
280
|
+
helper.static_navigation.should match /Test Link/
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'should show default header if navigation_static_label not defined in config' do
|
284
|
+
RailsAdmin.config do |config|
|
285
|
+
config.navigation_static_links = {
|
286
|
+
'Test Link' => 'http://www.google.com'
|
287
|
+
}
|
288
|
+
end
|
289
|
+
helper.static_navigation.should match I18n.t('admin.misc.navigation_static_label')
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'should show custom header if defined' do
|
293
|
+
RailsAdmin.config do |config|
|
294
|
+
config.navigation_static_label = "Test Header"
|
295
|
+
config.navigation_static_links = {
|
296
|
+
'Test Link' => 'http://www.google.com'
|
297
|
+
}
|
298
|
+
end
|
299
|
+
helper.static_navigation.should match /Test Header/
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
266
303
|
describe "#bulk_menu" do
|
267
304
|
it 'should include all visible bulkable actions' do
|
268
305
|
RailsAdmin.config do |config|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin::FormBuilder" do
|
4
|
+
describe '#generate' do
|
5
|
+
before do
|
6
|
+
helper.stub(:authorized?).and_return(true)
|
7
|
+
(@object = Player.new).save
|
8
|
+
@builder = RailsAdmin::FormBuilder.new(:player, @object, helper, {}, nil)
|
9
|
+
@builder.stub(:field_for).and_return("field")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not add additional error div from default ActionView::Base.field_error_proc' do
|
13
|
+
@builder.generate({ :action => :create, :model_config => RailsAdmin.config(Player) }).should_not have_css(".field_with_errors")
|
14
|
+
@builder.generate({ :action => :create, :model_config => RailsAdmin.config(Player) }).should have_css(".control-group.error")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -18,7 +18,15 @@ class Ability
|
|
18
18
|
can :access, :rails_admin
|
19
19
|
can :manage, :all
|
20
20
|
can :show_in_app, :all
|
21
|
-
|
21
|
+
|
22
|
+
|
23
|
+
# fix for buggy and inconsistent behaviour in Cancan 1.6.8 => https://github.com/ryanb/cancan/issues/721
|
24
|
+
if CI_ORM != :mongoid
|
25
|
+
cannot [:update, :destroy], Player
|
26
|
+
can [:update, :destroy], Player, :retired => false
|
27
|
+
else
|
28
|
+
cannot [:update, :destroy], Player, :retired => true
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -47,7 +55,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
47
55
|
|
48
56
|
describe "with no roles" do
|
49
57
|
before(:each) do
|
50
|
-
@user.
|
58
|
+
@user.update_attributes(:roles => [])
|
51
59
|
end
|
52
60
|
|
53
61
|
it "GET /admin should raise CanCan::AccessDenied" do
|
@@ -63,7 +71,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
63
71
|
|
64
72
|
describe "with read player role" do
|
65
73
|
before(:each) do
|
66
|
-
@user.
|
74
|
+
@user.update_attributes(:roles => [:admin, :read_player])
|
67
75
|
end
|
68
76
|
|
69
77
|
it "GET /admin should show Player but not League" do
|
@@ -111,7 +119,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
111
119
|
|
112
120
|
describe "with create and read player role" do
|
113
121
|
before(:each) do
|
114
|
-
@user.
|
122
|
+
@user.update_attributes(:roles => [:admin, :read_player, :create_player])
|
115
123
|
end
|
116
124
|
|
117
125
|
it "GET /admin/player/new should render and create record upon submission" do
|
@@ -144,7 +152,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
144
152
|
|
145
153
|
describe "with update and read player role" do
|
146
154
|
before(:each) do
|
147
|
-
@user.
|
155
|
+
@user.update_attributes(:roles => [:admin, :read_player, :update_player])
|
148
156
|
end
|
149
157
|
|
150
158
|
it "GET /admin/player/1/edit should render and update record upon submission" do
|
@@ -179,7 +187,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
179
187
|
describe "with history role" do
|
180
188
|
it 'shows links to history action' do
|
181
189
|
|
182
|
-
@user.
|
190
|
+
@user.update_attributes(:roles => [:admin, :read_player, :history_player])
|
183
191
|
@player = FactoryGirl.create :player
|
184
192
|
|
185
193
|
visit index_path(:model_name => "player")
|
@@ -200,7 +208,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
200
208
|
describe "with show in app role" do
|
201
209
|
it 'shows links to show in app action' do
|
202
210
|
|
203
|
-
@user.
|
211
|
+
@user.update_attributes(:roles => [:admin, :read_player, :show_in_app_player])
|
204
212
|
@player = FactoryGirl.create :player
|
205
213
|
|
206
214
|
visit index_path(:model_name => "player")
|
@@ -223,7 +231,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
223
231
|
describe "with all roles" do
|
224
232
|
it 'shows links to all actions' do
|
225
233
|
|
226
|
-
@user.
|
234
|
+
@user.update_attributes(:roles => [:admin, :manage_player])
|
227
235
|
@player = FactoryGirl.create :player
|
228
236
|
|
229
237
|
visit index_path(:model_name => "player")
|
@@ -245,7 +253,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
245
253
|
|
246
254
|
describe "with destroy and read player role" do
|
247
255
|
before(:each) do
|
248
|
-
@user.
|
256
|
+
@user.update_attributes(:roles => [:admin, :read_player, :destroy_player])
|
249
257
|
end
|
250
258
|
|
251
259
|
it "GET /admin/player/1/delete should render and destroy record upon submission" do
|
@@ -286,18 +294,18 @@ describe "RailsAdmin CanCan Authorization" do
|
|
286
294
|
|
287
295
|
describe "with exception role" do
|
288
296
|
it "GET /admin/player/bulk_delete should render records which are authorized to" do
|
289
|
-
@user.
|
297
|
+
@user.update_attributes(:roles => [:admin, :test_exception])
|
290
298
|
active_player = FactoryGirl.create :player, :retired => false
|
291
299
|
retired_player = FactoryGirl.create :player, :retired => true
|
292
300
|
|
293
301
|
page.driver.post(bulk_action_path(:bulk_action => 'bulk_delete', :model_name => "player", :bulk_ids => [active_player, retired_player].map(&:id)))
|
294
|
-
|
302
|
+
|
295
303
|
should have_content(active_player.name)
|
296
304
|
should_not have_content(retired_player.name)
|
297
305
|
end
|
298
306
|
|
299
307
|
it "POST /admin/player/bulk_destroy should destroy records which are authorized to" do
|
300
|
-
@user.
|
308
|
+
@user.update_attributes(:roles => [:admin, :test_exception])
|
301
309
|
active_player = FactoryGirl.create :player, :retired => false
|
302
310
|
retired_player = FactoryGirl.create :player, :retired => true
|
303
311
|
|
@@ -316,7 +324,7 @@ describe "RailsAdmin CanCan Authorization" do
|
|
316
324
|
|
317
325
|
describe "with admin role only" do
|
318
326
|
before(:each) do
|
319
|
-
@user.
|
327
|
+
@user.update_attributes(:roles => [:admin])
|
320
328
|
end
|
321
329
|
|
322
330
|
it "GET /admin/team should render successfully" do
|
@@ -4,18 +4,11 @@ describe "RailsAdmin Namespaced Model Create" do
|
|
4
4
|
|
5
5
|
subject { page }
|
6
6
|
|
7
|
-
|
7
|
+
it 'should create object with correct attributes' do
|
8
8
|
visit new_path(:model_name => "cms~basic_page")
|
9
9
|
|
10
10
|
fill_in "cms_basic_page[title]", :with => "Hello"
|
11
11
|
fill_in "cms_basic_page[content]", :with => "World"
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should be successful' do
|
15
|
-
click_button "Save"
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should create object with correct attributes' do
|
19
12
|
expect {
|
20
13
|
click_button "Save"
|
21
14
|
}.to change(Cms::BasicPage, :count).by(1)
|
@@ -5,14 +5,11 @@ describe "RailsAdmin Basic Delete" do
|
|
5
5
|
subject { page }
|
6
6
|
|
7
7
|
describe "delete" do
|
8
|
-
|
8
|
+
it "should show \"Delete model\"" do
|
9
9
|
@draft = FactoryGirl.create :draft
|
10
10
|
@player = @draft.player
|
11
11
|
@comment = @player.comments.create
|
12
12
|
visit delete_path(:model_name => "player", :id => @player.id)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should show \"Delete model\"" do
|
16
13
|
should have_content("delete this player")
|
17
14
|
should have_link(@player.name, :href => "/admin/player/#{@player.id}")
|
18
15
|
should have_link("Draft ##{@draft.id}", :href => "/admin/draft/#{@draft.id}")
|
@@ -50,4 +47,18 @@ describe "RailsAdmin Basic Delete" do
|
|
50
47
|
should_not have_selector("a[href=\"/admin/comment/#{@comment.id}\"]")
|
51
48
|
end
|
52
49
|
end
|
50
|
+
|
51
|
+
describe "delete of an object which has an associated item without id" do
|
52
|
+
before(:each) do
|
53
|
+
@player = FactoryGirl.create :player
|
54
|
+
Player.any_instance.stub(:draft).and_return(Draft.new)
|
55
|
+
visit delete_path(:model_name => "player", :id => @player.id)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should show \"Delete model\"" do
|
59
|
+
should_not have_content("Routing Error")
|
60
|
+
should have_content("delete this player")
|
61
|
+
should have_link(@player.name, :href => "/admin/player/#{@player.id}")
|
62
|
+
end
|
63
|
+
end
|
53
64
|
end
|
@@ -29,12 +29,9 @@ describe "RailsAdmin Basic List" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "GET /admin/player as list" do
|
32
|
-
|
32
|
+
it "should show \"List of Models\", should show filters and should show column headers" do
|
33
33
|
21.times { FactoryGirl.create :player } # two pages of players
|
34
34
|
visit index_path(:model_name => "player")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should show \"List of Models\", should show filters and should show column headers" do
|
38
35
|
should have_content("List of Players")
|
39
36
|
should have_content("Created at")
|
40
37
|
should have_content("Updated at")
|
@@ -281,31 +278,31 @@ describe "RailsAdmin Basic List" do
|
|
281
278
|
end
|
282
279
|
end
|
283
280
|
|
284
|
-
describe "GET /admin/player with
|
281
|
+
describe "GET /admin/player with 3 pages, page 2" do
|
285
282
|
before(:each) do
|
286
283
|
items_per_page = RailsAdmin.config.default_items_per_page
|
287
|
-
(items_per_page *
|
288
|
-
visit index_path(:model_name => "player", :page =>
|
284
|
+
(items_per_page * 3).times { FactoryGirl.create(:player) }
|
285
|
+
visit index_path(:model_name => "player", :page => 2)
|
289
286
|
end
|
290
287
|
|
291
288
|
it "should paginate correctly" do
|
292
289
|
find('.pagination ul li:first').should have_content("« Prev")
|
293
290
|
find('.pagination ul li:last').should have_content("Next »")
|
294
|
-
find('.pagination ul li.active').should have_content("
|
291
|
+
find('.pagination ul li.active').should have_content("2")
|
295
292
|
end
|
296
293
|
end
|
297
294
|
|
298
|
-
describe "list with
|
295
|
+
describe "list with 3 pages, page 3" do
|
299
296
|
before(:each) do
|
300
297
|
items_per_page = RailsAdmin.config.default_items_per_page
|
301
|
-
@players = (items_per_page *
|
302
|
-
visit index_path(:model_name => "player", :page =>
|
298
|
+
@players = (items_per_page * 3).times.map { FactoryGirl.create(:player) }
|
299
|
+
visit index_path(:model_name => "player", :page => 3)
|
303
300
|
end
|
304
301
|
|
305
302
|
it "should paginate correctly and contain the right item" do
|
306
303
|
find('.pagination ul li:first').should have_content("« Prev")
|
307
304
|
find('.pagination ul li:last').should have_content("Next »")
|
308
|
-
find('.pagination ul li.active').should have_content("
|
305
|
+
find('.pagination ul li.active').should have_content("3")
|
309
306
|
end
|
310
307
|
end
|
311
308
|
|
@@ -4,22 +4,14 @@ describe "RailsAdmin Basic Show" do
|
|
4
4
|
subject { page }
|
5
5
|
|
6
6
|
describe "show" do
|
7
|
-
|
7
|
+
it "should have History, Edit, Delete, Details and attributes" do
|
8
8
|
@player = FactoryGirl.create :player
|
9
9
|
visit show_path(:model_name => "player", :id => @player.id)
|
10
|
-
end
|
11
10
|
|
12
|
-
it "should have History, Edit, Delete" do
|
13
11
|
should have_selector("a", :text => "History")
|
14
12
|
should have_selector("a", :text => "Edit")
|
15
13
|
should have_selector("a", :text => "Delete")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should show 'Details'" do
|
19
14
|
should have_content("Details")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should show attributes" do
|
23
15
|
should have_content("Name")
|
24
16
|
should have_content(@player.name)
|
25
17
|
should have_content("Number")
|
@@ -39,7 +31,7 @@ describe "RailsAdmin Basic Show" do
|
|
39
31
|
before(:each) do
|
40
32
|
@player = FactoryGirl.create :player
|
41
33
|
@team = FactoryGirl.create :team
|
42
|
-
@player.
|
34
|
+
@player.update_attributes(:team_id => @team.id)
|
43
35
|
visit show_path(:model_name => "player", :id => @player.id)
|
44
36
|
end
|
45
37
|
|
@@ -143,6 +143,12 @@ describe "RailsAdmin Basic Update" do
|
|
143
143
|
|
144
144
|
describe "update with serialized objects" do
|
145
145
|
before(:each) do
|
146
|
+
RailsAdmin.config do |c|
|
147
|
+
c.model User do
|
148
|
+
configure :roles, :serialized
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
146
152
|
@user = FactoryGirl.create :user
|
147
153
|
|
148
154
|
visit edit_path(:model_name => "user", :id => @user.id)
|
@@ -5,6 +5,22 @@ require 'spec_helper'
|
|
5
5
|
describe "RailsAdmin Config DSL Edit Section" do
|
6
6
|
|
7
7
|
subject { page }
|
8
|
+
|
9
|
+
describe " a field with 'format' as a name (Kernel function)" do
|
10
|
+
|
11
|
+
it "should be updatable without any error" do
|
12
|
+
RailsAdmin.config FieldTest do
|
13
|
+
edit do
|
14
|
+
field :format
|
15
|
+
end
|
16
|
+
end
|
17
|
+
visit new_path(:model_name => "field_test")
|
18
|
+
fill_in "field_test[format]", :with => "test for format"
|
19
|
+
click_button "Save"
|
20
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
21
|
+
@record.format.should eql("test for format")
|
22
|
+
end
|
23
|
+
end
|
8
24
|
|
9
25
|
describe "default_value" do
|
10
26
|
|
@@ -154,7 +170,7 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
154
170
|
column :name, 'string(50)'
|
155
171
|
column :division, :string
|
156
172
|
end
|
157
|
-
RailsAdmin.config.included_models = [HelpTest]
|
173
|
+
RailsAdmin.config.included_models = [HelpTest, Team]
|
158
174
|
end
|
159
175
|
|
160
176
|
after(:each) do
|
@@ -163,6 +179,41 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
163
179
|
HelpTest.reset_callbacks(:validate)
|
164
180
|
end
|
165
181
|
|
182
|
+
context "using mongoid", :skip_active_record => true do
|
183
|
+
it "should use the db column size for the maximum length" do
|
184
|
+
visit new_path(:model_name => "help_test")
|
185
|
+
find("#help_test_name_field .help-block").should have_content("Length up to 255.")
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return nil for the maximum length" do
|
189
|
+
visit new_path(:model_name => "team")
|
190
|
+
find("#team_custom_field_field .help-block").should_not have_content("Length")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "using active_record", :skip_mongoid => true do
|
195
|
+
it "should use the db column size for the maximum length" do
|
196
|
+
visit new_path(:model_name => "help_test")
|
197
|
+
find("#help_test_name_field .help-block").should have_content("Length up to 50.")
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should use the :minimum setting from the validation" do
|
201
|
+
HelpTest.class_eval do
|
202
|
+
validates_length_of :name, :minimum => 1
|
203
|
+
end
|
204
|
+
visit new_path(:model_name => "help_test")
|
205
|
+
find("#help_test_name_field .help-block").should have_content("Length of 1-50.")
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should use the minimum of db column size or :maximum setting from the validation" do
|
209
|
+
HelpTest.class_eval do
|
210
|
+
validates_length_of :name, :maximum => 51
|
211
|
+
end
|
212
|
+
visit new_path(:model_name => "help_test")
|
213
|
+
find("#help_test_name_field .help-block").should have_content("Length up to 50.")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
166
217
|
it "should show help section if present" do
|
167
218
|
RailsAdmin.config HelpTest do
|
168
219
|
edit do
|
@@ -215,35 +266,12 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
215
266
|
find("#help_test_name_field .help-block").should have_content("Length of 3.")
|
216
267
|
end
|
217
268
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
find("#help_test_name_field .help-block").should have_content("Length up to 50.")
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should use the :minimum setting from the validation" do
|
225
|
-
HelpTest.class_eval do
|
226
|
-
validates_length_of :name, :minimum => 1
|
227
|
-
end
|
228
|
-
visit new_path(:model_name => "help_test")
|
229
|
-
find("#help_test_name_field .help-block").should have_content("Length of 1-50.")
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should use the :maximum setting from the validation" do
|
233
|
-
HelpTest.class_eval do
|
234
|
-
validates_length_of :name, :maximum => 49
|
235
|
-
end
|
236
|
-
visit new_path(:model_name => "help_test")
|
237
|
-
find("#help_test_name_field .help-block").should have_content("Length up to 49.")
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should use the minimum of db column size or :maximum setting from the validation" do
|
241
|
-
HelpTest.class_eval do
|
242
|
-
validates_length_of :name, :maximum => 51
|
243
|
-
end
|
244
|
-
visit new_path(:model_name => "help_test")
|
245
|
-
find("#help_test_name_field .help-block").should have_content("Length up to 50.")
|
269
|
+
it "should use the :maximum setting from the validation" do
|
270
|
+
HelpTest.class_eval do
|
271
|
+
validates_length_of :name, :maximum => 49
|
246
272
|
end
|
273
|
+
visit new_path(:model_name => "help_test")
|
274
|
+
find("#help_test_name_field .help-block").should have_content("Length up to 49.")
|
247
275
|
end
|
248
276
|
|
249
277
|
it "should use the :minimum and :maximum from the validation" do
|
@@ -424,7 +452,7 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
424
452
|
end
|
425
453
|
|
426
454
|
it "should be globally renameable by type" do
|
427
|
-
RailsAdmin
|
455
|
+
RailsAdmin.config 'Team' do
|
428
456
|
edit do
|
429
457
|
fields_of_type :string do
|
430
458
|
label { "#{label} (STRING)" }
|
@@ -503,7 +531,7 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
503
531
|
end
|
504
532
|
|
505
533
|
it "should be globally hideable by type" do
|
506
|
-
RailsAdmin
|
534
|
+
RailsAdmin.config 'Team' do
|
507
535
|
edit do
|
508
536
|
fields_of_type :string do
|
509
537
|
hide
|
@@ -563,203 +591,6 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
563
591
|
end
|
564
592
|
end
|
565
593
|
|
566
|
-
describe "input format of" do
|
567
|
-
|
568
|
-
before(:each) do
|
569
|
-
@time = ::Time.now.getutc
|
570
|
-
end
|
571
|
-
|
572
|
-
after(:each) do
|
573
|
-
Time.zone = 'UTC'
|
574
|
-
end
|
575
|
-
|
576
|
-
describe "a datetime field" do
|
577
|
-
|
578
|
-
it "should default to %B %d, %Y %H:%M" do
|
579
|
-
visit new_path(:model_name => "field_test")
|
580
|
-
fill_in "field_test[datetime_field]", :with => @time.strftime("%B %d, %Y %H:%M")
|
581
|
-
click_button "Save"
|
582
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
583
|
-
@record.datetime_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
|
584
|
-
end
|
585
|
-
|
586
|
-
it "should have a simple customization option" do
|
587
|
-
RailsAdmin.config FieldTest do
|
588
|
-
edit do
|
589
|
-
field :datetime_field do
|
590
|
-
date_format :default
|
591
|
-
end
|
592
|
-
end
|
593
|
-
end
|
594
|
-
visit new_path(:model_name => "field_test")
|
595
|
-
fill_in "field_test[datetime_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
|
596
|
-
click_button "Save"
|
597
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
598
|
-
@record.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
599
|
-
end
|
600
|
-
|
601
|
-
it "should have a customization option" do
|
602
|
-
RailsAdmin.config FieldTest do
|
603
|
-
list do
|
604
|
-
field :datetime_field do
|
605
|
-
strftime_format "%Y-%m-%d %H:%M:%S"
|
606
|
-
end
|
607
|
-
end
|
608
|
-
end
|
609
|
-
visit new_path(:model_name => "field_test")
|
610
|
-
fill_in "field_test[datetime_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
|
611
|
-
click_button "Save"
|
612
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
613
|
-
@record.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
614
|
-
end
|
615
|
-
end
|
616
|
-
|
617
|
-
describe "a timestamp field", :active_record => true do
|
618
|
-
|
619
|
-
it "should default to %B %d, %Y %H:%M" do
|
620
|
-
visit new_path(:model_name => "field_test")
|
621
|
-
fill_in "field_test[timestamp_field]", :with => @time.strftime("%B %d, %Y %H:%M")
|
622
|
-
click_button "Save"
|
623
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
624
|
-
@record.timestamp_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
|
625
|
-
end
|
626
|
-
|
627
|
-
it "should have a simple customization option" do
|
628
|
-
RailsAdmin.config FieldTest do
|
629
|
-
edit do
|
630
|
-
field :timestamp_field do
|
631
|
-
date_format :default
|
632
|
-
end
|
633
|
-
end
|
634
|
-
end
|
635
|
-
visit new_path(:model_name => "field_test")
|
636
|
-
fill_in "field_test[timestamp_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
|
637
|
-
click_button "Save"
|
638
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
639
|
-
@record.timestamp_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
640
|
-
end
|
641
|
-
|
642
|
-
it "should have a customization option" do
|
643
|
-
RailsAdmin.config FieldTest do
|
644
|
-
edit do
|
645
|
-
field :timestamp_field do
|
646
|
-
strftime_format "%Y-%m-%d %H:%M:%S"
|
647
|
-
end
|
648
|
-
end
|
649
|
-
end
|
650
|
-
visit new_path(:model_name => "field_test")
|
651
|
-
fill_in "field_test[timestamp_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
|
652
|
-
click_button "Save"
|
653
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
654
|
-
@record.timestamp_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
655
|
-
end
|
656
|
-
end
|
657
|
-
|
658
|
-
describe " a field with 'format' as a name (Kernel function)" do
|
659
|
-
|
660
|
-
it "should be updatable without any error" do
|
661
|
-
RailsAdmin.config FieldTest do
|
662
|
-
edit do
|
663
|
-
field :format
|
664
|
-
end
|
665
|
-
end
|
666
|
-
visit new_path(:model_name => "field_test")
|
667
|
-
fill_in "field_test[format]", :with => "test for format"
|
668
|
-
click_button "Save"
|
669
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
670
|
-
@record.format.should eql("test for format")
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
|
675
|
-
describe "a time field" do
|
676
|
-
|
677
|
-
it "should default to %H:%M" do
|
678
|
-
visit new_path(:model_name => "field_test")
|
679
|
-
fill_in "field_test[time_field]", :with => @time.strftime("%H:%M")
|
680
|
-
click_button "Save"
|
681
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
682
|
-
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
683
|
-
end
|
684
|
-
|
685
|
-
it "should interpret time value as UTC when timezone is specified" do
|
686
|
-
Time.zone = 'Eastern Time (US & Canada)' # -05:00
|
687
|
-
|
688
|
-
visit new_path(:model_name => "field_test")
|
689
|
-
fill_in "field_test[time_field]", :with => @time.strftime("%H:%M")
|
690
|
-
click_button "Save"
|
691
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
692
|
-
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
693
|
-
end
|
694
|
-
|
695
|
-
it "should have a customization option" do
|
696
|
-
RailsAdmin.config FieldTest do
|
697
|
-
edit do
|
698
|
-
field :time_field do
|
699
|
-
strftime_format "%I:%M %p"
|
700
|
-
end
|
701
|
-
end
|
702
|
-
end
|
703
|
-
visit new_path(:model_name => "field_test")
|
704
|
-
fill_in "field_test[time_field]", :with => @time.strftime("%I:%M %p")
|
705
|
-
click_button "Save"
|
706
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
707
|
-
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
708
|
-
end
|
709
|
-
end
|
710
|
-
|
711
|
-
describe "a date field" do
|
712
|
-
|
713
|
-
it "should default to %B %d, %Y" do
|
714
|
-
visit new_path(:model_name => "field_test")
|
715
|
-
fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
|
716
|
-
click_button "Save"
|
717
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
718
|
-
@record.date_field.should eql(::Date.parse(@time.to_s))
|
719
|
-
end
|
720
|
-
|
721
|
-
it "should cover a timezone lag even if in UTC+n:00 timezone." do
|
722
|
-
Time.zone = 'Tokyo' # +09:00
|
723
|
-
|
724
|
-
visit new_path(:model_name => "field_test")
|
725
|
-
fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
|
726
|
-
click_button "Save"
|
727
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
728
|
-
@record.date_field.should eql(::Date.parse(@time.to_s))
|
729
|
-
end
|
730
|
-
|
731
|
-
it "should have a simple customization option" do
|
732
|
-
RailsAdmin.config FieldTest do
|
733
|
-
edit do
|
734
|
-
field :date_field do
|
735
|
-
date_format :default
|
736
|
-
end
|
737
|
-
end
|
738
|
-
end
|
739
|
-
visit new_path(:model_name => "field_test")
|
740
|
-
fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
|
741
|
-
click_button "Save"
|
742
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
743
|
-
@record.date_field.should eql(::Date.parse(@time.to_s))
|
744
|
-
end
|
745
|
-
|
746
|
-
it "should have a customization option" do
|
747
|
-
RailsAdmin.config FieldTest do
|
748
|
-
edit do
|
749
|
-
field :date_field do
|
750
|
-
strftime_format "%Y-%m-%d"
|
751
|
-
end
|
752
|
-
end
|
753
|
-
end
|
754
|
-
visit new_path(:model_name => "field_test")
|
755
|
-
fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
|
756
|
-
click_button "Save"
|
757
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
758
|
-
@record.date_field.should eql(::Date.parse(@time.to_s))
|
759
|
-
end
|
760
|
-
end
|
761
|
-
end
|
762
|
-
|
763
594
|
describe 'bindings' do
|
764
595
|
it 'should be present at creation time' do
|
765
596
|
RailsAdmin.config do |config|
|
@@ -785,17 +616,15 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
785
616
|
|
786
617
|
describe 'nested form' do
|
787
618
|
it 'should work' do
|
788
|
-
|
789
|
-
fill_in "field_test_comment_attributes_content", :with => 'nested comment content'
|
790
|
-
click_button "Save"
|
791
|
-
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
792
|
-
@record.comment.content.should == 'nested comment content'
|
619
|
+
@record = FactoryGirl.create :field_test
|
793
620
|
@record.nested_field_tests = [NestedFieldTest.create!(:title => 'title 1'), NestedFieldTest.create!(:title => 'title 2')]
|
794
621
|
visit edit_path(:model_name => "field_test", :id => @record.id)
|
622
|
+
fill_in "field_test_comment_attributes_content", :with => 'nested comment content'
|
795
623
|
fill_in "field_test_nested_field_tests_attributes_0_title", :with => 'nested field test title 1 edited'
|
796
624
|
page.find('#field_test_nested_field_tests_attributes_1__destroy').set('true')
|
797
625
|
click_button "Save"
|
798
626
|
@record.reload
|
627
|
+
@record.comment.content.should == 'nested comment content'
|
799
628
|
@record.nested_field_tests.length.should == 1
|
800
629
|
@record.nested_field_tests[0].title.should == 'nested field test title 1 edited'
|
801
630
|
end
|
@@ -850,7 +679,15 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
850
679
|
visit edit_path(:model_name => "field_test", :id => @record.id)
|
851
680
|
find('#field_test_nested_field_tests_attributes_0_title').value.should == 'nested title 1'
|
852
681
|
should_not have_selector('form .remove_nested_fields')
|
853
|
-
should have_selector('
|
682
|
+
should have_selector('[id$="_fields_blueprint"] .remove_nested_fields')
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
describe "when a field which have the same name of nested_in field's" do
|
687
|
+
it "should not hide fields which is not associated with nesting parent field's model" do
|
688
|
+
visit new_path(:model_name => "field_test")
|
689
|
+
should_not have_selector('select#field_test_nested_field_tests_attributes_new_nested_field_tests_field_test_id')
|
690
|
+
should have_selector('select#field_test_nested_field_tests_attributes_new_nested_field_tests_another_field_test_id')
|
854
691
|
end
|
855
692
|
end
|
856
693
|
end
|
@@ -938,6 +775,26 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
938
775
|
end
|
939
776
|
end
|
940
777
|
|
778
|
+
describe "bootstrap_wysihtml5 Support" do
|
779
|
+
|
780
|
+
it "should start with bootstrap_wysihtml5 disabled" do
|
781
|
+
field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :notes}
|
782
|
+
field.bootstrap_wysihtml5.should be false
|
783
|
+
end
|
784
|
+
|
785
|
+
it "should add Javascript to enable bootstrap_wysihtml5" do
|
786
|
+
RailsAdmin.config Draft do
|
787
|
+
edit do
|
788
|
+
field :notes do
|
789
|
+
bootstrap_wysihtml5 true
|
790
|
+
end
|
791
|
+
end
|
792
|
+
end
|
793
|
+
visit new_path(:model_name => "draft")
|
794
|
+
should have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"]')
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
941
798
|
describe "Paperclip Support" do
|
942
799
|
|
943
800
|
it "should show a file upload field" do
|
@@ -952,101 +809,185 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
952
809
|
end
|
953
810
|
|
954
811
|
describe "Enum field support" do
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
812
|
+
describe "when object responds to '\#{method}_enum'" do
|
813
|
+
before do
|
814
|
+
Team.class_eval do
|
815
|
+
def color_enum
|
816
|
+
["blue", "green", "red"]
|
817
|
+
end
|
959
818
|
end
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
819
|
+
RailsAdmin.config Team do
|
820
|
+
edit do
|
821
|
+
field :color
|
822
|
+
end
|
964
823
|
end
|
824
|
+
visit new_path(:model_name => "team")
|
825
|
+
end
|
826
|
+
|
827
|
+
after do
|
828
|
+
Team.send(:remove_method, :color_enum)
|
829
|
+
end
|
830
|
+
|
831
|
+
it "should auto-detect enumeration" do
|
832
|
+
should have_selector(".enum_type select")
|
833
|
+
should_not have_selector(".enum_type select[multiple]")
|
834
|
+
should have_content("green")
|
965
835
|
end
|
966
|
-
visit new_path(:model_name => "team")
|
967
|
-
should have_selector(".enum_type select")
|
968
|
-
should have_content("green")
|
969
|
-
Team.send(:remove_method, :color_enum) # Reset
|
970
836
|
end
|
971
837
|
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
838
|
+
describe "when class responds to '\#{method}_enum'" do
|
839
|
+
before do
|
840
|
+
Team.instance_eval do
|
841
|
+
def color_enum
|
842
|
+
["blue", "green", "red"]
|
843
|
+
end
|
976
844
|
end
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
845
|
+
RailsAdmin.config Team do
|
846
|
+
edit do
|
847
|
+
field :color
|
848
|
+
end
|
981
849
|
end
|
850
|
+
visit new_path(:model_name => "team")
|
851
|
+
end
|
852
|
+
|
853
|
+
after do
|
854
|
+
Team.instance_eval { undef :color_enum }
|
855
|
+
end
|
856
|
+
|
857
|
+
it "should auto-detect enumeration" do
|
858
|
+
should have_selector(".enum_type select")
|
859
|
+
should have_content("green")
|
982
860
|
end
|
983
|
-
visit new_path(:model_name => "team")
|
984
|
-
should have_selector(".enum_type select")
|
985
|
-
should have_content("green")
|
986
|
-
Team.instance_eval { undef :color_enum } # Reset
|
987
861
|
end
|
988
862
|
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
863
|
+
describe "the enum instance method" do
|
864
|
+
before do
|
865
|
+
Team.class_eval do
|
866
|
+
def color_list
|
867
|
+
["blue", "green", "red"]
|
868
|
+
end
|
993
869
|
end
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
870
|
+
RailsAdmin.config Team do
|
871
|
+
edit do
|
872
|
+
field :color, :enum do
|
873
|
+
enum_method :color_list
|
874
|
+
end
|
999
875
|
end
|
1000
876
|
end
|
877
|
+
visit new_path(:model_name => "team")
|
878
|
+
end
|
879
|
+
|
880
|
+
after do
|
881
|
+
Team.send(:remove_method, :color_list)
|
882
|
+
end
|
883
|
+
|
884
|
+
it "should allow configuration" do
|
885
|
+
should have_selector(".enum_type select")
|
886
|
+
should have_content("green")
|
1001
887
|
end
|
1002
|
-
visit new_path(:model_name => "team")
|
1003
|
-
should have_selector(".enum_type select")
|
1004
|
-
should have_content("green")
|
1005
|
-
Team.send(:remove_method, :color_list) # Reset
|
1006
888
|
end
|
1007
889
|
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
890
|
+
describe "the enum class method" do
|
891
|
+
before do
|
892
|
+
Team.instance_eval do
|
893
|
+
def color_list
|
894
|
+
["blue", "green", "red"]
|
895
|
+
end
|
1012
896
|
end
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
897
|
+
RailsAdmin.config Team do
|
898
|
+
edit do
|
899
|
+
field :color, :enum do
|
900
|
+
enum_method :color_list
|
901
|
+
end
|
1018
902
|
end
|
1019
903
|
end
|
904
|
+
visit new_path(:model_name => "team")
|
905
|
+
end
|
906
|
+
|
907
|
+
after do
|
908
|
+
Team.instance_eval { undef :color_list }
|
909
|
+
end
|
910
|
+
|
911
|
+
it "should allow configuration" do
|
912
|
+
should have_selector(".enum_type select")
|
913
|
+
should have_content("green")
|
1020
914
|
end
|
1021
|
-
visit new_path(:model_name => "team")
|
1022
|
-
should have_selector(".enum_type select")
|
1023
|
-
should have_content("green")
|
1024
|
-
Team.instance_eval { undef :color_list } # Reset
|
1025
915
|
end
|
1026
916
|
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
917
|
+
describe "when overriding enum configuration" do
|
918
|
+
before do
|
919
|
+
Team.class_eval do
|
920
|
+
def color_list
|
921
|
+
["blue", "green", "red"]
|
922
|
+
end
|
1031
923
|
end
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
924
|
+
RailsAdmin.config Team do
|
925
|
+
edit do
|
926
|
+
field :color, :enum do
|
927
|
+
enum_method :color_list
|
928
|
+
enum do
|
929
|
+
["yellow", "black"]
|
930
|
+
end
|
1039
931
|
end
|
1040
932
|
end
|
1041
933
|
end
|
934
|
+
visit new_path(:model_name => "team")
|
935
|
+
end
|
936
|
+
|
937
|
+
after do
|
938
|
+
Team.send(:remove_method, :color_list)
|
939
|
+
end
|
940
|
+
|
941
|
+
it "should allow direct listing of enumeration options and override enum method" do
|
942
|
+
should have_selector(".enum_type select")
|
943
|
+
should have_no_content("green")
|
944
|
+
should have_content("yellow")
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
describe "when serialize is enabled in ActiveRecord model", :active_record => true do
|
949
|
+
before do
|
950
|
+
Team.instance_eval do
|
951
|
+
serialize :color
|
952
|
+
def color_enum
|
953
|
+
["blue", "green", "red"]
|
954
|
+
end
|
955
|
+
end
|
956
|
+
visit new_path(:model_name => "team")
|
957
|
+
end
|
958
|
+
|
959
|
+
after do
|
960
|
+
Team.serialized_attributes.clear
|
961
|
+
Team.instance_eval { undef :color_enum }
|
962
|
+
end
|
963
|
+
|
964
|
+
it "should make enumeration multi-selectable" do
|
965
|
+
should have_selector(".enum_type select[multiple]")
|
1042
966
|
end
|
1043
|
-
visit new_path(:model_name => "team")
|
1044
|
-
should have_selector(".enum_type select")
|
1045
|
-
should have_no_content("green")
|
1046
|
-
should have_content("yellow")
|
1047
|
-
Team.send(:remove_method, :color_list) # Reset
|
1048
967
|
end
|
1049
968
|
|
969
|
+
describe "when serialize is enabled in Mongoid model", :mongoid => true do
|
970
|
+
before do
|
971
|
+
Team.instance_eval do
|
972
|
+
field :color, :type => Array
|
973
|
+
def color_enum
|
974
|
+
["blue", "green", "red"]
|
975
|
+
end
|
976
|
+
end
|
977
|
+
visit new_path(:model_name => "team")
|
978
|
+
end
|
979
|
+
|
980
|
+
after do
|
981
|
+
Team.instance_eval do
|
982
|
+
field :color, :type => String
|
983
|
+
undef :color_enum
|
984
|
+
end
|
985
|
+
end
|
986
|
+
|
987
|
+
it "should make enumeration multi-selectable" do
|
988
|
+
should have_selector(".enum_type select[multiple]")
|
989
|
+
end
|
990
|
+
end
|
1050
991
|
end
|
1051
992
|
|
1052
993
|
describe "ColorPicker Support" do
|