title: undefined method `reject' for #<String:0x007ffc976cb9e8>
body: <p>I am running features tests with Rspec and Capybara.</p>
  
  <p>I have no problem when I add attachments to an existing article on the browser...
  But when I run the test, that fails and I don't understand what is happening...
  What is the problem?</p>
  
  <p>that is the full error:</p>
  
  <pre><code>Failures:
  
    1) managing article The admin is logged in add images for an article
       Failure/Error: flash[:error] = "Failed uploading attachments" unless @article.save
  
       NoMethodError:
         undefined method `reject' for #&lt;String:0x007ffc976cb9e8&gt;
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/carrierwave-1.2.3/lib/carrierwave/mounter.rb:130:in `remove_previous'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/carrierwave-1.2.3/lib/carrierwave/mount.rb:349:in `remove_previously_stored_attachments'
       # ./app/controllers/attachments_controller.rb:6:in `create'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/tempfile_reaper.rb:15:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/etag.rb:25:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/conditional_get.rb:38:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/head.rb:12:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-l2.0.5/lib/rack/session/abstract/id.rb:232:in `context'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:226:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-test-1.1.0/lib/rack/test.rb:129:in `custom_request'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/rack-test-1.1.0/lib/rack/test.rb:66:in `post'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/rack_test/browser.rb:75:in `process'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/rack_test/browser.rb:42:in `process_and_follow_redirects'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/rack_test/browser.rb:33:in `submit'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/rack_test/form.rb:46:in `submit'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/rack_test/node.rb:69:in `click'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/node/element.rb:154:in `block in click'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/node/base.rb:82:in `synchronize'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/node/element.rb:154:in `click'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/node/actions.rb:58:in `click_button'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/session.rb:728:in `block (2 levels) in &lt;class:Session&gt;'
       # /Users/bill/.rvm/gems/ruby-2.4.1/gems/capybara-3.7.1/lib/capybara/dsl.rb:51:in `block (2 levels) in &lt;module:DSL&gt;'
       # ./spec/features/managing_article_spec.rb:54:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>This is a piece of my failing test:</p>
  
  <pre><code>    scenario "add images for a guitar"  do
          guitar = articles(:gibson)
          visit article_path(guitar)
  
          click_on "Add pictures"
  
          within "#label_uploader_2" do 
              within "#span_uploader_2" do 
                  attach_file("article[attachments][]" , Rails.root.join("spec/assets/images/img_2.jpg"))
              end
          end
  
  
          click_on "Update Finished guitar"
  
          expect(page).to have_content("Picture was successfully added")
      end
  </code></pre>
  
  <p>And here is my attachments controller</p>
  
  <pre><code> class AttachmentsController &lt; ApplicationController
        before_action :set_article
  
     def create
      add_more_attachments(attachments_params[:attachments])
      if @article.save
        redirect_to @article, notice: "Picture was successfully added"
      else
        flash[:error] = "Failed uploading attachments"
      end
    end
  
    def destroy
      remove_attachments_at_index(params[:id].to_i)
      if @article.save 
        redirect_to @article, notice: "Picture was successfully destroyed"
      else
        flash[:error] = "Failed deleting attachments"
      end
    end
  
    private
  
    def set_article
      @article = FinishedGuitar.find(params[:article_id])
    end
  
    def add_more_attachments(new_attachments)
      attachments = @article.attachments 
      attachments += new_attachments
      @article.attachments = attachments
    end
  
    def remove_attachments_at_index(index)
      remain_attachments = @article.attachments # copy the array
      deleted_attachments = remain_attachments.delete_at(index) # delete the target attachments
      deleted_attachments.try(:remove!) # delete attachments from S3
      @article.attachments = remain_attachments # re-assign back
    end
  
    def attachments_params
      params.require(:article).permit({attachments: []}) # allow nested params as array
    end
  end
  </code></pre>
  
  <h2>EDIT</h2>
  
  <p>if I remove the line <code>attachments</code> in my fixtures, the tests are green... The idea is to test the adding of pictures. 
  Maybe I haven't set my tests the good way</p>
  
  <p>my fixture for articles.yml </p>
  
  <pre><code>gibson:
    title: Gibson Les Paul
    description: Une jolie description pour une jolie guitare.
    attachments: &lt;%= Rails.root.join("spec/assets/images/img_2.jpg") %&gt;
  </code></pre>
  
  <p>here are my db logs just after running the test: </p>
  
  <pre><code>Completed 200 OK in 24ms (Views: 20.9ms | ActiveRecord: 0.6ms)
  Started POST "/articles/1072060877/attachments" for 127.0.0.1 at 2018-09-11 23:03:45 +0200
  Processing by AttachmentsController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "article"=&gt;{"attachments"=&gt;[#&lt;ActionDispatch::Http::UploadedFile:0x00007fc76d6838a0 @tempfile=#&lt;Tempfile:/var/folders/11/mdddnw8d0zd961bsfkq1cjy00000gn/T/RackMultipart20180911-67380-ir0qv2.jpg&gt;, @original_filename="img_2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"article[attachments][]\"; filename=\"img_2.jpg\"\r\nContent-Type: image/jpeg\r\nContent-Length: 232558\r\n"&gt;]}, "commit"=&gt;"Update article", "article_id"=&gt;"1072060877"}
    Article Load (0.4ms)  SELECT  "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2  [["id", 1072060877], ["LIMIT", 1]]
     (0.3ms)  SAVEPOINT active_record_1
    Article Update (0.5ms)  UPDATE "articles" SET "attachments" = $1, "updated_at" = $2 WHERE "articles"."id" = $3  [["attachments", "[null,\"img_2.jpg\"]"], ["updated_at", "2018-09-11 21:03:45.472070"], ["id", 1072060877]]
     (0.2ms)  RELEASE SAVEPOINT active_record_1
  Completed 500 Internal Server Error in 172ms (ActiveRecord: 1.3ms)
     (0.3ms)  ROLLBACK
  </code></pre>