Commit e2a6a002baa33e61ef9c673e27dd0719fc97e960
Committed by
Paulo Meireles
1 parent
59c59bd5
Exists in
master
and in
28 other branches
[Mezuro] fixes in reading and reading group.
Showing
3 changed files
with
23 additions
and
2 deletions
Show diff stats
plugins/mezuro/lib/kalibro/reading.rb
@@ -14,4 +14,22 @@ class Kalibro::Reading < Kalibro::Model | @@ -14,4 +14,22 @@ class Kalibro::Reading < Kalibro::Model | ||
14 | new request(:reading_of, {:range_id => range_id} )[:reading] | 14 | new request(:reading_of, {:range_id => range_id} )[:reading] |
15 | end | 15 | end |
16 | 16 | ||
17 | + def id=(value) | ||
18 | + @id = value.to_i | ||
19 | + end | ||
20 | + | ||
21 | + def grade=(value) | ||
22 | + @grade = value.to_f | ||
23 | + end | ||
24 | + | ||
25 | + def save(reading_group_id) | ||
26 | + begin | ||
27 | + self.id = self.class.request(:save_reading, {:reading => self.to_hash, :group_id => reading_group_id})[:reading_id] | ||
28 | + true | ||
29 | + rescue Exception => exception | ||
30 | + add_error exception | ||
31 | + false | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
17 | end | 35 | end |
plugins/mezuro/test/unit/kalibro/reading_group_test.rb
@@ -11,6 +11,7 @@ class ReadingGroupTest < ActiveSupport::TestCase | @@ -11,6 +11,7 @@ class ReadingGroupTest < ActiveSupport::TestCase | ||
11 | 11 | ||
12 | should 'create reading group from hash' do | 12 | should 'create reading group from hash' do |
13 | assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name | 13 | assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name |
14 | + assert_equal @hash[:id].to_i, Kalibro::ReadingGroup.new(@hash).id | ||
14 | end | 15 | end |
15 | 16 | ||
16 | should 'convert reading group to hash' do | 17 | should 'convert reading group to hash' do |
@@ -20,9 +21,9 @@ class ReadingGroupTest < ActiveSupport::TestCase | @@ -20,9 +21,9 @@ class ReadingGroupTest < ActiveSupport::TestCase | ||
20 | should 'verify existence of reading group' do | 21 | should 'verify existence of reading group' do |
21 | fake_id = 0 | 22 | fake_id = 0 |
22 | Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => fake_id}).returns({:exists => false}) | 23 | Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => fake_id}).returns({:exists => false}) |
23 | - Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true}) | 24 | + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id].to_i}).returns({:exists => true}) |
24 | assert !Kalibro::ReadingGroup.exists?(fake_id) | 25 | assert !Kalibro::ReadingGroup.exists?(fake_id) |
25 | - assert Kalibro::ReadingGroup.exists?(@hash[:id]) | 26 | + assert Kalibro::ReadingGroup.exists?(@hash[:id].to_i) |
26 | end | 27 | end |
27 | 28 | ||
28 | should 'get reading group' do | 29 | should 'get reading group' do |
plugins/mezuro/test/unit/kalibro/reading_test.rb
@@ -11,6 +11,8 @@ class ReadingTest < ActiveSupport::TestCase | @@ -11,6 +11,8 @@ class ReadingTest < ActiveSupport::TestCase | ||
11 | 11 | ||
12 | should 'create reading from hash' do | 12 | should 'create reading from hash' do |
13 | assert_equal @hash[:label], Kalibro::Reading.new(@hash).label | 13 | assert_equal @hash[:label], Kalibro::Reading.new(@hash).label |
14 | + assert_equal @hash[:id].to_i, Kalibro::Reading.new(@hash).id | ||
15 | + assert_equal @hash[:grade].to_f, Kalibro::Reading.new(@hash).grade | ||
14 | end | 16 | end |
15 | 17 | ||
16 | should 'convert reading to hash' do | 18 | should 'convert reading to hash' do |