saulolso-activeadmin 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. data/.document +5 -0
  2. data/.gitignore +32 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.rdoc +76 -0
  5. data/Gemfile +26 -0
  6. data/LICENSE +25 -0
  7. data/README.rdoc +450 -0
  8. data/Rakefile +100 -0
  9. data/activeadmin.gemspec +28 -0
  10. data/cucumber.yml +2 -0
  11. data/features/comments/commenting.feature +99 -0
  12. data/features/comments/viewing_index.feature +19 -0
  13. data/features/dashboard.feature +26 -0
  14. data/features/edit_page.feature +77 -0
  15. data/features/first_boot.feature +16 -0
  16. data/features/global_navigation.feature +30 -0
  17. data/features/index/format_as_csv.feature +45 -0
  18. data/features/index/formats.feature +10 -0
  19. data/features/index/index_as_block.feature +15 -0
  20. data/features/index/index_as_blog.feature +50 -0
  21. data/features/index/index_as_grid.feature +45 -0
  22. data/features/index/index_as_table.feature +79 -0
  23. data/features/index/index_scopes.feature +52 -0
  24. data/features/index/pagination.feature +23 -0
  25. data/features/menu.feature +26 -0
  26. data/features/new_page.feature +75 -0
  27. data/features/registering_assets.feature +35 -0
  28. data/features/registering_resources.feature +33 -0
  29. data/features/show/default_content.feature +43 -0
  30. data/features/show/page_title.feature +33 -0
  31. data/features/sidebar_sections.feature +127 -0
  32. data/features/specifying_actions.feature +60 -0
  33. data/features/step_definitions/action_item_steps.rb +7 -0
  34. data/features/step_definitions/additional_web_steps.rb +67 -0
  35. data/features/step_definitions/asset_steps.rb +7 -0
  36. data/features/step_definitions/attribute_steps.rb +15 -0
  37. data/features/step_definitions/comment_steps.rb +8 -0
  38. data/features/step_definitions/configuration_steps.rb +31 -0
  39. data/features/step_definitions/dashboard_steps.rb +11 -0
  40. data/features/step_definitions/factory_steps.rb +28 -0
  41. data/features/step_definitions/flash_steps.rb +3 -0
  42. data/features/step_definitions/format_steps.rb +34 -0
  43. data/features/step_definitions/index_scope_steps.rb +20 -0
  44. data/features/step_definitions/menu_steps.rb +7 -0
  45. data/features/step_definitions/pagination_steps.rb +8 -0
  46. data/features/step_definitions/sidebar_steps.rb +11 -0
  47. data/features/step_definitions/tab_steps.rb +3 -0
  48. data/features/step_definitions/user_steps.rb +20 -0
  49. data/features/step_definitions/web_steps.rb +219 -0
  50. data/features/sti_resource.feature +49 -0
  51. data/features/support/env.rb +92 -0
  52. data/features/support/paths.rb +48 -0
  53. data/features/users/logging_in.feature +34 -0
  54. data/features/users/logging_out.feature +13 -0
  55. data/lib/active_admin/abstract_view_factory.rb +95 -0
  56. data/lib/active_admin/action_items.rb +37 -0
  57. data/lib/active_admin/application.rb +204 -0
  58. data/lib/active_admin/arbre/attributes.rb +20 -0
  59. data/lib/active_admin/arbre/class_list.rb +28 -0
  60. data/lib/active_admin/arbre/collection.rb +27 -0
  61. data/lib/active_admin/arbre/context.rb +8 -0
  62. data/lib/active_admin/arbre/core_extensions.rb +5 -0
  63. data/lib/active_admin/arbre/document.rb +42 -0
  64. data/lib/active_admin/arbre/element.rb +151 -0
  65. data/lib/active_admin/arbre/html.rb +84 -0
  66. data/lib/active_admin/arbre/html5_elements.rb +47 -0
  67. data/lib/active_admin/arbre/tag.rb +137 -0
  68. data/lib/active_admin/arbre/text_node.rb +35 -0
  69. data/lib/active_admin/arbre.rb +23 -0
  70. data/lib/active_admin/asset_registration.rb +34 -0
  71. data/lib/active_admin/callbacks.rb +87 -0
  72. data/lib/active_admin/comments/comment.rb +21 -0
  73. data/lib/active_admin/comments/configuration.rb +18 -0
  74. data/lib/active_admin/comments/namespace_helper.rb +14 -0
  75. data/lib/active_admin/comments/resource_helper.rb +17 -0
  76. data/lib/active_admin/comments/show_page_helper.rb +23 -0
  77. data/lib/active_admin/comments/views/active_admin_comment.rb +0 -0
  78. data/lib/active_admin/comments/views/active_admin_comments.rb +82 -0
  79. data/lib/active_admin/comments/views.rb +3 -0
  80. data/lib/active_admin/comments.rb +88 -0
  81. data/lib/active_admin/component.rb +22 -0
  82. data/lib/active_admin/controller_action.rb +12 -0
  83. data/lib/active_admin/csv_builder.rb +45 -0
  84. data/lib/active_admin/dashboards/dashboard_controller.rb +47 -0
  85. data/lib/active_admin/dashboards/section.rb +34 -0
  86. data/lib/active_admin/dashboards.rb +48 -0
  87. data/lib/active_admin/devise.rb +43 -0
  88. data/lib/active_admin/dsl.rb +215 -0
  89. data/lib/active_admin/event.rb +31 -0
  90. data/lib/active_admin/form_builder.rb +109 -0
  91. data/lib/active_admin/helpers/optional_display.rb +34 -0
  92. data/lib/active_admin/iconic/icons.rb +142 -0
  93. data/lib/active_admin/iconic.rb +51 -0
  94. data/lib/active_admin/locales/da.yml +26 -0
  95. data/lib/active_admin/locales/en.yml +34 -0
  96. data/lib/active_admin/locales/es.yml +34 -0
  97. data/lib/active_admin/locales/pt.yml +34 -0
  98. data/lib/active_admin/menu.rb +42 -0
  99. data/lib/active_admin/menu_item.rb +73 -0
  100. data/lib/active_admin/namespace.rb +198 -0
  101. data/lib/active_admin/page_config.rb +15 -0
  102. data/lib/active_admin/renderer.rb +87 -0
  103. data/lib/active_admin/resource/belongs_to.rb +31 -0
  104. data/lib/active_admin/resource.rb +229 -0
  105. data/lib/active_admin/resource_controller/action_builder.rb +21 -0
  106. data/lib/active_admin/resource_controller/actions.rb +79 -0
  107. data/lib/active_admin/resource_controller/callbacks.rb +47 -0
  108. data/lib/active_admin/resource_controller/collection.rb +144 -0
  109. data/lib/active_admin/resource_controller/filters.rb +58 -0
  110. data/lib/active_admin/resource_controller/form.rb +42 -0
  111. data/lib/active_admin/resource_controller/menu.rb +29 -0
  112. data/lib/active_admin/resource_controller/page_configurations.rb +53 -0
  113. data/lib/active_admin/resource_controller/scoping.rb +36 -0
  114. data/lib/active_admin/resource_controller/sidebars.rb +38 -0
  115. data/lib/active_admin/resource_controller.rb +119 -0
  116. data/lib/active_admin/router.rb +85 -0
  117. data/lib/active_admin/scope.rb +17 -0
  118. data/lib/active_admin/sidebar.rb +43 -0
  119. data/lib/active_admin/stylesheets/active_admin/_comments.scss +40 -0
  120. data/lib/active_admin/stylesheets/active_admin/_flash_messages.scss +13 -0
  121. data/lib/active_admin/stylesheets/active_admin/_forms.scss +168 -0
  122. data/lib/active_admin/stylesheets/active_admin/_header.scss +108 -0
  123. data/lib/active_admin/stylesheets/active_admin/_typography.scss +100 -0
  124. data/lib/active_admin/stylesheets/active_admin/mixins/_all.scss +8 -0
  125. data/lib/active_admin/stylesheets/active_admin/mixins/_buttons.scss +27 -0
  126. data/lib/active_admin/stylesheets/active_admin/mixins/_gradients.scss +21 -0
  127. data/lib/active_admin/stylesheets/active_admin/mixins/_icons.scss +20 -0
  128. data/lib/active_admin/stylesheets/active_admin/mixins/_reset.scss +165 -0
  129. data/lib/active_admin/stylesheets/active_admin/mixins/_rounded.scss +43 -0
  130. data/lib/active_admin/stylesheets/active_admin/mixins/_sections.scss +27 -0
  131. data/lib/active_admin/stylesheets/active_admin/mixins/_shadows.scss +21 -0
  132. data/lib/active_admin/stylesheets/active_admin/mixins/_variables.scss +12 -0
  133. data/lib/active_admin/stylesheets/active_admin.scss +429 -0
  134. data/lib/active_admin/version.rb +3 -0
  135. data/lib/active_admin/view_factory.rb +21 -0
  136. data/lib/active_admin/view_helpers/active_admin_application_helper.rb +12 -0
  137. data/lib/active_admin/view_helpers/assigns_with_indifferent_access_helper.rb +7 -0
  138. data/lib/active_admin/view_helpers/auto_link_helper.rb +42 -0
  139. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +29 -0
  140. data/lib/active_admin/view_helpers/display_helper.rb +38 -0
  141. data/lib/active_admin/view_helpers/filter_form_helper.rb +185 -0
  142. data/lib/active_admin/view_helpers/form_helper.rb +12 -0
  143. data/lib/active_admin/view_helpers/icon_helper.rb +12 -0
  144. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +26 -0
  145. data/lib/active_admin/view_helpers/renderer_helper.rb +29 -0
  146. data/lib/active_admin/view_helpers/sidebar_helper.rb +15 -0
  147. data/lib/active_admin/view_helpers/table_helper.rb +12 -0
  148. data/lib/active_admin/view_helpers/title_helper.rb +11 -0
  149. data/lib/active_admin/view_helpers/view_factory_helper.rb +11 -0
  150. data/lib/active_admin/view_helpers.rb +23 -0
  151. data/lib/active_admin/views/action_items.rb +17 -0
  152. data/lib/active_admin/views/components/attributes_table.rb +66 -0
  153. data/lib/active_admin/views/components/columns.rb +47 -0
  154. data/lib/active_admin/views/components/paginated_collection.rb +92 -0
  155. data/lib/active_admin/views/components/panel.rb +26 -0
  156. data/lib/active_admin/views/components/scopes.rb +70 -0
  157. data/lib/active_admin/views/components/sidebar_section.rb +30 -0
  158. data/lib/active_admin/views/components/status_tag.rb +55 -0
  159. data/lib/active_admin/views/components/table_for.rb +193 -0
  160. data/lib/active_admin/views/dashboard_section_renderer.rb +19 -0
  161. data/lib/active_admin/views/header_renderer.rb +37 -0
  162. data/lib/active_admin/views/index_as_block.rb +24 -0
  163. data/lib/active_admin/views/index_as_blog.rb +89 -0
  164. data/lib/active_admin/views/index_as_grid.rb +49 -0
  165. data/lib/active_admin/views/index_as_table.rb +75 -0
  166. data/lib/active_admin/views/pages/base.rb +144 -0
  167. data/lib/active_admin/views/pages/dashboard.rb +59 -0
  168. data/lib/active_admin/views/pages/edit.rb +27 -0
  169. data/lib/active_admin/views/pages/index.rb +66 -0
  170. data/lib/active_admin/views/pages/new.rb +27 -0
  171. data/lib/active_admin/views/pages/show.rb +56 -0
  172. data/lib/active_admin/views/tabs_renderer.rb +58 -0
  173. data/lib/active_admin/views/templates/active_admin/dashboard/index.html.arb +1 -0
  174. data/lib/active_admin/views/templates/active_admin/devise/mailer/reset_password_instructions.html.erb +8 -0
  175. data/lib/active_admin/views/templates/active_admin/devise/mailer/unlock_instructions.html.erb +7 -0
  176. data/lib/active_admin/views/templates/active_admin/devise/passwords/edit.html.erb +16 -0
  177. data/lib/active_admin/views/templates/active_admin/devise/passwords/new.html.erb +14 -0
  178. data/lib/active_admin/views/templates/active_admin/devise/sessions/new.html.erb +18 -0
  179. data/lib/active_admin/views/templates/active_admin/devise/shared/_links.erb +20 -0
  180. data/lib/active_admin/views/templates/active_admin/devise/unlocks/new.html.erb +12 -0
  181. data/lib/active_admin/views/templates/active_admin/resource/edit.html.arb +1 -0
  182. data/lib/active_admin/views/templates/active_admin/resource/index.csv.erb +20 -0
  183. data/lib/active_admin/views/templates/active_admin/resource/index.html.arb +1 -0
  184. data/lib/active_admin/views/templates/active_admin/resource/new.html.arb +1 -0
  185. data/lib/active_admin/views/templates/active_admin/resource/show.html.arb +1 -0
  186. data/lib/active_admin/views/templates/layouts/active_admin.html.erb +39 -0
  187. data/lib/active_admin/views/templates/layouts/active_admin_logged_out.html.erb +31 -0
  188. data/lib/active_admin/views.rb +8 -0
  189. data/lib/active_admin.rb +71 -0
  190. data/lib/activeadmin.rb +1 -0
  191. data/lib/generators/active_admin/devise/devise_generator.rb +49 -0
  192. data/lib/generators/active_admin/install/install_generator.rb +46 -0
  193. data/lib/generators/active_admin/install/templates/active_admin.js +51 -0
  194. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +78 -0
  195. data/lib/generators/active_admin/install/templates/active_admin_vendor.js +382 -0
  196. data/lib/generators/active_admin/install/templates/dashboards.rb +38 -0
  197. data/lib/generators/active_admin/install/templates/images/admin_notes_icon.png +0 -0
  198. data/lib/generators/active_admin/install/templates/images/loading.gif +0 -0
  199. data/lib/generators/active_admin/install/templates/images/nested_menu_arrow.gif +0 -0
  200. data/lib/generators/active_admin/install/templates/images/nested_menu_arrow_dark.gif +0 -0
  201. data/lib/generators/active_admin/install/templates/images/orderable.png +0 -0
  202. data/lib/generators/active_admin/install/templates/migrations/1_create_admin_notes.rb +16 -0
  203. data/lib/generators/active_admin/install/templates/migrations/2_move_admin_notes_to_comments.rb +25 -0
  204. data/lib/generators/active_admin/resource/resource_generator.rb +16 -0
  205. data/lib/generators/active_admin/resource/templates/admin.rb +3 -0
  206. data/spec/integration/belongs_to_spec.rb +42 -0
  207. data/spec/spec_helper.rb +156 -0
  208. data/spec/support/integration_example_group.rb +33 -0
  209. data/spec/support/rails_template.rb +32 -0
  210. data/spec/support/rails_template_with_data.rb +32 -0
  211. data/spec/support/templates/cucumber.rb +24 -0
  212. data/spec/unit/abstract_view_factory_spec.rb +79 -0
  213. data/spec/unit/action_builder_spec.rb +88 -0
  214. data/spec/unit/action_items_spec.rb +27 -0
  215. data/spec/unit/application_spec.rb +67 -0
  216. data/spec/unit/arbre/html/element_finder_methods_spec.rb +54 -0
  217. data/spec/unit/arbre/html/element_spec.rb +224 -0
  218. data/spec/unit/arbre/html/tag_attributes_spec.rb +61 -0
  219. data/spec/unit/arbre/html/tag_spec.rb +63 -0
  220. data/spec/unit/arbre/html_spec.rb +210 -0
  221. data/spec/unit/asset_registration_spec.rb +37 -0
  222. data/spec/unit/auto_link_spec.rb +39 -0
  223. data/spec/unit/belongs_to_spec.rb +45 -0
  224. data/spec/unit/breadcrumbs_spec.rb +110 -0
  225. data/spec/unit/comments_spec.rb +57 -0
  226. data/spec/unit/component_spec.rb +18 -0
  227. data/spec/unit/components/attributes_table_spec.rb +100 -0
  228. data/spec/unit/components/columns_spec.rb +75 -0
  229. data/spec/unit/components/panel_spec.rb +31 -0
  230. data/spec/unit/components/sidebar_section_spec.rb +37 -0
  231. data/spec/unit/components/status_tag_spec.rb +81 -0
  232. data/spec/unit/components/table_for_spec.rb +130 -0
  233. data/spec/unit/controller_filters_spec.rb +27 -0
  234. data/spec/unit/csv_builder_spec.rb +83 -0
  235. data/spec/unit/dashboard_controller_spec.rb +26 -0
  236. data/spec/unit/dashboard_section_spec.rb +56 -0
  237. data/spec/unit/dashboards_spec.rb +59 -0
  238. data/spec/unit/display_name_spec.rb +29 -0
  239. data/spec/unit/event_spec.rb +41 -0
  240. data/spec/unit/filter_form_builder_spec.rb +179 -0
  241. data/spec/unit/form_builder_spec.rb +238 -0
  242. data/spec/unit/menu_item_spec.rb +143 -0
  243. data/spec/unit/menu_spec.rb +53 -0
  244. data/spec/unit/namespace_spec.rb +203 -0
  245. data/spec/unit/pretty_format_spec.rb +35 -0
  246. data/spec/unit/registration_spec.rb +76 -0
  247. data/spec/unit/renderer_spec.rb +108 -0
  248. data/spec/unit/resource_controller/collection_spec.rb +34 -0
  249. data/spec/unit/resource_controller_spec.rb +147 -0
  250. data/spec/unit/resource_spec.rb +290 -0
  251. data/spec/unit/routing_spec.rb +88 -0
  252. data/spec/unit/scope_spec.rb +31 -0
  253. data/spec/unit/tabs_renderer_spec.rb +85 -0
  254. data/spec/unit/view_factory_spec.rb +16 -0
  255. metadata +482 -0
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Registering an object to administer" do
4
+ let(:application){ ActiveAdmin::Application.new }
5
+
6
+ context "with no configuration" do
7
+ let(:namespace) { ActiveAdmin::Namespace.new(application, :admin) }
8
+ it "should call register on the namespace" do
9
+ application.namespaces[namespace.name] = namespace
10
+ namespace.should_receive(:register)
11
+
12
+ application.register Category
13
+ end
14
+
15
+ it "should dispatch a Resource::RegisterEvent" do
16
+ ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource))
17
+ application.register Category
18
+ end
19
+ end
20
+
21
+ context "with a different namespace" do
22
+ it "should call register on the namespace" do
23
+ namespace = ActiveAdmin::Namespace.new(application, :hello_world)
24
+ application.namespaces[namespace.name] = namespace
25
+ namespace.should_receive(:register)
26
+
27
+ application.register Category, :namespace => :hello_world
28
+ end
29
+ it "should generate a menu item for the dashboard" do
30
+ application.register Category, :namespace => :hello_world
31
+ application.namespaces[:hello_world].load_menu!
32
+ application.namespaces[:hello_world].menu['Dashboard'].instance_variable_get("@url").should == :hello_world_dashboard_path
33
+ end
34
+ it "should generate a Namespace::RegisterEvent and a Resource::RegisterEvent" do
35
+ ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Namespace::RegisterEvent, an_instance_of(ActiveAdmin::Namespace))
36
+ ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource))
37
+ application.register Category, :namespace => :not_yet_created
38
+ end
39
+ end
40
+
41
+ context "with no namespace" do
42
+ it "should call register on the root namespace" do
43
+ namespace = ActiveAdmin::Namespace.new(application, :root)
44
+ application.namespaces[namespace.name] = namespace
45
+ namespace.should_receive(:register)
46
+
47
+ application.register Category, :namespace => false
48
+ end
49
+
50
+ it "should generate a menu item for the dashboard" do
51
+ application.register Category, :namespace => false
52
+ application.namespaces[:root].load_menu!
53
+ application.namespaces[:root].menu['Dashboard'].instance_variable_get("@url").should == :dashboard_path
54
+ end
55
+
56
+ end
57
+
58
+ context "when being registered multiple times" do
59
+ it "should run the dsl in the same config object" do
60
+ config_1 = ActiveAdmin.register(Category) { filter :name }
61
+ config_2 = ActiveAdmin.register(Category) { filter :id }
62
+ config_1.should == config_2
63
+ config_1.controller.filters_config.size.should == 2
64
+ end
65
+
66
+ context "with different resource classes" do
67
+ it "should raise an ActiveAdmin::ResourceMismatch" do
68
+ lambda {
69
+ ActiveAdmin.register Category
70
+ ActiveAdmin.register Post, :as => "Category"
71
+ }.should raise_error(ActiveAdmin::ResourceMismatchError)
72
+ end
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ include ActiveAdmin
4
+
5
+ describe ActiveAdmin::Renderer do
6
+
7
+ context "when initiailizing from a view" do
8
+ it "should have a view" do
9
+ view = action_view
10
+ renderer = Renderer.new(view)
11
+ renderer.view.should == view
12
+ end
13
+
14
+ it "should assign all local variables from the view" do
15
+ Renderer.new(action_view(:foo => "bar")).send(:instance_variable_get, "@foo").should == "bar"
16
+ end
17
+
18
+ it "should assing an instance variable to the view" do
19
+ view = action_view
20
+ renderer = Renderer.new(view)
21
+ renderer.send :set_ivar_on_view, "@my_ivar", 'Hello World'
22
+ view.instance_variable_get("@my_ivar").should == 'Hello World'
23
+ end
24
+ end
25
+
26
+ context "when initializing from another renderer" do
27
+ it "should have the view" do
28
+ view = action_view
29
+ renderer = Renderer.new(Renderer.new(view))
30
+ renderer.view.should == view
31
+ end
32
+
33
+ it "should assign local variables from the renderer" do
34
+ view = action_view(:foo => 'bar')
35
+ renderer = Renderer.new(Renderer.new(view))
36
+ renderer.send(:instance_variable_get, "@foo").should == 'bar'
37
+ end
38
+
39
+ it "should assing an instance variable to the view" do
40
+ view = action_view
41
+ renderer = Renderer.new(Renderer.new(view))
42
+ renderer.send :set_ivar_on_view, "@my_ivar", 'Hello World'
43
+ view.instance_variable_get("@my_ivar").should == 'Hello World'
44
+ end
45
+ end
46
+
47
+ context "when initializing from some other object" do
48
+ it "should initialize successfully" do
49
+ lambda {
50
+ Renderer.new "Hello World"
51
+ }.should_not raise_exception
52
+ end
53
+ end
54
+
55
+ describe "rendering HAML" do
56
+ before do
57
+ @haml_renderer = Class.new(Renderer)
58
+ @haml_renderer.class_eval do
59
+ def hello_world
60
+ "Hello World"
61
+ end
62
+ end
63
+ end
64
+ it "should render haml within the context of the renderer" do
65
+ @haml_renderer.class_eval do
66
+ def to_html
67
+ haml <<-HAML
68
+ %p
69
+ =hello_world
70
+ HAML
71
+ end
72
+ end
73
+ @renderer = @haml_renderer.new(action_view)
74
+ @renderer.to_html.should == "<p>\n Hello World\n</p>\n"
75
+ end
76
+
77
+ it "should allow for indentation at the start of the template" do
78
+ @haml_renderer.class_eval do
79
+ def to_html
80
+ haml <<-HAML
81
+ %p
82
+ =hello_world
83
+ HAML
84
+ end
85
+ end
86
+ @renderer = @haml_renderer.new(action_view)
87
+ @renderer.to_html.should == "<p>\n Hello World\n</p>\n"
88
+ end
89
+ end
90
+
91
+ describe "#call_method_or_proc_on" do
92
+ let(:renderer){ Renderer.new(action_view) }
93
+ let(:obj){ "Hello World" }
94
+ it "should return nil if no symbol or proc given" do
95
+ renderer.send(:call_method_or_proc_on, obj, 1).should == nil
96
+ end
97
+ it "should call the method if a symbol is given" do
98
+ renderer.send(:call_method_or_proc_on, obj, :size).should == obj.size
99
+ end
100
+ it "should call the method if a string is given" do
101
+ renderer.send(:call_method_or_proc_on, obj, "size").should == obj.size
102
+ end
103
+ it "should call the proc with the object if a proc is given" do
104
+ p = Proc.new{|string| string.size }
105
+ renderer.send(:call_method_or_proc_on, obj, p).should == obj.size
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::ResourceController::Collection do
4
+ let(:params) do
5
+ {}
6
+ end
7
+
8
+ let(:controller) do
9
+ rc = Admin::PostsController.new
10
+ rc.stub!(:params) do
11
+ params
12
+ end
13
+ rc
14
+ end
15
+
16
+ describe ActiveAdmin::ResourceController::Collection::Search do
17
+ let(:params){ {:q => {} }}
18
+ it "should call the metasearch method" do
19
+ chain = mock("ChainObj")
20
+ chain.should_receive(:metasearch).with(params[:q]).once.and_return(Post.search)
21
+ controller.send :search, chain
22
+ end
23
+ end
24
+
25
+ describe ActiveAdmin::ResourceController::Collection::Sorting do
26
+ let(:params){ {:order => "id_asc" }}
27
+ it "should prepend the table name" do
28
+ chain = mock("ChainObj")
29
+ chain.should_receive(:order).with("posts.id asc").once.and_return(Post.search)
30
+ controller.send :sort_order, chain
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::ResourceController do
4
+
5
+ [:index, :show].each do |page|
6
+ describe "#{page} config" do
7
+ before do
8
+ Admin::PostsController.send(:"reset_#{page}_config!")
9
+ end
10
+
11
+ it "should be set" do
12
+ Admin::PostsController.send(:set_page_config, page, {})
13
+ Admin::PostsController.send(:"#{page}_config").should be_an_instance_of(ActiveAdmin::PageConfig)
14
+ end
15
+
16
+ it "should store the block" do
17
+ block = Proc.new {}
18
+ Admin::PostsController.send(:set_page_config, page, {}, &block)
19
+ Admin::PostsController.send(:"#{page}_config").block.should == block
20
+ end
21
+
22
+ it "should be reset" do
23
+ Admin::PostsController.send(:"reset_#{page}_config!")
24
+ Admin::PostsController.send(:"#{page}_config").should == nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "setting the current tab" do
30
+ let(:controller) { ActiveAdmin::ResourceController.new }
31
+ before do
32
+ controller.stub!(:active_admin_config => resource, :parent? => true)
33
+ controller.send :set_current_tab # Run the before filter
34
+ end
35
+ subject{ controller.instance_variable_get(:@current_tab) }
36
+
37
+ context "when menu item name is 'Resources' without a parent menu item" do
38
+ let(:resource){ mock(:menu_item_name => "Resources", :parent_menu_item_name => nil, :belongs_to? => false) }
39
+ it { should == "Resources" }
40
+ end
41
+
42
+ context "when there is a parent menu item of 'Admin'" do
43
+ let(:resource){ mock(:parent_menu_item_name => "Admin", :menu_item_name => "Resources", :belongs_to? => false) }
44
+ it { should == "Admin/Resources" }
45
+ end
46
+ end
47
+
48
+ ActiveAdmin.register Post do
49
+ after_build :call_after_build
50
+ before_save :call_before_save
51
+ after_save :call_after_save
52
+ before_create :call_before_create
53
+ after_create :call_after_create
54
+ before_update :call_before_update
55
+ after_update :call_after_update
56
+ before_destroy :call_before_destroy
57
+ after_destroy :call_after_destroy
58
+ end
59
+
60
+ class Admin::PostsController < ActiveAdmin::ResourceController
61
+ def call_after_build(obj); end
62
+ def call_before_save(obj); end
63
+ def call_after_save(obj); end
64
+ def call_before_create(obj); end
65
+ def call_after_create(obj); end
66
+ def call_before_update(obj); end
67
+ def call_after_update(obj); end
68
+ def call_before_destroy(obj); end
69
+ def call_after_destroy(obj); end
70
+ end
71
+
72
+ describe "callbacks" do
73
+ describe "performing create" do
74
+ let(:controller){ Admin::PostsController.new }
75
+ let(:resource){ mock("Resource", :save => true) }
76
+
77
+ before do
78
+ resource.should_receive(:save)
79
+ end
80
+
81
+ it "should call the before create callback" do
82
+ controller.should_receive(:call_before_create).with(resource)
83
+ controller.send :create_resource, resource
84
+ end
85
+ it "should call the before save callback" do
86
+ controller.should_receive(:call_before_save).with(resource)
87
+ controller.send :create_resource, resource
88
+ end
89
+ it "should call the after save callback" do
90
+ controller.should_receive(:call_after_save).with(resource)
91
+ controller.send :create_resource, resource
92
+ end
93
+ it "should call the after create callback" do
94
+ controller.should_receive(:call_after_create).with(resource)
95
+ controller.send :create_resource, resource
96
+ end
97
+ end
98
+
99
+ describe "performing update" do
100
+ let(:controller){ Admin::PostsController.new }
101
+ let(:resource){ mock("Resource", :attributes= => true, :save => true) }
102
+ let(:attributes){ {} }
103
+
104
+ before do
105
+ resource.should_receive(:attributes=).with(attributes)
106
+ resource.should_receive(:save)
107
+ end
108
+
109
+ it "should call the before update callback" do
110
+ controller.should_receive(:call_before_update).with(resource)
111
+ controller.send :update_resource, resource, attributes
112
+ end
113
+ it "should call the before save callback" do
114
+ controller.should_receive(:call_before_save).with(resource)
115
+ controller.send :update_resource, resource, attributes
116
+ end
117
+ it "should call the after save callback" do
118
+ controller.should_receive(:call_after_save).with(resource)
119
+ controller.send :update_resource, resource, attributes
120
+ end
121
+ it "should call the after create callback" do
122
+ controller.should_receive(:call_after_update).with(resource)
123
+ controller.send :update_resource, resource, attributes
124
+ end
125
+ end
126
+
127
+ describe "performing destroy" do
128
+ let(:controller){ Admin::PostsController.new }
129
+ let(:resource){ mock("Resource", :destroy => true) }
130
+
131
+ before do
132
+ resource.should_receive(:destroy)
133
+ end
134
+
135
+ it "should call the before destroy callback" do
136
+ controller.should_receive(:call_before_destroy).with(resource)
137
+ controller.send :destroy_resource, resource
138
+ end
139
+
140
+ it "should call the after destroy callback" do
141
+ controller.should_receive(:call_after_destroy).with(resource)
142
+ controller.send :destroy_resource, resource
143
+ end
144
+ end
145
+ end
146
+
147
+ end
@@ -0,0 +1,290 @@
1
+ require 'spec_helper'
2
+
3
+ module ActiveAdmin
4
+ describe Resource do
5
+
6
+ before { load_defaults! }
7
+
8
+ let(:application){ ActiveAdmin::Application.new }
9
+ let(:namespace){ Namespace.new(application, :admin) }
10
+
11
+ def config(options = {})
12
+ @config ||= Resource.new(namespace, Category, options)
13
+ end
14
+
15
+ describe "underscored resource name" do
16
+ context "when class" do
17
+ it "should be the underscored singular resource name" do
18
+ config.underscored_resource_name.should == "category"
19
+ end
20
+ end
21
+ context "when a class in a module" do
22
+ it "should underscore the module and the class" do
23
+ module ::Mock; class Resource; end; end
24
+ Resource.new(namespace, Mock::Resource).underscored_resource_name.should == "mock_resource"
25
+ end
26
+ end
27
+ context "when you pass the 'as' option" do
28
+ it "should underscore the passed through string and singulralize" do
29
+ config(:as => "Blog Categories").underscored_resource_name.should == "blog_category"
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "camelized resource name" do
35
+ it "should return a camelized version of the underscored resource name" do
36
+ config(:as => "Blog Categories").camelized_resource_name.should == "BlogCategory"
37
+ end
38
+ end
39
+
40
+ describe "resource name" do
41
+ it "should return a pretty name" do
42
+ config.resource_name.should == "Category"
43
+ end
44
+ it "should return the plural version" do
45
+ config.plural_resource_name.should == "Categories"
46
+ end
47
+ context "when the :as option is given" do
48
+ it "should return the custom name" do
49
+ config(:as => "My Category").resource_name.should == "My Category"
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#resource_table_name" do
55
+ it "should return the resource's table name" do
56
+ config.resource_table_name.should == 'categories'
57
+ end
58
+ context "when the :as option is given" do
59
+ it "should return the resource's table name" do
60
+ config(:as => "My Category").resource_table_name.should == 'categories'
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "namespace" do
66
+ it "should return the namespace" do
67
+ config.namespace.should == namespace
68
+ end
69
+ end
70
+
71
+ describe "controller name" do
72
+ it "should return a namespaced controller name" do
73
+ config.controller_name.should == "Admin::CategoriesController"
74
+ end
75
+ context "when non namespaced controller" do
76
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :root) }
77
+ it "should return a non namespaced controller name" do
78
+ config.controller_name.should == "CategoriesController"
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "#include_in_menu?" do
84
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
85
+ subject{ resource }
86
+
87
+ context "when regular resource" do
88
+ let(:resource){ namespace.register(Post) }
89
+ it { should be_include_in_menu }
90
+ end
91
+ context "when belongs to" do
92
+ let(:resource){ namespace.register(Post){ belongs_to :author } }
93
+ it { should_not be_include_in_menu }
94
+ end
95
+ context "when belongs to optional" do
96
+ let(:resource){ namespace.register(Post){ belongs_to :author, :optional => true} }
97
+ it { should be_include_in_menu }
98
+ end
99
+ context "when menu set to false" do
100
+ let(:resource){ namespace.register(Post){ menu false } }
101
+ it { should_not be_include_in_menu }
102
+ end
103
+ end
104
+
105
+ describe "menu item name" do
106
+ it "should be the resource name when not set" do
107
+ config.menu_item_name.should == "Categories"
108
+ end
109
+ it "should be settable" do
110
+ config.menu :label => "My Label"
111
+ config.menu_item_name.should == "My Label"
112
+ end
113
+ end
114
+
115
+ describe "parent menu item name" do
116
+ it "should be nil when not set" do
117
+ config.parent_menu_item_name.should == nil
118
+ end
119
+ it "should return the name if set" do
120
+ config.tap do |c|
121
+ c.menu :parent => "Blog"
122
+ end.parent_menu_item_name.should == "Blog"
123
+ end
124
+ end
125
+
126
+ describe "menu item priority" do
127
+ it "should be 10 when not set" do
128
+ config.menu_item_priority.should == 10
129
+ end
130
+ it "should be settable" do
131
+ config.menu :priority => 2
132
+ config.menu_item_priority.should == 2
133
+ end
134
+ end
135
+
136
+ describe "menu item display if" do
137
+ it "should be a proc always returning true if not set" do
138
+ config.menu_item_display_if.should be_instance_of(Proc)
139
+ config.menu_item_display_if.call.should == true
140
+ end
141
+ it "should be settable" do
142
+ config.menu :if => proc { false }
143
+ config.menu_item_display_if.call.should == false
144
+ end
145
+ end
146
+
147
+ describe "route names" do
148
+ let(:config){ application.register Category }
149
+ it "should return the route prefix" do
150
+ config.route_prefix.should == "admin"
151
+ end
152
+ it "should return the route collection path" do
153
+ config.route_collection_path.should == :admin_categories_path
154
+ end
155
+
156
+ context "when in the root namespace" do
157
+ let(:config){ application.register Category, :namespace => false}
158
+ it "should have a nil route_prefix" do
159
+ config.route_prefix.should == nil
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "page configs" do
165
+ context "when initialized" do
166
+ it "should be empty" do
167
+ config.page_configs.should == {}
168
+ end
169
+ end
170
+ it "should be set-able" do
171
+ config.page_configs[:index] = "hello world"
172
+ config.page_configs[:index].should == "hello world"
173
+ end
174
+ end
175
+
176
+ describe "scoping" do
177
+ context "when using a block" do
178
+ before do
179
+ @resource = application.register Category do
180
+ scope_to do
181
+ "scoped"
182
+ end
183
+ end
184
+ end
185
+ it "should call the proc for the begin of association chain" do
186
+ begin_of_association_chain = @resource.controller.new.send(:begin_of_association_chain)
187
+ begin_of_association_chain.should == "scoped"
188
+ end
189
+ end
190
+
191
+ context "when using a symbol" do
192
+ before do
193
+ @resource = application.register Category do
194
+ scope_to :current_user
195
+ end
196
+ end
197
+ it "should call the method for the begin of association chain" do
198
+ controller = @resource.controller.new
199
+ controller.should_receive(:current_user).and_return(true)
200
+ begin_of_association_chain = controller.send(:begin_of_association_chain)
201
+ begin_of_association_chain.should == true
202
+ end
203
+ end
204
+
205
+ context "when not using a block or symbol" do
206
+ before do
207
+ @resource = application.register Category do
208
+ scope_to "Some string"
209
+ end
210
+ end
211
+ it "should raise and exception" do
212
+ lambda {
213
+ @resource.controller.new.send(:begin_of_association_chain)
214
+ }.should raise_error(ArgumentError)
215
+ end
216
+ end
217
+
218
+ describe "getting the method for the association chain" do
219
+ context "when a simple registration" do
220
+ before do
221
+ @resource = application.register Category do
222
+ scope_to :current_user
223
+ end
224
+ end
225
+ it "should return the pluralized collection name" do
226
+ @resource.controller.new.send(:method_for_association_chain).should == :categories
227
+ end
228
+ end
229
+ context "when passing in the method as an option" do
230
+ before do
231
+ @resource = application.register Category do
232
+ scope_to :current_user, :association_method => :blog_categories
233
+ end
234
+ end
235
+ it "should return the method from the option" do
236
+ @resource.controller.new.send(:method_for_association_chain).should == :blog_categories
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+
243
+ describe "sort order" do
244
+ subject { resource_config.sort_order }
245
+
246
+ context "by default" do
247
+ let(:resource_config) { config }
248
+
249
+ it { should == application.default_sort_order }
250
+ end
251
+
252
+ context "when default_sort_order is set" do
253
+ let(:sort_order) { "name_desc" }
254
+ let(:resource_config) { config :sort_order => sort_order }
255
+
256
+ it { should == sort_order }
257
+ end
258
+ end
259
+
260
+ describe "adding a scope" do
261
+
262
+ it "should add a scope" do
263
+ config.scope :published
264
+ config.scopes.first.should be_a(ActiveAdmin::Scope)
265
+ config.scopes.first.name.should == "Published"
266
+ end
267
+
268
+ it "should retrive a scope by its id" do
269
+ config.scope :published
270
+ config.get_scope_by_id(:published).name.should == "Published"
271
+ end
272
+ end
273
+
274
+ describe "#csv_builder" do
275
+ context "when no csv builder set" do
276
+ it "should return a default column builder with id and content columns" do
277
+ config.csv_builder.columns.size.should == Category.content_columns.size + 1
278
+ end
279
+ end
280
+
281
+ context "when csv builder set" do
282
+ it "shuld return the csv_builder we set" do
283
+ csv_builder = CSVBuilder.new
284
+ config.csv_builder = csv_builder
285
+ config.csv_builder.should == csv_builder
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end