You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With an existing active record with an existing file, if you assign a new version of the file (with the same file name but different content), the "_changed?" method returns false instead true.
To demonstrate this, we can add a test in activerecord_spec.rb, just after the test "should mark image as changed when saving a new image".
it "should mark image as changed when saving a new image with same file name" do
@event.image = stub_file("test.jpeg")
@event.save
@event.image = stub_file_alt("test.jpeg")
expect(@event.image_changed?).to be_truthy
@event.save
expect(@event.reload.image.read).to eq "this is new stuff\n"
end
Here the stub_file_alt is similar to stub_file. The difference is that it gets the file from another directory (so that we can have a different fixture with the same file name).
def stub_file_alt(filename, mime_type=nil, fake_name=nil)
f = File.open(file_path("alternatives", filename))
allow(f).to receive(:content_type) { mime_type } if mime_type
f
end
The test failed the first expect. However the second expect would pass should we comment out the first one.
Note that this is the same scenario mentioned in #2712. But the issue here is the "_changed?", ".changes" methods do not reflect the fact that the content of the file has been changed.
This seems to be an issue since version 3.0.0.rc.
The text was updated successfully, but these errors were encountered:
With an existing active record with an existing file, if you assign a new version of the file (with the same file name but different content), the "_changed?" method returns false instead true.
To demonstrate this, we can add a test in
activerecord_spec.rb
, just after the test "should mark image as changed when saving a new image".Here the
stub_file_alt
is similar tostub_file
. The difference is that it gets the file from another directory (so that we can have a different fixture with the same file name).The test failed the first
expect
. However the secondexpect
would pass should we comment out the first one.Note that this is the same scenario mentioned in #2712. But the issue here is the "_changed?", ".changes" methods do not reflect the fact that the content of the file has been changed.
This seems to be an issue since version 3.0.0.rc.
The text was updated successfully, but these errors were encountered: