diff options
author | Petteri Räty <petsku@petteriraty.eu> | 2011-08-01 17:35:02 +0300 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2011-08-01 17:35:02 +0300 |
commit | 4f32847c92654f3e8b9e8a0569872cdc1336e537 (patch) | |
tree | d83748c6285828e3c6b089c4d2523ac991362ccd /site/spec/models | |
parent | Show use hints for users (diff) | |
parent | Add and cleanup validations (diff) | |
download | council-webapp-4f32847c92654f3e8b9e8a0569872cdc1336e537.tar.gz council-webapp-4f32847c92654f3e8b9e8a0569872cdc1336e537.tar.bz2 council-webapp-4f32847c92654f3e8b9e8a0569872cdc1336e537.zip |
Merge remote-tracking branch 'github/review'
Diffstat (limited to 'site/spec/models')
-rw-r--r-- | site/spec/models/agenda_item_spec.rb | 2 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 41 | ||||
-rw-r--r-- | site/spec/models/approval_spec.rb | 36 | ||||
-rw-r--r-- | site/spec/models/participation_spec.rb | 4 | ||||
-rw-r--r-- | site/spec/models/proxy_spec.rb | 6 | ||||
-rw-r--r-- | site/spec/models/user_spec.rb | 6 | ||||
-rw-r--r-- | site/spec/models/vote_spec.rb | 10 | ||||
-rw-r--r-- | site/spec/models/voting_option_spec.rb | 4 |
8 files changed, 89 insertions, 20 deletions
diff --git a/site/spec/models/agenda_item_spec.rb b/site/spec/models/agenda_item_spec.rb index 961b663..fe4f906 100644 --- a/site/spec/models/agenda_item_spec.rb +++ b/site/spec/models/agenda_item_spec.rb @@ -52,7 +52,7 @@ describe AgendaItem do owner = Factory(:user) agenda = Factory(:agenda, :state => 'old') a = Factory(:agenda_item, :user => owner, :agenda => agenda) - for u in users_factory(AllRoles) + [owner] + for u in users_factory(:all_roles) + [owner] a.should_not be_editable_by(u) a.should_not be_updatable_by(u) end diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb index f0dc747..738db63 100644 --- a/site/spec/models/agenda_spec.rb +++ b/site/spec/models/agenda_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Agenda do it 'shouldn not allow anyone to create' do a = Agenda.new - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) a.should_not be_creatable_by(u) a.should_not be_destroyable_by(u) end @@ -11,18 +11,32 @@ describe Agenda do it 'shouldn not allow anyone to destory' do a = Factory(:agenda) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) a.should_not be_destroyable_by(u) end end it 'should allow everybody to view' do a = Factory(:agenda) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) a.should be_viewable_by(u) end end + it 'should allow everybody to view summaries after 4 council members approved it' do + agenda = Agenda.current + + for u in users_factory(:guest, :user, :admin) + agenda.should_not be_viewable_by(u, :summary) + end + + (1..4).each { |i| Factory(:approval, :agenda => agenda) } + + for u in users_factory(:all_roles) + agenda.should be_viewable_by(u, :summary) + end + end + it 'should allow only administrators and council members to edit and update' do a = Factory(:agenda) for u in users_factory(:guest, :user) @@ -35,12 +49,23 @@ describe Agenda do a = Factory(:agenda) a.meeting_log = 'changed' - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) a.should_not be_editable_by(u, :meeting_log) a.should_not be_updatable_by(u) end end + it 'should allow council memebers to change summaries of old meetings' do + a = Factory(:agenda, :state => 'old') + a.summary = 'changed' + + for u in users_factory(:council, :council_admin) + a.should be_editable_by(u) + a.should be_editable_by(u, :summary) + a.should be_updatable_by(u) + end + end + def test_migration(object, migration, prohibited, allowed, final_state) # object - object to migrate # migration - migration name @@ -299,4 +324,12 @@ describe Agenda do VotingOption.last.description.should == 'new option' end end + + it 'should remove approvals for summary, when summary changes' do + agenda = Agenda.current + Factory(:approval, :agenda => agenda) + agenda.summary = 'changed' + agenda.save! + Approval.count.should be_zero + end end diff --git a/site/spec/models/approval_spec.rb b/site/spec/models/approval_spec.rb new file mode 100644 index 0000000..701504e --- /dev/null +++ b/site/spec/models/approval_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Approval do + it 'should be viewable by everybody' do + approval = Factory(:approval) + for user in users_factory(:all_roles) + approval.should be_viewable_by(user) + end + end + + it 'only council members should be able to change it - and only for themselves' do + for user in users_factory(:council, :council_admin) + approval = Factory(:approval, :user => user) + approval.should be_creatable_by(user) + approval.should be_editable_by(user) + approval.should be_updatable_by(user) + approval.should be_destroyable_by(user) + end + + approval = Factory(:approval) + for user in users_factory(:council, :council_admin) + approval.should_not be_creatable_by(user) + approval.should_not be_editable_by(user) + approval.should_not be_updatable_by(user) + approval.should_not be_destroyable_by(user) + end + + for user in users_factory(:user, :admin) + approval = Approval.new :user => user, :agenda => Agenda.current + approval.should_not be_creatable_by(user) + approval.should_not be_editable_by(user) + approval.should_not be_updatable_by(user) + approval.should_not be_destroyable_by(user) + end + end +end diff --git a/site/spec/models/participation_spec.rb b/site/spec/models/participation_spec.rb index 395dc03..75485e6 100644 --- a/site/spec/models/participation_spec.rb +++ b/site/spec/models/participation_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Participation do it 'should not allow anyone to create, edit, update or destroy' do p = Factory(:participation) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) p.should_not be_creatable_by(u) p.should_not be_editable_by(u) p.should_not be_updatable_by(u) @@ -13,7 +13,7 @@ describe Participation do it 'should allow everybody to view' do p = Factory(:participation) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) p.should be_viewable_by(u) end end diff --git a/site/spec/models/proxy_spec.rb b/site/spec/models/proxy_spec.rb index a94aa06..995ebb1 100644 --- a/site/spec/models/proxy_spec.rb +++ b/site/spec/models/proxy_spec.rb @@ -63,7 +63,7 @@ describe Proxy do it 'should allow no one to update or edit' do p = Factory(:proxy) - for u in users_factory(AllRoles) + [p.council_member, p.proxy] + for u in users_factory(:all_roles) + [p.council_member, p.proxy] p.should_not be_editable_by(u) p.should_not be_updatable_by(u) end @@ -72,7 +72,7 @@ describe Proxy do it 'should allow everyone to view' do p = Factory(:proxy) - for u in users_factory(AllRoles) + [p.council_member, p.proxy] + for u in users_factory(:all_roles) + [p.council_member, p.proxy] p.should be_viewable_by(u) end end @@ -92,7 +92,7 @@ describe Proxy do it 'should not allow users to destoy someone else proxy' do a = Factory(:agenda) p = Factory(:proxy, :agenda => a) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) p.should_not be_destroyable_by(u) end end diff --git a/site/spec/models/user_spec.rb b/site/spec/models/user_spec.rb index ad36761..c9f36b9 100644 --- a/site/spec/models/user_spec.rb +++ b/site/spec/models/user_spec.rb @@ -90,7 +90,7 @@ describe User do end it 'should allow no one to create' do - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) User.new.should_not be_creatable_by(u) end end @@ -106,8 +106,8 @@ describe User do end it 'should allow everybody to view' do - for u1 in users_factory(AllRoles) - for u2 in users_factory(AllRoles - [:guest]) + for u1 in users_factory(:all_roles) + for u2 in users_factory(:registered) u2.should be_viewable_by(u1) end end diff --git a/site/spec/models/vote_spec.rb b/site/spec/models/vote_spec.rb index f2d529e..5f53a69 100644 --- a/site/spec/models/vote_spec.rb +++ b/site/spec/models/vote_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Vote do it 'should allow anyone to create, update and destroy their own votes' do - for u in users_factory(AllRoles - [:guest]) do + for u in users_factory(:registered) do vote = Factory(:vote, :user => u) vote.should be_creatable_by(u) vote.should be_updatable_by(u) @@ -12,7 +12,7 @@ describe Vote do it 'should not allow anyone to create, update and destroy vote of someone else' do vote = Factory(:vote) - for u in users_factory(AllRoles) do + for u in users_factory(:all_roles) do vote.should_not be_creatable_by(u) vote.should_not be_updatable_by(u) vote.should_not be_destroyable_by(u) @@ -21,13 +21,13 @@ describe Vote do it 'should allow anyone to view' do vote = Factory(:vote) - for u in users_factory(AllRoles) do + for u in users_factory(:all_roles) do vote.should be_viewable_by(u) end end it 'should allow all users to vote' do - for u in users_factory(AllRoles - [:guest]) do + for u in users_factory(:registered) do Vote.new(:user => u, :voting_option => Factory(:voting_option)).should be_valid end end @@ -39,7 +39,7 @@ describe Vote do end it 'should prevent users from setting council_vote to true' do - for u in users_factory(AllRoles - [:guest]) + for u in users_factory(:registered) v = Factory(:vote, :user => u, :council_vote => true) v.should_not be_editable_by(u) v.should_not be_updatable_by(u) diff --git a/site/spec/models/voting_option_spec.rb b/site/spec/models/voting_option_spec.rb index 87074c6..5054f43 100644 --- a/site/spec/models/voting_option_spec.rb +++ b/site/spec/models/voting_option_spec.rb @@ -31,7 +31,7 @@ describe VotingOption do a2 = Factory(:agenda, :state => 'old') i2 = Factory(:agenda_item, :agenda => a2) v2 = Factory(:voting_option, :agenda_item => i2) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) v1.should_not be_updatable_by(u) v1.should_not be_destroyable_by(u) v2.should_not be_updatable_by(u) @@ -41,7 +41,7 @@ describe VotingOption do it 'should allow everyone to view' do v = Factory(:voting_option) - for u in users_factory(AllRoles) + for u in users_factory(:all_roles) v.should be_viewable_by(u) end end |