Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding 'reload' to trackables specs #111

Closed
wants to merge 12 commits into from
Closed

Adding 'reload' to trackables specs #111

wants to merge 12 commits into from

Conversation

jeremylynch
Copy link
Contributor

When using Mongoid 3.1.6, ruby 1.9.3 and Rails 3.2.16 I have found that Undo! and Redo! methods are not persisting when called directly on the document. For example:

@book = Book.create(:name => 'name 1')
@book.update_attributes(:name => 'name 2')
@book.update_attributes(:name => 'name 3')
@book.undo! @user, :from => 3, :to => 1             #=> true
@book.name    #=> 'name 1'
@book.reload.name    #=> 'name 3'

However when calling these methods on the history tracks, changes are being persisted. For example:

@track = @book.history_tracks.last
@track.undo!  #=> true
@book.name    #=> 'name 2'
@book.reload.name    #=> 'name 2'

I am not sure why this is the case, though I had a look at the specs and discovered that reload was not being called on the objects before checking if undo! or redo! worked. I've decided to add that and the specs are now failing. Is this the intended behaviour?

@dblock
Copy link
Collaborator

dblock commented Jul 16, 2014

Yes, undo! and redo! should be properly persisting data, since they call update_attributes!.

We actually want to test both with and without reload I think, so maybe you can do something like

[ nil, :reload ].each do |method|
  context "#{method || 'instance'}" do
    it "should recognize :from, :to options" do
        comment.undo! user, from: 4, to: 2
        comment.send(method) if method
        comment.title.should == "test"
    end
  end
end

This should be debugged.

@dblock
Copy link
Collaborator

dblock commented Jul 16, 2014

Also we should change all update_attributes to update_attributes! so we don't swallow errors.

@jeremylynch
Copy link
Contributor Author

I've made the changes to the specs as you suggested. How can we go about solving the issue and getting the specs passing?

@@ -677,22 +687,22 @@ class Foo < Comment

it "should recognize :from, :to options" do
comment.redo! user, from: 2, to: 4
comment.title.should == "Test4"
comment.reload.title.should == "Test4"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still reload, I think you meant to delete these tests.

@dblock
Copy link
Collaborator

dblock commented Jul 17, 2014

I can take a look soon, but in the meantime, see what is being passed into the final update_attributes! and why that's not persisting.

@dblock
Copy link
Collaborator

dblock commented Jul 17, 2014

The Travis specs fail for a Rubocop violation, you should fix that.

@jeremylynch
Copy link
Contributor Author

I have solved the issue and all the specs are passing. Please review

@dblock
Copy link
Collaborator

dblock commented Jul 18, 2014

Perfect.

Can you please update CHANGELOG and squash these commits? Thx.

@jeremylynch
Copy link
Contributor Author

To squash all the commits I have to delete my fork, create a new one and repush the squashed commits. Please view the new pull request #113

@johnnyshields
Copy link
Member

Closing this PR as you've moved it to #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants