activeadmin 0.5.0 → 0.5.1

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 (117) hide show
  1. data/.travis.yml +1 -1
  2. data/CHANGELOG.md +92 -1
  3. data/CONTRIBUTING.md +3 -3
  4. data/Gemfile +6 -5
  5. data/README.rdoc +6 -1
  6. data/Rakefile +2 -2
  7. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -2
  8. data/app/assets/stylesheets/active_admin/components/_comments.css.scss +1 -0
  9. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -1
  10. data/app/views/active_admin/resource/index.csv.erb +4 -1
  11. data/app/views/layouts/active_admin_logged_out.html.erb +3 -3
  12. data/docs/0-installation.md +0 -7
  13. data/docs/1-general-configuration.md +37 -0
  14. data/docs/11-decorators.md +48 -0
  15. data/docs/12-arbre-components.md +145 -0
  16. data/docs/2-resource-customization.md +23 -6
  17. data/docs/3-index-pages.md +5 -0
  18. data/docs/4-csv-format.md +11 -2
  19. data/docs/8-custom-actions.md +2 -2
  20. data/features/breadcrumb.feature +27 -0
  21. data/features/decorators.feature +41 -0
  22. data/features/i18n.feature +7 -0
  23. data/features/index/format_as_csv.feature +40 -3
  24. data/features/index/index_as_table.feature +6 -6
  25. data/features/step_definitions/format_steps.rb +6 -1
  26. data/lib/active_admin.rb +1 -1
  27. data/lib/active_admin/application.rb +15 -7
  28. data/lib/active_admin/comments/comment.rb +4 -2
  29. data/lib/active_admin/csv_builder.rb +2 -1
  30. data/lib/active_admin/devise.rb +1 -0
  31. data/lib/active_admin/dsl.rb +25 -0
  32. data/lib/active_admin/filters/dsl.rb +9 -0
  33. data/lib/active_admin/filters/forms.rb +2 -0
  34. data/lib/active_admin/filters/resource_extension.rb +32 -2
  35. data/lib/active_admin/form_builder.rb +29 -12
  36. data/lib/active_admin/inputs.rb +1 -0
  37. data/lib/active_admin/inputs/filter_boolean_input.rb +40 -0
  38. data/lib/active_admin/inputs/filter_select_input.rb +5 -1
  39. data/lib/active_admin/locales/bg.yml +1 -0
  40. data/lib/active_admin/locales/ca.yml +1 -0
  41. data/lib/active_admin/locales/cs.yml +9 -1
  42. data/lib/active_admin/locales/da.yml +1 -0
  43. data/lib/active_admin/locales/de.yml +16 -3
  44. data/lib/active_admin/locales/en.yml +1 -0
  45. data/lib/active_admin/locales/es.yml +1 -0
  46. data/lib/active_admin/locales/fr.yml +5 -1
  47. data/lib/active_admin/locales/he.yml +3 -2
  48. data/lib/active_admin/locales/hr.yml +1 -0
  49. data/lib/active_admin/locales/hu.yml +1 -0
  50. data/lib/active_admin/locales/it.yml +5 -4
  51. data/lib/active_admin/locales/ja.yml +12 -12
  52. data/lib/active_admin/locales/ko.yml +1 -0
  53. data/lib/active_admin/locales/lt.yml +81 -0
  54. data/lib/active_admin/locales/lv.yml +2 -1
  55. data/lib/active_admin/locales/nl.yml +1 -0
  56. data/lib/active_admin/locales/no-NB.yml +1 -0
  57. data/lib/active_admin/locales/pl.yml +1 -0
  58. data/lib/active_admin/locales/pt-BR.yml +3 -2
  59. data/lib/active_admin/locales/ro.yml +1 -0
  60. data/lib/active_admin/locales/ru.yml +7 -6
  61. data/lib/active_admin/locales/sv-SE.yml +1 -0
  62. data/lib/active_admin/locales/tr.yml +3 -2
  63. data/lib/active_admin/locales/vi.yml +1 -0
  64. data/lib/active_admin/locales/zh-CN.yml +1 -0
  65. data/lib/active_admin/locales/zh-TW.yml +1 -0
  66. data/lib/active_admin/menu_item.rb +6 -0
  67. data/lib/active_admin/page.rb +3 -0
  68. data/lib/active_admin/page_presenter.rb +2 -0
  69. data/lib/active_admin/resource.rb +12 -1
  70. data/lib/active_admin/resource/menu.rb +8 -1
  71. data/lib/active_admin/resource_controller.rb +3 -1
  72. data/lib/active_admin/resource_controller/collection.rb +1 -1
  73. data/lib/active_admin/resource_controller/decorators.rb +19 -0
  74. data/lib/active_admin/resource_dsl.rb +1 -1
  75. data/lib/active_admin/version.rb +1 -1
  76. data/lib/active_admin/view_helpers.rb +1 -0
  77. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -1
  78. data/lib/active_admin/view_helpers/download_format_links_helper.rb +50 -0
  79. data/lib/active_admin/view_helpers/fields_for.rb +4 -0
  80. data/lib/active_admin/view_helpers/flash_helper.rb +13 -0
  81. data/lib/active_admin/views/components/paginated_collection.rb +2 -11
  82. data/lib/active_admin/views/components/table_for.rb +21 -27
  83. data/lib/active_admin/views/footer.rb +3 -1
  84. data/lib/active_admin/views/index_as_block.rb +1 -1
  85. data/lib/active_admin/views/index_as_grid.rb +1 -1
  86. data/lib/active_admin/views/pages/base.rb +3 -3
  87. data/lib/active_admin/views/pages/index.rb +1 -7
  88. data/lib/active_admin/views/title_bar.rb +6 -3
  89. data/lib/generators/active_admin/devise/devise_generator.rb +1 -1
  90. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +6 -3
  91. data/lib/generators/active_admin/install/templates/admin_user.rb.erb +1 -1
  92. data/lib/generators/active_admin/install/templates/dashboard.rb +2 -2
  93. data/lib/generators/active_admin/install/templates/migrations/2_move_admin_notes_to_comments.rb +2 -1
  94. data/spec/integration/memory_spec.rb +1 -1
  95. data/spec/support/rails_template.rb +41 -2
  96. data/spec/support/rails_template_with_data.rb +2 -1
  97. data/spec/support/templates/en.yml +2 -0
  98. data/spec/support/templates/post_decorator.rb +53 -0
  99. data/spec/unit/application_spec.rb +17 -4
  100. data/spec/unit/belongs_to_spec.rb +1 -1
  101. data/spec/unit/config_shared_examples.rb +15 -7
  102. data/spec/unit/controller_filters_spec.rb +8 -8
  103. data/spec/unit/csv_builder_spec.rb +10 -0
  104. data/spec/unit/devise_spec.rb +28 -7
  105. data/spec/unit/filters/filter_form_builder_spec.rb +24 -0
  106. data/spec/unit/filters/resource_spec.rb +15 -1
  107. data/spec/unit/form_builder_spec.rb +4 -0
  108. data/spec/unit/resource_controller_spec.rb +67 -3
  109. data/spec/unit/resource_spec.rb +17 -0
  110. data/spec/unit/view_helpers/download_format_links_helper_spec.rb +39 -0
  111. data/spec/unit/view_helpers/fields_for_spec.rb +5 -0
  112. data/spec/unit/views/components/table_for_spec.rb +31 -0
  113. data/spec/unit/views/pages/layout_spec.rb +1 -1
  114. data/spec/unit/views/pages/show_spec.rb +21 -0
  115. data/tasks/parallel_tests.rake +60 -0
  116. data/tasks/test.rake +2 -1
  117. metadata +44 -26
@@ -30,7 +30,7 @@ describe ActiveAdmin::Application do
30
30
  application.site_title = "New Title"
31
31
  application.site_title.should == "New Title"
32
32
  end
33
-
33
+
34
34
  it "should store the site's title link" do
35
35
  application.site_title_link.should == ""
36
36
  end
@@ -39,11 +39,11 @@ describe ActiveAdmin::Application do
39
39
  application.site_title_link = "http://www.mygreatsite.com"
40
40
  application.site_title_link.should == "http://www.mygreatsite.com"
41
41
  end
42
-
42
+
43
43
  it "should store the site's title image" do
44
44
  application.site_title_image.should == ""
45
45
  end
46
-
46
+
47
47
  it "should set the site's title image" do
48
48
  application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
49
49
  application.site_title_image.should == "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
@@ -53,7 +53,7 @@ describe ActiveAdmin::Application do
53
53
  application.view_factory.should be_an_instance_of(ActiveAdmin::ViewFactory)
54
54
  end
55
55
 
56
- it "should have deprecated admin notes by default" do
56
+ it "should have deprecated admin notes by default" do
57
57
  application.admin_notes.should be_nil
58
58
  end
59
59
 
@@ -80,6 +80,19 @@ describe ActiveAdmin::Application do
80
80
  end
81
81
  end
82
82
 
83
+ describe "inheritable settings" do
84
+ it "should set csv_options" do
85
+ application.csv_options.should == {}
86
+ end
87
+
88
+ context "when deprecated" do
89
+ it "should set and warn csv_column_separator" do
90
+ ActiveAdmin::Deprecation.should_receive(:warn)
91
+ application.csv_column_separator.should == ','
92
+ end
93
+ end
94
+ end
95
+
83
96
  describe "files in load path" do
84
97
  it "should load files in the first level directory" do
85
98
  application.files_in_load_path.should include(File.expand_path("app/admin/dashboard.rb", Rails.root))
@@ -4,7 +4,7 @@ describe ActiveAdmin::Resource::BelongsTo do
4
4
 
5
5
 
6
6
  let(:application){ ActiveAdmin::Application.new }
7
- let(:namespace){ Namespace.new(application, :admin) }
7
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
8
8
  let(:post){ namespace.register(Post) }
9
9
  let(:belongs_to){ ActiveAdmin::Resource::BelongsTo.new(post, :user) }
10
10
 
@@ -33,16 +33,20 @@ shared_examples_for "ActiveAdmin::Config" do
33
33
  describe "Menu" do
34
34
  describe "menu item" do
35
35
 
36
- it "initializes a new menu item with defaults" do
36
+ it "initializes a new menu item with defaults" do
37
37
  config.menu_item.label.should == config.plural_resource_label
38
- end
38
+ end
39
39
 
40
- it "initialize a new menu item with custom options" do
41
- config.menu :label => "Hello"
42
- config.menu_item.label.should == "Hello"
43
- end
40
+ it "initialize a new menu item with custom options" do
41
+ config.menu :label => "Hello"
42
+ config.menu_item.label.should == "Hello"
43
+ end
44
44
 
45
+ it "initialize a new menu item with label as Proc object" do
46
+ config.menu :label => proc { "Hello" }
47
+ config.menu_item.label.should == "Hello"
45
48
  end
49
+ end
46
50
 
47
51
  describe "#include_in_menu?" do
48
52
  it "should be included in menu by default" do
@@ -62,10 +66,14 @@ shared_examples_for "ActiveAdmin::Config" do
62
66
  end
63
67
 
64
68
  it "should return the name if set" do
65
- config.menu :parent => "Blog"
69
+ config.menu :parent => "Blog"
66
70
  config.parent_menu_item_name.should == "Blog"
67
71
  end
68
72
 
73
+ it "initialize a new parent menu item with label as Proc object" do
74
+ config.menu :parent => proc{ "Blog" }
75
+ config.parent_menu_item_name.should == "Blog"
76
+ end
69
77
  end
70
78
 
71
79
  end
@@ -4,29 +4,29 @@ describe ActiveAdmin, "filters" do
4
4
  let(:application){ ActiveAdmin::Application.new }
5
5
 
6
6
  describe "before filters" do
7
- it "should add a new before filter to ActiveAdmin::ResourceController" do
8
- ActiveAdmin::ResourceController.should_receive(:before_filter).and_return(true)
7
+ it "should add a new before filter to ActiveAdmin::BaseController" do
8
+ ActiveAdmin::BaseController.should_receive(:before_filter).and_return(true)
9
9
  application.before_filter :my_filter, :only => :show
10
10
  end
11
11
  end
12
12
 
13
13
  describe "skip before filters" do
14
- it "should add a new skip before filter to ActiveAdmin::ResourceController" do
15
- ActiveAdmin::ResourceController.should_receive(:skip_before_filter).and_return(true)
14
+ it "should add a new skip before filter to ActiveAdmin::BaseController" do
15
+ ActiveAdmin::BaseController.should_receive(:skip_before_filter).and_return(true)
16
16
  application.skip_before_filter :my_filter, :only => :show
17
17
  end
18
18
  end
19
19
 
20
20
  describe "after filters" do
21
- it "should add a new after filter to ActiveAdmin::ResourceController" do
22
- ActiveAdmin::ResourceController.should_receive(:after_filter).and_return(true)
21
+ it "should add a new after filter to ActiveAdmin::BaseController" do
22
+ ActiveAdmin::BaseController.should_receive(:after_filter).and_return(true)
23
23
  application.after_filter :my_filter, :only => :show
24
24
  end
25
25
  end
26
26
 
27
27
  describe "around filters" do
28
- it "should add a new around filter to ActiveAdmin::ResourceController" do
29
- ActiveAdmin::ResourceController.should_receive(:around_filter).and_return(true)
28
+ it "should add a new around filter to ActiveAdmin::BaseController" do
29
+ ActiveAdmin::BaseController.should_receive(:around_filter).and_return(true)
30
30
  application.around_filter :my_filter, :only => :show
31
31
  end
32
32
  end
@@ -90,4 +90,14 @@ describe ActiveAdmin::CSVBuilder do
90
90
  end
91
91
  end
92
92
 
93
+ context "with csv_options" do
94
+ let(:builder) do
95
+ ActiveAdmin::CSVBuilder.new :options => {:force_quotes => true}
96
+ end
97
+
98
+ it "should have proper separator" do
99
+ builder.options.should == {:force_quotes => true}
100
+ end
101
+ end
102
+
93
103
  end
@@ -12,16 +12,37 @@ describe ActiveAdmin::Devise::Controller do
12
12
  end
13
13
 
14
14
  let(:controller) { controller_class.new }
15
+
16
+ context 'with a RAILS_RELATIVE_URL_ROOT set' do
17
+
18
+ before { Rails.configuration.action_controller[:relative_url_root] = '/foo' }
19
+
20
+ it "should set the root path to the default namespace" do
21
+ controller.root_path.should == "/foo/admin"
22
+ end
15
23
 
16
- it "should set the root path to the default namespace" do
17
- controller.root_path.should == "/admin"
24
+ it "should set the root path to '/' when no default namespace" do
25
+ ActiveAdmin.application.stub!(:default_namespace => false)
26
+ controller.root_path.should == "/foo/"
27
+ end
28
+
18
29
  end
19
-
20
- it "should set the root path to '/' when no default namespace" do
21
- ActiveAdmin.application.stub!(:default_namespace => false)
22
- controller.root_path.should == "/"
30
+
31
+ context 'without a RAILS_RELATIVE_URL_ROOT set' do
32
+
33
+ before { Rails.configuration.action_controller[:relative_url_root] = nil }
34
+
35
+ it "should set the root path to the default namespace" do
36
+ controller.root_path.should == "/admin"
37
+ end
38
+
39
+ it "should set the root path to '/' when no default namespace" do
40
+ ActiveAdmin.application.stub!(:default_namespace => false)
41
+ controller.root_path.should == "/"
42
+ end
43
+
23
44
  end
24
-
45
+
25
46
  describe "#config" do
26
47
  let(:config) { ActiveAdmin::Devise.config }
27
48
 
@@ -119,6 +119,28 @@ describe ActiveAdmin::Filters::ViewHelper do
119
119
  it "should select the option which is currently being filtered"
120
120
  end
121
121
 
122
+ describe "boolean attribute" do
123
+ context "boolean datatypes" do
124
+ let(:body) { filter :starred }
125
+
126
+ it "should create a check box for equals to" do
127
+ body.should have_tag("input", :attributes => {
128
+ :name => "q[starred_eq]",
129
+ :type => "checkbox" })
130
+ end
131
+ end
132
+
133
+ context "non-boolean data types" do
134
+ let(:body) { filter :title_is_present, :as => :boolean }
135
+
136
+ it "should create a check box for equals to" do
137
+ body.should have_tag("input", :attributes => {
138
+ :name => "q[title_is_present]",
139
+ :type => "checkbox" })
140
+ end
141
+ end
142
+ end
143
+
122
144
  describe "belong to" do
123
145
  before do
124
146
  @john = User.create :first_name => "John", :last_name => "Doe", :username => "john_doe"
@@ -135,6 +157,8 @@ describe ActiveAdmin::Filters::ViewHelper do
135
157
  it "should render as belongs to select" do
136
158
  body.should have_tag("select", :attributes => {
137
159
  :name => "q[author_id_eq]"})
160
+ body.should have_tag("option", "john_doe", :attributes => {
161
+ :value => @john.id })
138
162
  body.should have_tag("option", "jane_doe", :attributes => {
139
163
  :value => @jane.id })
140
164
  end
@@ -9,7 +9,7 @@ describe ActiveAdmin::Filters::ResourceExtension do
9
9
 
10
10
  it "should return the defaults if no filters are set" do
11
11
  resource.filters.map{|f| f[:attribute].to_s }.sort.should == %w{
12
- author body category created_at published_at title updated_at
12
+ author body category created_at published_at starred title updated_at
13
13
  }
14
14
  end
15
15
 
@@ -28,6 +28,12 @@ describe ActiveAdmin::Filters::ResourceExtension do
28
28
  resource.filters.should be_empty
29
29
  end
30
30
 
31
+ it "should remove a filter" do
32
+ resource.filters.should include({:attribute => :author})
33
+ resource.remove_filter :author
34
+ resource.filters.should_not include({:attribute => :author})
35
+ end
36
+
31
37
  it "should add a filter" do
32
38
  resource.add_filter :title
33
39
  resource.filters.should == [{:attribute => :title}]
@@ -38,6 +44,14 @@ describe ActiveAdmin::Filters::ResourceExtension do
38
44
  resource.filters.should == [{:attribute => :title, :as => :string}]
39
45
  end
40
46
 
47
+ it "should preserve default filters" do
48
+ resource.preserve_default_filters!
49
+ resource.add_filter :count, :as => :string
50
+ resource.filters.map{|f| f[:attribute].to_s }.sort.should == %w{
51
+ author body category count created_at published_at starred title updated_at
52
+ }
53
+ end
54
+
41
55
  it "should raise an exception if trying to add a filter when they are disabled" do
42
56
  resource.filters = false
43
57
  expect {
@@ -338,6 +338,10 @@ describe ActiveAdmin::FormBuilder do
338
338
  Capybara.string(body).should have_css(".has_many > fieldset > ol > li > a", :class => "button", :href => "#", :content => "Delete")
339
339
  end
340
340
 
341
+ it "should include the nested record's class name in the js" do
342
+ body.should have_tag("a", :attributes => { :onclick => /NEW_POST_RECORD/ })
343
+ end
344
+
341
345
  it "should add a link to add new nested records" do
342
346
  Capybara.string(body).should have_css(".has_many > fieldset > ol > li > a", :class => "button", :href => "#", :content => "Add New Post")
343
347
  end
@@ -55,6 +55,7 @@ describe ActiveAdmin::ResourceController do
55
55
  end
56
56
  end
57
57
 
58
+
58
59
  describe "callbacks" do
59
60
  let(:application){ ::ActiveAdmin::Application.new }
60
61
  let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
@@ -162,6 +163,69 @@ end
162
163
 
163
164
  describe Admin::PostsController, :type => "controller" do
164
165
 
166
+ describe 'retreiving the resource' do
167
+ let(:controller){ Admin::PostsController.new }
168
+ let(:post) { Post.new :title => "An incledibly unique Post Title" }
169
+ before do
170
+ Post.stub(:find).and_return(post)
171
+ controller.class_eval { public :resource }
172
+ controller.stub(:params).and_return({ :id => '1' })
173
+ end
174
+
175
+ subject { controller.resource }
176
+ it "returns a Post" do
177
+ subject.should be_kind_of(Post)
178
+ end
179
+
180
+ context 'with a decorator' do
181
+ let(:config) { controller.class.active_admin_config }
182
+ before { config.decorator_class_name = '::PostDecorator' }
183
+ it 'returns a PostDecorator' do
184
+ subject.should be_kind_of(PostDecorator)
185
+ end
186
+
187
+ it 'returns a PostDecorator that wraps the post' do
188
+ subject.title.should == post.title
189
+ end
190
+ end
191
+ end
192
+
193
+ describe 'retreiving the resource collection' do
194
+ let(:controller){ Admin::PostsController.new }
195
+ before do
196
+ Post.create!(:title => "An incledibly unique Post Title") if Post.count == 0
197
+ controller.class_eval { public :collection }
198
+ end
199
+
200
+ subject { controller.collection }
201
+
202
+ it {
203
+ pending # doesn't pass when running whole spec suite (WTF)
204
+ should be_kind_of(ActiveRecord::Relation)
205
+ }
206
+
207
+ it "returns a collection of posts" do
208
+ pending # doesn't pass when running whole spec suite (WTF)
209
+ subject.first.should be_kind_of(Post)
210
+ end
211
+
212
+ context 'with a decorator' do
213
+ let(:config) { controller.class.active_admin_config }
214
+ before { config.decorator_class_name = '::PostDecorator' }
215
+
216
+ it 'returns a PostDecorator' do
217
+ pending # doesn't pass when running whole spec suite (WTF)
218
+ subject.should be_kind_of(PostDecorator::DecoratedEnumerableProxy)
219
+ end
220
+
221
+ it 'returns a PostDecorator that wraps the post' do
222
+ pending # doesn't pass when running whole spec suite (WTF)
223
+ subject.first.title.should == Post.first.title
224
+ end
225
+ end
226
+ end
227
+
228
+
165
229
  describe "performing batch_action" do
166
230
  let(:controller){ Admin::PostsController.new }
167
231
  before do
@@ -171,7 +235,7 @@ describe Admin::PostsController, :type => "controller" do
171
235
 
172
236
  controller.class.active_admin_config.stub!(:batch_actions).and_return([batch_action])
173
237
  end
174
-
238
+
175
239
  describe "when params batch_action matches existing BatchAction" do
176
240
  it "should call the block with args" do
177
241
  pending # dont know how to check if the block was called
@@ -181,7 +245,7 @@ describe Admin::PostsController, :type => "controller" do
181
245
  describe "when params batch_action doesn't match a BatchAction" do
182
246
  it "should raise an error" do
183
247
  pending # doesn't pass when running whole spec suite (WTF)
184
-
248
+
185
249
  lambda {
186
250
  post(:batch_action, :batch_action => "derp", :collection_selection => ["1"])
187
251
  }.should raise_error("Couldn't find batch action \"derp\"")
@@ -191,7 +255,7 @@ describe Admin::PostsController, :type => "controller" do
191
255
  describe "when params batch_action is blank" do
192
256
  it "should raise an error" do
193
257
  pending # doesn't pass when running whole spec suite (WTF)
194
-
258
+
195
259
  lambda {
196
260
  post(:batch_action, :collection_selection => ["1"])
197
261
  }.should raise_error("Couldn't find batch action \"\"")
@@ -28,6 +28,23 @@ module ActiveAdmin
28
28
  end
29
29
  end
30
30
 
31
+ describe '#decorator_class' do
32
+ it 'returns nil by default' do
33
+ config.decorator_class.should be_nil
34
+ end
35
+ context 'when a decorator is defined' do
36
+ let(:resource) { namespace.register(Post) { decorate_with PostDecorator } }
37
+ specify '#decorator_class_name should return PostDecorator' do
38
+ resource.decorator_class_name.should == '::PostDecorator'
39
+ end
40
+
41
+ it 'returns the decorator class' do
42
+ resource.decorator_class.should == PostDecorator
43
+ end
44
+ end
45
+ end
46
+
47
+
31
48
  describe "controller name" do
32
49
  it "should return a namespaced controller name" do
33
50
  config.controller_name.should == "Admin::CategoriesController"
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::ViewHelpers::DownloadFormatLinksHelper do
4
+
5
+ describe "class methods" do
6
+ before :each do
7
+
8
+ begin
9
+ # The mime type to be used in respond_to |format| style web-services in rails
10
+ Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
11
+ rescue NameError
12
+ puts "Mime module not defined. Skipping registration of xlsx"
13
+ end
14
+
15
+ class Foo
16
+ include ActiveAdmin::ViewHelpers::DownloadFormatLinksHelper
17
+ end
18
+ end
19
+
20
+ it "extends the class to add a formats class method that returns the default formats." do
21
+ Foo.formats.should == [:csv, :xml, :json]
22
+ end
23
+
24
+ it "does not let you alter the formats array directly" do
25
+ Foo.formats << :xlsx
26
+ Foo.formats.should == [:csv, :xml, :json]
27
+ end
28
+
29
+ it "allows us to add new formats" do
30
+ Foo.add_format :xlsx
31
+ Foo.formats.should == [:csv, :xml, :json, :xlsx]
32
+ end
33
+
34
+ it "raises an exception if you provide an unregisterd mime type extension" do
35
+ expect{ Foo.add_format :hoge }.to raise_error
36
+ end
37
+
38
+ end
39
+ end