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
@@ -19,7 +19,7 @@ describe Arbre::HTML::Tag do
19
19
  end
20
20
 
21
21
  describe "creating a tag 'for' an object" do
22
- let(:model_name){ mock(:singular => "resource_class")}
22
+ let(:model_name){ mock(:singular => "resource_class", :param_key => 'resource_class')}
23
23
  let(:resource_class){ mock(:model_name => model_name) }
24
24
  let(:resource){ mock(:class => resource_class, :to_key => ['5'])}
25
25
 
@@ -6,7 +6,7 @@ describe Arbre do
6
6
 
7
7
  it "should render a single element" do
8
8
  content = span("Hello World")
9
- content.to_html.should == <<-HTML
9
+ content.to_s.should == <<-HTML
10
10
  <span>Hello World</span>
11
11
  HTML
12
12
  end
@@ -15,7 +15,7 @@ HTML
15
15
  content = span do
16
16
  span "Hello World"
17
17
  end
18
- content.to_html.should == <<-HTML
18
+ content.to_s.should == <<-HTML
19
19
  <span>
20
20
  <span>Hello World</span>
21
21
  </span>
@@ -28,7 +28,7 @@ HTML
28
28
  li "Second"
29
29
  li "Third"
30
30
  end
31
- content.to_html.should == <<-HTML
31
+ content.to_s.should == <<-HTML
32
32
  <ul>
33
33
  <li>First</li>
34
34
  <li>Second</li>
@@ -51,7 +51,7 @@ HTML
51
51
  li first
52
52
  li second
53
53
  end
54
- content.to_html.should == <<-EOS
54
+ content.to_s.should == <<-EOS
55
55
  <ul>
56
56
  <li>First</li>
57
57
  <li>Second</li>
@@ -66,7 +66,7 @@ EOS
66
66
  li
67
67
  end
68
68
  end
69
- content.to_html.should == <<-HTML
69
+ content.to_s.should == <<-HTML
70
70
  <div>
71
71
  <ul></ul>
72
72
  <li>
@@ -82,7 +82,7 @@ HTML
82
82
  li
83
83
  end
84
84
  end
85
- content.to_html.should == <<-HTML
85
+ content.to_s.should == <<-HTML
86
86
  <div>
87
87
  <ul>
88
88
  <li></li>
@@ -95,7 +95,7 @@ HTML
95
95
  content = div do
96
96
  span(ul(li))
97
97
  end
98
- content.to_html.should == <<-HTML
98
+ content.to_s.should == <<-HTML
99
99
  <div>
100
100
  <span>
101
101
  <ul>
@@ -113,7 +113,7 @@ HTML
113
113
  li
114
114
  end
115
115
  end
116
- content.to_html.should == <<-HTML
116
+ content.to_s.should == <<-HTML
117
117
  <div id="my-tag">
118
118
  <ul>
119
119
  <li></li>
@@ -131,12 +131,22 @@ HTML
131
131
  item.parent.should == list
132
132
  end
133
133
 
134
- it "should set a string content return value with no children" do
135
- li do
136
- "Hello World"
137
- end.to_html.should == <<-HTML
138
- <li>Hello World</li>
139
- HTML
134
+
135
+ ["Hello World", 1, 1.5].each do |value|
136
+ it "should append the return value of '#{value}' when no other children added to the DOM" do
137
+ li do
138
+ value
139
+ end.to_s.should == "<li>#{value}</li>\n"
140
+ end
141
+ end
142
+
143
+ ["Hello World", 1, 1.5].each do |value|
144
+ it "should not append the return value of '#{value}' when children have been added to the DOM" do
145
+ li do
146
+ text_node("Already Added")
147
+ value
148
+ end.to_s.should == "<li>Already Added</li>\n"
149
+ end
140
150
  end
141
151
 
142
152
  describe "text nodes" do
@@ -150,19 +160,19 @@ HTML
150
160
  describe "self-closing nodes" do
151
161
  it "should not self-close script tags" do
152
162
  tag = script :type => 'text/javascript'
153
- tag.to_html.should == <<-HTML
163
+ tag.to_s.should == <<-HTML
154
164
  <script type="text/javascript"></script>
155
165
  HTML
156
166
  end
157
167
  it "should self-close meta tags" do
158
168
  tag = meta :content => "text/html; charset=utf-8"
159
- tag.to_html.should == <<-HTML
169
+ tag.to_s.should == <<-HTML
160
170
  <meta content="text/html; charset=utf-8\"/>
161
171
  HTML
162
172
  end
163
173
  it "should self-close link tags" do
164
174
  tag = link :rel => "stylesheet"
165
- tag.to_html.should == <<-HTML
175
+ tag.to_s.should == <<-HTML
166
176
  <link rel="stylesheet"/>
167
177
  HTML
168
178
  end
@@ -170,17 +180,17 @@ HTML
170
180
 
171
181
  describe "html safe" do
172
182
  it "should escape the contents" do
173
- span("<br />").to_html.should == <<-HTML
183
+ span("<br />").to_s.should == <<-HTML
174
184
  <span>&lt;br /&gt;</span>
175
185
  HTML
176
186
  end
177
187
 
178
188
  it "should return html safe strings" do
179
- span("<br />").to_html.should be_html_safe
189
+ span("<br />").to_s.should be_html_safe
180
190
  end
181
191
 
182
192
  it "should not escape html passed in" do
183
- span(span("<br />")).to_html.should == <<-HTML
193
+ span(span("<br />")).to_s.should == <<-HTML
184
194
  <span>
185
195
  <span>&lt;br /&gt;</span>
186
196
  </span>
@@ -192,7 +202,7 @@ HTML
192
202
  span {
193
203
  "<br />"
194
204
  }
195
- }.to_html.should == <<-HTML
205
+ }.to_s.should == <<-HTML
196
206
  <span>
197
207
  <span>&lt;br /&gt;</span>
198
208
  </span>
@@ -200,7 +210,7 @@ HTML
200
210
  end
201
211
 
202
212
  it "should escape the contents of attributes" do
203
- span(:class => "<br />").to_html.should == <<-HTML
213
+ span(:class => "<br />").to_s.should == <<-HTML
204
214
  <span class="&lt;br /&gt;"></span>
205
215
  HTML
206
216
  end
@@ -13,14 +13,20 @@ describe ActiveAdmin::AssetRegistration do
13
13
 
14
14
  it "should register a stylesheet file" do
15
15
  MockRegistration.register_stylesheet "active_admin.css"
16
- MockRegistration.stylesheets.should == ["active_admin.css"]
16
+ MockRegistration.stylesheets.length.should == 1
17
+ MockRegistration.stylesheets.first.path.should == "active_admin.css"
17
18
  end
18
19
 
19
20
  it "should clear all existing stylesheets" do
20
21
  MockRegistration.register_stylesheet "active_admin.css"
21
- MockRegistration.stylesheets.should == ["active_admin.css"]
22
+ MockRegistration.stylesheets.length.should == 1
22
23
  MockRegistration.clear_stylesheets!
23
- MockRegistration.stylesheets.should == []
24
+ MockRegistration.stylesheets.length.should == 0
25
+ end
26
+
27
+ it "should allow media option when registering stylesheet" do
28
+ MockRegistration.register_stylesheet "active_admin.css", :media => :print
29
+ MockRegistration.stylesheets.first.options[:media].should == :print
24
30
  end
25
31
 
26
32
  it "should register a javascript file" do
@@ -13,7 +13,7 @@ describe "auto linking resources" do
13
13
  include ActiveAdmin::ViewHelpers::DisplayHelper
14
14
 
15
15
  let(:active_admin_config) { AutoLinkMockResource.new(namespace) }
16
- let(:namespace){ ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin) }
16
+ let(:active_admin_namespace){ ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin) }
17
17
  let(:post){ Post.create! :title => "Hello World" }
18
18
 
19
19
  def admin_post_path(post)
@@ -28,7 +28,7 @@ describe "auto linking resources" do
28
28
 
29
29
  context "when the resource is registered" do
30
30
  before do
31
- namespace.register Post
31
+ active_admin_namespace.register Post
32
32
  end
33
33
  it "should return a link with the display name of the object" do
34
34
  self.should_receive(:link_to).with("Hello World", admin_post_path(post))
@@ -0,0 +1,28 @@
1
+ # Required methods:
2
+ # * controller_class
3
+ # * controller
4
+ #
5
+ shared_examples_for "BaseController" do
6
+ let(:controller_class) { described_class }
7
+
8
+ describe "Menu" do
9
+ describe "setting the current tab" do
10
+ before do
11
+ controller.stub!(:active_admin_config => resource, :parent? => true)
12
+ controller.send :set_current_tab # Run the before filter
13
+ end
14
+ subject{ controller.instance_variable_get(:@current_tab) }
15
+
16
+ context "when menu item name is 'Resources' without a parent menu item" do
17
+ let(:resource){ mock(:menu_item_name => "Resources", :parent_menu_item_name => nil, :belongs_to? => false) }
18
+ it { should == "Resources" }
19
+ end
20
+
21
+ context "when there is a parent menu item of 'Admin'" do
22
+ let(:resource){ mock(:parent_menu_item_name => "Admin", :menu_item_name => "Resources", :belongs_to? => false) }
23
+ it { should == "Admin/Resources" }
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -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,119 @@
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
+ it "implements #safe_resource_name" do
33
+ expect { config.safe_resource_name }.should_not raise_error
34
+ end
35
+
36
+ describe "#camelized_resource_name" do
37
+ it "returns a camelized version of the safe_resource_name" do
38
+ config.should_receive(:safe_resource_name).and_return "My resource"
39
+ config.camelized_resource_name.should == "MyResource"
40
+ end
41
+ end
42
+
43
+ describe "#plural_camelized_resource_name" do
44
+ it "returns a camelized version of the plural_safe_resource_name" do
45
+ config.should_receive(:safe_resource_name).and_return "My resource"
46
+ config.camelized_resource_name.should == "MyResource"
47
+ end
48
+ end
49
+
50
+ describe "#underscored_resource_name" do
51
+ it "returns the camelized_resource_name underscored" do
52
+ config.should_receive(:camelized_resource_name).and_return "MyResource"
53
+ config.underscored_resource_name.should == "my_resource"
54
+ end
55
+ end
56
+
57
+ describe "#plural_underscored_resource_name" do
58
+ it "returns the plural_camelized_resource_name underscored" do
59
+ config.should_receive(:plural_camelized_resource_name).and_return "MyResources"
60
+ config.plural_underscored_resource_name.should == "my_resources"
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "Menu" do
66
+ describe "menu item name" do
67
+ it "should be the plural resource name when not set" do
68
+ config.menu_item_name.should == config.plural_resource_name
69
+ end
70
+ it "should be settable" do
71
+ config.menu :label => "My Label"
72
+ config.menu_item_name.should == "My Label"
73
+ end
74
+ end
75
+
76
+ describe "#include_in_menu?" do
77
+ it "should be included in menu by default" do
78
+ config.include_in_menu?.should == true
79
+ end
80
+
81
+ it "should not be included in menu when menu set to false" do
82
+ config.menu false
83
+ config.include_in_menu?.should == false
84
+ end
85
+ end
86
+
87
+ describe "parent menu item name" do
88
+ it "should be nil when not set" do
89
+ config.parent_menu_item_name.should == nil
90
+ end
91
+ it "should return the name if set" do
92
+ config.tap do |c|
93
+ c.menu :parent => "Blog"
94
+ end.parent_menu_item_name.should == "Blog"
95
+ end
96
+ end
97
+
98
+ describe "menu item priority" do
99
+ it "should be 10 when not set" do
100
+ config.menu_item_priority.should == 10
101
+ end
102
+ it "should be settable" do
103
+ config.menu :priority => 2
104
+ config.menu_item_priority.should == 2
105
+ end
106
+ end
107
+
108
+ describe "menu item display if" do
109
+ it "should be a proc always returning true if not set" do
110
+ config.menu_item_display_if.should be_instance_of(Proc)
111
+ config.menu_item_display_if.call.should == true
112
+ end
113
+ it "should be settable" do
114
+ config.menu :if => proc { false }
115
+ config.menu_item_display_if.call.should == false
116
+ end
117
+ end
118
+ end
119
+ end