Commit 570dc3a4e94b6017a00a6f4a57abe564e15f10f3
Committed by
Diego Camarinha
1 parent
c4dca0da
Exists in
colab
and in
4 other branches
Added unit tests for uncovered lines from ReadingGroup and KalibroConfiguration
Showing
2 changed files
with
64 additions
and
30 deletions
Show diff stats
spec/models/kalibro_configuration_spec.rb
| @@ -28,30 +28,47 @@ describe KalibroConfiguration, :type => :model do | @@ -28,30 +28,47 @@ describe KalibroConfiguration, :type => :model do | ||
| 28 | let(:ones_or_public_attrs) { public_attrs + [ones_private_attrs] } | 28 | let(:ones_or_public_attrs) { public_attrs + [ones_private_attrs] } |
| 29 | let(:ones_or_public_kalibro_configurations) { ones_or_public_attrs.map(&:kalibro_configuration) } | 29 | let(:ones_or_public_kalibro_configurations) { ones_or_public_attrs.map(&:kalibro_configuration) } |
| 30 | 30 | ||
| 31 | - before :each do | ||
| 32 | - # Map the reading group attributes to the corresponding Reading Group | ||
| 33 | - kalibro_configurations.each do |kc| | ||
| 34 | - KalibroConfiguration.stubs(:find).with(kc.id).returns(kc) | 31 | + context 'when the kalibro configuration exists' do |
| 32 | + before :each do | ||
| 33 | + # Map the kalibro_configuration attributes to the corresponding Kalibro Configuration | ||
| 34 | + kalibro_configurations.each do |kc| | ||
| 35 | + KalibroConfiguration.stubs(:find).with(kc.id).returns(kc) | ||
| 36 | + end | ||
| 35 | end | 37 | end |
| 36 | - end | ||
| 37 | 38 | ||
| 38 | - context 'when user is not provided' do | ||
| 39 | - before do | ||
| 40 | - KalibroConfigurationAttributes.expects(:where).with(public: true).returns(public_attrs) | 39 | + context 'when user is not provided' do |
| 40 | + before do | ||
| 41 | + KalibroConfigurationAttributes.expects(:where).with(public: true).returns(public_attrs) | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + it 'should find all public reading groups' do | ||
| 45 | + expect(KalibroConfiguration.public).to eq(public_kalibro_configurations) | ||
| 46 | + end | ||
| 41 | end | 47 | end |
| 42 | 48 | ||
| 43 | - it 'should find all public reading groups' do | ||
| 44 | - expect(KalibroConfiguration.public).to eq(public_kalibro_configurations) | 49 | + context 'when user is provided' do |
| 50 | + before do | ||
| 51 | + KalibroConfigurationAttributes.expects(:where).with(kind_of(String), one_user.id).returns(ones_or_public_attrs) | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + it 'should find all public and owned reading groups' do | ||
| 55 | + expect(KalibroConfiguration.public_or_owned_by_user(one_user)).to eq(ones_or_public_kalibro_configurations) | ||
| 56 | + end | ||
| 45 | end | 57 | end |
| 46 | end | 58 | end |
| 47 | 59 | ||
| 48 | - context 'when user is provided' do | ||
| 49 | - before do | ||
| 50 | - KalibroConfigurationAttributes.expects(:where).with(kind_of(String), one_user.id).returns(ones_or_public_attrs) | 60 | + context 'when the kalibro configuration does not' do |
| 61 | + before :each do | ||
| 62 | + # Map the kalibro_configuration attributes to the corresponding Kalibro Configuration | ||
| 63 | + kalibro_configurations.each do |kc| | ||
| 64 | + KalibroConfiguration.stubs(:find).with(kc.id).raises(KalibroClient::Errors::RecordNotFound) | ||
| 65 | + end | ||
| 66 | + | ||
| 67 | + KalibroConfigurationAttributes.expects(:where).with(public: true).returns(public_attrs) | ||
| 51 | end | 68 | end |
| 52 | 69 | ||
| 53 | - it 'should find all public and owned reading groups' do | ||
| 54 | - expect(KalibroConfiguration.public_or_owned_by_user(one_user)).to eq(ones_or_public_kalibro_configurations) | 70 | + it 'is expected to be empty' do |
| 71 | + expect(KalibroConfiguration.public).to be_empty | ||
| 55 | end | 72 | end |
| 56 | end | 73 | end |
| 57 | end | 74 | end |
spec/models/reading_group_spec.rb
| @@ -73,30 +73,47 @@ describe ReadingGroup, :type => :model do | @@ -73,30 +73,47 @@ describe ReadingGroup, :type => :model do | ||
| 73 | let(:ones_or_public_attrs) { public_attrs + [ones_private_attrs] } | 73 | let(:ones_or_public_attrs) { public_attrs + [ones_private_attrs] } |
| 74 | let(:ones_or_public_reading_groups) { ones_or_public_attrs.map(&:reading_group) } | 74 | let(:ones_or_public_reading_groups) { ones_or_public_attrs.map(&:reading_group) } |
| 75 | 75 | ||
| 76 | - before :each do | ||
| 77 | - # Map the reading group attributes to the corresponding Reading Group | ||
| 78 | - reading_groups.each do |rg| | ||
| 79 | - ReadingGroup.stubs(:find).with(rg.id).returns(rg) | 76 | + context 'when the reading group exists' do |
| 77 | + before :each do | ||
| 78 | + # Map the reading group attributes to the corresponding Reading Group | ||
| 79 | + reading_groups.each do |rg| | ||
| 80 | + ReadingGroup.stubs(:find).with(rg.id).returns(rg) | ||
| 81 | + end | ||
| 80 | end | 82 | end |
| 81 | - end | ||
| 82 | 83 | ||
| 83 | - context 'when user is not provided' do | ||
| 84 | - before do | ||
| 85 | - ReadingGroupAttributes.expects(:where).with(public: true).returns(public_attrs) | 84 | + context 'when user is not provided' do |
| 85 | + before do | ||
| 86 | + ReadingGroupAttributes.expects(:where).with(public: true).returns(public_attrs) | ||
| 87 | + end | ||
| 88 | + | ||
| 89 | + it 'should find all public reading groups' do | ||
| 90 | + expect(ReadingGroup.public).to eq(public_reading_groups) | ||
| 91 | + end | ||
| 86 | end | 92 | end |
| 87 | 93 | ||
| 88 | - it 'should find all public reading groups' do | ||
| 89 | - expect(ReadingGroup.public).to eq(public_reading_groups) | 94 | + context 'when user is provided' do |
| 95 | + before do | ||
| 96 | + ReadingGroupAttributes.expects(:where).with(kind_of(String), one_user.id).returns(ones_or_public_attrs) | ||
| 97 | + end | ||
| 98 | + | ||
| 99 | + it 'should find all public and owned reading groups' do | ||
| 100 | + expect(ReadingGroup.public_or_owned_by_user(one_user)).to eq(ones_or_public_reading_groups) | ||
| 101 | + end | ||
| 90 | end | 102 | end |
| 91 | end | 103 | end |
| 92 | 104 | ||
| 93 | - context 'when user is provided' do | ||
| 94 | - before do | ||
| 95 | - ReadingGroupAttributes.expects(:where).with(kind_of(String), one_user.id).returns(ones_or_public_attrs) | 105 | + context 'when the reading group does not' do |
| 106 | + before :each do | ||
| 107 | + # Map the reading group attributes to the corresponding Reading Group | ||
| 108 | + reading_groups.each do |rg| | ||
| 109 | + ReadingGroup.stubs(:find).with(rg.id).raises(KalibroClient::Errors::RecordNotFound) | ||
| 110 | + end | ||
| 111 | + | ||
| 112 | + ReadingGroupAttributes.expects(:where).with(public: true).returns(public_attrs) | ||
| 96 | end | 113 | end |
| 97 | 114 | ||
| 98 | - it 'should find all public and owned reading groups' do | ||
| 99 | - expect(ReadingGroup.public_or_owned_by_user(one_user)).to eq(ones_or_public_reading_groups) | 115 | + it 'is expected to be empty' do |
| 116 | + expect(ReadingGroup.public).to be_empty | ||
| 100 | end | 117 | end |
| 101 | end | 118 | end |
| 102 | end | 119 | end |