Commit 59c59bd5f2c3b1177b5c7ccfeea41fd4dd9d8db1
Committed by
Paulo Meireles
1 parent
7bed0f95
Exists in
master
and in
22 other branches
[Mezuro] Fixed project content edition and "all" methods in project and reading group.
Showing
4 changed files
with
32 additions
and
7 deletions
Show diff stats
plugins/mezuro/lib/kalibro/reading_group.rb
@@ -2,8 +2,15 @@ class Kalibro::ReadingGroup < Kalibro::Model | @@ -2,8 +2,15 @@ class Kalibro::ReadingGroup < Kalibro::Model | ||
2 | 2 | ||
3 | attr_accessor :id, :name, :description | 3 | attr_accessor :id, :name, :description |
4 | 4 | ||
5 | + def id=(value) | ||
6 | + @id = value.to_i | ||
7 | + end | ||
8 | + | ||
5 | def self.all | 9 | def self.all |
6 | - request(:all_reading_groups)[:reading_group].to_a.map { |reading_group| new reading_group } | 10 | + response = request(:all_reading_groups)[:reading_group] |
11 | + response = [] if response.nil? | ||
12 | + response = [response] if response.is_a?(Hash) | ||
13 | + response.map { |reading_group| new reading_group } | ||
7 | end | 14 | end |
8 | 15 | ||
9 | def self.reading_group_of( metric_configuration_id ) | 16 | def self.reading_group_of( metric_configuration_id ) |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
@@ -84,7 +84,8 @@ class MezuroPlugin::ProjectContent < Article | @@ -84,7 +84,8 @@ class MezuroPlugin::ProjectContent < Article | ||
84 | def create_kalibro_project | 84 | def create_kalibro_project |
85 | Kalibro::Project.create( | 85 | Kalibro::Project.create( |
86 | :name => name, | 86 | :name => name, |
87 | - :description => description | 87 | + :description => description, |
88 | + :id => self.project_id | ||
88 | ) | 89 | ) |
89 | end | 90 | end |
90 | 91 |
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -43,11 +43,18 @@ class ProjectTest < ActiveSupport::TestCase | @@ -43,11 +43,18 @@ class ProjectTest < ActiveSupport::TestCase | ||
43 | assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name | 43 | assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name |
44 | end | 44 | end |
45 | 45 | ||
46 | - should 'get all project' do | ||
47 | - Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash]}) | 46 | + should 'get all projects when there is only one project' do |
47 | + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => @hash}) | ||
48 | assert_equal @hash[:name], Kalibro::Project.all.first.name | 48 | assert_equal @hash[:name], Kalibro::Project.all.first.name |
49 | end | 49 | end |
50 | 50 | ||
51 | + should 'get all projects when there are many projects' do | ||
52 | + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash, @hash]}) | ||
53 | + projects = Kalibro::Project.all | ||
54 | + assert_equal @hash[:name], projects.first.name | ||
55 | + assert_equal @hash[:name], projects.last.name | ||
56 | + end | ||
57 | + | ||
51 | should 'return empty when there are no projects' do | 58 | should 'return empty when there are no projects' do |
52 | Kalibro::Project.expects(:request).with(:all_projects).returns({:project => nil}) | 59 | Kalibro::Project.expects(:request).with(:all_projects).returns({:project => nil}) |
53 | assert_equal [], Kalibro::Project.all | 60 | assert_equal [], Kalibro::Project.all |
plugins/mezuro/test/unit/kalibro/reading_group_test.rb
@@ -32,11 +32,21 @@ class ReadingGroupTest < ActiveSupport::TestCase | @@ -32,11 +32,21 @@ class ReadingGroupTest < ActiveSupport::TestCase | ||
32 | assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name | 32 | assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name |
33 | end | 33 | end |
34 | 34 | ||
35 | + should 'get all reading groups when there is only one reading group' do | ||
36 | + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => @hash}) | ||
37 | + assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name | ||
38 | + end | ||
35 | 39 | ||
40 | + should 'get all reading groups when there are many reading groups' do | ||
41 | + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash, @hash]}) | ||
42 | + reading_groups = Kalibro::ReadingGroup.all | ||
43 | + assert_equal @hash[:name], reading_groups.first.name | ||
44 | + assert_equal @hash[:name], reading_groups.last.name | ||
45 | + end | ||
36 | 46 | ||
37 | - should 'get all reading groups' do | ||
38 | - Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash]}) | ||
39 | - assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name | 47 | + should 'return empty when there are no reading groups' do |
48 | + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => nil}) | ||
49 | + assert_equal [], Kalibro::ReadingGroup.all | ||
40 | end | 50 | end |
41 | 51 | ||
42 | should 'get reading group of a metric configuration' do | 52 | should 'get reading group of a metric configuration' do |