On 16 July 2011 09:31, Ahmy Yulrizka <[email protected]> wrote:
> Hi,
> I have this small problem that made me really frustrating for 3 hours.
> the code is simple. Im using rails 3.1. it uses paperclip gem to
> manage attachment. this code works fine on production and development either
> with mri 1.9.2 or ree 1.8.7, the problem is when i test it using cucumber
> here is the code
> def create
>   @photo = Photo.new(params[:photo])
>
>   @photo.md5sum = @photo.file.fingerprint
>   @duplicate = Photo.find_by_md5sum(@photo.md5sum)
>
>   @test = Photo.all
>
>   if @duplicate
>     flash[:error] = "Found duplicate entry"
>   else
>     @result = @photo.save
>   end
> end
> it just check for the md5sum of the photo, and save if it's not duplicate.
> i test it using cucumber, the problem is with Photo.find_by_md5sum. it
> return nil. but the @test return all of the record, including the record
> with the md5sum that should be matched.

Have a look in the log to see what query is being generated for the
find_by_md5sum and see if anything looks odd.

Also you could use ruby-debug to break in at the find_by_md5sum and
inspect the data to make sure it looks ok.  In the console then use
find(6) or whatever is the id of the existing duplicate record and
then inspect it's sum and the sum of the new one you have just made.
I presume these are all string types?

> i also try to changed it with Photo.where(:md5sum => @photo.md5sum) but on
> 1.9.2 its return to [].
> but funny, when I change it using like cause, Photo.where("md5sum like ?",
> @photo.md5sum) it return the right object.

Are you sure there is not a space or something at the end of the one
in the database or in the query so Like finds it but equality does
not.

> the only problem if i try to use equality in the query. it always returns
> nil on 1.9.2. when i test it using ree 1.8.2 everything works fine.
>
> I have no idea how this happend, maybe some one here face the same problem ?

In the rails console play about with the find, putting in the md5sum
manually for example, to see what happens.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to