diff --git a/plugins/mezuro/test/fixtures/reading_group_fixtures.rb b/plugins/mezuro/test/fixtures/reading_group_fixtures.rb new file mode 100644 index 0000000..a1c9933 --- /dev/null +++ b/plugins/mezuro/test/fixtures/reading_group_fixtures.rb @@ -0,0 +1,11 @@ +class ReadingGroupFixtures + + def self.reading_group + Kalibro::ReadingGroup.new reading_group_hash + end + + def self.reading_group_hash + {:id => 42, :name => "Reading Group Test", :description => "Reading group in the fixtures"} + end + +end diff --git a/plugins/mezuro/test/unit/kalibro/reading_group_test.rb b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb new file mode 100644 index 0000000..04b2a0c --- /dev/null +++ b/plugins/mezuro/test/unit/kalibro/reading_group_test.rb @@ -0,0 +1,58 @@ +require "test_helper" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures" + +class ReadingGroupTest < ActiveSupport::TestCase + + def setup + @hash = ReadingGroupFixtures.reading_group_hash + @reading_group = ReadingGroupFixtures.reading_group + end + + should 'create reading group from hash' do + assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name + end + + should 'convert reading group to hash' do + assert_equal @hash, @reading_group.to_hash + end + + should 'verify existence of reading group' do + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true}) + assert Kalibro::ReadingGroup.exists?(@hash[:id]) + end + + should 'get reading group' do + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :get_reading_group, {:group_id => @hash[:id]}). + returns({:reading_group => @hash}) + assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name + end + + should 'get all reading groups' do + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_group).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}) + assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name + end + + should 'return true when reading group is saved successfully' do + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @reading_group.to_hash}).returns(-1) + assert @reading_group.save + end + + should 'return false when reading group is not saved successfully' do + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @reading_group.to_hash}).raises(Exception.new) + 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 + end + +end + -- libgit2 0.21.2