drewda_rails_admin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +53 -0
- data/LICENSE.md +20 -0
- data/README.md +160 -0
- data/Rakefile +19 -0
- 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_black.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_indic.gif +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_indic.gif +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/javascripts/rails_admin/custom/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
- data/app/assets/javascripts/rails_admin/jquery.pjax.js +431 -0
- data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1371 -0
- data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
- data/app/assets/javascripts/rails_admin/ra.filter-box.js +129 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +280 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +181 -0
- data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +40 -0
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +150 -0
- data/app/assets/javascripts/rails_admin/rails_admin.js.erb +25 -0
- data/app/assets/javascripts/rails_admin/themes/default/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/ui.js.coffee +61 -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/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
- data/app/assets/stylesheets/rails_admin/base/README +2 -0
- data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +263 -0
- data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +12 -0
- data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +13 -0
- data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +15 -0
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +76 -0
- data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +180 -0
- data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +69 -0
- data/app/assets/stylesheets/rails_admin/ra.calendar-additions.css.scss +25 -0
- data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +85 -0
- data/app/assets/stylesheets/rails_admin/rails_admin.css +4 -0
- data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +8 -0
- data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +11 -0
- data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +12 -0
- data/app/controllers/rails_admin/application_controller.rb +82 -0
- data/app/controllers/rails_admin/main_controller.rb +151 -0
- data/app/helpers/rails_admin/application_helper.rb +123 -0
- data/app/helpers/rails_admin/form_builder.rb +104 -0
- data/app/helpers/rails_admin/main_helper.rb +36 -0
- data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
- data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
- data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
- data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +12 -0
- data/app/views/layouts/rails_admin/application.html.haml +39 -0
- data/app/views/rails_admin/main/_dashboard_history.html.haml +10 -0
- data/app/views/rails_admin/main/_delete_notice.html.haml +18 -0
- data/app/views/rails_admin/main/_form_colorpicker.html.haml +24 -0
- data/app/views/rails_admin/main/_form_datetime.html.haml +4 -0
- data/app/views/rails_admin/main/_form_enumeration.html.haml +4 -0
- data/app/views/rails_admin/main/_form_field.html.haml +1 -0
- data/app/views/rails_admin/main/_form_file_upload.html.haml +18 -0
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +59 -0
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +47 -0
- data/app/views/rails_admin/main/_form_nested_many.html.haml +41 -0
- data/app/views/rails_admin/main/_form_nested_one.html.haml +35 -0
- data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +34 -0
- data/app/views/rails_admin/main/_form_text.html.haml +9 -0
- data/app/views/rails_admin/main/_submit_buttons.html.haml +15 -0
- data/app/views/rails_admin/main/bulk_delete.html.haml +11 -0
- data/app/views/rails_admin/main/dashboard.html.haml +31 -0
- data/app/views/rails_admin/main/delete.html.haml +18 -0
- data/app/views/rails_admin/main/edit.html.haml +2 -0
- data/app/views/rails_admin/main/export.html.haml +75 -0
- data/app/views/rails_admin/main/history.html.haml +42 -0
- data/app/views/rails_admin/main/index.html.haml +140 -0
- data/app/views/rails_admin/main/new.html.haml +2 -0
- data/app/views/rails_admin/main/show.html.haml +14 -0
- data/config/initializers/active_record_extensions.rb +19 -0
- data/config/initializers/devise_patch.rb +9 -0
- data/config/initializers/haml.rb +2 -0
- data/config/initializers/mongoid_extensions.rb +4 -0
- data/config/locales/fr.yml +24 -0
- data/config/locales/rails_admin.en.yml +130 -0
- data/config/routes.rb +12 -0
- data/lib/generators/rails_admin/install_generator.rb +84 -0
- data/lib/generators/rails_admin/templates/drop.rb +18 -0
- data/lib/generators/rails_admin/templates/initializer.erb +101 -0
- data/lib/generators/rails_admin/templates/migration.rb +18 -0
- data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
- data/lib/generators/rails_admin/utils.rb +30 -0
- data/lib/rails_admin.rb +34 -0
- data/lib/rails_admin/abstract_model.rb +110 -0
- data/lib/rails_admin/adapters/active_record.rb +247 -0
- data/lib/rails_admin/adapters/active_record/abstract_object.rb +32 -0
- data/lib/rails_admin/adapters/mongoid.rb +333 -0
- data/lib/rails_admin/adapters/mongoid/abstract_object.rb +32 -0
- data/lib/rails_admin/adapters/mongoid/extension.rb +27 -0
- data/lib/rails_admin/config.rb +322 -0
- data/lib/rails_admin/config/actions.rb +121 -0
- data/lib/rails_admin/config/actions/base.rb +117 -0
- data/lib/rails_admin/config/actions/bulk_delete.rb +55 -0
- data/lib/rails_admin/config/actions/dashboard.rb +44 -0
- data/lib/rails_admin/config/actions/delete.rb +53 -0
- data/lib/rails_admin/config/actions/edit.rb +60 -0
- data/lib/rails_admin/config/actions/export.rb +40 -0
- data/lib/rails_admin/config/actions/history_index.rb +38 -0
- data/lib/rails_admin/config/actions/history_show.rb +38 -0
- data/lib/rails_admin/config/actions/index.rb +85 -0
- data/lib/rails_admin/config/actions/new.rb +64 -0
- data/lib/rails_admin/config/actions/show.rb +32 -0
- data/lib/rails_admin/config/actions/show_in_app.rb +28 -0
- data/lib/rails_admin/config/configurable.rb +92 -0
- data/lib/rails_admin/config/fields.rb +88 -0
- data/lib/rails_admin/config/fields/association.rb +108 -0
- data/lib/rails_admin/config/fields/base.rb +281 -0
- data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +29 -0
- data/lib/rails_admin/config/fields/factories/carrierwave.rb +31 -0
- data/lib/rails_admin/config/fields/factories/devise.rb +27 -0
- data/lib/rails_admin/config/fields/factories/dragonfly.rb +27 -0
- data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
- data/lib/rails_admin/config/fields/factories/paperclip.rb +26 -0
- data/lib/rails_admin/config/fields/factories/password.rb +17 -0
- data/lib/rails_admin/config/fields/factories/serialized.rb +17 -0
- data/lib/rails_admin/config/fields/group.rb +78 -0
- data/lib/rails_admin/config/fields/types.rb +27 -0
- data/lib/rails_admin/config/fields/types/all.rb +26 -0
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +41 -0
- data/lib/rails_admin/config/fields/types/boolean.rb +31 -0
- data/lib/rails_admin/config/fields/types/bson_object_id.rb +42 -0
- data/lib/rails_admin/config/fields/types/carrierwave.rb +31 -0
- data/lib/rails_admin/config/fields/types/color.rb +37 -0
- data/lib/rails_admin/config/fields/types/date.rb +24 -0
- data/lib/rails_admin/config/fields/types/datetime.rb +165 -0
- data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
- data/lib/rails_admin/config/fields/types/dragonfly.rb +41 -0
- data/lib/rails_admin/config/fields/types/enum.rb +35 -0
- data/lib/rails_admin/config/fields/types/file_upload.rb +61 -0
- data/lib/rails_admin/config/fields/types/float.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_many_association.rb +32 -0
- data/lib/rails_admin/config/fields/types/has_one_association.rb +39 -0
- data/lib/rails_admin/config/fields/types/hidden.rb +21 -0
- data/lib/rails_admin/config/fields/types/integer.rb +22 -0
- data/lib/rails_admin/config/fields/types/mongoid_type.rb +25 -0
- data/lib/rails_admin/config/fields/types/paperclip.rb +28 -0
- data/lib/rails_admin/config/fields/types/password.rb +39 -0
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +76 -0
- data/lib/rails_admin/config/fields/types/serialized.rb +22 -0
- data/lib/rails_admin/config/fields/types/string.rb +41 -0
- data/lib/rails_admin/config/fields/types/text.rb +36 -0
- data/lib/rails_admin/config/fields/types/time.rb +36 -0
- data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
- data/lib/rails_admin/config/groupable.rb +18 -0
- data/lib/rails_admin/config/has_fields.rb +135 -0
- data/lib/rails_admin/config/has_groups.rb +23 -0
- data/lib/rails_admin/config/hideable.rb +28 -0
- data/lib/rails_admin/config/model.rb +88 -0
- data/lib/rails_admin/config/proxyable.rb +12 -0
- data/lib/rails_admin/config/proxyable/proxy.rb +43 -0
- data/lib/rails_admin/config/sections.rb +38 -0
- data/lib/rails_admin/config/sections/base.rb +29 -0
- data/lib/rails_admin/config/sections/create.rb +11 -0
- data/lib/rails_admin/config/sections/edit.rb +11 -0
- data/lib/rails_admin/config/sections/export.rb +11 -0
- data/lib/rails_admin/config/sections/list.rb +27 -0
- data/lib/rails_admin/config/sections/nested.rb +10 -0
- data/lib/rails_admin/config/sections/show.rb +10 -0
- data/lib/rails_admin/config/sections/update.rb +10 -0
- data/lib/rails_admin/engine.rb +22 -0
- data/lib/rails_admin/extension.rb +29 -0
- data/lib/rails_admin/extensions/cancan.rb +5 -0
- data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +59 -0
- data/lib/rails_admin/extensions/history.rb +5 -0
- data/lib/rails_admin/extensions/history/auditing_adapter.rb +37 -0
- data/lib/rails_admin/extensions/history/history.rb +69 -0
- data/lib/rails_admin/extensions/paper_trail.rb +5 -0
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +92 -0
- data/lib/rails_admin/i18n_support.rb +43 -0
- data/lib/rails_admin/support/core_extensions.rb +44 -0
- data/lib/rails_admin/support/csv_converter.rb +109 -0
- data/lib/rails_admin/version.rb +6 -0
- data/lib/tasks/prepare_ci_env.rake +27 -0
- data/lib/tasks/rails_admin.rake +18 -0
- data/spec/ci.sh +2 -0
- data/spec/controllers/application_controller_spec.rb +30 -0
- data/spec/controllers/main_controller_spec.rb +180 -0
- data/spec/database_helpers.rb +15 -0
- data/spec/dummy_app/Gemfile +58 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/assets/images/rails.png +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/app/controllers/players_controller.rb +5 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/locales/models.en.yml +16 -0
- data/spec/dummy_app/app/models/abstract.rb +5 -0
- data/spec/dummy_app/app/models/article.rb +9 -0
- data/spec/dummy_app/app/models/author.rb +6 -0
- data/spec/dummy_app/app/models/ball.rb +8 -0
- data/spec/dummy_app/app/models/category.rb +3 -0
- data/spec/dummy_app/app/models/cms.rb +5 -0
- data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
- data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
- data/spec/dummy_app/app/models/comment.rb +3 -0
- data/spec/dummy_app/app/models/division.rb +12 -0
- data/spec/dummy_app/app/models/draft.rb +11 -0
- data/spec/dummy_app/app/models/fan.rb +5 -0
- data/spec/dummy_app/app/models/field_test.rb +20 -0
- data/spec/dummy_app/app/models/hardball.rb +2 -0
- data/spec/dummy_app/app/models/league.rb +10 -0
- data/spec/dummy_app/app/models/mongoid_field_test.rb +22 -0
- data/spec/dummy_app/app/models/nested_field_test.rb +6 -0
- data/spec/dummy_app/app/models/player.rb +23 -0
- data/spec/dummy_app/app/models/rel_test.rb +6 -0
- data/spec/dummy_app/app/models/tag.rb +7 -0
- data/spec/dummy_app/app/models/team.rb +25 -0
- data/spec/dummy_app/app/models/user.rb +21 -0
- data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_app/app/views/players/show.html.haml +1 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/config/application.rb +62 -0
- data/spec/dummy_app/config/boot.rb +6 -0
- data/spec/dummy_app/config/database.yml +25 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +37 -0
- data/spec/dummy_app/config/environments/production.rb +67 -0
- data/spec/dummy_app/config/environments/test.rb +37 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/devise.rb +148 -0
- data/spec/dummy_app/config/initializers/inflections.rb +15 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/rails_admin.rb +11 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_app/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/config/mongoid.yml +17 -0
- data/spec/dummy_app/config/routes.rb +10 -0
- data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
- data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
- data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
- data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
- data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +49 -0
- data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
- data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
- data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
- data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
- data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
- data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
- data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
- data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
- data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
- data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
- data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
- data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
- data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
- data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
- data/spec/dummy_app/db/migrate/20111115041025_add_type_to_balls.rb +5 -0
- data/spec/dummy_app/db/migrate/20111123092549_create_nested_field_tests.rb +10 -0
- data/spec/dummy_app/db/migrate/20111130075338_add_dragonfly_asset_name_to_field_tests.rb +5 -0
- data/spec/dummy_app/db/migrate/20111215083258_create_foo_bars.rb +8 -0
- data/spec/dummy_app/db/migrate/20120117151733_add_custom_field_to_teams.rb +5 -0
- data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +7 -0
- data/spec/dummy_app/db/seeds.rb +18 -0
- data/spec/dummy_app/doc/README_FOR_APP +2 -0
- data/spec/dummy_app/public/404.html +26 -0
- data/spec/dummy_app/public/422.html +26 -0
- data/spec/dummy_app/public/500.html +25 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg.meta +1 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg.meta +1 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/original/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/thumb/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/original/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/thumb/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/original/liste-electorale.pdf +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/thumb/liste-electorale.pdf +148 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/thumb_Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/thumb_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/thumb_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/script/rails +6 -0
- data/spec/factories.rb +89 -0
- data/spec/helpers/application_helper_spec.rb +277 -0
- data/spec/integration/authorization/cancan_spec.rb +349 -0
- data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +44 -0
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +154 -0
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +23 -0
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +27 -0
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +109 -0
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +87 -0
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +392 -0
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +74 -0
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +91 -0
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +219 -0
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +954 -0
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +509 -0
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +302 -0
- data/spec/integration/history/rails_admin_history_spec.rb +66 -0
- data/spec/integration/rails_admin_spec.rb +113 -0
- data/spec/integration/relation_spec.rb +26 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/tableless.rb +27 -0
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +131 -0
- data/spec/unit/adapters/active_record_spec.rb +373 -0
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +30 -0
- data/spec/unit/adapters/mongoid_spec.rb +581 -0
- data/spec/unit/config/actions_spec.rb +181 -0
- data/spec/unit/config/fields/base_spec.rb +300 -0
- data/spec/unit/config/model_spec.rb +75 -0
- data/spec/unit/config/sections_spec.rb +123 -0
- data/spec/unit/config_spec.rb +273 -0
- metadata +823 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin Basic New" do
|
4
|
+
|
5
|
+
subject { page }
|
6
|
+
|
7
|
+
describe "GET /admin/player/new" do
|
8
|
+
before(:each) do
|
9
|
+
visit new_path(:model_name => "player")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should show \"New Model\"" do
|
13
|
+
should have_content("New Player")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should show required fields as \"Required\"" do
|
17
|
+
should have_selector("div", :text => /Name\s*Required/)
|
18
|
+
should have_selector("div", :text => /Number\s*Required/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should show non-required fields as \"Optional\"" do
|
22
|
+
should have_selector("#player_position_field .help-block", :text => "Optional")
|
23
|
+
should have_selector("#player_born_on_field .help-block", :text => "Optional")
|
24
|
+
should have_selector("#player_notes_field .help-block", :text => "Optional")
|
25
|
+
end
|
26
|
+
|
27
|
+
# https://github.com/sferik/rails_admin/issues/362
|
28
|
+
# test that no link uses the "wildcard route" with the main
|
29
|
+
# controller and new method
|
30
|
+
it "should not use the 'wildcard route'" do
|
31
|
+
should have_no_selector("a[href^='/rails_admin/main/new']")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "GET /admin/player/new with has-one/belongs_to/has_many association" do
|
36
|
+
before(:each) do
|
37
|
+
FactoryGirl.create :draft
|
38
|
+
visit new_path(:model_name => "player")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should show selects" do
|
42
|
+
should have_selector("select#player_draft_id")
|
43
|
+
should have_selector("select#player_team_id")
|
44
|
+
should have_selector("select#player_comment_ids")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "GET /admin/player/new with missing label" do
|
49
|
+
before(:each) do
|
50
|
+
FactoryGirl.create :team, :name => ""
|
51
|
+
visit new_path(:model_name => "player")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET /admin/player/new with parameters for pre-population" do
|
56
|
+
it "should populate form field when corresponding parameters are passed in" do
|
57
|
+
visit new_path(:model_name => 'player', :player => {:name => 'Sam'})
|
58
|
+
page.should have_css('input[value=Sam]')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should prepropulate belongs to relationships" do
|
62
|
+
@team = FactoryGirl.create :team, :name => "belongs_to association prepopulated"
|
63
|
+
visit new_path(:model_name => 'player', :associations => { :team => @team.id } )
|
64
|
+
page.should have_css("select#player_team_id option[selected='selected'][value='#{@team.id}']")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should prepropulate has_many relationships" do
|
68
|
+
@player = FactoryGirl.create :player, :name => "has_many association prepopulated"
|
69
|
+
visit new_path(:model_name => 'team', :associations => { :players => @player.id } )
|
70
|
+
page.should have_css("select#team_player_ids option[selected='selected'][value='#{@player.id}']")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin Namespaced Model New" do
|
4
|
+
|
5
|
+
subject { page }
|
6
|
+
|
7
|
+
describe "AbstractModel#to_param" do
|
8
|
+
it 'turns namespaces into prefixes with ~' do
|
9
|
+
RailsAdmin::AbstractModel.new("Cms::BasicPage").to_param.should == 'cms~basic_page'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "ApplicationController#to_model_name" do
|
14
|
+
it 'turns cms~basic_page into Cms::BasicPage' do
|
15
|
+
RailsAdmin::ApplicationController.new.to_model_name('cms~basic_page').should == 'Cms::BasicPage'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "GET /admin/cms_basic_page/new" do
|
20
|
+
before(:each) do
|
21
|
+
visit new_path(:model_name => "cms~basic_page")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have correct input field names' do
|
25
|
+
should have_selector("label[for=cms_basic_page_title]")
|
26
|
+
should have_selector("input#cms_basic_page_title[name='cms_basic_page[title]']")
|
27
|
+
should have_selector("label[for=cms_basic_page_content]")
|
28
|
+
should have_selector("textarea#cms_basic_page_content[name='cms_basic_page[content]']")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin Basic Show" do
|
4
|
+
subject { page }
|
5
|
+
|
6
|
+
describe "show" do
|
7
|
+
before(:each) do
|
8
|
+
@player = FactoryGirl.create :player
|
9
|
+
visit show_path(:model_name => "player", :id => @player.id)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have History, Edit, Delete" do
|
13
|
+
should have_selector("a", :text => "History")
|
14
|
+
should have_selector("a", :text => "Edit")
|
15
|
+
should have_selector("a", :text => "Delete")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should show 'Details'" do
|
19
|
+
should have_content("Details")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should show attributes" do
|
23
|
+
should have_content("Name")
|
24
|
+
should have_content(@player.name)
|
25
|
+
should have_content("Number")
|
26
|
+
should have_content(@player.number)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "GET /admin/players/123this-id-doesnt-exist" do
|
31
|
+
it "should raise NotFound" do
|
32
|
+
visit '/admin/players/123this-id-doesnt-exist'
|
33
|
+
page.driver.status_code.should eql(404)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe "show with belongs_to association" do
|
39
|
+
before(:each) do
|
40
|
+
@player = FactoryGirl.create :player
|
41
|
+
@team = FactoryGirl.create :team
|
42
|
+
@player.update_attribute(:team, @team)
|
43
|
+
visit show_path(:model_name => "player", :id => @player.id)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should show associated objects" do
|
47
|
+
should have_css("a[href='/admin/team/#{@team.id}']")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "show with has-one association" do
|
52
|
+
before(:each) do
|
53
|
+
@player = FactoryGirl.create :player
|
54
|
+
@draft = FactoryGirl.create :draft, :player => @player
|
55
|
+
visit show_path(:model_name => "player", :id => @player.id)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should show associated objects" do
|
59
|
+
should have_css("a[href='/admin/draft/#{@draft.id}']")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "show with has-and-belongs-to-many association" do
|
64
|
+
before(:each) do
|
65
|
+
@player = FactoryGirl.create :player
|
66
|
+
@comment1 = FactoryGirl.create :comment, :commentable => @player
|
67
|
+
@comment2 = FactoryGirl.create :comment, :commentable => @player
|
68
|
+
@comment3 = FactoryGirl.create :comment, :commentable => FactoryGirl.create(:player)
|
69
|
+
|
70
|
+
visit show_path(:model_name => "player", :id => @player.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should show associated objects" do
|
74
|
+
should have_css("a[href='/admin/comment/#{@comment1.id}']")
|
75
|
+
should have_css("a[href='/admin/comment/#{@comment2.id}']")
|
76
|
+
should_not have_css("a[href='/admin/comment/#{@comment3.id}']")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "show for polymorphic objects" do
|
81
|
+
before(:each) do
|
82
|
+
@player = FactoryGirl.create :player
|
83
|
+
@comment = FactoryGirl.create :comment, :commentable => @player
|
84
|
+
visit show_path(:model_name => "comment", :id => @comment.id)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should show associated object" do
|
88
|
+
should have_css("a[href='/admin/player/#{@player.id}']")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin Basic Update" do
|
4
|
+
|
5
|
+
subject { page }
|
6
|
+
|
7
|
+
describe "update with errors" do
|
8
|
+
before(:each) do
|
9
|
+
@player = FactoryGirl.create :player
|
10
|
+
visit edit_path(:model_name => "player", :id => @player.id)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return to edit page" do
|
14
|
+
fill_in "player[name]", :with => ""
|
15
|
+
click_button "Save"
|
16
|
+
page.driver.status_code.should eql(406)
|
17
|
+
should have_selector "form", :action => "/admin/players/#{@player.id}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "update and add another" do
|
22
|
+
before(:each) do
|
23
|
+
@player = FactoryGirl.create :player
|
24
|
+
|
25
|
+
visit edit_path(:model_name => "player", :id => @player.id)
|
26
|
+
|
27
|
+
fill_in "player[name]", :with => "Jackie Robinson"
|
28
|
+
fill_in "player[number]", :with => "42"
|
29
|
+
fill_in "player[position]", :with => "Second baseman"
|
30
|
+
click_button "Save"
|
31
|
+
|
32
|
+
@player = RailsAdmin::AbstractModel.new("Player").first
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should update an object with correct attributes" do
|
36
|
+
@player.name.should eql("Jackie Robinson")
|
37
|
+
@player.number.should eql(42)
|
38
|
+
@player.position.should eql("Second baseman")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "update and edit" do
|
43
|
+
before(:each) do
|
44
|
+
@player = FactoryGirl.create :player
|
45
|
+
|
46
|
+
visit edit_path(:model_name => "player", :id => @player.id)
|
47
|
+
|
48
|
+
fill_in "player[name]", :with => "Jackie Robinson"
|
49
|
+
fill_in "player[number]", :with => "42"
|
50
|
+
fill_in "player[position]", :with => "Second baseman"
|
51
|
+
click_button "Save and edit"
|
52
|
+
|
53
|
+
@player.reload
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should update an object with correct attributes" do
|
57
|
+
@player.name.should eql("Jackie Robinson")
|
58
|
+
@player.number.should eql(42)
|
59
|
+
@player.position.should eql("Second baseman")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "update with has-one association" do
|
64
|
+
before(:each) do
|
65
|
+
@player = FactoryGirl.create :player
|
66
|
+
@draft = FactoryGirl.create :draft
|
67
|
+
page.driver.put edit_path(:model_name => "player", :id => @player.id, :player => {:name => "Jackie Robinson", :draft_id => @draft.id, :number => 42, :position => "Second baseman"})
|
68
|
+
@player.reload
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should update an object with correct attributes" do
|
72
|
+
@player.name.should eql("Jackie Robinson")
|
73
|
+
@player.number.should eql(42)
|
74
|
+
@player.position.should eql("Second baseman")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should update an object with correct associations" do
|
78
|
+
@draft.reload
|
79
|
+
@player.draft.should eql(@draft)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "update with has-many association" do
|
84
|
+
it "should be fillable and emptyable" do
|
85
|
+
RailsAdmin.config do |c|
|
86
|
+
c.audit_with :history
|
87
|
+
end
|
88
|
+
|
89
|
+
@league = FactoryGirl.create :league
|
90
|
+
@divisions = 3.times.map { Division.create!(:name => "div #{Time.now.to_f}", :league => League.create!(:name => "league #{Time.now.to_f}")) }
|
91
|
+
|
92
|
+
page.driver.put edit_path(:model_name => "league", :id => @league.id, :league => {:name => "National League", :division_ids => [@divisions[0].id] })
|
93
|
+
|
94
|
+
@league.reload
|
95
|
+
@league.name.should eql("National League")
|
96
|
+
@divisions[0].reload
|
97
|
+
@league.divisions.should include(@divisions[0])
|
98
|
+
@league.divisions.should_not include(@divisions[1])
|
99
|
+
@league.divisions.should_not include(@divisions[2])
|
100
|
+
|
101
|
+
RailsAdmin::History.where(:item => @league.id).collect(&:message).should include("Added Divisions ##{@divisions[0].id} associations, Changed name")
|
102
|
+
|
103
|
+
page.driver.put edit_path(:model_name => "league", :id => @league.id, :league => {:division_ids => [""]})
|
104
|
+
|
105
|
+
@league.reload
|
106
|
+
@league.divisions.should be_empty
|
107
|
+
RailsAdmin::History.where(:item => @league.id).collect(&:message).should include("Removed Divisions ##{@divisions[0].id} associations")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "update with missing object" do
|
112
|
+
before(:each) do
|
113
|
+
page.driver.put(edit_path(:model_name => "player", :id => 1), :params => {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should raise NotFound" do
|
117
|
+
page.driver.status_code.should eql(404)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "update with invalid object" do
|
122
|
+
before(:each) do
|
123
|
+
@player = FactoryGirl.create :player
|
124
|
+
|
125
|
+
visit edit_path(:model_name => "player", :id => @player.id)
|
126
|
+
|
127
|
+
fill_in "player[name]", :with => "Jackie Robinson"
|
128
|
+
fill_in "player[number]", :with => "a"
|
129
|
+
fill_in "player[position]", :with => "Second baseman"
|
130
|
+
click_button "Save"
|
131
|
+
|
132
|
+
@player.reload
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should show an error message" do
|
136
|
+
body.should have_content("Player failed to be updated")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "update with serialized objects" do
|
141
|
+
before(:each) do
|
142
|
+
@user = FactoryGirl.create :user
|
143
|
+
|
144
|
+
visit edit_path(:model_name => "user", :id => @user.id)
|
145
|
+
|
146
|
+
fill_in "user[roles]", :with => %{['admin', 'user']}
|
147
|
+
click_button "Save"
|
148
|
+
|
149
|
+
@user.reload
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should save the serialized data" do
|
153
|
+
@user.roles.should eql(['admin','user'])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "update with serialized objects of Mongoid" do
|
158
|
+
before(:each) do
|
159
|
+
@field_test = FactoryGirl.create :mongoid_field_test
|
160
|
+
|
161
|
+
visit edit_path(:model_name => "mongoid_field_test", :id => @field_test.id)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should save the serialized data" do
|
165
|
+
fill_in "mongoid_field_test[array_field]", :with => "[4, 2]"
|
166
|
+
fill_in "mongoid_field_test[hash_field]", :with => "{ a: 6, b: 2 }"
|
167
|
+
click_button "Save"
|
168
|
+
|
169
|
+
@field_test.reload
|
170
|
+
@field_test.array_field.should eql([4, 2])
|
171
|
+
@field_test.hash_field.should eql({ "a" => 6, "b" => 2 })
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should clear data when empty string is passed" do
|
175
|
+
fill_in "mongoid_field_test[array_field]", :with => ""
|
176
|
+
fill_in "mongoid_field_test[hash_field]", :with => ""
|
177
|
+
click_button "Save"
|
178
|
+
|
179
|
+
@field_test.reload
|
180
|
+
@field_test.array_field.should eql(nil)
|
181
|
+
@field_test.hash_field.should eql(nil)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "update with overridden to_param" do
|
186
|
+
before(:each) do
|
187
|
+
@ball = FactoryGirl.create :ball
|
188
|
+
|
189
|
+
visit edit_path(:model_name => "ball", :id => @ball.id)
|
190
|
+
|
191
|
+
fill_in "ball[color]", :with => "gray"
|
192
|
+
click_button "Save and edit"
|
193
|
+
|
194
|
+
@ball.reload
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should update an object with correct attributes" do
|
198
|
+
@ball.color.should eql("gray")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "update of STI subclass on superclass view" do
|
203
|
+
before(:each) do
|
204
|
+
@hardball = FactoryGirl.create :hardball
|
205
|
+
|
206
|
+
visit edit_path(:model_name => "ball", :id => @hardball.id)
|
207
|
+
|
208
|
+
fill_in "ball[color]", :with => "cyan"
|
209
|
+
click_button "Save and edit"
|
210
|
+
|
211
|
+
@hardball.reload
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should update an object with correct attributes" do
|
215
|
+
@hardball.color.should eql("cyan")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
@@ -0,0 +1,954 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "RailsAdmin Config DSL Edit Section" do
|
6
|
+
|
7
|
+
subject { page }
|
8
|
+
|
9
|
+
describe "default_value" do
|
10
|
+
|
11
|
+
it "should be set for all types of input fields" do
|
12
|
+
RailsAdmin.config do |config|
|
13
|
+
config.excluded_models = []
|
14
|
+
config.model(FieldTest) do
|
15
|
+
|
16
|
+
field :string_field do
|
17
|
+
default_value 'string_field default_value'
|
18
|
+
end
|
19
|
+
field :text_field do
|
20
|
+
default_value 'string_field text_field'
|
21
|
+
end
|
22
|
+
field :boolean_field do
|
23
|
+
default_value true
|
24
|
+
end
|
25
|
+
field :date_field do
|
26
|
+
default_value Date.today.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
visit new_path(:model_name => "field_test")
|
32
|
+
find_field('field_test[string_field]').value.should == 'string_field default_value'
|
33
|
+
find_field('field_test[text_field]').value.should == 'string_field text_field'
|
34
|
+
find_field('field_test[date_field]').value.should == Date.today.to_s
|
35
|
+
has_checked_field?('field_test[boolean_field]').should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set default value for selects" do
|
39
|
+
RailsAdmin.config(Team) do
|
40
|
+
field :color, :enum do
|
41
|
+
default_value 'black'
|
42
|
+
enum do
|
43
|
+
['black', 'white']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
visit new_path(:model_name => "team")
|
48
|
+
find_field('team[color]').value.should == 'black'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "attr_accessible" do
|
53
|
+
|
54
|
+
|
55
|
+
it "should be configurable in the controller scope" do
|
56
|
+
|
57
|
+
RailsAdmin.config do |config|
|
58
|
+
config.excluded_models = []
|
59
|
+
config.attr_accessible_role do
|
60
|
+
_current_user.attr_accessible_role # sould be :custom_role
|
61
|
+
end
|
62
|
+
|
63
|
+
config.model FieldTest do
|
64
|
+
edit do
|
65
|
+
field :string_field
|
66
|
+
field :restricted_field
|
67
|
+
field :protected_field
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
visit new_path(:model_name => "field_test")
|
73
|
+
fill_in "field_test[string_field]", :with => "No problem here"
|
74
|
+
fill_in "field_test[restricted_field]", :with => "I'm allowed to do that as :custom_role only"
|
75
|
+
should have_no_selector "field_test[protected_field]"
|
76
|
+
click_button "Save"
|
77
|
+
@field_test = FieldTest.first
|
78
|
+
@field_test.string_field.should == "No problem here"
|
79
|
+
@field_test.restricted_field.should == "I'm allowed to do that as :custom_role only"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "css hooks" do
|
84
|
+
it "should be present" do
|
85
|
+
visit new_path(:model_name => "team")
|
86
|
+
should have_selector("#team_division_id_field.belongs_to_association_type.division_field")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "field groupings" do
|
91
|
+
|
92
|
+
it "should be hideable" do
|
93
|
+
RailsAdmin.config Team do
|
94
|
+
edit do
|
95
|
+
group :default do
|
96
|
+
label "Hidden group"
|
97
|
+
hide
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
visit new_path(:model_name => "team")
|
102
|
+
# Should not have the group header
|
103
|
+
should have_no_selector("legend", :text => "Hidden Group")
|
104
|
+
# Should not have any of the group's fields either
|
105
|
+
should have_no_selector("select#team_division")
|
106
|
+
should have_no_selector("input#team_name")
|
107
|
+
should have_no_selector("input#team_logo_url")
|
108
|
+
should have_no_selector("input#team_manager")
|
109
|
+
should have_no_selector("input#team_ballpark")
|
110
|
+
should have_no_selector("input#team_mascot")
|
111
|
+
should have_no_selector("input#team_founded")
|
112
|
+
should have_no_selector("input#team_wins")
|
113
|
+
should have_no_selector("input#team_losses")
|
114
|
+
should have_no_selector("input#team_win_percentage")
|
115
|
+
should have_no_selector("input#team_revenue")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should hide association groupings" do
|
119
|
+
RailsAdmin.config Team do
|
120
|
+
edit do
|
121
|
+
group :players do
|
122
|
+
label "Players"
|
123
|
+
field :players
|
124
|
+
hide
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
visit new_path(:model_name => "team")
|
129
|
+
# Should not have the group header
|
130
|
+
should have_no_selector("legend", :text => "Players")
|
131
|
+
# Should not have any of the group's fields either
|
132
|
+
should have_no_selector("select#team_player_ids")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be renameable" do
|
136
|
+
RailsAdmin.config Team do
|
137
|
+
edit do
|
138
|
+
group :default do
|
139
|
+
label "Renamed group"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
visit new_path(:model_name => "team")
|
144
|
+
should have_selector("legend", :text => "Renamed group")
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "help" do
|
148
|
+
|
149
|
+
it "should show help section if present" do
|
150
|
+
RailsAdmin.config Team do
|
151
|
+
edit do
|
152
|
+
group :default do
|
153
|
+
help "help paragraph to display"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
visit new_path(:model_name => "team")
|
158
|
+
should have_selector('fieldset>p', :text => "help paragraph to display")
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should not show help if not present" do
|
162
|
+
RailsAdmin.config Team do
|
163
|
+
edit do
|
164
|
+
group :default do
|
165
|
+
label 'no help'
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
visit new_path(:model_name => "team")
|
170
|
+
should_not have_selector('fieldset>p')
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should be able to display multiple help if there are multiple sections" do
|
174
|
+
RailsAdmin.config Team do
|
175
|
+
edit do
|
176
|
+
group :default do
|
177
|
+
field :name
|
178
|
+
help 'help for default'
|
179
|
+
end
|
180
|
+
group :other_section do
|
181
|
+
label "Other Section"
|
182
|
+
field :division
|
183
|
+
help 'help for other section'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
visit new_path(:model_name => "team")
|
188
|
+
should have_selector("fieldset>p", :text => 'help for default')
|
189
|
+
should have_selector("fieldset>p", :text => 'help for other section')
|
190
|
+
should have_selector("fieldset>p", :count => 2)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should use the db column size for the maximum length" do
|
194
|
+
visit new_path(:model_name => "team")
|
195
|
+
find("#team_name_field .help-block").should have_content("Length up to 50.")
|
196
|
+
end
|
197
|
+
|
198
|
+
# FIXME validates_length_of are leaking in FactoryGirl WTF?
|
199
|
+
|
200
|
+
it "should use the :is setting from the validation" do
|
201
|
+
# class Team
|
202
|
+
# validates_length_of :name, :is => 3
|
203
|
+
# end
|
204
|
+
# visit new_path(:model_name => "team")
|
205
|
+
# find("#team_name_field .help-block").should have_content("Length of 3.")
|
206
|
+
# Team._validators[:name] = []
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should use the :minimum setting from the validation" do
|
210
|
+
class Team
|
211
|
+
validates_length_of :name, :minimum => 1
|
212
|
+
end
|
213
|
+
visit new_path(:model_name => "team")
|
214
|
+
find("#team_name_field .help-block").should have_content("Length of 1-50.")
|
215
|
+
Team._validators[:name] = []
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should use the :maximum setting from the validation" do
|
219
|
+
class Team
|
220
|
+
validates_length_of :name, :maximum => 49
|
221
|
+
end
|
222
|
+
visit new_path(:model_name => "team")
|
223
|
+
find("#team_name_field .help-block").should have_content("Length up to 49.")
|
224
|
+
Team._validators[:name] = []
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should use the minimum of db column size or :maximum setting from the validation" do
|
228
|
+
class Team
|
229
|
+
validates_length_of :name, :maximum => 51
|
230
|
+
end
|
231
|
+
visit new_path(:model_name => "team")
|
232
|
+
find("#team_name_field .help-block").should have_content("Length up to 50.")
|
233
|
+
Team._validators[:name] = []
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should use the :minimum and :maximum from the validation" do
|
237
|
+
class Team
|
238
|
+
validates_length_of :name, :minimum => 1, :maximum => 49
|
239
|
+
end
|
240
|
+
visit new_path(:model_name => "team")
|
241
|
+
find("#team_name_field .help-block").should have_content("Length of 1-49.")
|
242
|
+
Team._validators[:name] = []
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should use the range from the validation" do
|
246
|
+
class Team
|
247
|
+
validates_length_of :name, :in => 1..49
|
248
|
+
end
|
249
|
+
visit new_path(:model_name => "team")
|
250
|
+
find("#team_name_field .help-block").should have_content("Length of 1-49.")
|
251
|
+
Team._validators[:name] = []
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should have accessor for its fields" do
|
257
|
+
RailsAdmin.config Team do
|
258
|
+
edit do
|
259
|
+
group :default do
|
260
|
+
field :name
|
261
|
+
field :logo_url
|
262
|
+
end
|
263
|
+
group :belongs_to_associations do
|
264
|
+
label "Belong's to associations"
|
265
|
+
field :division
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
visit new_path(:model_name => "team")
|
270
|
+
should have_selector("legend", :text => "Basic info")
|
271
|
+
should have_selector("legend", :text => "Belong's to associations")
|
272
|
+
should have_selector("label", :text => "Name")
|
273
|
+
should have_selector("label", :text => "Logo url")
|
274
|
+
should have_selector("label", :text => "Division")
|
275
|
+
should have_selector(".control-group", :count => 3)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should have accessor for its fields by type" do
|
279
|
+
RailsAdmin.config Team do
|
280
|
+
edit do
|
281
|
+
group :default do
|
282
|
+
field :name
|
283
|
+
field :logo_url
|
284
|
+
end
|
285
|
+
group :other do
|
286
|
+
field :division_id
|
287
|
+
field :manager
|
288
|
+
field :ballpark
|
289
|
+
fields_of_type :string do
|
290
|
+
label { "#{label} (STRING)" }
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
visit new_path(:model_name => "team")
|
296
|
+
should have_selector("label", :text => "Name")
|
297
|
+
should have_selector("label", :text => "Logo url")
|
298
|
+
should have_selector("label", :text => "Division")
|
299
|
+
should have_selector("label", :text => "Manager (STRING)")
|
300
|
+
should have_selector("label", :text => "Ballpark (STRING)")
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "items' fields" do
|
305
|
+
|
306
|
+
it "should show all by default" do
|
307
|
+
visit new_path(:model_name => "team")
|
308
|
+
should have_selector("select#team_division_id")
|
309
|
+
should have_selector("input#team_name")
|
310
|
+
should have_selector("input#team_logo_url")
|
311
|
+
should have_selector("input#team_manager")
|
312
|
+
should have_selector("input#team_ballpark")
|
313
|
+
should have_selector("input#team_mascot")
|
314
|
+
should have_selector("input#team_founded")
|
315
|
+
should have_selector("input#team_wins")
|
316
|
+
should have_selector("input#team_losses")
|
317
|
+
should have_selector("input#team_win_percentage")
|
318
|
+
should have_selector("input#team_revenue")
|
319
|
+
should have_selector("select#team_player_ids")
|
320
|
+
should have_selector("select#team_fan_ids")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should appear in order defined" do
|
324
|
+
RailsAdmin.config Team do
|
325
|
+
edit do
|
326
|
+
field :manager
|
327
|
+
field :division
|
328
|
+
field :name
|
329
|
+
end
|
330
|
+
end
|
331
|
+
visit new_path(:model_name => "team")
|
332
|
+
should have_selector(:xpath, "//*[contains(@class, 'field')][1]//*[@id='team_manager']")
|
333
|
+
should have_selector(:xpath, "//*[contains(@class, 'field')][2]//*[@id='team_division_id']")
|
334
|
+
should have_selector(:xpath, "//*[contains(@class, 'field')][3]//*[@id='team_name']")
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should only show the defined fields if some fields are defined" do
|
338
|
+
RailsAdmin.config Team do
|
339
|
+
edit do
|
340
|
+
field :division
|
341
|
+
field :name
|
342
|
+
end
|
343
|
+
end
|
344
|
+
visit new_path(:model_name => "team")
|
345
|
+
should have_selector("label", :text => "Division")
|
346
|
+
should have_selector("label", :text => "Name")
|
347
|
+
should have_selector(".control-group", :count => 2)
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should delegates the label option to the ActiveModel API and memoize I18n awarly" do
|
351
|
+
RailsAdmin.config Team do
|
352
|
+
edit do
|
353
|
+
field :manager
|
354
|
+
field :fans
|
355
|
+
end
|
356
|
+
end
|
357
|
+
visit new_path(:model_name => "team")
|
358
|
+
should have_selector("label", :text => "Team Manager")
|
359
|
+
should have_selector("label", :text => "Some Fans")
|
360
|
+
I18n.locale = :fr
|
361
|
+
visit new_path(:model_name => "team")
|
362
|
+
should have_selector("label", :text => "Manager de l'équipe")
|
363
|
+
should have_selector("label", :text => "Quelques fans")
|
364
|
+
I18n.locale = :en
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should be renameable" do
|
368
|
+
RailsAdmin.config Team do
|
369
|
+
edit do
|
370
|
+
field :manager do
|
371
|
+
label "Renamed field"
|
372
|
+
end
|
373
|
+
field :division
|
374
|
+
field :name
|
375
|
+
end
|
376
|
+
end
|
377
|
+
visit new_path(:model_name => "team")
|
378
|
+
should have_selector("label", :text => "Renamed field")
|
379
|
+
should have_selector("label", :text => "Division")
|
380
|
+
should have_selector("label", :text => "Name")
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should be renameable by type" do
|
384
|
+
RailsAdmin.config Team do
|
385
|
+
edit do
|
386
|
+
fields_of_type :string do
|
387
|
+
label { "#{label} (STRING)" }
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
visit new_path(:model_name => "team")
|
392
|
+
should have_selector("label", :text => "Division")
|
393
|
+
should have_selector("label", :text => "Name (STRING)")
|
394
|
+
should have_selector("label", :text => "Logo url (STRING)")
|
395
|
+
should have_selector("label", :text => "Manager (STRING)")
|
396
|
+
should have_selector("label", :text => "Ballpark (STRING)")
|
397
|
+
should have_selector("label", :text => "Mascot (STRING)")
|
398
|
+
should have_selector("label", :text => "Founded")
|
399
|
+
should have_selector("label", :text => "Wins")
|
400
|
+
should have_selector("label", :text => "Losses")
|
401
|
+
should have_selector("label", :text => "Win percentage")
|
402
|
+
should have_selector("label", :text => "Revenue")
|
403
|
+
should have_selector("label", :text => "Players")
|
404
|
+
should have_selector("label", :text => "Fans")
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should be globally renameable by type" do
|
408
|
+
RailsAdmin::Config.models do
|
409
|
+
edit do
|
410
|
+
fields_of_type :string do
|
411
|
+
label { "#{label} (STRING)" }
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
visit new_path(:model_name => "team")
|
416
|
+
should have_selector("label", :text => "Division")
|
417
|
+
should have_selector("label", :text => "Name (STRING)")
|
418
|
+
should have_selector("label", :text => "Logo url (STRING)")
|
419
|
+
should have_selector("label", :text => "Manager (STRING)")
|
420
|
+
should have_selector("label", :text => "Ballpark (STRING)")
|
421
|
+
should have_selector("label", :text => "Mascot (STRING)")
|
422
|
+
should have_selector("label", :text => "Founded")
|
423
|
+
should have_selector("label", :text => "Wins")
|
424
|
+
should have_selector("label", :text => "Losses")
|
425
|
+
should have_selector("label", :text => "Win percentage")
|
426
|
+
should have_selector("label", :text => "Revenue")
|
427
|
+
should have_selector("label", :text => "Players")
|
428
|
+
should have_selector("label", :text => "Fans")
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should be flaggable as read only and be configurable with formatted_value" do
|
432
|
+
RailsAdmin.config Team do
|
433
|
+
edit do
|
434
|
+
field :name do
|
435
|
+
read_only true
|
436
|
+
formatted_value do
|
437
|
+
"I'm outputed in the form"
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
visit new_path(:model_name => "team")
|
443
|
+
should have_content("I'm outputed in the form")
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should be hideable" do
|
447
|
+
RailsAdmin.config Team do
|
448
|
+
edit do
|
449
|
+
field :manager do
|
450
|
+
hide
|
451
|
+
end
|
452
|
+
field :division
|
453
|
+
field :name
|
454
|
+
end
|
455
|
+
end
|
456
|
+
visit new_path(:model_name => "team")
|
457
|
+
should have_no_selector("#team_manager")
|
458
|
+
should have_selector("#team_division_id")
|
459
|
+
should have_selector("#team_name")
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should be hideable by type" do
|
463
|
+
RailsAdmin.config Team do
|
464
|
+
edit do
|
465
|
+
fields_of_type :string do
|
466
|
+
hide
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
visit new_path(:model_name => "team")
|
471
|
+
should have_selector("label", :text => "Division")
|
472
|
+
should have_no_selector("label", :text => "Name")
|
473
|
+
should have_no_selector("label", :text => "Logo url")
|
474
|
+
should have_no_selector("label", :text => "Manager")
|
475
|
+
should have_no_selector("label", :text => "Ballpark")
|
476
|
+
should have_no_selector("label", :text => "Mascot")
|
477
|
+
should have_selector("label", :text => "Founded")
|
478
|
+
should have_selector("label", :text => "Wins")
|
479
|
+
should have_selector("label", :text => "Losses")
|
480
|
+
should have_selector("label", :text => "Win percentage")
|
481
|
+
should have_selector("label", :text => "Revenue")
|
482
|
+
should have_selector("label", :text => "Players")
|
483
|
+
should have_selector("label", :text => "Fans")
|
484
|
+
end
|
485
|
+
|
486
|
+
it "should be globally hideable by type" do
|
487
|
+
RailsAdmin::Config.models do
|
488
|
+
edit do
|
489
|
+
fields_of_type :string do
|
490
|
+
hide
|
491
|
+
end
|
492
|
+
end
|
493
|
+
end
|
494
|
+
visit new_path(:model_name => "team")
|
495
|
+
should have_selector("label", :text => "Division")
|
496
|
+
should have_no_selector("label", :text => "Name")
|
497
|
+
should have_no_selector("label", :text => "Logo url")
|
498
|
+
should have_no_selector("label", :text => "Manager")
|
499
|
+
should have_no_selector("label", :text => "Ballpark")
|
500
|
+
should have_no_selector("label", :text => "Mascot")
|
501
|
+
should have_selector("label", :text => "Founded")
|
502
|
+
should have_selector("label", :text => "Wins")
|
503
|
+
should have_selector("label", :text => "Losses")
|
504
|
+
should have_selector("label", :text => "Win percentage")
|
505
|
+
should have_selector("label", :text => "Revenue")
|
506
|
+
should have_selector("label", :text => "Players")
|
507
|
+
should have_selector("label", :text => "Fans")
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should have option to customize the help text" do
|
511
|
+
RailsAdmin.config Team do
|
512
|
+
edit do
|
513
|
+
field :manager do
|
514
|
+
help "#{help} Additional help text for manager field."
|
515
|
+
end
|
516
|
+
field :division
|
517
|
+
field :name
|
518
|
+
end
|
519
|
+
end
|
520
|
+
visit new_path(:model_name => "team")
|
521
|
+
find("#team_manager_field .help-block").should have_content("Required. Length up to 100. Additional help text for manager field.")
|
522
|
+
find("#team_division_id_field .help-block").should have_content("Required")
|
523
|
+
find("#team_name_field .help-block").should have_content("Optional. Length up to 50.")
|
524
|
+
end
|
525
|
+
|
526
|
+
it "should have option to override required status" do
|
527
|
+
RailsAdmin.config Team do
|
528
|
+
edit do
|
529
|
+
field :manager do
|
530
|
+
optional true
|
531
|
+
end
|
532
|
+
field :division do
|
533
|
+
optional true
|
534
|
+
end
|
535
|
+
field :name do
|
536
|
+
required true
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
visit new_path(:model_name => "team")
|
541
|
+
find("#team_manager_field .help-block").should have_content("Optional. Length up to 100.")
|
542
|
+
find("#team_division_id_field .help-block").should have_content("Optional")
|
543
|
+
find("#team_name_field .help-block").should have_content("Required. Length up to 50.")
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
describe "input format of" do
|
548
|
+
|
549
|
+
before(:each) do
|
550
|
+
RailsAdmin::Config.excluded_models = [RelTest]
|
551
|
+
@time = ::Time.now.getutc
|
552
|
+
end
|
553
|
+
|
554
|
+
after(:each) do
|
555
|
+
Time.zone = 'UTC'
|
556
|
+
end
|
557
|
+
|
558
|
+
describe "a datetime field" do
|
559
|
+
|
560
|
+
it "should default to %B %d, %Y %H:%M" do
|
561
|
+
visit new_path(:model_name => "field_test")
|
562
|
+
fill_in "field_test[datetime_field]", :with => @time.strftime("%B %d, %Y %H:%M")
|
563
|
+
click_button "Save"
|
564
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
565
|
+
@record.datetime_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
|
566
|
+
end
|
567
|
+
|
568
|
+
it "should have a simple customization option" do
|
569
|
+
RailsAdmin.config FieldTest do
|
570
|
+
edit do
|
571
|
+
field :datetime_field do
|
572
|
+
date_format :default
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
visit new_path(:model_name => "field_test")
|
577
|
+
fill_in "field_test[datetime_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
|
578
|
+
click_button "Save"
|
579
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
580
|
+
@record.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
581
|
+
end
|
582
|
+
|
583
|
+
it "should have a customization option" do
|
584
|
+
RailsAdmin.config FieldTest do
|
585
|
+
list do
|
586
|
+
field :datetime_field do
|
587
|
+
strftime_format "%Y-%m-%d %H:%M:%S"
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
visit new_path(:model_name => "field_test")
|
592
|
+
fill_in "field_test[datetime_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
|
593
|
+
click_button "Save"
|
594
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
595
|
+
@record.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
describe "a timestamp field" do
|
600
|
+
|
601
|
+
it "should default to %B %d, %Y %H:%M" do
|
602
|
+
visit new_path(:model_name => "field_test")
|
603
|
+
fill_in "field_test[timestamp_field]", :with => @time.strftime("%B %d, %Y %H:%M")
|
604
|
+
click_button "Save"
|
605
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
606
|
+
@record.timestamp_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
|
607
|
+
end
|
608
|
+
|
609
|
+
it "should have a simple customization option" do
|
610
|
+
RailsAdmin.config FieldTest do
|
611
|
+
edit do
|
612
|
+
field :timestamp_field do
|
613
|
+
date_format :default
|
614
|
+
end
|
615
|
+
end
|
616
|
+
end
|
617
|
+
visit new_path(:model_name => "field_test")
|
618
|
+
fill_in "field_test[timestamp_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
|
619
|
+
click_button "Save"
|
620
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
621
|
+
@record.timestamp_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
622
|
+
end
|
623
|
+
|
624
|
+
it "should have a customization option" do
|
625
|
+
RailsAdmin.config FieldTest do
|
626
|
+
edit do
|
627
|
+
field :timestamp_field do
|
628
|
+
strftime_format "%Y-%m-%d %H:%M:%S"
|
629
|
+
end
|
630
|
+
end
|
631
|
+
end
|
632
|
+
visit new_path(:model_name => "field_test")
|
633
|
+
fill_in "field_test[timestamp_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
|
634
|
+
click_button "Save"
|
635
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
636
|
+
@record.timestamp_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
describe " a field with 'format' as a name (Kernel function)" do
|
641
|
+
|
642
|
+
it "should be updatable without any error" do
|
643
|
+
RailsAdmin.config FieldTest do
|
644
|
+
edit do
|
645
|
+
field :format
|
646
|
+
end
|
647
|
+
end
|
648
|
+
visit new_path(:model_name => "field_test")
|
649
|
+
fill_in "field_test[format]", :with => "test for format"
|
650
|
+
click_button "Save"
|
651
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
652
|
+
@record.format.should eql("test for format")
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
|
657
|
+
describe "a time field" do
|
658
|
+
|
659
|
+
it "should default to %H:%M" do
|
660
|
+
visit new_path(:model_name => "field_test")
|
661
|
+
fill_in "field_test[time_field]", :with => @time.strftime("%H:%M")
|
662
|
+
click_button "Save"
|
663
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
664
|
+
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
665
|
+
end
|
666
|
+
|
667
|
+
it "should interpret time value as UTC when timezone is specified" do
|
668
|
+
Time.zone = 'Eastern Time (US & Canada)' # -05:00
|
669
|
+
|
670
|
+
visit new_path(:model_name => "field_test")
|
671
|
+
fill_in "field_test[time_field]", :with => @time.strftime("%H:%M")
|
672
|
+
click_button "Save"
|
673
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
674
|
+
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
675
|
+
end
|
676
|
+
|
677
|
+
it "should have a customization option" do
|
678
|
+
RailsAdmin.config FieldTest do
|
679
|
+
edit do
|
680
|
+
field :time_field do
|
681
|
+
strftime_format "%I:%M %p"
|
682
|
+
end
|
683
|
+
end
|
684
|
+
end
|
685
|
+
visit new_path(:model_name => "field_test")
|
686
|
+
fill_in "field_test[time_field]", :with => @time.strftime("%I:%M %p")
|
687
|
+
click_button "Save"
|
688
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
689
|
+
@record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
describe "a date field" do
|
694
|
+
|
695
|
+
it "should default to %B %d, %Y" do
|
696
|
+
visit new_path(:model_name => "field_test")
|
697
|
+
fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
|
698
|
+
click_button "Save"
|
699
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
700
|
+
@record.date_field.should eql(::Date.parse(@time.to_s))
|
701
|
+
end
|
702
|
+
|
703
|
+
it "should cover a timezone lag even if in UTC+n:00 timezone." do
|
704
|
+
Time.zone = 'Tokyo' # +09:00
|
705
|
+
|
706
|
+
visit new_path(:model_name => "field_test")
|
707
|
+
fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
|
708
|
+
click_button "Save"
|
709
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
710
|
+
@record.date_field.should eql(::Date.parse(@time.to_s))
|
711
|
+
end
|
712
|
+
|
713
|
+
it "should have a simple customization option" do
|
714
|
+
RailsAdmin.config FieldTest do
|
715
|
+
edit do
|
716
|
+
field :date_field do
|
717
|
+
date_format :default
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|
721
|
+
visit new_path(:model_name => "field_test")
|
722
|
+
fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
|
723
|
+
click_button "Save"
|
724
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
725
|
+
@record.date_field.should eql(::Date.parse(@time.to_s))
|
726
|
+
end
|
727
|
+
|
728
|
+
it "should have a customization option" do
|
729
|
+
RailsAdmin.config FieldTest do
|
730
|
+
edit do
|
731
|
+
field :date_field do
|
732
|
+
strftime_format "%Y-%m-%d"
|
733
|
+
end
|
734
|
+
end
|
735
|
+
end
|
736
|
+
visit new_path(:model_name => "field_test")
|
737
|
+
fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
|
738
|
+
click_button "Save"
|
739
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
740
|
+
@record.date_field.should eql(::Date.parse(@time.to_s))
|
741
|
+
end
|
742
|
+
end
|
743
|
+
end
|
744
|
+
|
745
|
+
describe 'bindings' do
|
746
|
+
it 'should be present at creation time' do
|
747
|
+
RailsAdmin.config do |config|
|
748
|
+
config.excluded_models = []
|
749
|
+
end
|
750
|
+
RailsAdmin.config Category do
|
751
|
+
field :parent_category do
|
752
|
+
visible do
|
753
|
+
!bindings[:object].new_record?
|
754
|
+
end
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
visit new_path(:model_name => 'category')
|
759
|
+
should have_no_css('#category_parent_category_id')
|
760
|
+
click_button 'Save'
|
761
|
+
visit edit_path(:model_name => 'category', :id => Category.first)
|
762
|
+
should have_css('#category_parent_category_id')
|
763
|
+
click_button 'Save'
|
764
|
+
should have_content('Category successfully updated')
|
765
|
+
end
|
766
|
+
end
|
767
|
+
|
768
|
+
describe 'nested form' do
|
769
|
+
|
770
|
+
it 'should work' do
|
771
|
+
RailsAdmin::Config.excluded_models = [RelTest]
|
772
|
+
visit new_path(:model_name => "field_test")
|
773
|
+
fill_in "field_test_comment_attributes_content", :with => 'nested comment content'
|
774
|
+
click_button "Save"
|
775
|
+
@record = RailsAdmin::AbstractModel.new("FieldTest").first
|
776
|
+
@record.comment.content.should == 'nested comment content'
|
777
|
+
@record.nested_field_tests = [NestedFieldTest.create!(:title => 'title 1'), NestedFieldTest.create!(:title => 'title 2')]
|
778
|
+
visit edit_path(:model_name => "field_test", :id => @record.id)
|
779
|
+
fill_in "field_test_nested_field_tests_attributes_0_title", :with => 'nested field test title 1 edited'
|
780
|
+
page.find('#field_test_nested_field_tests_attributes_1__destroy').set('true')
|
781
|
+
click_button "Save"
|
782
|
+
@record.reload
|
783
|
+
@record.nested_field_tests.length.should == 1
|
784
|
+
@record.nested_field_tests[0].title.should == 'nested field test title 1 edited'
|
785
|
+
end
|
786
|
+
|
787
|
+
it 'should set bindings[:object] to nested object' do
|
788
|
+
RailsAdmin::Config.excluded_models = [RelTest]
|
789
|
+
RailsAdmin.config(NestedFieldTest) do
|
790
|
+
nested do
|
791
|
+
field :title do
|
792
|
+
label do
|
793
|
+
bindings[:object].class.name
|
794
|
+
end
|
795
|
+
end
|
796
|
+
end
|
797
|
+
end
|
798
|
+
@record = FieldTest.create
|
799
|
+
@record.nested_field_tests << NestedFieldTest.create!(:title => 'title 1')
|
800
|
+
visit edit_path(:model_name => "field_test", :id => @record.id)
|
801
|
+
find('#field_test_nested_field_tests_attributes_0_title_field').should have_content('NestedFieldTest')
|
802
|
+
end
|
803
|
+
|
804
|
+
it 'should be desactivable' do
|
805
|
+
RailsAdmin::Config.excluded_models = [RelTest]
|
806
|
+
|
807
|
+
visit new_path(:model_name => "field_test")
|
808
|
+
should have_selector('.add_nested_fields')
|
809
|
+
RailsAdmin.config(FieldTest) do
|
810
|
+
configure :nested_field_tests do
|
811
|
+
nested_form false
|
812
|
+
end
|
813
|
+
end
|
814
|
+
visit new_path(:model_name => "field_test")
|
815
|
+
should have_no_selector('.add_nested_fields')
|
816
|
+
end
|
817
|
+
end
|
818
|
+
|
819
|
+
|
820
|
+
describe "fields which are nullable and have AR validations" do
|
821
|
+
|
822
|
+
it "should be required" do
|
823
|
+
# draft.notes is nullable and has no validation
|
824
|
+
field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :notes}
|
825
|
+
field.properties[:nullable?].should be true
|
826
|
+
field.required?.should be false
|
827
|
+
|
828
|
+
# draft.date is nullable in the schema but has an AR
|
829
|
+
# validates_presence_of validation that makes it required
|
830
|
+
field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :date}
|
831
|
+
field.properties[:nullable?].should be true
|
832
|
+
field.required?.should be true
|
833
|
+
|
834
|
+
# draft.round is nullable in the schema but has an AR
|
835
|
+
# validates_numericality_of validation that makes it required
|
836
|
+
field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :round}
|
837
|
+
field.properties[:nullable?].should be true
|
838
|
+
field.required?.should be true
|
839
|
+
|
840
|
+
# team.revenue is nullable in the schema but has an AR
|
841
|
+
# validates_numericality_of validation that allows nil
|
842
|
+
field = RailsAdmin::config("Team").edit.fields.find{|f| f.name == :revenue}
|
843
|
+
field.properties[:nullable?].should be true
|
844
|
+
field.required?.should be false
|
845
|
+
end
|
846
|
+
end
|
847
|
+
|
848
|
+
describe "CKEditor Support" do
|
849
|
+
|
850
|
+
it "should start with CKEditor disabled" do
|
851
|
+
field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :notes}
|
852
|
+
field.ckeditor.should be false
|
853
|
+
end
|
854
|
+
|
855
|
+
it "should add Javascript to enable CKEditor" do
|
856
|
+
RailsAdmin.config Draft do
|
857
|
+
edit do
|
858
|
+
field :notes do
|
859
|
+
ckeditor true
|
860
|
+
end
|
861
|
+
end
|
862
|
+
end
|
863
|
+
visit new_path(:model_name => "draft")
|
864
|
+
should have_selector("script", :text => /CKEDITOR\.replace.*?draft_notes/)
|
865
|
+
end
|
866
|
+
end
|
867
|
+
|
868
|
+
describe "Paperclip Support" do
|
869
|
+
|
870
|
+
it "should show a file upload field" do
|
871
|
+
RailsAdmin.config User do
|
872
|
+
edit do
|
873
|
+
field :avatar
|
874
|
+
end
|
875
|
+
end
|
876
|
+
visit new_path(:model_name => "user")
|
877
|
+
should have_selector("input#user_avatar")
|
878
|
+
end
|
879
|
+
end
|
880
|
+
|
881
|
+
describe "Enum field support" do
|
882
|
+
it "should auto-detect enumeration when object responds to '\#{method}_enum'" do
|
883
|
+
class Team
|
884
|
+
def color_enum
|
885
|
+
["blue", "green", "red"]
|
886
|
+
end
|
887
|
+
end
|
888
|
+
RailsAdmin.config Team do
|
889
|
+
edit do
|
890
|
+
field :color
|
891
|
+
end
|
892
|
+
end
|
893
|
+
visit new_path(:model_name => "team")
|
894
|
+
should have_selector(".enum_type select")
|
895
|
+
should have_content("green")
|
896
|
+
Team.send(:remove_method, :color_enum) # Reset
|
897
|
+
end
|
898
|
+
|
899
|
+
it "should allow configuration of the enum method" do
|
900
|
+
class Team
|
901
|
+
def color_list
|
902
|
+
["blue", "green", "red"]
|
903
|
+
end
|
904
|
+
end
|
905
|
+
RailsAdmin.config Team do
|
906
|
+
edit do
|
907
|
+
field :color, :enum do
|
908
|
+
enum_method :color_list
|
909
|
+
end
|
910
|
+
end
|
911
|
+
end
|
912
|
+
visit new_path(:model_name => "team")
|
913
|
+
should have_selector(".enum_type select")
|
914
|
+
should have_content("green")
|
915
|
+
Team.send(:remove_method, :color_list) # Reset
|
916
|
+
end
|
917
|
+
|
918
|
+
it "should allow direct listing of enumeration options and override enum method" do
|
919
|
+
class Team
|
920
|
+
def color_list
|
921
|
+
["blue", "green", "red"]
|
922
|
+
end
|
923
|
+
end
|
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
|
931
|
+
end
|
932
|
+
end
|
933
|
+
end
|
934
|
+
visit new_path(:model_name => "team")
|
935
|
+
should have_selector(".enum_type select")
|
936
|
+
should have_no_content("green")
|
937
|
+
should have_content("yellow")
|
938
|
+
Team.send(:remove_method, :color_list) # Reset
|
939
|
+
end
|
940
|
+
|
941
|
+
end
|
942
|
+
|
943
|
+
describe "ColorPicker Support" do
|
944
|
+
it "should show input with class color" do
|
945
|
+
RailsAdmin.config Team do
|
946
|
+
edit do
|
947
|
+
field :color, :color
|
948
|
+
end
|
949
|
+
end
|
950
|
+
visit new_path(:model_name => "team")
|
951
|
+
should have_selector(".color_type input")
|
952
|
+
end
|
953
|
+
end
|
954
|
+
end
|