From e2a6a002baa33e61ef9c673e27dd0719fc97e960 Mon Sep 17 00:00:00 2001 From: Joao M. M. da Silva + Alessandro Palmeira Date: Wed, 16 Jan 2013 19:38:16 +0000 Subject: [PATCH] [Mezuro] fixes in reading and reading group. --- plugins/mezuro/lib/kalibro/reading.rb | 18 ++++++++++++++++++ plugins/mezuro/test/unit/kalibro/reading_group_test.rb | 5 +++-- plugins/mezuro/test/unit/kalibro/reading_test.rb | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/mezuro/lib/kalibro/reading.rb b/plugins/mezuro/lib/kalibro/reading.rb index 51e2b3f..a183445 100644 --- a/plugins/mezuro/lib/kalibro/reading.rb +++ b/plugins/mezuro/lib/kalibro/reading.rb @@ -14,4 +14,22 @@ class Kalibro::Reading < Kalibro::Model new request(:reading_of, {:range_id => range_id} )[:reading] end + def id=(value) + @id = value.to_i + end + + def grade=(value) + @grade = value.to_f + end + + def save(reading_group_id) + begin + self.id = self.class.request(:save_reading, {:reading => self.to_hash, :group_id => reading_group_id})[:reading_id] + true + rescue Exception => exception + add_error exception + false + end + end + end diff --git a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb index a8f9309..814595a 100644 --- a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb +++ b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb @@ -11,6 +11,7 @@ class ReadingGroupTest < ActiveSupport::TestCase should 'create reading group from hash' do assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name + assert_equal @hash[:id].to_i, Kalibro::ReadingGroup.new(@hash).id end should 'convert reading group to hash' do @@ -20,9 +21,9 @@ class ReadingGroupTest < ActiveSupport::TestCase should 'verify existence of reading group' do fake_id = 0 Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => fake_id}).returns({:exists => false}) - Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true}) + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id].to_i}).returns({:exists => true}) assert !Kalibro::ReadingGroup.exists?(fake_id) - assert Kalibro::ReadingGroup.exists?(@hash[:id]) + assert Kalibro::ReadingGroup.exists?(@hash[:id].to_i) end should 'get reading group' do diff --git a/plugins/mezuro/test/unit/kalibro/reading_test.rb b/plugins/mezuro/test/unit/kalibro/reading_test.rb index fe665c4..e969e3e 100644 --- a/plugins/mezuro/test/unit/kalibro/reading_test.rb +++ b/plugins/mezuro/test/unit/kalibro/reading_test.rb @@ -11,6 +11,8 @@ class ReadingTest < ActiveSupport::TestCase should 'create reading from hash' do assert_equal @hash[:label], Kalibro::Reading.new(@hash).label + assert_equal @hash[:id].to_i, Kalibro::Reading.new(@hash).id + assert_equal @hash[:grade].to_f, Kalibro::Reading.new(@hash).grade end should 'convert reading to hash' do -- libgit2 0.21.2