andrewroth_activeadmin 0.3.4 → 0.3.4.1

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 (201) hide show
  1. data/CHANGELOG.md +159 -3
  2. data/CONTRIBUTING.md +113 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +19 -20
  5. data/activeadmin.gemspec +3 -1
  6. data/app/assets/javascripts/active_admin/application.js +9 -0
  7. data/app/assets/javascripts/active_admin/base.js +4 -12
  8. data/app/assets/stylesheets/active_admin/_base.css.scss +16 -340
  9. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  10. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  11. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  12. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  13. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  14. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  15. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  16. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  17. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  18. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  19. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  20. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  22. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  23. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  24. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  25. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  26. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  27. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  28. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  29. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  30. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  31. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  32. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  33. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  34. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  35. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  36. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  37. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  38. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  39. data/app/views/active_admin/page/index.html.arb +1 -0
  40. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  41. data/cucumber.yml +3 -2
  42. data/docs/1-general-configuration.md +46 -10
  43. data/docs/6-show-screens.md +7 -0
  44. data/docs/8-custom-actions.md +12 -2
  45. data/docs/9-custom-pages.md +84 -0
  46. data/features/belongs_to.feature +27 -0
  47. data/features/comments/commenting.feature +3 -2
  48. data/features/dashboard.feature +18 -0
  49. data/features/development_reloading.feature +19 -0
  50. data/features/index/filter_with_check_boxes.feature +25 -0
  51. data/features/index/index_as_table.feature +14 -0
  52. data/features/index/index_scopes.feature +42 -0
  53. data/features/index/pagination.feature +19 -1
  54. data/features/menu.feature +22 -2
  55. data/features/registering_assets.feature +2 -2
  56. data/features/registering_pages.feature +66 -0
  57. data/features/specifying_actions.feature +5 -0
  58. data/features/step_definitions/action_item_steps.rb +2 -6
  59. data/features/step_definitions/action_link_steps.rb +7 -0
  60. data/features/step_definitions/additional_web_steps.rb +8 -0
  61. data/features/step_definitions/asset_steps.rb +5 -1
  62. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  63. data/features/step_definitions/configuration_steps.rb +56 -8
  64. data/features/step_definitions/dashboard_steps.rb +5 -1
  65. data/features/step_definitions/factory_steps.rb +9 -2
  66. data/features/step_definitions/flash_steps.rb +9 -1
  67. data/features/step_definitions/index_scope_steps.rb +16 -4
  68. data/features/step_definitions/member_link_steps.rb +7 -0
  69. data/features/step_definitions/site_title_steps.rb +15 -0
  70. data/features/support/paths.rb +6 -0
  71. data/features/users/logging_out.feature +11 -0
  72. data/lib/active_admin.rb +25 -10
  73. data/lib/active_admin/application.rb +63 -20
  74. data/lib/active_admin/arbre/html/element.rb +10 -0
  75. data/lib/active_admin/asset_registration.rb +15 -2
  76. data/lib/active_admin/base_controller.rb +61 -0
  77. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  78. data/lib/active_admin/comments.rb +48 -54
  79. data/lib/active_admin/comments/comment.rb +13 -2
  80. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  81. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  82. data/lib/active_admin/dashboards.rb +4 -0
  83. data/lib/active_admin/dashboards/dashboard_controller.rb +20 -4
  84. data/lib/active_admin/dsl.rb +6 -159
  85. data/lib/active_admin/event.rb +5 -3
  86. data/lib/active_admin/filter_form_builder.rb +53 -0
  87. data/lib/active_admin/form_builder.rb +25 -19
  88. data/lib/active_admin/inputs.rb +14 -0
  89. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  90. data/lib/active_admin/inputs/filter_base.rb +46 -0
  91. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  92. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  93. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  94. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  95. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  96. data/lib/active_admin/locales/ca.yml +44 -0
  97. data/lib/active_admin/locales/cs.yml +14 -10
  98. data/lib/active_admin/locales/de.yml +43 -0
  99. data/lib/active_admin/locales/en.yml +5 -0
  100. data/lib/active_admin/locales/hr.yml +40 -0
  101. data/lib/active_admin/locales/ko.yml +40 -0
  102. data/lib/active_admin/locales/lv.yml +43 -0
  103. data/lib/active_admin/locales/nl.yml +40 -0
  104. data/lib/active_admin/locales/no-NB.yml +40 -0
  105. data/lib/active_admin/locales/pl.yml +7 -1
  106. data/lib/active_admin/locales/pt-BR.yml +6 -2
  107. data/lib/active_admin/namespace.rb +48 -33
  108. data/lib/active_admin/page.rb +54 -0
  109. data/lib/active_admin/page_controller.rb +15 -0
  110. data/lib/active_admin/page_dsl.rb +21 -0
  111. data/lib/active_admin/page_presenter.rb +30 -0
  112. data/lib/active_admin/resource.rb +38 -44
  113. data/lib/active_admin/resource/action_items.rb +5 -0
  114. data/lib/active_admin/resource/belongs_to.rb +4 -2
  115. data/lib/active_admin/resource/controllers.rb +35 -0
  116. data/lib/active_admin/resource/menu.rb +1 -2
  117. data/lib/active_admin/resource/naming.rb +43 -31
  118. data/lib/active_admin/resource/page_presenters.rb +28 -0
  119. data/lib/active_admin/resource/scopes.rb +16 -3
  120. data/lib/active_admin/resource/sidebars.rb +4 -0
  121. data/lib/active_admin/resource_collection.rb +88 -0
  122. data/lib/active_admin/resource_controller.rb +18 -54
  123. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  124. data/lib/active_admin/resource_controller/actions.rb +1 -1
  125. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  126. data/lib/active_admin/resource_controller/collection.rb +8 -4
  127. data/lib/active_admin/resource_controller/filters.rb +1 -1
  128. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  129. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  130. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  131. data/lib/active_admin/resource_dsl.rb +157 -0
  132. data/lib/active_admin/router.rb +21 -14
  133. data/lib/active_admin/scope.rb +15 -3
  134. data/lib/active_admin/version.rb +1 -1
  135. data/lib/active_admin/view_factory.rb +4 -3
  136. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  137. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  138. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  139. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  140. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  141. data/lib/active_admin/views/components/scopes.rb +17 -17
  142. data/lib/active_admin/views/components/status_tag.rb +6 -5
  143. data/lib/active_admin/views/components/table_for.rb +6 -2
  144. data/lib/active_admin/views/header_renderer.rb +31 -12
  145. data/lib/active_admin/views/index_as_block.rb +2 -2
  146. data/lib/active_admin/views/index_as_blog.rb +3 -3
  147. data/lib/active_admin/views/index_as_grid.rb +4 -4
  148. data/lib/active_admin/views/index_as_table.rb +13 -6
  149. data/lib/active_admin/views/pages/base.rb +4 -4
  150. data/lib/active_admin/views/pages/form.rb +49 -0
  151. data/lib/active_admin/views/pages/index.rb +18 -6
  152. data/lib/active_admin/views/pages/page.rb +24 -0
  153. data/lib/active_admin/views/pages/show.rb +1 -1
  154. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  155. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  156. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  157. data/spec/spec_helper.rb +4 -0
  158. data/spec/support/rails_template.rb +11 -0
  159. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  160. data/spec/unit/active_admin_spec.rb +8 -0
  161. data/spec/unit/application_spec.rb +48 -2
  162. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  163. data/spec/unit/asset_registration_spec.rb +9 -3
  164. data/spec/unit/auto_link_spec.rb +2 -2
  165. data/spec/unit/base_controller_shared_examples.rb +28 -0
  166. data/spec/unit/base_controller_spec.rb +8 -0
  167. data/spec/unit/belongs_to_spec.rb +30 -33
  168. data/spec/unit/comments_spec.rb +45 -15
  169. data/spec/unit/config_shared_examples.rb +108 -0
  170. data/spec/unit/dashboard_controller_spec.rb +44 -0
  171. data/spec/unit/event_spec.rb +6 -0
  172. data/spec/unit/filter_form_builder_spec.rb +9 -0
  173. data/spec/unit/form_builder_spec.rb +8 -14
  174. data/spec/unit/namespace/register_page_spec.rb +102 -0
  175. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  176. data/spec/unit/namespace_spec.rb +11 -183
  177. data/spec/unit/page_controller_spec.rb +8 -0
  178. data/spec/unit/page_spec.rb +60 -0
  179. data/spec/unit/resource/menu_spec.rb +1 -51
  180. data/spec/unit/resource/naming_spec.rb +24 -19
  181. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  182. data/spec/unit/resource/scopes_spec.rb +13 -0
  183. data/spec/unit/resource_collection_spec.rb +101 -0
  184. data/spec/unit/resource_controller_spec.rb +40 -32
  185. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  186. data/spec/unit/resource_spec.rb +8 -24
  187. data/spec/unit/routing_spec.rb +50 -1
  188. data/spec/unit/scope_spec.rb +18 -4
  189. data/spec/unit/views/components/paginated_collection_spec.rb +150 -0
  190. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  191. data/tasks/test.rake +43 -27
  192. metadata +140 -31
  193. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  194. data/lib/active_admin/comments/configuration.rb +0 -18
  195. data/lib/active_admin/page_config.rb +0 -15
  196. data/lib/active_admin/resource_controller/form.rb +0 -42
  197. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  198. data/lib/active_admin/views/pages/edit.rb +0 -28
  199. data/lib/active_admin/views/pages/new.rb +0 -28
  200. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  201. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require File.expand_path('base_controller_shared_examples', File.dirname(__FILE__))
3
+
4
+ describe ActiveAdmin::BaseController do
5
+ let(:controller) { ActiveAdmin::BaseController.new }
6
+
7
+ it_should_behave_like "BaseController"
8
+ end
@@ -1,45 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
- module ActiveAdmin
4
- class Resource
5
- describe BelongsTo do
3
+ describe ActiveAdmin::Resource::BelongsTo do
6
4
 
7
- let(:application){ ActiveAdmin::Application.new }
8
- let(:namespace){ Namespace.new(application, :admin) }
9
- let(:post){ namespace.register(Post) }
10
- let(:belongs_to){ BelongsTo.new(post, :user) }
11
5
 
12
- it "should have an owner" do
13
- belongs_to.owner.should == post
14
- end
6
+ let(:application){ ActiveAdmin::Application.new }
7
+ let(:namespace){ Namespace.new(application, :admin) }
8
+ let(:post){ namespace.register(Post) }
9
+ let(:belongs_to){ ActiveAdmin::Resource::BelongsTo.new(post, :user) }
15
10
 
16
- it "should have a namespace" do
17
- belongs_to.namespace.should == namespace
18
- end
11
+ it "should have an owner" do
12
+ belongs_to.owner.should == post
13
+ end
14
+
15
+ it "should have a namespace" do
16
+ belongs_to.namespace.should == namespace
17
+ end
19
18
 
20
- describe "finding the target" do
21
- context "when the resource has been registered" do
22
- let(:user){ namespace.register(User) }
23
- before { user } # Ensure user is registered
24
-
25
- it "should return the target resource" do
26
- belongs_to.target.should == user
27
- end
28
- end
29
-
30
- context "when the resource has not been registered" do
31
- it "should raise a ActiveAdmin::BelongsTo::TargetNotFound" do
32
- lambda {
33
- belongs_to.target
34
- }.should raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
35
- end
36
- end
19
+ describe "finding the target" do
20
+ context "when the resource has been registered" do
21
+ let(:user){ namespace.register(User) }
22
+ before { user } # Ensure user is registered
23
+
24
+ it "should return the target resource" do
25
+ belongs_to.target.should == user
37
26
  end
27
+ end
38
28
 
39
- it "should be optional" do
40
- belongs_to = BelongsTo.new post, :user, :optional => true
41
- belongs_to.should be_optional
29
+ context "when the resource has not been registered" do
30
+ it "should raise a ActiveAdmin::BelongsTo::TargetNotFound" do
31
+ lambda {
32
+ belongs_to.target
33
+ }.should raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
42
34
  end
43
35
  end
44
36
  end
37
+
38
+ it "should be optional" do
39
+ belongs_to = ActiveAdmin::Resource::BelongsTo.new post, :user, :optional => true
40
+ belongs_to.should be_optional
41
+ end
45
42
  end
@@ -3,38 +3,68 @@ require 'spec_helper'
3
3
  describe "Comments" do
4
4
  let(:application){ ActiveAdmin::Application.new }
5
5
 
6
- describe "Configuration" do
7
- it "should have an array of namespaces which allow comments" do
8
- application.allow_comments_in.should be_an_instance_of(Array)
9
- end
10
-
11
- it "should allow comments in the default namespace by default" do
12
- application.allow_comments_in.should include(application.default_namespace)
13
- end
14
- end
15
-
16
6
  describe ActiveAdmin::Comment do
17
7
  describe "Associations and Validations" do
18
8
  it { should belong_to :resource }
19
9
  it { should belong_to :author }
20
10
 
21
- it { should validate_presence_of :resource_id }
22
- it { should validate_presence_of :resource_type }
11
+ it { should validate_presence_of :resource }
23
12
  it { should validate_presence_of :body }
24
13
  it { should validate_presence_of :namespace }
25
14
  end
15
+
16
+ describe ".find_for_resource_in_namespace" do
17
+ let(:post){ Post.create!(:title => "Hello World") }
18
+ let(:namespace_name){ "admin" }
19
+
20
+ before do
21
+ @comment = ActiveAdmin::Comment.create! :resource => post,
22
+ :body => "A Comment",
23
+ :namespace => namespace_name
24
+ end
25
+
26
+ it "should return a comment for the resource in the same namespace" do
27
+ ActiveAdmin::Comment.find_for_resource_in_namespace(post, namespace_name).should == [@comment]
28
+ end
29
+
30
+ it "should not return a comment for the same resource in a different namespace" do
31
+ ActiveAdmin::Comment.find_for_resource_in_namespace(post, 'public').should == []
32
+ end
33
+
34
+ it "should not return a comment for a different resource" do
35
+ another_post = Post.create! :title => "Another Hello World"
36
+ ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name).should == []
37
+ end
38
+ end
26
39
  end
27
40
 
28
41
  describe ActiveAdmin::Comments::NamespaceHelper do
29
42
  describe "#comments?" do
30
- it "should have comments if the namespace is in the settings" do
43
+
44
+ it "should have comments when the namespace allows comments" do
31
45
  ns = ActiveAdmin::Namespace.new(application, :admin)
46
+ ns.allow_comments = true
32
47
  ns.comments?.should be_true
33
48
  end
34
- it "should not have comments if the namespace is not in the settings" do
35
- ns = ActiveAdmin::Namespace.new(application, :not_in_comments)
49
+
50
+ it "should not have comments when the namespace does not allow comments" do
51
+ ns = ActiveAdmin::Namespace.new(application, :admin)
52
+ ns.allow_comments = false
36
53
  ns.comments?.should be_false
37
54
  end
55
+
56
+ it "should have comments when the application allows comments and no local namespace config" do
57
+ application.allow_comments = true
58
+ ns = ActiveAdmin::Namespace.new(application, :admin)
59
+ ns.comments?.should be_true
60
+ end
61
+
62
+ it "should not have comments when the application does not allow commands and no local namespace config" do
63
+ application.allow_comments = false
64
+ ns = ActiveAdmin::Namespace.new(application, :admin)
65
+ ns.comments?.should be_false
66
+ end
67
+
38
68
  end
39
69
  end
40
70
 
@@ -0,0 +1,108 @@
1
+ shared_examples_for "ActiveAdmin::Config" do
2
+ describe "namespace" do
3
+ it "should return the namespace" do
4
+ config.namespace.should == namespace
5
+ end
6
+ end
7
+
8
+ describe "page_presenters" do
9
+ it "should return an empty hash by default" do
10
+ config.page_presenters.should == {}
11
+ end
12
+ end
13
+
14
+ it { respond_to :controller_name }
15
+ it { respond_to :controller }
16
+ it { respond_to :route_prefix }
17
+ it { respond_to :route_collection_path }
18
+ it { respond_to :comments? }
19
+ it { respond_to :belongs_to? }
20
+ it { respond_to :action_items? }
21
+ it { respond_to :sidebar_sections? }
22
+
23
+ describe "Naming" do
24
+ it "implements #resource_name" do
25
+ expect { config.resource_name }.should_not raise_error
26
+ end
27
+
28
+ it "implements #plural_resource_name" do
29
+ expect { config.plural_resource_name }.should_not raise_error
30
+ end
31
+
32
+ describe "#camelized_resource_name" do
33
+ it "returns a camelized version of the resource_name" do
34
+ config.should_receive(:resource_name).and_return "My resource"
35
+ config.camelized_resource_name.should == "MyResource"
36
+ end
37
+ end
38
+
39
+ describe "#underscored_resource_name" do
40
+ it "returns the camelized_resource_name underscored" do
41
+ config.should_receive(:camelized_resource_name).and_return "MyResource"
42
+ config.underscored_resource_name.should == "my_resource"
43
+ end
44
+ end
45
+
46
+ describe "#plural_underscored_resource_name" do
47
+ it "returns the plural_camelized_resource_name underscored" do
48
+ config.should_receive(:plural_camelized_resource_name).and_return "MyResources"
49
+ config.plural_underscored_resource_name.should == "my_resources"
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "Menu" do
55
+ describe "menu item name" do
56
+ it "should be the plural resource name when not set" do
57
+ config.menu_item_name.should == config.plural_resource_name
58
+ end
59
+ it "should be settable" do
60
+ config.menu :label => "My Label"
61
+ config.menu_item_name.should == "My Label"
62
+ end
63
+ end
64
+
65
+ describe "#include_in_menu?" do
66
+ it "should be included in menu by default" do
67
+ config.include_in_menu?.should == true
68
+ end
69
+
70
+ it "should not be included in menu when menu set to false" do
71
+ config.menu false
72
+ config.include_in_menu?.should == false
73
+ end
74
+ end
75
+
76
+ describe "parent menu item name" do
77
+ it "should be nil when not set" do
78
+ config.parent_menu_item_name.should == nil
79
+ end
80
+ it "should return the name if set" do
81
+ config.tap do |c|
82
+ c.menu :parent => "Blog"
83
+ end.parent_menu_item_name.should == "Blog"
84
+ end
85
+ end
86
+
87
+ describe "menu item priority" do
88
+ it "should be 10 when not set" do
89
+ config.menu_item_priority.should == 10
90
+ end
91
+ it "should be settable" do
92
+ config.menu :priority => 2
93
+ config.menu_item_priority.should == 2
94
+ end
95
+ end
96
+
97
+ describe "menu item display if" do
98
+ it "should be a proc always returning true if not set" do
99
+ config.menu_item_display_if.should be_instance_of(Proc)
100
+ config.menu_item_display_if.call.should == true
101
+ end
102
+ it "should be settable" do
103
+ config.menu :if => proc { false }
104
+ config.menu_item_display_if.call.should == false
105
+ end
106
+ end
107
+ end
108
+ end
@@ -23,4 +23,48 @@ describe ActiveAdmin::Dashboards::DashboardController do
23
23
  end
24
24
  end
25
25
 
26
+ describe "conditionally displaying sections" do
27
+ before { ActiveAdmin::Dashboards.clear_all_sections! }
28
+ let(:controller){ Admin::DashboardController.new }
29
+
30
+ context "when :if not specified" do
31
+ before do
32
+ @section = ActiveAdmin::Dashboards.add_section('Stats').last
33
+ end
34
+
35
+ it "should include section" do
36
+ controller.send(:find_sections).should include(@section)
37
+ end
38
+ end
39
+
40
+ context "when :if option specified as a method" do
41
+ before do
42
+ @section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => :i_am_awesome?).last
43
+ end
44
+
45
+ it "should call the method of the same name" do
46
+ controller.should_receive(:i_am_awesome?).and_return(true)
47
+ controller.send(:find_sections).should include(@section)
48
+
49
+ controller.should_receive(:i_am_awesome?).and_return(false)
50
+ controller.send(:find_sections).should_not include(@section)
51
+ end
52
+ end
53
+
54
+ context "when :if option specified as block" do
55
+ before do
56
+ @proc = Proc.new { true }
57
+ @section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => proc {}).last
58
+ end
59
+
60
+ it "should evaluate the block" do
61
+ controller.should_receive(:instance_exec).with(&@proc).and_return(true)
62
+ controller.send(:find_sections).should include(@section)
63
+
64
+ controller.should_receive(:instance_exec).with(&@proc).and_return(false)
65
+ controller.send(:find_sections).should_not include(@section)
66
+ end
67
+ end
68
+ end
69
+
26
70
  end
@@ -12,6 +12,12 @@ describe ActiveAdmin::EventDispatcher do
12
12
  dispatcher.subscribers(test_event).size.should == 1
13
13
  end
14
14
 
15
+ it "should add a subscriber for multiple events" do
16
+ dispatcher.subscribe(test_event, test_event + "1"){ true }
17
+ dispatcher.subscribers(test_event).size.should == 1
18
+ dispatcher.subscribers(test_event + "1").size.should == 1
19
+ end
20
+
15
21
  it "should call the dispatch block with no arguments" do
16
22
  dispatcher.subscribe(test_event){ raise StandardError, "From Event Handler" }
17
23
  lambda {
@@ -56,6 +56,15 @@ describe ActiveAdmin::ViewHelpers::FilterFormHelper do
56
56
  it "should label a text field with search" do
57
57
  body.should have_tag('label', 'Search Title')
58
58
  end
59
+
60
+ it "should translate the label for text field" do
61
+ begin
62
+ I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :title => "Name" } } })
63
+ body.should have_tag('label', 'Search Name')
64
+ ensure
65
+ I18n.backend.reload!
66
+ end
67
+ end
59
68
  end
60
69
 
61
70
  describe "text attribute" do
@@ -65,19 +65,13 @@ describe ActiveAdmin::FormBuilder do
65
65
  end
66
66
 
67
67
  context "when polymorphic relationship" do
68
-
69
- let(:body) do
70
- comment = ActiveAdmin::Comment.new
71
-
72
- active_admin_form_for comment, :url => "admins/comments" do |f|
73
- f.inputs :resource
74
- end
75
-
76
- end
77
-
78
- it "should not generate any field" do
79
- body.should have_tag("form", :attributes => { :method => 'post' })
80
- body.should_not have_tag("select")
68
+ it "should raise error" do
69
+ lambda {
70
+ comment = ActiveAdmin::Comment.new
71
+ active_admin_form_for comment, :url => "admins/comments" do |f|
72
+ f.inputs :resource
73
+ end
74
+ }.should raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
81
75
  end
82
76
  end
83
77
 
@@ -215,7 +209,7 @@ describe ActiveAdmin::FormBuilder do
215
209
  body = build_form do |f|
216
210
  f.input :title, :wrapper_html => { :class => "important" }
217
211
  end
218
- body.should have_tag("li", :attributes => {:class => "string optional important"})
212
+ body.should have_tag("li", :attributes => {:class => "important string input optional stringish"})
219
213
  end
220
214
  end
221
215
 
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Namespace, "registering a page" do
4
+
5
+ let(:application){ ActiveAdmin::Application.new }
6
+
7
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
8
+
9
+ context "with no configuration" do
10
+ before do
11
+ namespace.register_page "Status"
12
+ end
13
+
14
+ it "should store the namespaced registered configuration" do
15
+ namespace.resources.keys.should include('Status')
16
+ end
17
+
18
+ it "should create a new controller in the default namespace" do
19
+ defined?(Admin::StatusController).should be_true
20
+ end
21
+
22
+ it "should create a menu item" do
23
+ namespace.load_menu!
24
+ namespace.menu["Status"].should be_an_instance_of(ActiveAdmin::MenuItem)
25
+ end
26
+ end # context "with no configuration"
27
+
28
+ context "with a block configuration" do
29
+ it "should be evaluated in the dsl" do
30
+ lambda {
31
+ namespace.register_page "Status" do
32
+ raise "Hello World"
33
+ end
34
+ }.should raise_error
35
+ end
36
+ end # context "with a block configuration"
37
+
38
+ describe "adding to the menu" do
39
+ describe "adding as a top level item" do
40
+ before do
41
+ namespace.register_page "Status"
42
+ namespace.load_menu!
43
+ end
44
+
45
+ it "should add a new menu item" do
46
+ namespace.menu['Status'].should_not be_nil
47
+ end
48
+ end # describe "adding as a top level item"
49
+
50
+ describe "adding as a child" do
51
+ before do
52
+ namespace.register_page "Status" do
53
+ menu :parent => 'Extra'
54
+ end
55
+ namespace.load_menu!
56
+ end
57
+ it "should generate the parent menu item" do
58
+ namespace.menu['Extra'].should_not be_nil
59
+ end
60
+ it "should generate its own child item" do
61
+ namespace.menu['Extra']['Status'].should_not be_nil
62
+ end
63
+ end # describe "adding as a child"
64
+
65
+ describe "disabling the menu" do
66
+ before do
67
+ namespace.register_page "Status" do
68
+ menu false
69
+ end
70
+ namespace.load_menu!
71
+ end
72
+ it "should not create a menu item" do
73
+ namespace.menu["Status"].should be_nil
74
+ end
75
+ end # describe "disabling the menu"
76
+
77
+ describe "setting menu priority" do
78
+ before do
79
+ namespace.register_page "Status" do
80
+ menu :priority => 2
81
+ end
82
+ namespace.load_menu!
83
+ end
84
+ it "should have a custom priority of 2" do
85
+ namespace.menu["Status"].priority.should == 2
86
+ end
87
+ end # describe "setting menu priority"
88
+
89
+ describe "setting a condition for displaying" do
90
+ before do
91
+ namespace.register_page "Status" do
92
+ menu :if => proc { false }
93
+ end
94
+ namespace.load_menu!
95
+ end
96
+ it "should have a proc returning false" do
97
+ namespace.menu["Status"].display_if_block.should be_instance_of(Proc)
98
+ namespace.menu["Status"].display_if_block.call.should == false
99
+ end
100
+ end # describe "setting a condition for displaying"
101
+ end # describe "adding to the menu"
102
+ end