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
@@ -28,18 +28,6 @@ describe "RailsAdmin Config DSL List Section" do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
it "should be configurable" do
|
32
|
-
RailsAdmin::Config.models do
|
33
|
-
list do
|
34
|
-
items_per_page 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
visit index_path(:model_name => "league")
|
38
|
-
should have_selector("tbody tr", :count => 1)
|
39
|
-
visit index_path(:model_name => "player")
|
40
|
-
should have_selector("tbody tr", :count => 1)
|
41
|
-
end
|
42
|
-
|
43
31
|
it "should be configurable per model" do
|
44
32
|
RailsAdmin.config League do
|
45
33
|
list do
|
@@ -51,23 +39,6 @@ describe "RailsAdmin Config DSL List Section" do
|
|
51
39
|
visit index_path(:model_name => "player")
|
52
40
|
should have_selector("tbody tr", :count => 2)
|
53
41
|
end
|
54
|
-
|
55
|
-
it "should be globally configurable and overrideable per model" do
|
56
|
-
RailsAdmin::Config.models do
|
57
|
-
list do
|
58
|
-
items_per_page 20
|
59
|
-
end
|
60
|
-
end
|
61
|
-
RailsAdmin.config League do
|
62
|
-
list do
|
63
|
-
items_per_page 1
|
64
|
-
end
|
65
|
-
end
|
66
|
-
visit index_path(:model_name => "league")
|
67
|
-
should have_selector("tbody tr", :count => 1)
|
68
|
-
visit index_path(:model_name => "player")
|
69
|
-
should have_selector("tbody tr", :count => 2)
|
70
|
-
end
|
71
42
|
end
|
72
43
|
|
73
44
|
describe "items' fields" do
|
@@ -211,7 +182,7 @@ describe "RailsAdmin Config DSL List Section" do
|
|
211
182
|
end
|
212
183
|
|
213
184
|
it "should be globally renameable by type" do
|
214
|
-
RailsAdmin
|
185
|
+
RailsAdmin.config 'Fan' do
|
215
186
|
list do
|
216
187
|
fields_of_type :datetime do
|
217
188
|
label { "#{label} (datetime)" }
|
@@ -265,7 +236,7 @@ describe "RailsAdmin Config DSL List Section" do
|
|
265
236
|
end
|
266
237
|
|
267
238
|
it "should have option to disable sortability by type globally" do
|
268
|
-
RailsAdmin
|
239
|
+
RailsAdmin.config 'Fan' do
|
269
240
|
list do
|
270
241
|
fields_of_type :datetime do
|
271
242
|
sortable false
|
@@ -297,7 +268,7 @@ describe "RailsAdmin Config DSL List Section" do
|
|
297
268
|
end
|
298
269
|
|
299
270
|
it "should have option to hide fields by type globally" do
|
300
|
-
RailsAdmin
|
271
|
+
RailsAdmin.config 'Fan' do
|
301
272
|
list do
|
302
273
|
fields_of_type :datetime do
|
303
274
|
hide
|
@@ -415,21 +386,6 @@ describe "RailsAdmin Config DSL List Section" do
|
|
415
386
|
before(:each) { @players = players.map{|h| Player.create(h) }}
|
416
387
|
|
417
388
|
context "should be configurable" do
|
418
|
-
it "globaly" do
|
419
|
-
RailsAdmin.config do |config|
|
420
|
-
config.models do
|
421
|
-
list do
|
422
|
-
sort_by :created_at
|
423
|
-
sort_reverse true
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
visit index_path(:model_name => "player")
|
428
|
-
player_names_by_date.reverse.each_with_index do |name, i|
|
429
|
-
find("tbody tr:nth-child(#{i + 1})").should have_content(name)
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
389
|
it "per model" do
|
434
390
|
RailsAdmin.config Player do
|
435
391
|
list do
|
@@ -442,40 +398,6 @@ describe "RailsAdmin Config DSL List Section" do
|
|
442
398
|
find("tbody tr:nth-child(#{i + 1})").should have_content(name)
|
443
399
|
end
|
444
400
|
end
|
445
|
-
|
446
|
-
it "globaly and overrideable per model" do
|
447
|
-
leagues.map{|h| League.create(h) }
|
448
|
-
|
449
|
-
RailsAdmin::Config.models do
|
450
|
-
list do
|
451
|
-
sort_by :created_at
|
452
|
-
sort_reverse true
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
RailsAdmin.config Player do
|
457
|
-
list do
|
458
|
-
sort_by PK_COLUMN
|
459
|
-
sort_reverse true
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
visit index_path(:model_name => "league")
|
464
|
-
league_names_by_date.reverse.each_with_index do |name, i|
|
465
|
-
find("tbody tr:nth-child(#{i + 1})").should have_content(name)
|
466
|
-
end
|
467
|
-
|
468
|
-
visit index_path(:model_name => "player")
|
469
|
-
@players.sort_by do |p|
|
470
|
-
if p[PK_COLUMN].is_a?(Integer)
|
471
|
-
p[PK_COLUMN]
|
472
|
-
else
|
473
|
-
p[PK_COLUMN].to_s
|
474
|
-
end
|
475
|
-
end.map{|p| p[:name]}.reverse.each_with_index do |name, i|
|
476
|
-
find("tbody tr:nth-child(#{i + 1})").should have_content(name)
|
477
|
-
end
|
478
|
-
end
|
479
401
|
end
|
480
402
|
|
481
403
|
it "should have reverse direction by default" do
|
@@ -242,7 +242,7 @@ describe "RailsAdmin Config DSL Show Section" do
|
|
242
242
|
end
|
243
243
|
|
244
244
|
it "should be globally renameable by type" do
|
245
|
-
RailsAdmin
|
245
|
+
RailsAdmin.config 'Team' do
|
246
246
|
show do
|
247
247
|
fields_of_type :string do
|
248
248
|
label { "#{label} (STRING)" }
|
@@ -298,7 +298,7 @@ describe "RailsAdmin Config DSL Show Section" do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
it "should be globally hideable by type" do
|
301
|
-
RailsAdmin
|
301
|
+
RailsAdmin.config 'Team' do
|
302
302
|
show do
|
303
303
|
fields_of_type :string do
|
304
304
|
hide
|
data/spec/spec_helper.rb
CHANGED
@@ -58,6 +58,7 @@ RSpec.configure do |config|
|
|
58
58
|
RailsAdmin::Config.reset
|
59
59
|
RailsAdmin::AbstractModel.reset
|
60
60
|
RailsAdmin::Config.audit_with(:history) if CI_ORM == :active_record
|
61
|
+
RailsAdmin::Config.yell_for_non_accessible_fields = false
|
61
62
|
login_as User.create(
|
62
63
|
:email => "username@example.com",
|
63
64
|
:password => "password"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path('../../../config/initializers/active_record_extensions', __FILE__)
|
3
|
+
|
4
|
+
describe 'ActiveRecord::Base', :active_record => true do
|
5
|
+
describe '#safe_send' do
|
6
|
+
it "only calls #read_attribute once" do
|
7
|
+
@player = Player.new
|
8
|
+
@player.number = 23
|
9
|
+
original_method = @player.method(:read_attribute)
|
10
|
+
@player.should_receive(:read_attribute).exactly(1).times do |*args|
|
11
|
+
original_method.call(*args)
|
12
|
+
end
|
13
|
+
@player.safe_send(:number).should == 23
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -151,14 +151,15 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
151
151
|
|
152
152
|
|
153
153
|
describe "#properties" do
|
154
|
-
before do
|
155
|
-
@abstract_model = RailsAdmin::AbstractModel.new('Player')
|
156
|
-
end
|
157
|
-
|
158
154
|
it "returns parameters of string-type field" do
|
159
|
-
|
155
|
+
RailsAdmin::AbstractModel.new('Player').properties.select{|f| f[:name] == :name}.should ==
|
160
156
|
[{:name => :name, :pretty_name => "Name", :type => :string, :length => 100, :nullable? => false, :serial? => false}]
|
161
157
|
end
|
158
|
+
|
159
|
+
it "maps serialized attribute to :serialized field type" do
|
160
|
+
RailsAdmin::AbstractModel.new('User').properties.find{|f| f[:name] == :roles}.should ==
|
161
|
+
{:name => :roles, :pretty_name => "Roles", :length => 255, :nullable? => true, :serial? => false, :type => :serialized}
|
162
|
+
end
|
162
163
|
end
|
163
164
|
|
164
165
|
describe "data access method" do
|
@@ -323,6 +324,11 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
323
324
|
@abstract_model.send(:build_statement, :field, :integer, 'word', nil).should be_nil
|
324
325
|
end
|
325
326
|
|
327
|
+
it "supports decimal type query" do
|
328
|
+
@abstract_model.send(:build_statement, :field, :decimal, "1.1", nil).should == ["(field = ?)", 1.1]
|
329
|
+
@abstract_model.send(:build_statement, :field, :decimal, 'word', nil).should be_nil
|
330
|
+
end
|
331
|
+
|
326
332
|
it "supports string type query" do
|
327
333
|
@abstract_model.send(:build_statement, :field, :string, "", nil).should be_nil
|
328
334
|
@abstract_model.send(:build_statement, :field, :string, "foo", "was").should be_nil
|
@@ -365,9 +371,5 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
365
371
|
it "#table_name works" do
|
366
372
|
@abstract_model.table_name.should == 'players'
|
367
373
|
end
|
368
|
-
|
369
|
-
it "#serialized_attributes works" do
|
370
|
-
RailsAdmin::AbstractModel.new('User').serialized_attributes.should == ["roles"]
|
371
|
-
end
|
372
374
|
end
|
373
375
|
end
|
@@ -686,10 +686,10 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
686
686
|
it "supports string type query" do
|
687
687
|
@abstract_model.send(:build_statement, :field, :string, "", nil).should be_nil
|
688
688
|
@abstract_model.send(:build_statement, :field, :string, "foo", "was").should be_nil
|
689
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "default").should == {:field=>/foo/}
|
690
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "like").should == {:field=>/foo/}
|
691
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == {:field=>/^foo/}
|
692
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == {:field=>/foo$/}
|
689
|
+
@abstract_model.send(:build_statement, :field, :string, "foo", "default").should == {:field=>/foo/i}
|
690
|
+
@abstract_model.send(:build_statement, :field, :string, "foo", "like").should == {:field=>/foo/i}
|
691
|
+
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == {:field=>/^foo/i}
|
692
|
+
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == {:field=>/foo$/i}
|
693
693
|
@abstract_model.send(:build_statement, :field, :string, "foo", "is").should == {:field=>'foo'}
|
694
694
|
end
|
695
695
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsAdmin::Config::Actions::Base do
|
4
|
+
|
5
|
+
describe "#visible?" do
|
6
|
+
it 'should exclude models not referenced in the only array' do
|
7
|
+
RailsAdmin.config do |config|
|
8
|
+
config.actions do
|
9
|
+
index do
|
10
|
+
only [Player, Cms::BasicPage]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Player)}).should be_visible
|
15
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Team)}).should be_nil
|
16
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Cms::BasicPage)}).should be_visible
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should exclude models referenced in the except array' do
|
20
|
+
RailsAdmin.config do |config|
|
21
|
+
config.actions do
|
22
|
+
index do
|
23
|
+
except [Player, Cms::BasicPage]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Player)}).should be_nil
|
28
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Team)}).should be_visible
|
29
|
+
RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Cms::BasicPage)}).should be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -2,6 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RailsAdmin::Config::Fields::Base do
|
4
4
|
|
5
|
+
describe "#required" do
|
6
|
+
it "should read the :on => :create/:update validate option" do
|
7
|
+
RailsAdmin.config Ball do
|
8
|
+
field 'color'
|
9
|
+
end
|
10
|
+
|
11
|
+
RailsAdmin.config('Ball').fields.first.with(:object => Ball.new).should be_required
|
12
|
+
RailsAdmin.config('Ball').fields.first.with(:object => FactoryGirl.create(:ball)).should_not be_required
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
describe "#name" do
|
6
17
|
it 'should be normalized to Symbol' do
|
7
18
|
RailsAdmin.config Team do
|
@@ -92,6 +103,21 @@ describe RailsAdmin::Config::Fields::Base do
|
|
92
103
|
end
|
93
104
|
end
|
94
105
|
|
106
|
+
describe "#hint" do
|
107
|
+
it "should be user customizable" do
|
108
|
+
RailsAdmin.config Team do
|
109
|
+
list do
|
110
|
+
field :division do
|
111
|
+
hint "Great Division"
|
112
|
+
end
|
113
|
+
field :name
|
114
|
+
end
|
115
|
+
end
|
116
|
+
RailsAdmin.config('Team').list.fields.find{|f| f.name == :division}.hint.should == "Great Division" # custom
|
117
|
+
RailsAdmin.config('Team').list.fields.find{|f| f.name == :name}.hint.should == "" # default
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
95
121
|
describe "#css_class" do
|
96
122
|
it "should have a default and be user customizable" do
|
97
123
|
RailsAdmin.config Team do
|
@@ -345,4 +371,34 @@ describe RailsAdmin::Config::Fields::Base do
|
|
345
371
|
RailsAdmin.config(FieldVisibilityTest).show.fields.select{|f| f.visible? }.map(&:name).should =~ [:name]
|
346
372
|
end
|
347
373
|
end
|
374
|
+
|
375
|
+
describe '#editable?' do
|
376
|
+
before do
|
377
|
+
Moped.logger.stub!(:debug) if defined?(Moped)
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'should yell for non attr_accessible fields if config.yell_for_non_accessible_fields is true' do
|
381
|
+
RailsAdmin.config do |config|
|
382
|
+
config.yell_for_non_accessible_fields = true
|
383
|
+
config.model FieldTest do
|
384
|
+
field :protected_field
|
385
|
+
end
|
386
|
+
end
|
387
|
+
Rails.logger.should_receive(:debug).with {|msg| msg =~ /Please add 'attr_accessible :protected_field'/ }
|
388
|
+
editable = RailsAdmin.config(FieldTest).field(:protected_field).with(:object => FactoryGirl.create(:field_test), :view => double(:controller => double(:_attr_accessible_role => :default))).editable?
|
389
|
+
editable.should == false
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should not yell for non attr_accessible fields if config.yell_for_non_accessible_fields is false' do
|
393
|
+
RailsAdmin.config do |config|
|
394
|
+
config.yell_for_non_accessible_fields = false
|
395
|
+
config.model FieldTest do
|
396
|
+
field :protected_field
|
397
|
+
end
|
398
|
+
end
|
399
|
+
Rails.logger.should_not_receive(:debug).with {|msg| msg =~ /Please add 'attr_accessible :protected_field'/ }
|
400
|
+
editable = RailsAdmin.config(FieldTest).field(:protected_field).with(:object => FactoryGirl.create(:field_test), :view => double(:controller => double(:_attr_accessible_role => :default))).editable?
|
401
|
+
editable.should == false
|
402
|
+
end
|
403
|
+
end
|
348
404
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsAdmin::Config::Fields::Types::Date do
|
4
|
+
describe "#parse_input" do
|
5
|
+
before :each do
|
6
|
+
@object = FactoryGirl.create(:field_test)
|
7
|
+
@time = ::Time.now.getutc
|
8
|
+
@field = RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :date_field }
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
Time.zone = 'UTC'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should read %B %d, %Y by default" do
|
16
|
+
@object.date_field = @field.parse_input({ :date_field => @time.strftime("%B %d, %Y") })
|
17
|
+
@object.date_field.should eql(::Date.parse(@time.to_s))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should cover a timezone lag even if in UTC+n:00 timezone." do
|
21
|
+
Time.zone = 'Tokyo' # +09:00
|
22
|
+
|
23
|
+
@object.date_field = @field.parse_input({ :date_field => @time.strftime("%B %d, %Y") })
|
24
|
+
@object.date_field.should eql(::Date.parse(@time.to_s))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have a simple customization option" do
|
28
|
+
RailsAdmin.config FieldTest do
|
29
|
+
edit do
|
30
|
+
field :date_field do
|
31
|
+
date_format :default
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@object.date_field = @field.parse_input({ :date_field => @time.strftime("%Y-%m-%d") })
|
37
|
+
@object.date_field.should eql(::Date.parse(@time.to_s))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have a customization option" do
|
41
|
+
RailsAdmin.config FieldTest do
|
42
|
+
edit do
|
43
|
+
field :date_field do
|
44
|
+
strftime_format "%Y/%m/%d"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@object.date_field = @field.parse_input({ :date_field => @time.strftime("%Y/%m/%d") })
|
50
|
+
@object.date_field.should eql(::Date.parse(@time.to_s))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsAdmin::Config::Fields::Types::Datetime do
|
4
|
+
describe "#parse_input" do
|
5
|
+
before :each do
|
6
|
+
@field = RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :datetime_field }
|
7
|
+
@object = FactoryGirl.create(:field_test)
|
8
|
+
@time = ::Time.now.getutc
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
Time.zone = 'UTC'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to read %B %d, %Y %H:%M" do
|
16
|
+
@object = FactoryGirl.create(:field_test)
|
17
|
+
@object.datetime_field = @field.parse_input({ :datetime_field => @time.strftime("%B %d, %Y %H:%M") })
|
18
|
+
@object.datetime_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to read %a, %d %b %Y %H:%M:%S" do
|
22
|
+
RailsAdmin.config FieldTest do
|
23
|
+
edit do
|
24
|
+
field :datetime_field do
|
25
|
+
date_format :default
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@object = FactoryGirl.create(:field_test)
|
30
|
+
@object.datetime_field = @field.parse_input({ :datetime_field => @time.strftime("%a, %d %b %Y %H:%M:%S") })
|
31
|
+
@object.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have a customization option" do
|
35
|
+
RailsAdmin.config FieldTest do
|
36
|
+
list do
|
37
|
+
field :datetime_field do
|
38
|
+
strftime_format "%Y-%m-%d %H:%M:%S"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@object = FactoryGirl.create(:field_test)
|
43
|
+
@object.datetime_field = @field.parse_input({ :datetime_field => @time.strftime("%Y-%m-%d %H:%M:%S") })
|
44
|
+
@object.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should do round-trip saving properly with non-UTC timezones" do
|
48
|
+
Time.zone = 'Vienna'
|
49
|
+
@object = FactoryGirl.create(:field_test)
|
50
|
+
@object.datetime_field = @field.parse_input({ :datetime_field => '2012-09-01 12:00:00 +02:00' })
|
51
|
+
@object.datetime_field.should == Time.zone.parse('2012-09-01 12:00:00 +02:00')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|