维斯塔版本的变化_之间不适合我
我期望它是两个版本之间所有更改的并集。 (使用 Vestal 版本 1.0.2)
ruby-1.8.7-p174 > contact.version
=> 12
ruby-1.8.7-p174 > contact.latest_approved_version
=> 8
ruby-1.8.7-p174 > contact.changes
=> {}
ruby-1.8.7-p174 > contact.versions.last.changes
=> {"first_name"=>["I changed this one baby", "AdminF"]}
ruby-1.8.7-p174 > contact.changes_between(8,12)
=> {}
ruby-1.8.7-p174 > contact.changes_between(9,12)
=> {"deleted"=>[true, false]}
ruby-1.8.7-p174 > contact.changes_between(10,12)
=> {}
ruby-1.8.7-p174 > contact.changes_between(11,12)
=> {"first_name"=>["I changed this one baby", "AdminF"]}
正如您所看到的,8 和 12 之间没有变化,但其中一些之间发生了变化。
奇怪的是我发誓这昨天还有效!
这是维斯塔正在使用的方法,我不确定问题是什么:
def changes_between(from, to)
from_number, to_number = versions.number_at(from), versions.number_at(to)
return {} if from_number == to_number
chain = versions.between(from_number, to_number).reject(&:initial?)
return {} if chain.empty?
backward = from_number > to_number
backward ? chain.pop : chain.shift unless from_number == 1 || to_number == 1
chain.inject({}) do |changes, version|
changes.append_changes!(backward ? version.changes.reverse_changes : version.changes)
end
end
I was expecting it to be the union of all changes between 2 versions. (using vestal versions 1.0.2)
ruby-1.8.7-p174 > contact.version
=> 12
ruby-1.8.7-p174 > contact.latest_approved_version
=> 8
ruby-1.8.7-p174 > contact.changes
=> {}
ruby-1.8.7-p174 > contact.versions.last.changes
=> {"first_name"=>["I changed this one baby", "AdminF"]}
ruby-1.8.7-p174 > contact.changes_between(8,12)
=> {}
ruby-1.8.7-p174 > contact.changes_between(9,12)
=> {"deleted"=>[true, false]}
ruby-1.8.7-p174 > contact.changes_between(10,12)
=> {}
ruby-1.8.7-p174 > contact.changes_between(11,12)
=> {"first_name"=>["I changed this one baby", "AdminF"]}
As you can see no changes between 8 and 12, but changes between some of them.
The weird thing is I swear this was working yesterday!
Here is the method vestal is using, im not sure what the problem is:
def changes_between(from, to)
from_number, to_number = versions.number_at(from), versions.number_at(to)
return {} if from_number == to_number
chain = versions.between(from_number, to_number).reject(&:initial?)
return {} if chain.empty?
backward = from_number > to_number
backward ? chain.pop : chain.shift unless from_number == 1 || to_number == 1
chain.inject({}) do |changes, version|
changes.append_changes!(backward ? version.changes.reverse_changes : version.changes)
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的示例可能没有任何问题。例如,如果版本 8 和 12 之间没有差异。即使版本 9、10 和 11 中发生了更改,如果模型的属性已恢复为相同的值,则 Changes_Between 方法将不会显示任何更改。
我认为验证这一点的最简单方法是检查:
然后比较输出。我想不出造成你所描述的结果的任何其他原因。
顺便说一句,您对“last_approved_version”所做的调用是您手动添加到模型中的内容还是vestal_versions 中内置的内容?因为我也使用 1.0.2lvestal_version,但我找不到任何参考。因此,如果它确实是内置的东西,那么我们可能有不同的 vestal_version 分支,这可能就是原因......
It is possible that there is nothing wrong with the example you provided. If for example there are no differences between version 8 and 12. Even though there has been changes in version 9, 10 and 11, the method changes_between will not show any changes if the model's attributes has been reverted to the same values.
I think the easiest way to verify that is to check:
And then compare the output. I can't think of any other reason for the result you described.
By the way, the call you made to "last_approved_version", is that something you manually added to your model or is it something built-in in vestal_versions? Because I also use the 1.0.2 vestal_version and I can't find any reference to that. So if it really is something built-in then we probably have different forks of vestal_version and that might be the cause...