https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Add the diff method for the system.
* web/ranch/app/models/system.rb: Add the diff method.
* web/ranch/test/unit/system_test.rb: Test it.
app/models/system.rb | 15 +++++++++++++++
test/unit/system_test.rb | 12 ++++++++++++
2 files changed, 27 insertions(+)
Index: web/ranch/test/unit/system_test.rb
--- web/ranch/test/unit/system_test.rb (revision 64)
+++ web/ranch/test/unit/system_test.rb (working copy)
@@ -27,4 +27,16 @@
assert_equal 3, systems.size
end
+ def test_diff
+ sys1 = systems("ouagadougou1")
+ sys2 = System.new
+ sys1.attributes.each do |k, v|
+ sys2.send("#{k}=", v)
+ end
+ assert ! sys1.diff?(sys2)
+ sys2 = systems("ouagadougou2")
+ require 'pp'
+ assert_equal ["cpu_frequency"], sys1.diff(sys2)
+ end
+
end
Index: web/ranch/app/models/system.rb
--- web/ranch/app/models/system.rb (revision 64)
+++ web/ranch/app/models/system.rb (working copy)
@@ -31,6 +31,21 @@
systems
end
+ def diff(other)
+ except = %w( info id )
+ ret = []
+ attributes.each do |k, v|
+ if not except.include? k and v != other.attributes[k]
+ ret << k
+ end
+ end
+ ret
+ end
+
+ def diff?(other)
+ ! diff(other).empty?
+ end
+
protected
def validate