Commit 548fc15230e8d6c5a31ec184f7fbcc127a6b5ca4

Authored by João M. M. da Silva + Alessandro Palmeira
Committed by João M. M. da Silva
1 parent 59026c1e

[Mezuro] Completed reading_group model.

plugins/mezuro/lib/kalibro/configuration.rb
@@ -16,9 +16,11 @@ class Kalibro::Configuration < Kalibro::Model @@ -16,9 +16,11 @@ class Kalibro::Configuration < Kalibro::Model
16 end 16 end
17 =end 17 =end
18 18
19 - def self.exists?(id)  
20 - request("Configuration", :configuration_exists, {:configuration_id => id})[:exists]  
21 - end 19 +# Should be on parent class
  20 +#
  21 +# def self.exists?(id)
  22 +# request("Configuration", :configuration_exists, {:configuration_id => id})[:exists]
  23 +# end
22 24
23 def self.find(id) 25 def self.find(id)
24 if(exists?(id)) 26 if(exists?(id))
plugins/mezuro/lib/kalibro/model.rb
@@ -66,6 +66,10 @@ class Kalibro::Model @@ -66,6 +66,10 @@ class Kalibro::Model
66 end 66 end
67 end 67 end
68 68
  69 + def self.exists?(id)
  70 + request(exists_endpoint, exists_action, exists_params(id))
  71 + end
  72 +
69 protected 73 protected
70 74
71 def fields 75 def fields
@@ -124,11 +128,27 @@ class Kalibro::Model @@ -124,11 +128,27 @@ class Kalibro::Model
124 end 128 end
125 129
126 def destroy_action 130 def destroy_action
127 - "remove_#{class_name.underscore}".to_sym 131 + "delete_#{class_name.underscore}".to_sym
128 end 132 end
129 133
130 def destroy_params 134 def destroy_params
131 - {"#{class_name.underscore}_name".to_sym => self.name} 135 + {"#{class_name.underscore}_id".to_sym => self.id}
  136 + end
  137 +
  138 + def self.exists_class_name
  139 + self.name.gsub(/Kalibro::/,"")
  140 + end
  141 +
  142 + def self.exists_endpoint
  143 + self.exists_class_name
  144 + end
  145 +
  146 + def self.exists_action
  147 + "#{exists_class_name.underscore}_exists".to_sym
  148 + end
  149 +
  150 + def self.exists_params(id)
  151 + {"#{exists_class_name.underscore}_id".to_sym => id}
132 end 152 end
133 153
134 def add_error(exception) 154 def add_error(exception)
plugins/mezuro/lib/kalibro/reading_group.rb 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +class Kalibro::ReadingGroup < Kalibro::Model
  2 +
  3 + attr_accessor :id, :name, :description
  4 +
  5 + def self.find(id)
  6 + new request("ReadingGroup", :get_reading_group, {:group_id => id})[:reading_group]
  7 + end
  8 +
  9 + def self.all
  10 + request("ReadingGroup", :all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group }
  11 + end
  12 +
  13 + def self.reading_group_of( metric_configuration_id )
  14 + new request("ReadingGroup", :reading_group_of, {:metric_configuration_id => metric_configuration_id} )[:reading_group]
  15 + end
  16 +
  17 + private
  18 +
  19 + def self.exists_params(id)
  20 + {:group_id => id}
  21 + end
  22 +
  23 + def destroy_params
  24 + {:group_id => self.id}
  25 + end
  26 +
  27 +end
plugins/mezuro/test/unit/kalibro/base_tool_test.rb
1 require "test_helper" 1 require "test_helper"
2 -  
3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" 2 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4 3
5 class BaseToolTest < ActiveSupport::TestCase 4 class BaseToolTest < ActiveSupport::TestCase
@@ -10,7 +9,7 @@ class BaseToolTest &lt; ActiveSupport::TestCase @@ -10,7 +9,7 @@ class BaseToolTest &lt; ActiveSupport::TestCase
10 end 9 end
11 10
12 should 'create base tool from hash' do 11 should 'create base tool from hash' do
13 - assert_equal @base_tool.name, Kalibro::BaseTool.new(@hash).name 12 + assert_equal @hash[:name], Kalibro::BaseTool.new(@hash).name
14 end 13 end
15 14
16 # Mezuro will not send a base_tool hash back to Kalibro 15 # Mezuro will not send a base_tool hash back to Kalibro
plugins/mezuro/test/unit/kalibro/reading_group_test.rb
@@ -28,13 +28,13 @@ class ReadingGroupTest &lt; ActiveSupport::TestCase @@ -28,13 +28,13 @@ class ReadingGroupTest &lt; ActiveSupport::TestCase
28 end 28 end
29 29
30 should 'get all reading groups' do 30 should 'get all reading groups' do
31 - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_group).returns({:reading_group => [@hash]}) 31 + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_groups).returns({:reading_group => [@hash]})
32 assert_equal @hash[:name], Kalibro::ReadingGroup.all[0].name 32 assert_equal @hash[:name], Kalibro::ReadingGroup.all[0].name
33 end 33 end
34 34
35 should 'get reading group of a metric configuration' do 35 should 'get reading group of a metric configuration' do
36 id = 31 36 id = 31
37 - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metricConfigurationId => id}).returns({:reading_group => @hash}) 37 + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metric_configuration_id => id}).returns({:reading_group => @hash})
38 assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name 38 assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name
39 end 39 end
40 40
@@ -48,7 +48,6 @@ class ReadingGroupTest &lt; ActiveSupport::TestCase @@ -48,7 +48,6 @@ class ReadingGroupTest &lt; ActiveSupport::TestCase
48 assert !(@reading_group.save) 48 assert !(@reading_group.save)
49 end 49 end
50 50
51 -  
52 should 'destroy reading group by id' do 51 should 'destroy reading group by id' do
53 Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :delete_reading_group, {:group_id => @reading_group.id}) 52 Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :delete_reading_group, {:group_id => @reading_group.id})
54 @reading_group.destroy 53 @reading_group.destroy