diff --git a/plugins/mezuro/lib/kalibro/reading_group.rb b/plugins/mezuro/lib/kalibro/reading_group.rb index c818cd6..f5181fd 100644 --- a/plugins/mezuro/lib/kalibro/reading_group.rb +++ b/plugins/mezuro/lib/kalibro/reading_group.rb @@ -2,8 +2,15 @@ class Kalibro::ReadingGroup < Kalibro::Model attr_accessor :id, :name, :description + def id=(value) + @id = value.to_i + end + def self.all - request(:all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group } + response = request(:all_reading_groups)[:reading_group] + response = [] if response.nil? + response = [response] if response.is_a?(Hash) + response.map { |reading_group| new reading_group } end def self.reading_group_of( metric_configuration_id ) diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb index fed899e..b9bd3e8 100644 --- a/plugins/mezuro/lib/mezuro_plugin/project_content.rb +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -84,7 +84,8 @@ class MezuroPlugin::ProjectContent < Article def create_kalibro_project Kalibro::Project.create( :name => name, - :description => description + :description => description, + :id => self.project_id ) end diff --git a/plugins/mezuro/test/unit/kalibro/project_test.rb b/plugins/mezuro/test/unit/kalibro/project_test.rb index 0e24abf..ab79039 100644 --- a/plugins/mezuro/test/unit/kalibro/project_test.rb +++ b/plugins/mezuro/test/unit/kalibro/project_test.rb @@ -43,11 +43,18 @@ class ProjectTest < ActiveSupport::TestCase assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name end - should 'get all project' do - Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash]}) + should 'get all projects when there is only one project' do + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => @hash}) assert_equal @hash[:name], Kalibro::Project.all.first.name end + should 'get all projects when there are many projects' do + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash, @hash]}) + projects = Kalibro::Project.all + assert_equal @hash[:name], projects.first.name + assert_equal @hash[:name], projects.last.name + end + should 'return empty when there are no projects' do Kalibro::Project.expects(:request).with(:all_projects).returns({:project => nil}) assert_equal [], Kalibro::Project.all diff --git a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb index 5a8fbe9..a8f9309 100644 --- a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb +++ b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb @@ -32,11 +32,21 @@ class ReadingGroupTest < ActiveSupport::TestCase assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name end + should 'get all reading groups when there is only one reading group' do + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => @hash}) + assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name + end + should 'get all reading groups when there are many reading groups' do + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash, @hash]}) + reading_groups = Kalibro::ReadingGroup.all + assert_equal @hash[:name], reading_groups.first.name + assert_equal @hash[:name], reading_groups.last.name + end - should 'get all reading groups' do - Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash]}) - assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name + should 'return empty when there are no reading groups' do + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => nil}) + assert_equal [], Kalibro::ReadingGroup.all end should 'get reading group of a metric configuration' do -- libgit2 0.21.2