Skip to content

Commit

Permalink
a bit of a cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GBH committed Dec 11, 2016
1 parent b6f01bf commit fe30d58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
8 changes: 7 additions & 1 deletion app/controllers/comfy/admin/cms/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ def new
end

def create
@file.category_ids = @site.categories.where(label: params[:category]).inject({}) {|hash, category| hash.merge category.id => 1} if params[:category]
if params[:category]
ids = @site.categories.of_type('Comfy::Cms::File')
.where(:label => params[:category])
.each_with_object({}){|c, h| h[c.id] = 1}
@file.category_ids = ids
end

@file.save!

case params[:source]
Expand Down
32 changes: 18 additions & 14 deletions test/controllers/comfy/admin/cms/files_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ def test_create_as_redactor_failure
assert_response :unprocessable_entity
end
end

def test_create_as_plupload_with_selected_category
category = comfy_cms_categories(:default)

assert_difference 'Comfy::Cms::File.count' do
post :create,
:source => 'plupload',
:site_id => @site,
:file => {
:file => fixture_file_upload('files/image.jpg', 'image/jpeg')
},
:category => [category.label]
assert_response :success

file = Comfy::Cms::File.last
assert_equal [category], file.categories
end
end

def test_update
put :update, :site_id => @site, :id => @file, :file => {
Expand Down Expand Up @@ -216,18 +234,4 @@ def test_reorder
assert_equal 0, file_two.position
end

def test_create_as_plupload_with_selected_category
assert_difference 'Comfy::Cms::File.count' do
post :create,
:source => 'plupload',
:site_id => @site,
:file => {
:file => fixture_file_upload('files/image.jpg', 'image/jpeg')
},
:category => [comfy_cms_categories(:default).label]
assert_response :success
assert_no_select "body"
assert_select "tr[id=comfy_cms_file_#{Comfy::Cms::File.last.id}] .category", comfy_cms_categories(:default).label
end
end
end

0 comments on commit fe30d58

Please sign in to comment.