Raisl 4.2 + Capybara + Paperclip = Race condition

49 views
Skip to first unread message

Cezinha Anjos

unread,
Jan 6, 2015, 6:35:45 AM1/6/15
to rubyonra...@googlegroups.com
Hi!

I'm upgrading a small Rails 4.1.x app to 4.2.

All my test suite is passing, except one spec:

    scenario "showing a video called from a track" do
      visit video_path(video, level_id: level.id)
      sign_in create(:confirmed_user)

      expect(page).to have_selector "video[poster=\"#{video.poster(:original)}\"]"      
    end

Here is the factory:

FactoryGirl.define do
  factory :video do
    title "Cadastrando um cliente"
    poster { Rack::Test::UploadedFile.new("#{::Rails.root}/spec/fixtures/image.png", "image/png") }
    video { Rack::Test::UploadedFile.new("#{::Rails.root}/spec/fixtures/video.mp4", "video/mp4") }
  end
end

That's the problem:

Video Pages

  when showing

    showing a video called from a track (FAILED - 1)

  HTML screenshot: /Users/cezinha/dev/universidade/tmp/capybara/2015-01-06-09-31-30-screenshot-showing-a-video-called-from-a-track.html


Failures:


  1) Video Pages when showing showing a video called from a track

     Failure/Error: expect(page).to have_selector "video[poster=\"#{video.poster(:original)}\"]"

       expected to find css "video[poster=\"/system/videos/posters/000/000/001/original/image.png?1420543889\"]" but there were no matches

     # ./spec/features/video_spec.rb:66:in `block (3 levels) in <top (required)>'


When I inspect the generated HTML I have:

<video class="img-responsive"

          controls preload autoplay poster="/system/videos/posters/000/000/001/original/image.png?1420543954"

          data-level_id=1

         <source src=/system/videos/videos/000/000/001/original/video.mp4?1420543954 type="video/mp4" />


When I inspect the video.poster(:original) I have:


/system/videos/posters/000/000/001/original/image.png?1420543953


The worst: sometimes it pass and sometimes not.

My impression is that the content of the file is changing while I'm testing and because of this, the fingerprint is different too.

Does anyone can help me?

Thanks.

Frederick Cheung

unread,
Jan 6, 2015, 7:29:56 AM1/6/15
to rubyonra...@googlegroups.com


On Tuesday, January 6, 2015 11:35:45 AM UTC, Cezinha Anjos wrote:
Hi!

When I inspect the generated HTML I have:

<video class="img-responsive"

          controls preload autoplay poster="/system/videos/posters/000/000/001/original/image.png?1420543954"

          data-level_id=1

         <source src=/system/videos/videos/000/000/001/original/video.mp4?1420543954 type="video/mp4" />


When I inspect the video.poster(:original) I have:


/system/videos/posters/000/000/001/original/image.png?1420543953


The worst: sometimes it pass and sometimes not.

My impression is that the content of the file is changing while I'm testing and because of this, the fingerprint is different too.

Does anyone can help me?



That's not a fingerprint, it's a timestamp. Who is inserting that timestamp?

Fred 

Cezinha - ASSEINFO

unread,
Jan 6, 2015, 7:56:37 AM1/6/15
to rubyonra...@googlegroups.com
It's generated by Paperclip!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2002b77e-6d7b-416c-b39f-321a777a357b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


César Luiz dos Anjos Júnior

Diretor

(48) 3263-7137
http://www.asseinfo.com.br



Descrição: Descrição: C:\assinatura_email\logo.jpg 

"A curiosidade é um dos maiores sinais de vitalidade de um profissional.”

Jim Collins

 

“Keep learning like a crazy...”

Uncle Bob

Cezinha Anjos

unread,
Jan 6, 2015, 4:52:38 PM1/6/15
to rubyonra...@googlegroups.com
Hi Fred!

I beg your pardon, but I think you're not right.

The ?"nnnnnnn" is really a fingerprint generated by paperclip. I checked here:


Do you have any idea to solve my problem?

I only think in two options:

1. The assertion is happening while the factory girl is loading the sample file.
2. For a weird reason, factory girl could be loading the sample file twice. 

I'm two days working on it and I'm not finding a solution.

Thanks.

Frederick Cheung

unread,
Jan 7, 2015, 4:05:37 AM1/7/15
to rubyonra...@googlegroups.com
On Tuesday, January 6, 2015 9:52:38 PM UTC, Cezinha Anjos wrote:
> Hi Fred!
>
>
>
> I beg your pardon, but I think you're not right.
>
>
> The ?"nnnnnnn" is really a fingerprint generated by paperclip. I checked here:
>
>
> https://github.com/thoughtbot/paperclip#md5-checksum--fingerprint
>
>
It's definitely not an md5 fingerprint - it's too short. Furthermore, when interpreted as a timestamp (try using Time.at) it returns a time a few minutes before your original post.

https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/url_generator.rb Seems to indicate that it uses the updated_at of the model. Perhaps a change in rails 4.2 is causing your model to be saved a second time during the call to visit. If that second save happens within the same second your spec will pass if not it will fail.

You could also take the view that the value of the timestamp isn't important and change your spec to only look at the path.

Fred

Cezinha - ASSEINFO

unread,
Jan 11, 2015, 8:24:19 AM1/11/15
to rubyonra...@googlegroups.com
Hi Fred!

I wouldn't like to change my test, but I had to!

Thanks for your attention!



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b7f98af2-b8ef-404b-af59-ee34c09f8565%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages