Commit beee73e684774d2ee4bb0b018413aab2b27b6fe4
Committed by
Rafael Manzo
1 parent
8a2b93d3
Exists in
colab
and in
4 other branches
Integrated Module Result to Kalibro Client
Signed off by: Daniel Alves <danpaulalves@gmail.com>
Showing
6 changed files
with
22 additions
and
47 deletions
Show diff stats
Gemfile.lock
app/models/date_module_result.rb
| 1 | -class DateModuleResult < KalibroGatekeeperClient::Entities::DateModuleResult | |
| 2 | - include KalibroRecord | |
| 3 | - | |
| 4 | - def module_result | |
| 5 | - ModuleResult.new @module_result.to_hash | |
| 6 | - end | |
| 7 | -end | |
| 8 | 1 | \ No newline at end of file |
| 2 | +class DateModuleResult < KalibroClient::Miscellaneous::DateModuleResult | |
| 3 | +end | ... | ... |
app/models/module_result.rb
| 1 | -class ModuleResult < KalibroGatekeeperClient::Entities::ModuleResult | |
| 2 | - include KalibroRecord | |
| 3 | - | |
| 4 | - def metric_results | |
| 5 | - KalibroGatekeeperClient::Entities::MetricResult.metric_results_of(@id) | |
| 6 | - end | |
| 7 | - | |
| 8 | - def history | |
| 9 | - self.class.history_of(@id).map { |date_module_result| DateModuleResult.new date_module_result.to_hash } | |
| 10 | - end | |
| 1 | +class ModuleResult < KalibroClient::Processor::ModuleResult | |
| 11 | 2 | |
| 12 | 3 | def metric_history(name) |
| 4 | + history = self.processing.repository.module_result_history_of(self) | |
| 13 | 5 | grade_history = Hash.new |
| 14 | 6 | |
| 15 | 7 | history.each { |date_module_result| grade_history[date_module_result.date] = | ... | ... |
spec/factories/date_module_results.rb
| ... | ... | @@ -2,5 +2,7 @@ FactoryGirl.define do |
| 2 | 2 | factory :date_module_result, class: DateModuleResult do |
| 3 | 3 | date "2011-10-20T18:26:43.151+00:00" |
| 4 | 4 | module_result {FactoryGirl.build(:module_result)} |
| 5 | + | |
| 6 | + initialize_with { new({:date => date, :module_result => module_result}) } | |
| 5 | 7 | end |
| 6 | -end | |
| 7 | 8 | \ No newline at end of file |
| 9 | +end | ... | ... |
spec/factories/module_results.rb
| 1 | 1 | FactoryGirl.define do |
| 2 | 2 | factory :module_result, class: ModuleResult do |
| 3 | - id "42" | |
| 3 | + id 42 | |
| 4 | 4 | self.module { FactoryGirl.build(:module) } |
| 5 | - grade "10.0" | |
| 6 | - parent_id "21" | |
| 7 | - height "6" | |
| 5 | + grade 10.0 | |
| 6 | + parent_id 21 | |
| 7 | + height 6 | |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | factory :root_module_result, class: ModuleResult do |
| 11 | - id "21" | |
| 11 | + id 21 | |
| 12 | 12 | self.module { FactoryGirl.build(:module) } |
| 13 | - grade "6.0" | |
| 13 | + grade 6.0 | |
| 14 | 14 | parent_id nil |
| 15 | - height "1" | |
| 15 | + height 1 | |
| 16 | 16 | end |
| 17 | -end | |
| 18 | 17 | \ No newline at end of file |
| 18 | +end | ... | ... |
spec/models/module_result_spec.rb
| ... | ... | @@ -4,30 +4,16 @@ describe ModuleResult, :type => :model do |
| 4 | 4 | describe 'methods' do |
| 5 | 5 | subject { FactoryGirl.build(:module_result) } |
| 6 | 6 | |
| 7 | - describe 'metric_results' do | |
| 8 | - it 'should call the metric_results_of method' do | |
| 9 | - KalibroGatekeeperClient::Entities::MetricResult.expects(:metric_results_of).with(subject.id).returns(nil) | |
| 10 | - | |
| 11 | - subject.metric_results | |
| 12 | - end | |
| 13 | - end | |
| 14 | - | |
| 15 | - describe 'history' do | |
| 16 | - before :each do | |
| 17 | - ModuleResult.expects(:history_of).with(subject.id).returns([FactoryGirl.build(:date_module_result)]) | |
| 18 | - end | |
| 19 | - | |
| 20 | - it 'should return a array of DateModuleResults' do | |
| 21 | - expect(subject.history.first).to be_a(DateModuleResult) | |
| 22 | - end | |
| 23 | - end | |
| 24 | - | |
| 25 | 7 | describe 'metric_history' do |
| 26 | 8 | let(:date_module_result) {FactoryGirl.build(:date_module_result)} |
| 27 | 9 | let(:metric_result) {FactoryGirl.build(:metric_result)} |
| 10 | + let(:processing) {FactoryGirl.build(:processing)} | |
| 11 | + let(:repository) {FactoryGirl.build(:repository)} | |
| 28 | 12 | |
| 29 | 13 | before :each do |
| 30 | - subject.expects(:history).returns([date_module_result]) | |
| 14 | + subject.expects(:processing).returns(processing) | |
| 15 | + processing.expects(:repository).returns(repository) | |
| 16 | + repository.expects(:module_result_history_of).with(subject).returns([date_module_result]) | |
| 31 | 17 | ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) |
| 32 | 18 | end |
| 33 | 19 | |
| ... | ... | @@ -36,4 +22,4 @@ describe ModuleResult, :type => :model do |
| 36 | 22 | end |
| 37 | 23 | end |
| 38 | 24 | end |
| 39 | -end | |
| 40 | 25 | \ No newline at end of file |
| 26 | +end | ... | ... |