Commit 1e0f1d797916e95662d42264c80c3828162b7285
1 parent
25ebd3b1
Exists in
master
and in
29 other branches
[Mezuro] Date Module Result and history of a module
Showing
5 changed files
with
66 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,13 @@ |
1 | +class Kalibro::DateModuleResult < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :date, :module_result | |
4 | + | |
5 | + def date=(value) | |
6 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
7 | + end | |
8 | + | |
9 | + def module_result=(value) | |
10 | + @module_result = Kalibro::ModuleResult.to_object value | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
plugins/mezuro/lib/kalibro/module_result.rb
... | ... | @@ -19,4 +19,8 @@ class Kalibro::ModuleResult < Kalibro::Model |
19 | 19 | @grade = value.to_f |
20 | 20 | end |
21 | 21 | |
22 | + def self.history_of(module_result_id) | |
23 | + self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result].to_a.map {|date_module_result| Kalibro::DateModuleResult.new date_module_result} | |
24 | + end | |
25 | + | |
22 | 26 | end | ... | ... |
plugins/mezuro/test/fixtures/date_module_result_fixtures.rb
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +require File.dirname(__FILE__) + '/module_result_fixtures' | |
2 | + | |
3 | +class DateModuleResultFixtures | |
4 | + | |
5 | + def self.date_module_result | |
6 | + Kalibro::DateModuleResult.new date_module_result_hash | |
7 | + end | |
8 | + | |
9 | + def self.date_module_result_hash | |
10 | + { | |
11 | + :date => '2011-10-20T18:26:43.151+00:00', | |
12 | + :module_result => ModuleResultFixtures.module_result_hash, | |
13 | + :attributes! => | |
14 | + { | |
15 | + :module_result => | |
16 | + { | |
17 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
18 | + "xsi:type"=>"kalibro:moduleResultXml" | |
19 | + } | |
20 | + } | |
21 | + } | |
22 | + end | |
23 | + | |
24 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/date_module_result_test.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures" | |
4 | + | |
5 | +class DateModuleResultTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = DateModule.date_module_result_hash | |
9 | + @date_module_result = DateModuleResultFixtures.date_module_result | |
10 | + end | |
11 | + | |
12 | + should 'create date_module_result from hash' do | |
13 | + assert_equal @hash[:module_result][:id], Kalibro::DateModuleResult.new(@hash).module_result.id | |
14 | + end | |
15 | + | |
16 | + should 'convert date_module_result to hash' do | |
17 | + assert_equal @hash, @date_module_result.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/module_result_test.rb
... | ... | @@ -29,4 +29,9 @@ class ModuleResultTest < ActiveSupport::TestCase |
29 | 29 | assert @hash[:id], @module_result.children.first.id |
30 | 30 | end |
31 | 31 | |
32 | + should 'return history of a module result' do | |
33 | + Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => module_id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) | |
34 | + assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id | |
35 | + end | |
36 | + | |
32 | 37 | end | ... | ... |