Sha256: a1477cb2f143da59f9ab965f13c968df1977d65ca4da34dbbccb221a550a62d5

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'test_helper'

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

  role :others do; end
  role :other do; 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
surrounded-0.9.11 test/collection_role_players_test.rb
surrounded-0.9.10 test/collection_role_players_test.rb
surrounded-0.9.9 test/collection_role_players_test.rb