activeadmin 0.3.4 → 0.4.0

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.

Files changed (244) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +164 -5
  4. data/CONTRIBUTING.md +113 -0
  5. data/Gemfile +7 -9
  6. data/LICENSE +1 -1
  7. data/README.rdoc +19 -20
  8. data/activeadmin.gemspec +4 -2
  9. data/app/assets/javascripts/active_admin/application.js +9 -0
  10. data/app/assets/javascripts/active_admin/base.js +4 -12
  11. data/app/assets/stylesheets/active_admin/_base.css.scss +17 -341
  12. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  13. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  14. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  15. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  16. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  17. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  18. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  19. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  20. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  21. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  22. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  23. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  24. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  25. data/app/assets/stylesheets/active_admin/components/_tables.css.scss +43 -2
  26. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  27. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  28. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  29. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  30. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  31. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  32. data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +9 -0
  33. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  34. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  35. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  36. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  37. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  38. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  39. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  40. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  41. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  42. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  43. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  44. data/app/views/active_admin/page/index.html.arb +1 -0
  45. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  46. data/cucumber.yml +3 -2
  47. data/docs/1-general-configuration.md +46 -10
  48. data/docs/6-show-screens.md +7 -0
  49. data/docs/8-custom-actions.md +12 -2
  50. data/docs/9-custom-pages.md +84 -0
  51. data/features/belongs_to.feature +27 -0
  52. data/features/comments/commenting.feature +3 -2
  53. data/features/dashboard.feature +18 -0
  54. data/features/development_reloading.feature +43 -0
  55. data/features/index/filter_with_check_boxes.feature +25 -0
  56. data/features/index/index_as_table.feature +14 -0
  57. data/features/index/index_scopes.feature +59 -0
  58. data/features/index/pagination.feature +19 -1
  59. data/features/menu.feature +22 -2
  60. data/features/registering_assets.feature +2 -2
  61. data/features/registering_pages.feature +66 -0
  62. data/features/specifying_actions.feature +5 -0
  63. data/features/step_definitions/action_item_steps.rb +2 -6
  64. data/features/step_definitions/action_link_steps.rb +7 -0
  65. data/features/step_definitions/additional_web_steps.rb +11 -3
  66. data/features/step_definitions/asset_steps.rb +5 -1
  67. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  68. data/features/step_definitions/comment_steps.rb +3 -3
  69. data/features/step_definitions/configuration_steps.rb +69 -13
  70. data/features/step_definitions/dashboard_steps.rb +7 -3
  71. data/features/step_definitions/factory_steps.rb +9 -2
  72. data/features/step_definitions/flash_steps.rb +9 -1
  73. data/features/step_definitions/format_steps.rb +9 -1
  74. data/features/step_definitions/index_scope_steps.rb +18 -6
  75. data/features/step_definitions/member_link_steps.rb +7 -0
  76. data/features/step_definitions/pagination_steps.rb +2 -2
  77. data/features/step_definitions/site_title_steps.rb +15 -0
  78. data/features/step_definitions/tab_steps.rb +1 -1
  79. data/features/step_definitions/user_steps.rb +1 -1
  80. data/features/step_definitions/web_steps.rb +4 -4
  81. data/features/support/paths.rb +6 -0
  82. data/features/users/logging_out.feature +11 -0
  83. data/lib/active_admin.rb +26 -10
  84. data/lib/active_admin/application.rb +64 -22
  85. data/lib/active_admin/arbre.rb +0 -1
  86. data/lib/active_admin/arbre/builder.rb +8 -5
  87. data/lib/active_admin/arbre/context.rb +1 -1
  88. data/lib/active_admin/arbre/html/attributes.rb +1 -1
  89. data/lib/active_admin/arbre/html/class_list.rb +0 -4
  90. data/lib/active_admin/arbre/html/collection.rb +2 -2
  91. data/lib/active_admin/arbre/html/document.rb +1 -1
  92. data/lib/active_admin/arbre/html/element.rb +19 -9
  93. data/lib/active_admin/arbre/html/tag.rb +3 -3
  94. data/lib/active_admin/arbre/html/text_node.rb +2 -2
  95. data/lib/active_admin/asset_registration.rb +15 -2
  96. data/lib/active_admin/base_controller.rb +61 -0
  97. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  98. data/lib/active_admin/callbacks.rb +16 -18
  99. data/lib/active_admin/comments.rb +48 -54
  100. data/lib/active_admin/comments/comment.rb +13 -2
  101. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  102. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  103. data/lib/active_admin/dashboards.rb +4 -0
  104. data/lib/active_admin/dashboards/dashboard_controller.rb +21 -5
  105. data/lib/active_admin/dsl.rb +6 -159
  106. data/lib/active_admin/event.rb +5 -3
  107. data/lib/active_admin/filter_form_builder.rb +53 -0
  108. data/lib/active_admin/form_builder.rb +25 -19
  109. data/lib/active_admin/helpers/settings.rb +6 -10
  110. data/lib/active_admin/inputs.rb +14 -0
  111. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  112. data/lib/active_admin/inputs/filter_base.rb +46 -0
  113. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  114. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  115. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  116. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  117. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  118. data/lib/active_admin/locales/ca.yml +44 -0
  119. data/lib/active_admin/locales/cs.yml +14 -10
  120. data/lib/active_admin/locales/de.yml +44 -0
  121. data/lib/active_admin/locales/en.yml +5 -0
  122. data/lib/active_admin/locales/hr.yml +40 -0
  123. data/lib/active_admin/locales/hu.yml +45 -0
  124. data/lib/active_admin/locales/it.yml +11 -6
  125. data/lib/active_admin/locales/ko.yml +40 -0
  126. data/lib/active_admin/locales/lv.yml +43 -0
  127. data/lib/active_admin/locales/nl.yml +40 -0
  128. data/lib/active_admin/locales/no-NB.yml +40 -0
  129. data/lib/active_admin/locales/pl.yml +7 -1
  130. data/lib/active_admin/locales/pt-BR.yml +6 -2
  131. data/lib/active_admin/menu_item.rb +25 -17
  132. data/lib/active_admin/namespace.rb +48 -33
  133. data/lib/active_admin/page.rb +65 -0
  134. data/lib/active_admin/page_controller.rb +15 -0
  135. data/lib/active_admin/page_dsl.rb +21 -0
  136. data/lib/active_admin/page_presenter.rb +30 -0
  137. data/lib/active_admin/reloader.rb +109 -42
  138. data/lib/active_admin/resource.rb +38 -44
  139. data/lib/active_admin/resource/action_items.rb +5 -0
  140. data/lib/active_admin/resource/belongs_to.rb +4 -2
  141. data/lib/active_admin/resource/controllers.rb +35 -0
  142. data/lib/active_admin/resource/menu.rb +1 -2
  143. data/lib/active_admin/resource/naming.rb +53 -31
  144. data/lib/active_admin/resource/page_presenters.rb +28 -0
  145. data/lib/active_admin/resource/scopes.rb +16 -3
  146. data/lib/active_admin/resource/sidebars.rb +4 -0
  147. data/lib/active_admin/resource_collection.rb +88 -0
  148. data/lib/active_admin/resource_controller.rb +18 -54
  149. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  150. data/lib/active_admin/resource_controller/actions.rb +8 -8
  151. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  152. data/lib/active_admin/resource_controller/collection.rb +8 -4
  153. data/lib/active_admin/resource_controller/filters.rb +1 -1
  154. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  155. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  156. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  157. data/lib/active_admin/resource_dsl.rb +157 -0
  158. data/lib/active_admin/router.rb +21 -14
  159. data/lib/active_admin/scope.rb +15 -3
  160. data/lib/active_admin/version.rb +1 -1
  161. data/lib/active_admin/view_factory.rb +4 -3
  162. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  163. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  164. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  165. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  166. data/lib/active_admin/views/components/columns.rb +4 -4
  167. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  168. data/lib/active_admin/views/components/panel.rb +8 -0
  169. data/lib/active_admin/views/components/scopes.rb +24 -18
  170. data/lib/active_admin/views/components/status_tag.rb +6 -5
  171. data/lib/active_admin/views/components/table_for.rb +6 -2
  172. data/lib/active_admin/views/header_renderer.rb +31 -12
  173. data/lib/active_admin/views/index_as_block.rb +2 -2
  174. data/lib/active_admin/views/index_as_blog.rb +3 -3
  175. data/lib/active_admin/views/index_as_grid.rb +4 -4
  176. data/lib/active_admin/views/index_as_table.rb +13 -6
  177. data/lib/active_admin/views/pages/base.rb +4 -4
  178. data/lib/active_admin/views/pages/form.rb +49 -0
  179. data/lib/active_admin/views/pages/index.rb +18 -6
  180. data/lib/active_admin/views/pages/page.rb +24 -0
  181. data/lib/active_admin/views/pages/show.rb +1 -1
  182. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  183. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  184. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  185. data/script/use_rails +14 -7
  186. data/spec/spec_helper.rb +9 -14
  187. data/spec/spec_helper_without_rails.rb +10 -0
  188. data/spec/support/detect_rails_version.rb +22 -3
  189. data/spec/support/integration_example_group.rb +5 -7
  190. data/spec/support/rails_template.rb +11 -0
  191. data/spec/support/rails_template_with_data.rb +25 -0
  192. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  193. data/spec/unit/active_admin_spec.rb +8 -0
  194. data/spec/unit/application_spec.rb +48 -2
  195. data/spec/unit/arbre/context_spec.rb +1 -1
  196. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  197. data/spec/unit/arbre/html/element_spec.rb +18 -5
  198. data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
  199. data/spec/unit/arbre/html/tag_spec.rb +1 -1
  200. data/spec/unit/arbre/html_spec.rb +32 -22
  201. data/spec/unit/asset_registration_spec.rb +9 -3
  202. data/spec/unit/auto_link_spec.rb +2 -2
  203. data/spec/unit/base_controller_shared_examples.rb +28 -0
  204. data/spec/unit/base_controller_spec.rb +8 -0
  205. data/spec/unit/belongs_to_spec.rb +30 -33
  206. data/spec/unit/comments_spec.rb +45 -15
  207. data/spec/unit/config_shared_examples.rb +119 -0
  208. data/spec/unit/dashboard_controller_spec.rb +44 -0
  209. data/spec/unit/event_spec.rb +6 -0
  210. data/spec/unit/filter_form_builder_spec.rb +9 -0
  211. data/spec/unit/form_builder_spec.rb +8 -14
  212. data/spec/unit/menu_item_spec.rb +25 -20
  213. data/spec/unit/namespace/register_page_spec.rb +102 -0
  214. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  215. data/spec/unit/namespace_spec.rb +11 -183
  216. data/spec/unit/page_controller_spec.rb +8 -0
  217. data/spec/unit/page_spec.rb +60 -0
  218. data/spec/unit/reloader_spec.rb +82 -38
  219. data/spec/unit/resource/menu_spec.rb +1 -51
  220. data/spec/unit/resource/naming_spec.rb +25 -20
  221. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  222. data/spec/unit/resource/scopes_spec.rb +13 -0
  223. data/spec/unit/resource_collection_spec.rb +101 -0
  224. data/spec/unit/resource_controller_spec.rb +40 -32
  225. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  226. data/spec/unit/resource_spec.rb +8 -24
  227. data/spec/unit/routing_spec.rb +50 -1
  228. data/spec/unit/scope_spec.rb +18 -4
  229. data/spec/unit/views/components/paginated_collection_spec.rb +163 -0
  230. data/spec/unit/views/components/panel_spec.rb +9 -0
  231. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  232. data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
  233. data/tasks/test.rake +44 -26
  234. metadata +176 -69
  235. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  236. data/lib/active_admin/arbre/core_extensions.rb +0 -5
  237. data/lib/active_admin/comments/configuration.rb +0 -18
  238. data/lib/active_admin/page_config.rb +0 -15
  239. data/lib/active_admin/resource_controller/form.rb +0 -42
  240. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  241. data/lib/active_admin/views/pages/edit.rb +0 -28
  242. data/lib/active_admin/views/pages/new.rb +0 -28
  243. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  244. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -1,5 +1,9 @@
1
1
  Then /^I should see the css file "([^"]*)"$/ do |path|
2
- page.should have_xpath("//link[contains(@href, /stylesheets/#{path})]")
2
+ step %{I should see the css file "#{path}" of media "screen"}
3
+ end
4
+
5
+ Then /^I should see the css file "([^"]*)" of media "([^"]*)"$/ do |path, media|
6
+ page.should have_xpath("//link[contains(@href, /stylesheets/#{path}) and contains(@media, #{media})]")
3
7
  end
4
8
 
5
9
  Then /^I should see the js file "([^"]*)"$/ do |path|
@@ -0,0 +1,5 @@
1
+ Then /^I should see a link to "([^"]*)" in the breadcrumb$/ do |text|
2
+ within ".breadcrumb" do
3
+ page.should have_css("a", :text => text)
4
+ end
5
+ end
@@ -1,8 +1,8 @@
1
1
  Then /^I should see a comment by "([^"]*)"$/ do |name|
2
- Then %{I should see "#{name}" within ".active_admin_comment_author"}
2
+ step %{I should see "#{name}" within ".active_admin_comment_author"}
3
3
  end
4
4
 
5
5
  When /^I add a comment "([^"]*)"$/ do |comment|
6
- When %{I fill in "active_admin_comment_body" with "#{comment}"}
7
- And %{I press "Add Comment"}
6
+ step %{I fill in "active_admin_comment_body" with "#{comment}"}
7
+ step %{I press "Add Comment"}
8
8
  end
@@ -1,31 +1,87 @@
1
+ module ActiveAdminReloading
2
+
3
+ def load_active_admin_configuration(configuration_content)
4
+ eval(configuration_content)
5
+ ActiveAdmin::Event.dispatch ActiveAdmin::Application::LoadEvent, ActiveAdmin.application
6
+ Rails.application.reload_routes!
7
+ ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! }
8
+ end
9
+
10
+ end
11
+
12
+ module ActiveAdminContentsRollback
13
+
14
+ def self.recorded_files
15
+ @files ||= {}
16
+ end
17
+
18
+ # Records the contents of a file the first time we are
19
+ # about to change it
20
+ def self.record(filename)
21
+ contents = File.read(filename) rescue nil
22
+ recorded_files[filename] = contents unless recorded_files.has_key?(filename)
23
+ end
24
+
25
+ # Rolls the recorded files back to their original states
26
+ def self.rollback!
27
+ recorded_files.each do |filename, contents|
28
+ # contents will be nil if the file didin't exist
29
+ if contents
30
+ File.open(filename, "w+") {|f| f << contents }
31
+ else
32
+ File.delete(filename)
33
+ end
34
+ end
35
+
36
+ @files = {}
37
+ end
38
+
39
+ end
40
+
41
+ World(ActiveAdminReloading)
42
+
43
+ After do
44
+ ActiveAdminContentsRollback.rollback!
45
+ end
46
+
1
47
  Given /^a configuration of:$/ do |configuration_content|
2
- eval configuration_content
3
- Rails.application.reload_routes!
48
+ load_active_admin_configuration(configuration_content)
4
49
  ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! }
5
50
  end
6
51
 
7
52
  Given /^an index configuration of:$/ do |configuration_content|
8
- eval configuration_content
9
- Rails.application.reload_routes!
10
- ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! }
53
+ load_active_admin_configuration(configuration_content)
11
54
 
12
- And 'I am logged in'
13
- When "I am on the index page for posts"
55
+ step 'I am logged in'
56
+ step "I am on the index page for posts"
14
57
  end
15
58
 
16
59
  Given /^a show configuration of:$/ do |configuration_content|
17
- eval configuration_content
18
- Rails.application.reload_routes!
19
- ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! }
60
+ load_active_admin_configuration(configuration_content)
20
61
 
21
- And 'I am logged in'
22
- When "I am on the index page for posts"
23
- And 'I follow "View"'
62
+ step 'I am logged in'
63
+ step "I am on the index page for posts"
64
+ step 'I follow "View"'
24
65
  end
25
66
 
26
67
  Given /^"([^"]*)" contains:$/ do |filename, contents|
27
68
  require 'fileutils'
28
69
  filepath = Rails.root + filename
29
70
  FileUtils.mkdir_p File.dirname(filepath)
71
+ ActiveAdminContentsRollback.record(filepath)
72
+
30
73
  File.open(filepath, 'w+'){|f| f << contents }
31
74
  end
75
+
76
+ Given /^I add "([^"]*)" to the "([^"]*)" model$/ do |code, model_name|
77
+ filename = File.join(Rails.root, "app", "models", "#{model_name}.rb")
78
+ ActiveAdminContentsRollback.record(filename)
79
+
80
+ # Update the file
81
+ contents = File.read(filename)
82
+ File.open(filename, "w+") do |f|
83
+ f << contents.gsub(/^(class .+)$/, "\\1\n #{code}\n")
84
+ end
85
+
86
+ ActiveSupport::Dependencies.clear
87
+ end
@@ -1,11 +1,15 @@
1
1
  Then /^I should see the default welcome message$/ do
2
- Then %{I should see "Welcome to Active Admin" within "#dashboard_default_message"}
2
+ step %{I should see "Welcome to Active Admin" within "#dashboard_default_message"}
3
3
  end
4
4
 
5
5
  Then /^I should not see the default welcome message$/ do
6
- Then %{I should not see "Welcome to Active Admin"}
6
+ step %{I should not see "Welcome to Active Admin"}
7
7
  end
8
8
 
9
9
  Then /^I should see a dashboard widget "([^"]*)"$/ do |name|
10
- Then %{I should see "#{name}" within ".dashboard .panel h3"}
10
+ page.should have_css('.dashboard .panel h3', :text => name)
11
+ end
12
+
13
+ Then /^I should not see a dashboard widget "([^"]*)"$/ do |name|
14
+ page.should_not have_css('.dashboard .panel h3', :text => name)
11
15
  end
@@ -12,9 +12,9 @@ Given /^a post with the title "([^"]*)" written by "([^"]*)" exists$/ do |title,
12
12
  Post.create! :title => title, :author => author
13
13
  end
14
14
 
15
- Given /^(\d+) posts? exists?/ do |count|
15
+ Given /^(\d+)( published)? posts? exists?$/ do |count, published|
16
16
  (0...count.to_i).each do |i|
17
- Post.create! :title => "Hello World #{i}"
17
+ Post.create! :title => "Hello World #{i}", :published_at => (published ? Time.now : nil)
18
18
  end
19
19
  end
20
20
 
@@ -27,3 +27,10 @@ Given /^a (user|publisher) named "([^"]*)" exists$/ do |type, name|
27
27
  type = type.camelize.constantize
28
28
  type.create! :first_name => first, :last_name => last, :username => name
29
29
  end
30
+
31
+ Given /^I create a new post with the title "([^"]*)"$/ do |title|
32
+ click_link "Posts"
33
+ click_link "New Post"
34
+ fill_in :title, :with => title
35
+ click_button "Create Post"
36
+ end
@@ -1,3 +1,11 @@
1
1
  Then /^I should see a flash with "([^"]*)"$/ do |text|
2
- Then %{I should see "#{text}"}
2
+ page.should have_content(text)
3
+ end
4
+
5
+ Then /^I should see a successful create flash$/ do
6
+ page.should have_css('div.flash_notice', :text => /was successfully created/)
7
+ end
8
+
9
+ Then /^I should not see a successful create flash$/ do
10
+ page.should_not have_css('div.flash_notice', :text => /was successfully created/)
3
11
  end
@@ -1,3 +1,11 @@
1
+ CSVLib = if RUBY_VERSION =~ /^1.8/
2
+ require 'fastercsv'
3
+ FasterCSV
4
+ else
5
+ require 'csv'
6
+ CSV
7
+ end
8
+
1
9
  Then "I should see nicely formatted datetimes" do
2
10
  page.body.should =~ /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/
3
11
  end
@@ -14,7 +22,7 @@ Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_nam
14
22
  body = page.driver.response.body
15
23
 
16
24
  begin
17
- csv = CSV.parse(body)
25
+ csv = CSVLib.parse(body)
18
26
  table.raw.each_with_index do |expected_row, row_index|
19
27
  expected_row.each_with_index do |expected_cell, col_index|
20
28
  cell = csv.try(:[], row_index).try(:[], col_index)
@@ -1,20 +1,32 @@
1
1
  Then /^I should see the scope "([^"]*)"$/ do |name|
2
- Then %{I should see "#{name}" within ".scopes"}
2
+ step %{I should see "#{name}" within ".scopes"}
3
+ end
4
+
5
+ Then /^I should not see the scope "([^"]*)"$/ do |name|
6
+ step %{I should not see "#{name}" within ".scopes"}
3
7
  end
4
8
 
5
9
  Then /^I should see the scope "([^"]*)" selected$/ do |name|
6
- Then %{I should see "#{name}" within ".scopes span.selected"}
10
+ step %{I should see "#{name}" within ".scopes .selected"}
7
11
  end
8
12
 
9
13
  Then /^I should see the scope "([^"]*)" not selected$/ do |name|
10
- Then %{I should see the scope "#{name}"}
11
- page.should_not have_css('.scopes span.selected', :text => name)
14
+ step %{I should see the scope "#{name}"}
15
+ page.should_not have_css('.scopes .selected', :text => name)
12
16
  end
13
17
 
14
18
  Then /^I should see the scope "([^"]*)" with the count (\d+)$/ do |name, count|
15
- Then %{I should see "#{count}" within ".scopes .#{name.downcase} .count"}
19
+ step %{I should see "#{count}" within ".scopes .#{name.gsub(" ", "").underscore.downcase} .count"}
16
20
  end
17
21
 
18
22
  Then /^I should see (\d+) ([\w]*) in the table$/ do |count, resource_type|
19
- page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
23
+ begin
24
+ page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
25
+ rescue
26
+ current_count = 0
27
+
28
+ all("table##{resource_type} tr > td:first").each { current_count += 1 }
29
+
30
+ raise "There were #{current_count} rows in the table not #{count}"
31
+ end
20
32
  end
@@ -0,0 +1,7 @@
1
+ Then /^I should see an action item button "([^"]*)"$/ do |content|
2
+ page.should have_css(".action_items a", :text => content)
3
+ end
4
+
5
+ Then /^I should not see an action item button "([^"]*)"$/ do |content|
6
+ page.should_not have_css(".action_items", :text => content)
7
+ end
@@ -3,6 +3,6 @@ Then /^I should not see pagination$/ do
3
3
  end
4
4
 
5
5
  Then /^I should see pagination with (\d+) pages$/ do |count|
6
- Then %{I should see "#{count}" within ".pagination a"}
7
- Then %{I should not see "#{count.to_i + 1}" within ".pagination a"}
6
+ step %{I should see "#{count}" within ".pagination a"}
7
+ step %{I should not see "#{count.to_i + 1}" within ".pagination a"}
8
8
  end
@@ -0,0 +1,15 @@
1
+ Then /^I should see the site title "([^"]*)"$/ do |title|
2
+ page.should have_css('h1#site_title', :text => title)
3
+ end
4
+
5
+ Then /^I should not see the site title "([^"]*)"$/ do |title|
6
+ page.should_not have_css('h1#site_title', :text => title)
7
+ end
8
+
9
+ Then /^I should see the site title image "([^"]*)"$/ do |image|
10
+ page.should have_css('h1#site_title img', :src => image)
11
+ end
12
+
13
+ Then /^I should see the site title image linked to "([^"]*)"$/ do |url|
14
+ page.should have_css('h1#site_title a', :href => url)
15
+ end
@@ -1,3 +1,3 @@
1
1
  Then /^the "([^"]*)" tab should be selected$/ do |name|
2
- Then %{I should see "#{name}" within "ul#tabs li.current"}
2
+ step %{I should see "#{name}" within "ul#tabs li.current"}
3
3
  end
@@ -5,7 +5,7 @@ Given /^I am logged out$/ do
5
5
  end
6
6
 
7
7
  Given /^I am logged in$/ do
8
- Given 'an admin user "admin@example.com" exists'
8
+ step 'an admin user "admin@example.com" exists'
9
9
 
10
10
  if page.all(:css, "a", :text => "Logout").size > 0
11
11
  click_link "Logout"
@@ -32,13 +32,13 @@ end
32
32
  World(WithinHelpers)
33
33
 
34
34
  # Single-line step scoper
35
- When /^(.*) within (.*[^:])$/ do |step, parent|
36
- with_scope(parent) { When step }
35
+ When /^(.*) within (.*[^:])$/ do |step_name, parent|
36
+ with_scope(parent) { step step_name }
37
37
  end
38
38
 
39
39
  # Multi-line step scoper
40
- When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
- with_scope(parent) { When "#{step}:", table_or_string }
40
+ When /^(.*) within (.*[^:]):$/ do |step_name, parent, table_or_string|
41
+ with_scope(parent) { step "#{step_name}:", table_or_string }
42
42
  end
43
43
 
44
44
  Given /^(?:|I )am on (.+)$/ do |page_name|
@@ -28,6 +28,12 @@ module NavigationHelpers
28
28
  when /^the index page for (.*)$/
29
29
  send(:"admin_#{$1}_path")
30
30
 
31
+ when /^the last author's posts$/
32
+ admin_user_posts_path(User.last)
33
+
34
+ when /^the last author's last post page$/
35
+ admin_user_post_path(User.last, Post.where(:author_id => User.last.id).last)
36
+
31
37
  # Add more mappings here.
32
38
  # Here is an example that pulls values out of the Regexp:
33
39
  #
@@ -11,3 +11,14 @@ Feature: User Logging out
11
11
  When I go to the dashboard
12
12
  And I follow "Logout"
13
13
  Then I should see "Login"
14
+
15
+ Scenario: With logout_link_path set to :logout_path (the symbol)
16
+ Given a configuration of:
17
+ """
18
+ ActiveAdmin.setup do |config|
19
+ config.logout_link_path = :logout_path
20
+ end
21
+ """
22
+ And I am logged in
23
+ When I go to the dashboard
24
+ Then I should see the default welcome message
@@ -1,7 +1,11 @@
1
1
  require 'meta_search'
2
+ require 'bourbon'
2
3
  require 'devise'
3
4
  require 'kaminari'
5
+ require 'formtastic'
4
6
  require 'sass'
7
+ require 'inherited_resources'
8
+ require 'jquery-rails'
5
9
  require 'active_admin/arbre'
6
10
  require 'active_admin/engine'
7
11
 
@@ -13,6 +17,7 @@ module ActiveAdmin
13
17
  autoload :Breadcrumbs, 'active_admin/breadcrumbs'
14
18
  autoload :Callbacks, 'active_admin/callbacks'
15
19
  autoload :Component, 'active_admin/component'
20
+ autoload :BaseController, 'active_admin/base_controller'
16
21
  autoload :ControllerAction, 'active_admin/controller_action'
17
22
  autoload :CSVBuilder, 'active_admin/csv_builder'
18
23
  autoload :Dashboards, 'active_admin/dashboards'
@@ -22,14 +27,20 @@ module ActiveAdmin
22
27
  autoload :DSL, 'active_admin/dsl'
23
28
  autoload :Event, 'active_admin/event'
24
29
  autoload :FormBuilder, 'active_admin/form_builder'
30
+ autoload :FilterFormBuilder, 'active_admin/filter_form_builder'
31
+ autoload :Inputs, 'active_admin/inputs'
25
32
  autoload :Iconic, 'active_admin/iconic'
26
33
  autoload :Menu, 'active_admin/menu'
27
34
  autoload :MenuItem, 'active_admin/menu_item'
28
35
  autoload :Namespace, 'active_admin/namespace'
29
- autoload :PageConfig, 'active_admin/page_config'
36
+ autoload :Page, 'active_admin/page'
37
+ autoload :PagePresenter, 'active_admin/page_presenter'
38
+ autoload :PageController, 'active_admin/page_controller'
39
+ autoload :PageDSL, 'active_admin/page_dsl'
30
40
  autoload :Reloader, 'active_admin/reloader'
31
41
  autoload :Resource, 'active_admin/resource'
32
42
  autoload :ResourceController, 'active_admin/resource_controller'
43
+ autoload :ResourceDSL, 'active_admin/resource_dsl'
33
44
  autoload :Renderer, 'active_admin/renderer'
34
45
  autoload :Scope, 'active_admin/scope'
35
46
  autoload :ScopeChain, 'active_admin/helpers/scope_chain'
@@ -45,27 +56,31 @@ module ActiveAdmin
45
56
  I18n.load_path += Dir[File.expand_path('../active_admin/locales/*.yml', __FILE__)]
46
57
  end
47
58
 
48
- # The instance of the configured application
49
- @@application = ::ActiveAdmin::Application.new
50
- mattr_accessor :application
51
-
52
59
  class << self
53
60
 
61
+ attr_accessor :application
62
+
63
+ def application
64
+ @application ||= ::ActiveAdmin::Application.new
65
+ end
66
+
54
67
  # Gets called within the initializer
55
68
  def setup
69
+ application.setup!
56
70
  yield(application)
57
71
  application.prepare!
58
72
  end
59
73
 
60
- delegate :register, :to => :application
61
- delegate :unload!, :to => :application
62
- delegate :load!, :to => :application
63
- delegate :routes, :to => :application
74
+ delegate :register, :to => :application
75
+ delegate :register_page, :to => :application
76
+ delegate :unload!, :to => :application
77
+ delegate :load!, :to => :application
78
+ delegate :routes, :to => :application
64
79
 
65
80
  # Returns true if this rails application has the asset
66
81
  # pipeline enabled.
67
82
  def use_asset_pipeline?
68
- DependencyChecker.rails_3_1? && Rails.application.config.assets.enabled
83
+ DependencyChecker.rails_3_1? && Rails.application.config.try(:assets).try(:enabled)
69
84
  end
70
85
 
71
86
  # Migration MoveAdminNotesToComments generated with version 0.2.2 might reference
@@ -75,6 +90,7 @@ module ActiveAdmin
75
90
  "ActiveAdmin.default_namespace is deprecated. Please use ActiveAdmin.application.default_namespace"
76
91
 
77
92
  end
93
+
78
94
  end
79
95
 
80
96
  ActiveAdmin::DependencyChecker.check!
@@ -5,6 +5,13 @@ module ActiveAdmin
5
5
  class Application
6
6
  include Settings
7
7
 
8
+ # Adds settings to both the Application and the Namespace instance
9
+ # so that they can be configured independantly.
10
+ def self.inheritable_setting(name, default)
11
+ Namespace.setting name, nil
12
+ setting name, default
13
+ end
14
+
8
15
  # The default namespace to put controllers and routes inside. Set this
9
16
  # in config/initializers/active_admin.rb using:
10
17
  #
@@ -12,40 +19,43 @@ module ActiveAdmin
12
19
  #
13
20
  setting :default_namespace, :admin
14
21
 
15
- # The default number of resources to display on index pages
16
- setting :default_per_page, 30
17
-
18
22
  # A hash of all the registered namespaces
19
23
  setting :namespaces, {}
20
24
 
21
- # The title which gets displayed in the main layout
22
- setting :site_title, ""
23
-
24
- # Set the site title link href (defaults to AA dashboard)
25
- setting :site_title_link, ""
26
-
27
25
  # Load paths for admin configurations. Add folders to this load path
28
26
  # to load up other resources for administration. External gems can
29
27
  # include their paths in this load path to provide active_admin UIs
30
28
  setting :load_paths, [File.expand_path('app/admin', Rails.root)]
31
29
 
30
+ # The default number of resources to display on index pages
31
+ inheritable_setting :default_per_page, 30
32
+
33
+ # The title which gets displayed in the main layout
34
+ inheritable_setting :site_title, ""
35
+
36
+ # Set the site title link href (defaults to AA dashboard)
37
+ inheritable_setting :site_title_link, ""
38
+
39
+ # Set the site title image displayed in the main layout (has precendence over :site_title)
40
+ inheritable_setting :site_title_image, ""
41
+
32
42
  # The view factory to use to generate all the view classes. Take
33
43
  # a look at ActiveAdmin::ViewFactory
34
- setting :view_factory, ActiveAdmin::ViewFactory.new
44
+ inheritable_setting :view_factory, ActiveAdmin::ViewFactory.new
35
45
 
36
46
  # The method to call in controllers to get the current user
37
- setting :current_user_method, false
47
+ inheritable_setting :current_user_method, false
38
48
 
39
49
  # The method to call in the controllers to ensure that there
40
50
  # is a currently authenticated admin user
41
- setting :authentication_method, false
51
+ inheritable_setting :authentication_method, false
42
52
 
43
53
  # The path to log user's out with. If set to a symbol, we assume
44
54
  # that it's a method to call which returns the path
45
- setting :logout_link_path, :destroy_admin_user_session_path
55
+ inheritable_setting :logout_link_path, :destroy_admin_user_session_path
46
56
 
47
57
  # The method to use when generating the link for user logout
48
- setting :logout_link_method, :get
58
+ inheritable_setting :logout_link_method, :get
49
59
 
50
60
  # Active Admin makes educated guesses when displaying objects, this is
51
61
  # the list of methods it tries calling in order
@@ -67,10 +77,12 @@ module ActiveAdmin
67
77
  # the #allow_comments_in option instead
68
78
  attr_accessor :admin_notes
69
79
 
70
-
71
80
  include AssetRegistration
72
81
 
73
- def initialize
82
+ # Event that gets triggered on load of Active Admin
83
+ LoadEvent = 'active_admin.application.load'.freeze
84
+
85
+ def setup!
74
86
  register_default_assets
75
87
  end
76
88
 
@@ -82,21 +94,39 @@ module ActiveAdmin
82
94
 
83
95
  # Registers a brand new configuration for the given resource.
84
96
  def register(resource, options = {}, &block)
85
- namespace_name = options.has_key?(:namespace) ? options[:namespace] : default_namespace
97
+ namespace_name = extract_namespace_name(options)
86
98
  namespace = find_or_create_namespace(namespace_name)
87
99
  namespace.register(resource, options, &block)
88
100
  end
89
101
 
90
102
  # Creates a namespace for the given name
103
+ #
104
+ # Yields the namespace if a block is given
105
+ #
106
+ # @returns [Namespace] the new or existing namespace
91
107
  def find_or_create_namespace(name)
92
108
  name ||= :root
93
109
  return namespaces[name] if namespaces[name]
94
110
  namespace = Namespace.new(self, name)
95
- ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
96
111
  namespaces[name] = namespace
112
+ ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
113
+ yield(namespace) if block_given?
97
114
  namespace
98
115
  end
99
116
 
117
+ alias_method :namespace, :find_or_create_namespace
118
+
119
+ # Register a page
120
+ #
121
+ # @param name [String] The page name
122
+ # @options [Hash] Accepts option :namespace.
123
+ # @&block The registration block.
124
+ #
125
+ def register_page(name, options = {}, &block)
126
+ namespace_name = extract_namespace_name(options)
127
+ namespace = find_or_create_namespace(namespace_name)
128
+ namespace.register_page(name, options, &block)
129
+ end
100
130
 
101
131
  # Stores if everything has been loaded or we need to reload
102
132
  @@loaded = false
@@ -113,7 +143,6 @@ module ActiveAdmin
113
143
  # to allow for changes without having to restart the server.
114
144
  def unload!
115
145
  namespaces.values.each{|namespace| namespace.unload! }
116
- self.namespaces = {}
117
146
  @@loaded = false
118
147
  end
119
148
 
@@ -137,6 +166,9 @@ module ActiveAdmin
137
166
  # Load Menus
138
167
  namespaces.values.each{|namespace| namespace.load_menu! }
139
168
 
169
+ # Dispatch an ActiveAdmin::Application::LoadEvent with the Application
170
+ ActiveAdmin::Event.dispatch LoadEvent, self
171
+
140
172
  @@loaded = true
141
173
  end
142
174
 
@@ -192,10 +224,21 @@ module ActiveAdmin
192
224
  private
193
225
 
194
226
  def register_default_assets
195
- register_stylesheet 'active_admin.css'
227
+ register_stylesheet 'active_admin.css', :media => 'all'
228
+
229
+ if !ActiveAdmin.use_asset_pipeline?
230
+ register_javascript 'jquery.min.js'
231
+ register_javascript 'jquery-ui.min.js'
232
+ register_javascript 'jquery_ujs.js'
233
+ end
234
+
196
235
  register_javascript 'active_admin.js'
197
236
  end
198
237
 
238
+ def extract_namespace_name(options)
239
+ options.has_key?(:namespace) ? options[:namespace] : default_namespace
240
+ end
241
+
199
242
  # Since we're dealing with all our own file loading, we need
200
243
  # to remove our paths from the ActiveSupport autoload paths.
201
244
  # If not, file naming becomes very important and can cause clashes.
@@ -208,10 +251,9 @@ module ActiveAdmin
208
251
  end
209
252
 
210
253
  def attach_reloader
211
- ActiveAdmin::Reloader.new(Rails.application, self, Rails.version).attach!
254
+ ActiveAdmin::Reloader.build(Rails.application, self, Rails.version).attach!
212
255
  end
213
256
 
214
-
215
257
  def generate_stylesheets
216
258
  # This must be required after initialization
217
259
  require 'sass/plugin'