Commit ab72759afbd0ae103556c512ff4fa05f317801e5
Committed by
João M. M. da Silva
1 parent
ecffc84d
Exists in
master
and in
29 other branches
[Mezuro] Finished Reading Group tests.
Showing
2 changed files
with
69 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +class ReadingGroupFixtures | ||
2 | + | ||
3 | + def self.reading_group | ||
4 | + Kalibro::ReadingGroup.new reading_group_hash | ||
5 | + end | ||
6 | + | ||
7 | + def self.reading_group_hash | ||
8 | + {:id => 42, :name => "Reading Group Test", :description => "Reading group in the fixtures"} | ||
9 | + end | ||
10 | + | ||
11 | +end |
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +require "test_helper" | ||
2 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures" | ||
3 | + | ||
4 | +class ReadingGroupTest < ActiveSupport::TestCase | ||
5 | + | ||
6 | + def setup | ||
7 | + @hash = ReadingGroupFixtures.reading_group_hash | ||
8 | + @reading_group = ReadingGroupFixtures.reading_group | ||
9 | + end | ||
10 | + | ||
11 | + should 'create reading group from hash' do | ||
12 | + assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name | ||
13 | + end | ||
14 | + | ||
15 | + should 'convert reading group to hash' do | ||
16 | + assert_equal @hash, @reading_group.to_hash | ||
17 | + end | ||
18 | + | ||
19 | + should 'verify existence of reading group' do | ||
20 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true}) | ||
21 | + assert Kalibro::ReadingGroup.exists?(@hash[:id]) | ||
22 | + end | ||
23 | + | ||
24 | + should 'get reading group' do | ||
25 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :get_reading_group, {:group_id => @hash[:id]}). | ||
26 | + returns({:reading_group => @hash}) | ||
27 | + assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name | ||
28 | + end | ||
29 | + | ||
30 | + should 'get all reading groups' do | ||
31 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :all_reading_group).returns({:reading_group => [@hash]}) | ||
32 | + assert_equal @hash[:name], Kalibro::ReadingGroup.all[0].name | ||
33 | + end | ||
34 | + | ||
35 | + should 'get reading group of a metric configuration' do | ||
36 | + id = 31 | ||
37 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :reading_group_of, {:metricConfigurationId => id}).returns({:reading_group => @hash}) | ||
38 | + assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name | ||
39 | + end | ||
40 | + | ||
41 | + should 'return true when reading group is saved successfully' do | ||
42 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @reading_group.to_hash}).returns(-1) | ||
43 | + assert @reading_group.save | ||
44 | + end | ||
45 | + | ||
46 | + should 'return false when reading group is not saved successfully' do | ||
47 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :save_reading_group, {:reading_group => @reading_group.to_hash}).raises(Exception.new) | ||
48 | + assert !(@reading_group.save) | ||
49 | + end | ||
50 | + | ||
51 | + | ||
52 | + should 'destroy reading group by id' do | ||
53 | + Kalibro::ReadingGroup.expects(:request).with("ReadingGroup", :delete_reading_group, {:group_id => @reading_group.id}) | ||
54 | + @reading_group.destroy | ||
55 | + end | ||
56 | + | ||
57 | +end | ||
58 | + |