Skip to content

Commit fe30d58

Browse files
committed
a bit of a cleanup
1 parent b6f01bf commit fe30d58

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

app/controllers/comfy/admin/cms/files_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ def new
4040
end
4141

4242
def create
43-
@file.category_ids = @site.categories.where(label: params[:category]).inject({}) {|hash, category| hash.merge category.id => 1} if params[:category]
43+
if params[:category]
44+
ids = @site.categories.of_type('Comfy::Cms::File')
45+
.where(:label => params[:category])
46+
.each_with_object({}){|c, h| h[c.id] = 1}
47+
@file.category_ids = ids
48+
end
49+
4450
@file.save!
4551

4652
case params[:source]

test/controllers/comfy/admin/cms/files_controller_test.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ def test_create_as_redactor_failure
157157
assert_response :unprocessable_entity
158158
end
159159
end
160+
161+
def test_create_as_plupload_with_selected_category
162+
category = comfy_cms_categories(:default)
163+
164+
assert_difference 'Comfy::Cms::File.count' do
165+
post :create,
166+
:source => 'plupload',
167+
:site_id => @site,
168+
:file => {
169+
:file => fixture_file_upload('files/image.jpg', 'image/jpeg')
170+
},
171+
:category => [category.label]
172+
assert_response :success
173+
174+
file = Comfy::Cms::File.last
175+
assert_equal [category], file.categories
176+
end
177+
end
160178

161179
def test_update
162180
put :update, :site_id => @site, :id => @file, :file => {
@@ -216,18 +234,4 @@ def test_reorder
216234
assert_equal 0, file_two.position
217235
end
218236

219-
def test_create_as_plupload_with_selected_category
220-
assert_difference 'Comfy::Cms::File.count' do
221-
post :create,
222-
:source => 'plupload',
223-
:site_id => @site,
224-
:file => {
225-
:file => fixture_file_upload('files/image.jpg', 'image/jpeg')
226-
},
227-
:category => [comfy_cms_categories(:default).label]
228-
assert_response :success
229-
assert_no_select "body"
230-
assert_select "tr[id=comfy_cms_file_#{Comfy::Cms::File.last.id}] .category", comfy_cms_categories(:default).label
231-
end
232-
end
233237
end

0 commit comments

Comments
 (0)