test/surrounded_context_test.rb in surrounded-0.8.2 vs test/surrounded_context_test.rb in surrounded-0.8.3
- old
+ new
@@ -171,14 +171,61 @@
context = ClassRoleAssignmentContext.new(user, self)
assert context.check_user_response
end
-
+
it 'allows usage of regular methods for triggers' do
assert context.regular_method_trigger
end
-
+
it 'ignores nil trigger names' do
assert context.class.send(:trigger)
end
-end
\ No newline at end of file
+end
+
+class CollectionContext
+ extend Surrounded::Context
+
+ initialize :members, :others
+
+ trigger :get_members_count do
+ members.member_count
+ end
+
+ trigger :get_member_show do
+ members.map(&:show).join(', ')
+ end
+
+ role :members do
+ def member_count
+ size
+ end
+ end
+
+ role :member do
+ def show
+ "member show"
+ end
+ end
+
+end
+
+describe Surrounded::Context, 'auto-assigning roles for collections' do
+ let(:member_one){ User.new('Jim') }
+ let(:member_two){ User.new('Amy') }
+ let(:members){ [member_one, member_two] }
+
+ let(:other_one){ User.new('Guille') }
+ let(:other_two){ User.new('Jason') }
+ let(:others){ [other_one, other_two] }
+
+ let(:context){ CollectionContext.new(members, others) }
+
+ it 'assigns the collection role to collections' do
+ assert_equal members.size, context.get_members_count
+ end
+
+ it 'assigns a defined role to each item in a role player collection' do
+ assert_equal "member show, member show", context.get_member_show
+ end
+end