activeadmin 0.4.4 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +50 -0
- data/CONTRIBUTING.md +2 -4
- data/Gemfile +10 -4
- data/Guardfile +0 -1
- data/LICENSE +1 -1
- data/README.rdoc +19 -8
- data/Rakefile +10 -1
- data/activeadmin.gemspec +2 -1
- data/app/assets/javascripts/active_admin/application.js +3 -9
- data/app/assets/javascripts/active_admin/base.js +1 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +64 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +107 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +100 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +27 -0
- data/app/assets/javascripts/active_admin/lib/namespace.js.coffee +3 -0
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -0
- data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +26 -0
- data/app/assets/stylesheets/active_admin/_base.css.scss +32 -26
- data/app/assets/stylesheets/active_admin/_forms.css.scss +12 -5
- data/app/assets/stylesheets/active_admin/_header.css.scss +1 -2
- data/app/assets/stylesheets/active_admin/_typography.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_batch_actions.css.scss +11 -0
- data/app/assets/stylesheets/active_admin/components/_buttons.scss +1 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +151 -0
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +3 -3
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +123 -0
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +20 -27
- data/app/assets/stylesheets/active_admin/components/_tables.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +38 -36
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -5
- data/app/assets/stylesheets/active_admin/mixins/_icons.css.scss +7 -3
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +19 -17
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +2 -2
- data/app/assets/stylesheets/active_admin/print.css.scss +290 -0
- data/app/views/active_admin/dashboard/index.html.arb +1 -1
- data/app/views/active_admin/devise/passwords/edit.html.erb +17 -14
- data/app/views/active_admin/devise/passwords/new.html.erb +4 -4
- data/app/views/active_admin/devise/sessions/new.html.erb +6 -6
- data/app/views/active_admin/devise/shared/_links.erb +6 -6
- data/app/views/active_admin/page/index.html.arb +1 -1
- data/app/views/active_admin/resource/edit.html.arb +1 -1
- data/app/views/active_admin/resource/index.csv.erb +1 -1
- data/app/views/active_admin/resource/index.html.arb +1 -1
- data/app/views/active_admin/resource/new.html.arb +1 -1
- data/app/views/active_admin/resource/show.html.arb +1 -1
- data/app/views/layouts/active_admin.html.arb +1 -1
- data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
- data/cucumber.yml +1 -1
- data/docs/0-installation.md +10 -1
- data/docs/{9-custom-pages.md → 10-custom-pages.md} +0 -0
- data/docs/2-resource-customization.md +19 -1
- data/docs/3-index-pages.md +31 -0
- data/docs/4-csv-format.md +9 -0
- data/docs/6-show-screens.md +1 -1
- data/docs/9-batch-actions.md +161 -0
- data/features/dashboard.feature +31 -8
- data/features/development_reloading.feature +1 -1
- data/features/edit_page.feature +3 -3
- data/features/i18n.feature +35 -0
- data/features/index/batch_actions.feature +98 -0
- data/features/index/filters.feature +26 -0
- data/features/index/format_as_csv.feature +35 -0
- data/features/index/index_as_table.feature +30 -2
- data/features/index/index_blank_slate.feature +8 -3
- data/features/index/index_scopes.feature +130 -24
- data/features/index/page_title.feature +12 -0
- data/features/new_page.feature +3 -3
- data/features/registering_pages.feature +61 -0
- data/features/root_to.feature +17 -0
- data/features/show/default_content.feature +1 -1
- data/features/show/page_title.feature +14 -0
- data/features/sidebar_sections.feature +26 -0
- data/features/site_title.feature +1 -1
- data/features/specifying_actions.feature +7 -6
- data/features/step_definitions/action_link_steps.rb +1 -1
- data/features/step_definitions/additional_web_steps.rb +7 -1
- data/features/step_definitions/batch_action_steps.rb +94 -0
- data/features/step_definitions/configuration_steps.rb +30 -8
- data/features/step_definitions/factory_steps.rb +12 -0
- data/features/step_definitions/format_steps.rb +6 -2
- data/features/step_definitions/i18n_steps.rb +3 -0
- data/features/step_definitions/table_steps.rb +114 -0
- data/features/step_definitions/user_steps.rb +30 -4
- data/features/support/env.rb +54 -15
- data/features/support/paths.rb +2 -0
- data/features/users/logging_in.feature +1 -1
- data/features/users/logging_out.feature +2 -1
- data/features/users/resetting_password.feature +34 -0
- data/lib/active_admin.rb +46 -7
- data/lib/active_admin/application.rb +30 -15
- data/lib/active_admin/base_controller/menu.rb +3 -3
- data/lib/active_admin/batch_actions.rb +17 -0
- data/lib/active_admin/batch_actions/controller.rb +25 -0
- data/lib/active_admin/batch_actions/resource_extension.rb +126 -0
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +35 -0
- data/lib/active_admin/batch_actions/views/batch_action_popover.rb +28 -0
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +63 -0
- data/lib/active_admin/batch_actions/views/selection_cells.rb +37 -0
- data/lib/active_admin/comments.rb +5 -2
- data/lib/active_admin/comments/comment.rb +4 -3
- data/lib/active_admin/comments/views/active_admin_comments.rb +5 -5
- data/lib/active_admin/component.rb +1 -18
- data/lib/active_admin/csv_builder.rb +8 -3
- data/lib/active_admin/dashboards.rb +21 -4
- data/lib/active_admin/dashboards/dashboard_controller.rb +1 -5
- data/lib/active_admin/dependency_checker.rb +1 -1
- data/lib/active_admin/dsl.rb +61 -4
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters.rb +8 -0
- data/lib/active_admin/filters/dsl.rb +12 -0
- data/lib/active_admin/filters/forms.rb +93 -0
- data/lib/active_admin/filters/resource_extension.rb +92 -0
- data/lib/active_admin/form_builder.rb +88 -33
- data/lib/active_admin/helpers/collection.rb +23 -0
- data/lib/active_admin/helpers/optional_display.rb +1 -1
- data/lib/active_admin/inputs/filter_select_input.rb +1 -1
- data/lib/active_admin/locales/bg.yml +37 -1
- data/lib/active_admin/locales/ca.yml +36 -0
- data/lib/active_admin/locales/cs.yml +36 -0
- data/lib/active_admin/locales/da.yml +36 -0
- data/lib/active_admin/locales/de.yml +42 -0
- data/lib/active_admin/locales/en.yml +27 -2
- data/lib/active_admin/locales/es.yml +45 -4
- data/lib/active_admin/locales/fr.yml +22 -0
- data/lib/active_admin/locales/{he_il.yml → he.yml} +37 -2
- data/lib/active_admin/locales/hr.yml +49 -5
- data/lib/active_admin/locales/hu.yml +21 -0
- data/lib/active_admin/locales/it.yml +36 -1
- data/lib/active_admin/locales/ja.yml +36 -0
- data/lib/active_admin/locales/ko.yml +36 -1
- data/lib/active_admin/locales/lv.yml +28 -2
- data/lib/active_admin/locales/nl.yml +42 -1
- data/lib/active_admin/locales/no-NB.yml +15 -0
- data/lib/active_admin/locales/pl.yml +45 -1
- data/lib/active_admin/locales/pt-BR.yml +36 -1
- data/lib/active_admin/locales/ro.yml +67 -0
- data/lib/active_admin/locales/ru.yml +43 -3
- data/lib/active_admin/locales/sv-SE.yml +41 -1
- data/lib/active_admin/locales/tr.yml +80 -0
- data/lib/active_admin/locales/vi.yml +80 -0
- data/lib/active_admin/locales/{zh_cn.yml → zh-CN.yml} +42 -2
- data/lib/active_admin/locales/zh-TW.yml +36 -1
- data/lib/active_admin/menu.rb +55 -30
- data/lib/active_admin/menu_builder.rb +65 -0
- data/lib/active_admin/menu_item.rb +55 -14
- data/lib/active_admin/namespace.rb +25 -55
- data/lib/active_admin/page.rb +15 -10
- data/lib/active_admin/resource.rb +9 -0
- data/lib/active_admin/resource/action_items.rb +4 -4
- data/lib/active_admin/resource/controllers.rb +1 -1
- data/lib/active_admin/resource/menu.rb +19 -21
- data/lib/active_admin/resource/naming.rb +55 -45
- data/lib/active_admin/resource/sidebars.rb +0 -13
- data/lib/active_admin/resource_collection.rb +10 -10
- data/lib/active_admin/resource_controller.rb +5 -5
- data/lib/active_admin/resource_controller/actions.rb +2 -0
- data/lib/active_admin/resource_controller/collection.rb +13 -4
- data/lib/active_admin/resource_dsl.rb +12 -6
- data/lib/active_admin/router.rb +27 -8
- data/lib/active_admin/scope.rb +1 -0
- data/lib/active_admin/sidebar_section.rb +2 -6
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +18 -13
- data/lib/active_admin/view_helpers.rb +0 -2
- data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +24 -25
- data/lib/active_admin/view_helpers/display_helper.rb +1 -1
- data/lib/active_admin/view_helpers/fields_for.rb +44 -0
- data/lib/active_admin/view_helpers/form_helper.rb +6 -0
- data/lib/active_admin/view_helpers/view_factory_helper.rb +1 -1
- data/lib/active_admin/views/components/action_list_popover.rb +29 -0
- data/lib/active_admin/views/components/attributes_table.rb +6 -2
- data/lib/active_admin/views/components/dropdown_menu.rb +73 -0
- data/lib/active_admin/views/components/paginated_collection.rb +13 -14
- data/lib/active_admin/views/components/popover.rb +27 -0
- data/lib/active_admin/views/components/scopes.rb +8 -13
- data/lib/active_admin/views/components/sidebar_section.rb +1 -1
- data/lib/active_admin/views/components/site_title.rb +55 -0
- data/lib/active_admin/views/components/status_tag.rb +4 -4
- data/lib/active_admin/views/components/table_for.rb +18 -18
- data/lib/active_admin/views/dashboard_section_renderer.rb +1 -1
- data/lib/active_admin/views/footer.rb +18 -0
- data/lib/active_admin/views/header.rb +31 -0
- data/lib/active_admin/views/index_as_block.rb +3 -0
- data/lib/active_admin/views/index_as_blog.rb +4 -0
- data/lib/active_admin/views/index_as_grid.rb +2 -0
- data/lib/active_admin/views/index_as_table.rb +19 -6
- data/lib/active_admin/views/pages/base.rb +14 -48
- data/lib/active_admin/views/pages/form.rb +3 -3
- data/lib/active_admin/views/pages/index.rb +56 -24
- data/lib/active_admin/views/pages/layout.rb +2 -2
- data/lib/active_admin/views/pages/page.rb +10 -4
- data/lib/active_admin/views/pages/show.rb +11 -8
- data/lib/active_admin/views/tabbed_navigation.rb +3 -3
- data/lib/active_admin/views/title_bar.rb +50 -0
- data/lib/active_admin/views/utility_nav.rb +41 -0
- data/lib/generators/active_admin/assets/assets_generator.rb +1 -1
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +1 -0
- data/lib/generators/active_admin/assets/templates/3.1/active_admin.css.scss +26 -3
- data/lib/generators/active_admin/devise/devise_generator.rb +2 -2
- data/lib/generators/active_admin/install/install_generator.rb +10 -10
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +21 -1
- data/lib/generators/active_admin/install/templates/admin_user.rb.erb +20 -0
- data/lib/generators/active_admin/install/templates/dashboard.rb +33 -0
- data/lib/generators/active_admin/resource/templates/admin.rb +1 -1
- data/spec/integration/memory_spec.rb +1 -11
- data/spec/javascripts/coffeescripts/jquery.aa.checkbox-toggler-spec.js.coffee +50 -0
- data/spec/javascripts/coffeescripts/jquery.aa.popover-spec.js.coffee +82 -0
- data/spec/javascripts/coffeescripts/jquery.aa.table-checkbox-toggler-spec.js.coffee +34 -0
- data/spec/javascripts/compiled/jquery.aa.checkbox-toggler-spec.js +60 -0
- data/spec/javascripts/compiled/jquery.aa.popover-spec.js +106 -0
- data/spec/javascripts/compiled/jquery.aa.table-checkbox-toggler-spec.js +37 -0
- data/spec/javascripts/fixtures/checkboxes.html +9 -0
- data/spec/javascripts/fixtures/table_checkboxes.html +17 -0
- data/spec/javascripts/helpers/SpecHelper.js +3 -0
- data/spec/javascripts/helpers/vendor/jasmine-fixture-0.0.5.js +108 -0
- data/spec/javascripts/helpers/vendor/jasmine-jquery.js +288 -0
- data/spec/javascripts/helpers/vendor/sinon-1.2.0.js +2915 -0
- data/spec/javascripts/support/jasmine.yml +74 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/javascripts/support/jquery-ui-1.8.16.custom.min.js +34 -0
- data/spec/javascripts/support/jquery.min.js +4 -0
- data/spec/spec_helper.rb +13 -13
- data/spec/spec_helper_without_rails.rb +2 -3
- data/spec/support/detect_rails_version.rb +16 -10
- data/spec/support/rails_template.rb +13 -1
- data/spec/support/templates/admin/stores.rb +1 -0
- data/spec/support/templates/en.yml +6 -0
- data/spec/unit/action_builder_spec.rb +38 -0
- data/spec/unit/application_spec.rb +12 -16
- data/spec/unit/base_controller_shared_examples.rb +3 -6
- data/spec/unit/batch_actions/resource_spec.rb +91 -0
- data/spec/unit/batch_actions/settings_spec.rb +61 -0
- data/spec/unit/breadcrumbs_spec.rb +33 -0
- data/spec/unit/comments_spec.rb +6 -0
- data/spec/unit/config_shared_examples.rb +17 -64
- data/spec/unit/csv_builder_spec.rb +12 -2
- data/spec/unit/dashboard_controller_spec.rb +11 -5
- data/spec/unit/dsl_include_spec.rb +20 -0
- data/spec/unit/{filter_form_builder_spec.rb → filters/filter_form_builder_spec.rb} +10 -7
- data/spec/unit/filters/resource_spec.rb +60 -0
- data/spec/unit/form_builder_spec.rb +180 -28
- data/spec/unit/helpers/collection_spec.rb +65 -0
- data/spec/unit/menu_item_spec.rb +48 -53
- data/spec/unit/menu_spec.rb +46 -32
- data/spec/unit/namespace/register_page_spec.rb +0 -6
- data/spec/unit/namespace/register_resource_spec.rb +1 -8
- data/spec/unit/namespace_spec.rb +8 -2
- data/spec/unit/page_spec.rb +20 -8
- data/spec/unit/resource/naming_spec.rb +27 -26
- data/spec/unit/resource/sidebars_spec.rb +0 -7
- data/spec/unit/resource_collection_spec.rb +11 -11
- data/spec/unit/resource_controller/collection_spec.rb +23 -1
- data/spec/unit/resource_controller/sidebars_spec.rb +46 -0
- data/spec/unit/resource_controller_spec.rb +43 -0
- data/spec/unit/resource_registration_spec.rb +2 -13
- data/spec/unit/resource_spec.rb +0 -42
- data/spec/unit/routing_spec.rb +60 -14
- data/spec/unit/scope_spec.rb +7 -0
- data/spec/unit/view_factory_spec.rb +9 -6
- data/spec/unit/view_helpers/fields_for_spec.rb +41 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +18 -0
- data/spec/unit/views/components/action_list_popover_spec.rb +30 -0
- data/spec/unit/views/components/attributes_table_spec.rb +32 -20
- data/spec/unit/views/components/batch_action_popover_spec.rb +33 -0
- data/spec/unit/views/components/blank_slate_spec.rb +5 -3
- data/spec/unit/views/components/columns_spec.rb +32 -22
- data/spec/unit/views/components/paginated_collection_spec.rb +54 -12
- data/spec/unit/views/components/panel_spec.rb +11 -6
- data/spec/unit/views/components/popover_spec.rb +33 -0
- data/spec/unit/views/components/sidebar_section_spec.rb +6 -6
- data/spec/unit/views/components/site_title_spec.rb +78 -0
- data/spec/unit/views/components/status_tag_spec.rb +17 -10
- data/spec/unit/views/components/table_for_spec.rb +37 -17
- data/spec/unit/views/pages/layout_spec.rb +51 -10
- data/spec/unit/views/tabbed_navigation_spec.rb +44 -23
- data/tasks/js.rake +32 -0
- data/tasks/test.rake +1 -1
- metadata +233 -200
- data/lib/active_admin/arbre.rb +0 -22
- data/lib/active_admin/arbre/builder.rb +0 -125
- data/lib/active_admin/arbre/context.rb +0 -45
- data/lib/active_admin/arbre/html/attributes.rb +0 -20
- data/lib/active_admin/arbre/html/class_list.rb +0 -24
- data/lib/active_admin/arbre/html/collection.rb +0 -27
- data/lib/active_admin/arbre/html/document.rb +0 -42
- data/lib/active_admin/arbre/html/element.rb +0 -161
- data/lib/active_admin/arbre/html/html5_elements.rb +0 -47
- data/lib/active_admin/arbre/html/tag.rb +0 -145
- data/lib/active_admin/arbre/html/text_node.rb +0 -35
- data/lib/active_admin/filter_form_builder.rb +0 -53
- data/lib/active_admin/renderer.rb +0 -87
- data/lib/active_admin/resource_controller/filters.rb +0 -58
- data/lib/active_admin/stylesheets/active_admin/mixins/_utilities.scss +0 -0
- data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -36
- data/lib/active_admin/view_helpers/renderer_helper.rb +0 -29
- data/lib/active_admin/views/header_renderer.rb +0 -82
- data/lib/generators/active_admin/assets/templates/dashboards.rb +0 -36
- data/lib/generators/active_admin/install/templates/dashboards.rb +0 -44
- data/spec/unit/arbre/context_spec.rb +0 -35
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +0 -110
- data/spec/unit/arbre/html/element_spec.rb +0 -236
- data/spec/unit/arbre/html/tag_attributes_spec.rb +0 -61
- data/spec/unit/arbre/html/tag_spec.rb +0 -63
- data/spec/unit/arbre/html_spec.rb +0 -228
- data/spec/unit/renderer_spec.rb +0 -126
@@ -13,6 +13,14 @@ Given /^a (published )?post with the title "([^"]*)" written by "([^"]*)" exists
|
|
13
13
|
Post.create! :title => title, :author => author, :published_at => published_at
|
14
14
|
end
|
15
15
|
|
16
|
+
Given /^(\d+)( published)? posts? written by "([^"]*)" exist$/ do |count, published, author_name|
|
17
|
+
first, last = author_name.split(' ')
|
18
|
+
author = User.find_or_create_by_first_name_and_last_name(first, last, :username => author_name.gsub(' ', '').underscore)
|
19
|
+
(0...count.to_i).each do |i|
|
20
|
+
Post.create! :title => "Hello World #{i}", :author => author, :published_at => (published ? Time.now : nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
16
24
|
Given /^(\d+)( published)? posts? exists?$/ do |count, published|
|
17
25
|
(0...count.to_i).each do |i|
|
18
26
|
Post.create! :title => "Hello World #{i}", :published_at => (published ? Time.now : nil)
|
@@ -35,3 +43,7 @@ Given /^I create a new post with the title "([^"]*)"$/ do |title|
|
|
35
43
|
fill_in :title, :with => title
|
36
44
|
click_button "Create Post"
|
37
45
|
end
|
46
|
+
|
47
|
+
Given /^a store named "([^"]*)" exists$/ do |name|
|
48
|
+
Store.create! :name => name
|
49
|
+
end
|
@@ -19,14 +19,14 @@ Then /^I should not see a link to download "([^"]*)"$/ do |format_type|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Check first rows of the displayed CSV.
|
22
|
-
Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_name, table|
|
22
|
+
Then /^I should download a CSV file with "([^"]*)" separator for "([^"]*)" containing:$/ do |sep, resource_name, table|
|
23
23
|
page.response_headers['Content-Type'].should == 'text/csv; charset=utf-8'
|
24
24
|
csv_filename = "#{resource_name}-#{Time.now.strftime("%Y-%m-%d")}.csv"
|
25
25
|
page.response_headers['Content-Disposition'].should == %{attachment; filename="#{csv_filename}"}
|
26
26
|
body = page.driver.response.body
|
27
27
|
|
28
28
|
begin
|
29
|
-
csv = CSVLib.parse(body)
|
29
|
+
csv = CSVLib.parse(body, :col_sep => sep)
|
30
30
|
table.raw.each_with_index do |expected_row, row_index|
|
31
31
|
expected_row.each_with_index do |expected_cell, col_index|
|
32
32
|
cell = csv.try(:[], row_index).try(:[], col_index)
|
@@ -45,3 +45,7 @@ Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_nam
|
|
45
45
|
raise $!
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_name, table|
|
50
|
+
step "I should download a CSV file with \",\" separator for \"#{resource_name}\" containing:", table
|
51
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class HtmlTableToTextHelper
|
2
|
+
def initialize(html, table_css_selector = "table")
|
3
|
+
@html = html
|
4
|
+
@selector = table_css_selector
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_array
|
8
|
+
rows = Nokogiri::HTML(@html).css("#{@selector} tr")
|
9
|
+
rows.map do |row|
|
10
|
+
row.css('th, td').map do |td|
|
11
|
+
cell_to_string(td)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def cell_to_string(td)
|
19
|
+
str = ""
|
20
|
+
input = td.css('input').last
|
21
|
+
|
22
|
+
if input
|
23
|
+
str << input_to_string(input)
|
24
|
+
end
|
25
|
+
|
26
|
+
str << td.content.strip.gsub("\n", ' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def input_to_string(input)
|
30
|
+
case input.attribute("type").value
|
31
|
+
when "checkbox"
|
32
|
+
if input.attribute("disabled")
|
33
|
+
"_"
|
34
|
+
else
|
35
|
+
if input.attribute("checked")
|
36
|
+
"[X]"
|
37
|
+
else
|
38
|
+
"[ ]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
when "text"
|
42
|
+
if input.attribute("value").present?
|
43
|
+
"[#{input.attribute("value")}]"
|
44
|
+
else
|
45
|
+
"[ ]"
|
46
|
+
end
|
47
|
+
when "submit"
|
48
|
+
input.attribute("value")
|
49
|
+
else
|
50
|
+
raise "I don't know what to do with #{input}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TableMatchHelper
|
56
|
+
|
57
|
+
|
58
|
+
# @param table [Array[Array]]
|
59
|
+
# @param expected_table [Array[Array[String]]]
|
60
|
+
# The expected_table values are String. They are converted to
|
61
|
+
# Regexp when they start and end with a '/'
|
62
|
+
# Example:
|
63
|
+
#
|
64
|
+
# assert_table_match(
|
65
|
+
# [["Name", "Date"], ["Philippe", "Feb 08"]],
|
66
|
+
# [["Name", "Date"], ["Philippe", "/\w{3} \d{2}/"]]
|
67
|
+
# )
|
68
|
+
def assert_tables_match(table, expected_table)
|
69
|
+
expected_table.each_index do |row_index|
|
70
|
+
expected_table[row_index].each_index do |column_index|
|
71
|
+
expected_cell = expected_table[row_index][column_index]
|
72
|
+
cell = table.try(:[], row_index).try(:[], column_index)
|
73
|
+
begin
|
74
|
+
assert_cells_match(cell, expected_cell)
|
75
|
+
rescue
|
76
|
+
puts "Cell at line #{row_index} and column #{column_index}: #{cell.inspect} does not match #{expected_cell.inspect}"
|
77
|
+
puts "Expecting:"
|
78
|
+
table.each { |row| puts row.inspect }
|
79
|
+
puts "to match:"
|
80
|
+
expected_table.each { |row| puts row.inspect }
|
81
|
+
raise $!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_cells_match(cell, expected_cell)
|
88
|
+
if expected_cell =~ /^\/.*\/$/
|
89
|
+
cell.should match(Regexp.new(expected_cell[1..-2]))
|
90
|
+
else
|
91
|
+
(cell || "").strip.should == expected_cell
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end # module TableMatchHelper
|
96
|
+
|
97
|
+
World(TableMatchHelper)
|
98
|
+
|
99
|
+
|
100
|
+
# Usage:
|
101
|
+
#
|
102
|
+
# I should see the "invoices" table:
|
103
|
+
# | Invoice # | Date | Total Amount |
|
104
|
+
# | /\d+/ | 27/01/12 | $30.00 |
|
105
|
+
# | /\d+/ | 12/02/12 | $25.00 |
|
106
|
+
#
|
107
|
+
Then /^I should see the "([^"]*)" table:$/ do |table_id, expected_table|
|
108
|
+
page.should have_css("table##{table_id}")
|
109
|
+
|
110
|
+
assert_tables_match(
|
111
|
+
HtmlTableToTextHelper.new(page.body, "table##{table_id}").to_array,
|
112
|
+
expected_table.raw
|
113
|
+
)
|
114
|
+
end
|
@@ -5,11 +5,14 @@ Given /^I am logged out$/ do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
Given /^I am logged in$/ do
|
8
|
-
|
8
|
+
create_admin_user_and_logout_if_needed
|
9
|
+
user = AdminUser.find_by_email "admin@example.com"
|
10
|
+
login_as(user)
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
# only for @requires-reloading scenario
|
14
|
+
Given /^I am logged in with capybara$/ do
|
15
|
+
create_admin_user_and_logout_if_needed
|
13
16
|
|
14
17
|
visit new_admin_user_session_path
|
15
18
|
fill_in "Email", :with => "admin@example.com"
|
@@ -17,6 +20,14 @@ Given /^I am logged in$/ do
|
|
17
20
|
click_button "Login"
|
18
21
|
end
|
19
22
|
|
23
|
+
def create_admin_user_and_logout_if_needed
|
24
|
+
step 'an admin user "admin@example.com" exists'
|
25
|
+
|
26
|
+
if page.all(:css, "a", :text => "Logout").size > 0
|
27
|
+
click_link "Logout"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
20
31
|
Given /^an admin user "([^"]*)" exists$/ do |admin_email|
|
21
32
|
user = AdminUser.find_or_create_by_email :email => admin_email,
|
22
33
|
:password => "password",
|
@@ -27,3 +38,18 @@ Given /^an admin user "([^"]*)" exists$/ do |admin_email|
|
|
27
38
|
raise "Could not create an admin user"
|
28
39
|
end
|
29
40
|
end
|
41
|
+
|
42
|
+
Given /^an admin user "([^"]*)" exists with (expired )?reset password token "(.*?)"$/ do |admin_email, expired, token|
|
43
|
+
user = AdminUser.find_or_create_by_email :email => admin_email,
|
44
|
+
:password => "password",
|
45
|
+
:password_confirmation => "password"
|
46
|
+
|
47
|
+
unless user.persisted?
|
48
|
+
puts "Coult not create an admin user #{admin_email}: #{user.errors.full_messages}"
|
49
|
+
raise "Could not create an admin user"
|
50
|
+
end
|
51
|
+
|
52
|
+
user.reset_password_token = token
|
53
|
+
user.reset_password_sent_at = 1.minute.ago unless expired
|
54
|
+
user.save
|
55
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -4,19 +4,18 @@
|
|
4
4
|
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
5
|
# files.
|
6
6
|
|
7
|
+
ENV["RAILS_ENV"] ||= "cucumber"
|
7
8
|
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __FILE__)
|
9
|
+
require "rubygems"
|
10
|
+
require "bundler"
|
11
|
+
Bundler.setup
|
8
12
|
|
9
13
|
require File.expand_path('../../../spec/support/detect_rails_version', __FILE__)
|
10
14
|
ENV["RAILS"] = detect_rails_version
|
11
15
|
|
12
|
-
ENV["RAILS_ENV"] ||= "cucumber"
|
13
16
|
ENV['RAILS_ROOT'] = File.expand_path("../../../spec/rails/rails-#{ENV["RAILS"]}", __FILE__)
|
14
17
|
|
15
18
|
|
16
|
-
require 'rubygems'
|
17
|
-
require "bundler"
|
18
|
-
Bundler.setup
|
19
|
-
|
20
19
|
# Create the test app if it doesn't exists
|
21
20
|
unless File.exists?(ENV['RAILS_ROOT'])
|
22
21
|
system 'rake setup'
|
@@ -79,18 +78,58 @@ if defined?(ActiveRecord::Base)
|
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def add_default_dashboard
|
82
|
+
begin
|
83
|
+
dashboard_file = ENV['RAILS_ROOT'] + "/app/admin/dashboard.rb"
|
84
|
+
dashboard_template = File.expand_path('../../../lib/generators/active_admin/install/templates/dashboard.rb', __FILE__)
|
85
|
+
cmd = "cp #{dashboard_template} #{dashboard_file}"
|
86
|
+
system cmd
|
87
|
+
rescue
|
88
|
+
p $!
|
89
|
+
raise $!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete_default_dashboard
|
94
|
+
begin
|
95
|
+
dashboard_file = ENV['RAILS_ROOT'] + "/app/admin/dashboard.rb"
|
96
|
+
File.delete(dashboard_file) if File.exists?(dashboard_file)
|
97
|
+
rescue
|
98
|
+
p $!
|
99
|
+
raise $!
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Warden helpers to speed up login
|
104
|
+
# See https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
|
105
|
+
include Warden::Test::Helpers
|
106
|
+
|
107
|
+
After do
|
108
|
+
add_default_dashboard
|
109
|
+
Warden.test_reset!
|
110
|
+
end
|
111
|
+
|
112
|
+
Before '@dashboard' do
|
113
|
+
delete_default_dashboard
|
85
114
|
end
|
86
115
|
|
87
|
-
# Remove all our constants
|
88
116
|
Before do
|
89
|
-
|
90
|
-
# the controllers. If they aren't clear, the router stores references
|
91
|
-
ActiveSupport::Dependencies.clear
|
117
|
+
add_default_dashboard
|
92
118
|
|
93
|
-
|
94
|
-
|
95
|
-
|
119
|
+
begin
|
120
|
+
# We are caching classes, but need to manually clear references to
|
121
|
+
# the controllers. If they aren't clear, the router stores references
|
122
|
+
ActiveSupport::Dependencies.clear
|
123
|
+
|
124
|
+
# Reload Active Admin
|
125
|
+
ActiveAdmin.unload!
|
126
|
+
ActiveAdmin.load!
|
127
|
+
rescue
|
128
|
+
p $!
|
129
|
+
raise $!
|
130
|
+
end
|
96
131
|
end
|
132
|
+
|
133
|
+
# improve the performance of the specs suite by not logging anything
|
134
|
+
# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
|
135
|
+
Rails.logger.level = 4
|
data/features/support/paths.rb
CHANGED
@@ -14,6 +14,8 @@ module NavigationHelpers
|
|
14
14
|
"/admin"
|
15
15
|
when /the new post page/
|
16
16
|
"/admin/posts/new"
|
17
|
+
when /the admin password reset form with reset password token "([^"]*)"/
|
18
|
+
"/admin/password/edit?reset_password_token=#{$1}"
|
17
19
|
|
18
20
|
# the index page for posts in the root namespace
|
19
21
|
# the index page for posts in the user_admin namespace
|
@@ -19,7 +19,7 @@ Feature: User Logging In
|
|
19
19
|
And I should see "Logout"
|
20
20
|
And I should see "admin@example.com"
|
21
21
|
|
22
|
-
Scenario: Attempting to log in with an
|
22
|
+
Scenario: Attempting to log in with an incorrect email address
|
23
23
|
When I fill in "Email" with "not-an-admin@example.com"
|
24
24
|
And I fill in "Password" with "not-my-password"
|
25
25
|
And I press "Login"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: User Resetting Password
|
2
|
+
|
3
|
+
Resetting my password as an admin user
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given a configuration of:
|
7
|
+
"""
|
8
|
+
ActiveAdmin.register Post
|
9
|
+
"""
|
10
|
+
And I am logged out
|
11
|
+
And an admin user "admin@example.com" exists
|
12
|
+
|
13
|
+
Scenario: Resetting password successfully
|
14
|
+
When I go to the dashboard
|
15
|
+
And I follow "Forgot your password?"
|
16
|
+
When I fill in "Email" with "admin@example.com"
|
17
|
+
And I press "Reset My Password"
|
18
|
+
Then I should see "You will receive an email with instructions about how to reset your password in a few minutes."
|
19
|
+
|
20
|
+
Scenario: Changing password after resetting
|
21
|
+
Given an admin user "admin@example.com" exists with reset password token "123reset"
|
22
|
+
When I go to the admin password reset form with reset password token "123reset"
|
23
|
+
And I fill in "Password" with "password"
|
24
|
+
And I fill in "Password confirmation" with "password"
|
25
|
+
And I press "Change my password"
|
26
|
+
Then I should see "success"
|
27
|
+
|
28
|
+
Scenario: Changing password after resetting with errors
|
29
|
+
Given an admin user "admin@example.com" exists with expired reset password token "123reset"
|
30
|
+
When I go to the admin password reset form with reset password token "123reset"
|
31
|
+
And I fill in "Password" with "password"
|
32
|
+
And I fill in "Password confirmation" with "wrong"
|
33
|
+
And I press "Change my password"
|
34
|
+
Then I should see "expired"
|
data/lib/active_admin.rb
CHANGED
@@ -6,7 +6,9 @@ require 'formtastic'
|
|
6
6
|
require 'sass'
|
7
7
|
require 'inherited_resources'
|
8
8
|
require 'jquery-rails'
|
9
|
-
require '
|
9
|
+
require 'arbre'
|
10
|
+
require 'active_admin/dependency_checker'
|
11
|
+
require 'active_admin/sass/helpers'
|
10
12
|
require 'active_admin/engine'
|
11
13
|
|
12
14
|
module ActiveAdmin
|
@@ -21,13 +23,11 @@ module ActiveAdmin
|
|
21
23
|
autoload :ControllerAction, 'active_admin/controller_action'
|
22
24
|
autoload :CSVBuilder, 'active_admin/csv_builder'
|
23
25
|
autoload :Dashboards, 'active_admin/dashboards'
|
24
|
-
autoload :DependencyChecker, 'active_admin/dependency_checker'
|
25
26
|
autoload :Deprecation, 'active_admin/deprecation'
|
26
27
|
autoload :Devise, 'active_admin/devise'
|
27
28
|
autoload :DSL, 'active_admin/dsl'
|
28
29
|
autoload :Event, 'active_admin/event'
|
29
30
|
autoload :FormBuilder, 'active_admin/form_builder'
|
30
|
-
autoload :FilterFormBuilder, 'active_admin/filter_form_builder'
|
31
31
|
autoload :Inputs, 'active_admin/inputs'
|
32
32
|
autoload :Iconic, 'active_admin/iconic'
|
33
33
|
autoload :Menu, 'active_admin/menu'
|
@@ -41,7 +41,6 @@ module ActiveAdmin
|
|
41
41
|
autoload :Resource, 'active_admin/resource'
|
42
42
|
autoload :ResourceController, 'active_admin/resource_controller'
|
43
43
|
autoload :ResourceDSL, 'active_admin/resource_dsl'
|
44
|
-
autoload :Renderer, 'active_admin/renderer'
|
45
44
|
autoload :Scope, 'active_admin/scope'
|
46
45
|
autoload :ScopeChain, 'active_admin/helpers/scope_chain'
|
47
46
|
autoload :SidebarSection, 'active_admin/sidebar_section'
|
@@ -51,9 +50,11 @@ module ActiveAdmin
|
|
51
50
|
autoload :Views, 'active_admin/views'
|
52
51
|
|
53
52
|
class Railtie < ::Rails::Railtie
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
config.after_initialize do
|
54
|
+
# Add load paths straight to I18n, so engines and application can overwrite it.
|
55
|
+
require 'active_support/i18n'
|
56
|
+
I18n.load_path += Dir[File.expand_path('../active_admin/locales/*.yml', __FILE__)]
|
57
|
+
end
|
57
58
|
end
|
58
59
|
|
59
60
|
class << self
|
@@ -89,10 +90,48 @@ module ActiveAdmin
|
|
89
90
|
ActiveAdmin::Deprecation.deprecate self, :default_namespace,
|
90
91
|
"ActiveAdmin.default_namespace is deprecated. Please use ActiveAdmin.application.default_namespace"
|
91
92
|
|
93
|
+
# A callback is triggered each time (before) Active Admin loads the configuration files.
|
94
|
+
# In development mode, this will happen whenever the user changes files. In production
|
95
|
+
# it only happens on boot.
|
96
|
+
#
|
97
|
+
# The block takes the current instance of [ActiveAdmin::Application]
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
#
|
101
|
+
# ActiveAdmin.before_load do |app|
|
102
|
+
# # Do some stuff before AA loads
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# @param [Block] block A block to call each time (before) AA loads resources
|
106
|
+
def before_load(&block)
|
107
|
+
ActiveAdmin::Event.subscribe ActiveAdmin::Application::BeforeLoadEvent, &block
|
108
|
+
end
|
109
|
+
|
110
|
+
# A callback is triggered each time (after) Active Admin loads the configuration files. This
|
111
|
+
# is an opportunity to hook into Resources after they've been loaded.
|
112
|
+
#
|
113
|
+
# The block takes the current instance of [ActiveAdmin::Application]
|
114
|
+
#
|
115
|
+
# Example:
|
116
|
+
#
|
117
|
+
# ActiveAdmin.after_load do |app|
|
118
|
+
# app.namespaces.each do |name, namespace|
|
119
|
+
# puts "Namespace: #{name} loaded!"
|
120
|
+
# end
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# @param [Block] block A block to call each time (after) AA loads resources
|
124
|
+
def after_load(&block)
|
125
|
+
ActiveAdmin::Event.subscribe ActiveAdmin::Application::AfterLoadEvent, &block
|
126
|
+
end
|
127
|
+
|
92
128
|
end
|
93
129
|
|
94
130
|
end
|
95
131
|
|
96
132
|
ActiveAdmin::DependencyChecker.check!
|
97
133
|
|
134
|
+
# Require internal Plugins
|
98
135
|
require 'active_admin/comments'
|
136
|
+
require 'active_admin/batch_actions'
|
137
|
+
require 'active_admin/filters'
|