aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-07-26 16:15:23 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-07-26 16:15:23 +0200
commit1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d (patch)
tree0a112d62e2e47be74d8efeb2c3ead50b17131077
parentCouncil members can approve summaries (diff)
downloadcouncil-webapp-1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d.tar.gz
council-webapp-1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d.tar.bz2
council-webapp-1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d.zip
Improve tests
use :all_roles and :registered to make users in factory
-rw-r--r--site/spec/models/agenda_item_spec.rb2
-rw-r--r--site/spec/models/agenda_spec.rb10
-rw-r--r--site/spec/models/approval_spec.rb2
-rw-r--r--site/spec/models/participation_spec.rb4
-rw-r--r--site/spec/models/proxy_spec.rb6
-rw-r--r--site/spec/models/user_spec.rb6
-rw-r--r--site/spec/models/vote_spec.rb10
-rw-r--r--site/spec/models/voting_option_spec.rb4
-rw-r--r--site/spec/support/users_factory.rb15
9 files changed, 35 insertions, 24 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 b9e564c..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,14 +11,14 @@ 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
@@ -32,7 +32,7 @@ describe Agenda do
(1..4).each { |i| Factory(:approval, :agenda => agenda) }
- for u in users_factory(AllRoles)
+ for u in users_factory(:all_roles)
agenda.should be_viewable_by(u, :summary)
end
end
@@ -49,7 +49,7 @@ 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
diff --git a/site/spec/models/approval_spec.rb b/site/spec/models/approval_spec.rb
index 4057a6d..701504e 100644
--- a/site/spec/models/approval_spec.rb
+++ b/site/spec/models/approval_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Approval do
it 'should be viewable by everybody' do
approval = Factory(:approval)
- for user in users_factory(AllRoles)
+ for user in users_factory(:all_roles)
approval.should be_viewable_by(user)
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
diff --git a/site/spec/support/users_factory.rb b/site/spec/support/users_factory.rb
index 40c715b..126a7b9 100644
--- a/site/spec/support/users_factory.rb
+++ b/site/spec/support/users_factory.rb
@@ -1,6 +1,19 @@
def users_factory(*roles)
roles.flatten!
+ roles.collect! do |role|
+ case role
+ when :all_roles
+ [:guest, :user, :council, :admin, :council_admin]
+ when :registered
+ [:user, :council, :admin, :council_admin]
+ else
+ role
+ end
+ end
+ roles.flatten!
+
r = []
+ roles
for role in roles
case role
when :guest
@@ -17,5 +30,3 @@ def users_factory(*roles)
end
(r.count < 2) ? r.first : r
end
-
-AllRoles = [:guest, :user, :council, :admin, :council_admin]