tatyree
unread,Feb 5, 2011, 10:13:01 AM2/5/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pickle
I've got an image model that has_many versions of itself as
alternates. When I try and test that a newly-uploaded alternate image
with an S3 stored paperclip attachment has the correct association
with an existing image instantiated using machinist, the model! method
in pickle only finds the machinist-created instance.
Anyone else seen anything similar? Any thoughts or suggestions (or a
steer towards a fix) would be appreciated.
Rails 3.0.3
paperclip 2.3.8
storage of images on s3 using most current aws-s3
most current beta version of machinist (with the caching turned off)
capybara
I've set this in my test environment,
Machinist.configure do |config|
config.cache_objects = false
end
but it doesn't help.
The image model with the attachment looks like this:
Class Image < ActiveRecord::Base
IMAGE_SIZES = {
:hero => '800x800>',
:large => '400x400#',
:thumb => '100x100#' }
has_many :images
belongs_to :image
has_many :alternates, :class_name => "Image", :foreign_key =>
"image_id"
has_attached_file :media,
:storage => :s3,
:s3_permissions => :authenticated_read,
:s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
:s3_protocol => 'http',
:path => ":attachment/:id/:style/:basename.:extension",
:styles => IMAGE_SIZES
end
The blueprint looks like this:
Image.blueprint do
title { "Image #{sn}"}
media { File.new(File.join(Rails.root, 'features', 'upload-files',
'default.jpg')) }
end
And the feature looks like this:
Scenario: I can create a new alternate image
Given I am on the images page
And a subsection exists with title: "Dockyards"
And an image "Main" exists with subsection: the subsection, title:
"The Main Image"
When I follow "new"
And I fill in "Title" with "New Dockyard Photo"
And I attach the file "features/upload-files/default.jpg" to "Media"
And I select "The Main Image" from "Image"
And I press "Create Image"
Then an image should exist
And the image "Main" should be the image's image
And I should see image: the image
When it's run, I get this result:
features/step_definitions/pickle_steps.rb:54
expected: #<Image id: 377, title: "The Main Image", created_at:
"2011-02-05 14:50:25", updated_at: "2011-02-05 14:50:25",
media_file_name: "default.jpg", media_content_type: "image/jpeg",
media_file_size: 2673, media_updated_at: "2011-02-05 14:50:25",
processing: nil, subsection_id: 337, position: 1, image_id: nil>
got: nil (using ==)
The problem come in with this step definition:
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |
target, owner, association|
model!(owner).send(association).should == model!(target)
end
The problem becomes pretty clear if you look at it in the debugger:
(rdb:1) owner
"the image"
(rdb:1) target
"the image \"Main\""
(rdb:1) model!(owner)
#<Image id: 391, title: "The Main Image", created_at: "2011-02-05
15:00:34", updated_at: "2011-02-05 15:00:34", media_file_name:
"default.jpg", media_content_type: "image/jpeg", media_file_size:
2673, media_updated_at: "2011-02-05 15:00:34", processing: nil,
subsection_id: 344, position: 1, image_id: nil>
(rdb:1) model!(target)
#<Image id: 391, title: "The Main Image", created_at: "2011-02-05
15:00:34", updated_at: "2011-02-05 15:00:34", media_file_name:
"default.jpg", media_content_type: "image/jpeg", media_file_size:
2673, media_updated_at: "2011-02-05 15:00:34", processing: nil,
subsection_id: 344, position: 1, image_id: nil>
(rdb:1) model!(owner) == model!(target)
true
(rdb:1)
I've tried setting up a different blueprint, thinking the naming might
be getting in the way:
Image.blueprint(:default) do
title { "Default Image"}
media { File.new(File.join(Rails.root, 'features', 'upload-files',
'default.jpg')) }
end
Scenario: I can create a new alternate image
Given I am on the images page
And a subsection exists with title: "Mumbai Dockyards"
And a default image exists with subsection: the subsection, title:
"The Main Image"
When I follow "new"
And I fill in "Title" with "New Dockyard Photo"
And I attach the file "features/upload-files/default.jpg" to "Media"
And I select "The Main Image" from "Image"
And I press "Create Image"
Then an image should exist
And the default image should be the image's image
But the same thing happens:
(rdb:1) owner
"the image"
(rdb:1) target
"the default image"
(rdb:1) model!(owner) == model!(target)
true
(rdb:1)
I also tried using the step for checking has_many, but get a similar
problem.