diff --git a/plugins/mezuro/lib/kalibro/configuration.rb b/plugins/mezuro/lib/kalibro/configuration.rb index 746e631..b8b7263 100644 --- a/plugins/mezuro/lib/kalibro/configuration.rb +++ b/plugins/mezuro/lib/kalibro/configuration.rb @@ -16,9 +16,11 @@ class Kalibro::Configuration < Kalibro::Model end =end - def self.exists?(id) - request("Configuration", :configuration_exists, {:configuration_id => id})[:exists] - end +# Should be on parent class +# +# def self.exists?(id) +# request("Configuration", :configuration_exists, {:configuration_id => id})[:exists] +# end def self.find(id) if(exists?(id)) diff --git a/plugins/mezuro/lib/kalibro/model.rb b/plugins/mezuro/lib/kalibro/model.rb index 6a72619..d453f50 100644 --- a/plugins/mezuro/lib/kalibro/model.rb +++ b/plugins/mezuro/lib/kalibro/model.rb @@ -66,6 +66,10 @@ class Kalibro::Model end end + def self.exists?(id) + request(exists_endpoint, exists_action, exists_params(id)) + end + protected def fields @@ -124,11 +128,27 @@ class Kalibro::Model end def destroy_action - "remove_#{class_name.underscore}".to_sym + "delete_#{class_name.underscore}".to_sym end def destroy_params - {"#{class_name.underscore}_name".to_sym => self.name} + {"#{class_name.underscore}_id".to_sym => self.id} + end + + def self.exists_class_name + self.name.gsub(/Kalibro::/,"") + end + + def self.exists_endpoint + self.exists_class_name + end + + def self.exists_action + "#{exists_class_name.underscore}_exists".to_sym + end + + def self.exists_params(id) + {"#{exists_class_name.underscore}_id".to_sym => id} end def add_error(exception) diff --git a/plugins/mezuro/lib/kalibro/reading_group.rb b/plugins/mezuro/lib/kalibro/reading_group.rb new file mode 100644 index 0000000..0eede2a --- /dev/null +++ b/plugins/mezuro/lib/kalibro/reading_group.rb @@ -0,0 +1,27 @@ +class Kalibro::ReadingGroup < Kalibro::Model + + attr_accessor :id, :name, :description + + def self.find(id) + new request("ReadingGroup", :get_reading_group, {:group_id => id})[:reading_group] + end + + def self.all + request("ReadingGroup", :all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group } + end + + def self.reading_group_of( metric_configuration_id ) + new request("ReadingGroup", :reading_group_of, {:metric_configuration_id => metric_configuration_id} )[:reading_group] + end + + private + + def self.exists_params(id) + {:group_id => id} + end + + def destroy_params + {:group_id => self.id} + end + +end diff --git a/plugins/mezuro/test/unit/kalibro/base_tool_test.rb b/plugins/mezuro/test/unit/kalibro/base_tool_test.rb index 7cc442b..d39bf3b 100644 --- a/plugins/mezuro/test/unit/kalibro/base_tool_test.rb +++ b/plugins/mezuro/test/unit/kalibro/base_tool_test.rb @@ -1,5 +1,4 @@ require "test_helper" - require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" class BaseToolTest < ActiveSupport::TestCase @@ -10,7 +9,7 @@ class BaseToolTest < ActiveSupport::TestCase end should 'create base tool from hash' do - assert_equal @base_tool.name, Kalibro::BaseTool.new(@hash).name + assert_equal @hash[:name], Kalibro::BaseTool.new(@hash).name end # Mezuro will not send a base_tool hash back to Kalibro diff --git a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb index 04b2a0c..993d7ad 100644 --- a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb +++ b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb @@ -28,13 +28,13 @@ class ReadingGroupTest < ActiveSupport::TestCase end should 'get all reading groups' do - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_group).returns({:reading_group => [@hash]}) + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_groups).returns({:reading_group => [@hash]}) assert_equal @hash[:name], Kalibro::ReadingGroup.all[0].name end should 'get reading group of a metric configuration' do id = 31 - Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metricConfigurationId => id}).returns({:reading_group => @hash}) + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metric_configuration_id => id}).returns({:reading_group => @hash}) assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name end @@ -48,7 +48,6 @@ class ReadingGroupTest < ActiveSupport::TestCase assert !(@reading_group.save) end - should 'destroy reading group by id' do Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :delete_reading_group, {:group_id => @reading_group.id}) @reading_group.destroy -- libgit2 0.21.2