Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make multiple resource uploads pass on form parameters, which should be ... #1884

Merged
merged 1 commit into from

3 participants

@robyurkowski
Collaborator

...expected behaviour.

In the situation where you add a field to Resources, upon create, you're unable to save any of those additional attributes because we only pass on the file attribute at the moment when the user is uploading multiple files. Of course, the user is always uploading multiple files, because the default html5ish behaviour is to send an array anyway. This corrects the existing create method and allows the user to submit multiple attributes to be saved.

@robyurkowski robyurkowski Make multiple resource uploads pass on form parameters, which should …
…be expected behaviour.

In the situation where you add a field to Resources, upon create, you're unable to save any of those additional attributes because we only pass on the file attribute at the moment when the user is uploading multiple files. Of course, the user is always uploading multiple files, because the default html5ish behaviour is to send an array anyway. This corrects the existing create method and allows the user to submit multiple attributes to be saved.
c98b9dc
@travisbot

This pull request passes (merged c98b9dc into 50749a6).

@parndt parndt merged commit 70516f2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2012
  1. @robyurkowski

    Make multiple resource uploads pass on form parameters, which should …

    robyurkowski authored
    …be expected behaviour.
    
    In the situation where you add a field to Resources, upon create, you're unable to save any of those additional attributes because we only pass on the file attribute at the moment when the user is uploading multiple files. Of course, the user is always uploading multiple files, because the default html5ish behaviour is to send an array anyway. This corrects the existing create method and allows the user to submit multiple attributes to be saved.
This page is out of date. Refresh to see the latest.
View
2  resources/app/models/refinery/resource.rb
@@ -43,7 +43,7 @@ def create_resources(params)
resources << create(params)
else
params[:file].each do |resource|
- resources << create(:file => resource)
+ resources << create({:file => resource}.merge(params.except(:file)))
end
end
View
7 resources/spec/models/refinery/resource_spec.rb
@@ -70,6 +70,13 @@ module Refinery
r.should be_an_instance_of(Resource)
end
end
+
+ specify "each returned array item should be passed form parameters" do
+ params = {:file => [file, file, file], :fake_param => 'blah'}
+
+ Resource.should_receive(:create).exactly(3).times.with({:file => file, :fake_param => 'blah'})
+ Resource.create_resources(params)
+ end
end
describe "validations" do
Something went wrong with that request. Please try again.