diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-05-10 17:42:24 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-05-11 20:12:32 +0300 |
commit | 37a64fc3e0581bad11b58524d8bf61cb29a1bfec (patch) | |
tree | 3d324693ddd1931dbcc4eecad54b381f34b445ec | |
parent | c93eb845d6a444d2ee53592b15ea8dd2c8bf7429 (diff) |
Added basic specs for Participable
-rw-r--r-- | spec/models/concerns/participable_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb new file mode 100644 index 00000000000..42c137e8473 --- /dev/null +++ b/spec/models/concerns/participable_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Participable, models: true do + let(:model) do + Class.new do + include Participable + end + end + + describe '.participant' do + it 'adds the participant attributes to the existing list' do + model.participant(:foo) + model.participant(:bar) + + expect(model.participant_attrs).to eq([:foo, :bar]) + end + end + + describe '#participants' do + it 'returns the list of participants' do + model.participant(:foo, :bar) + + user1 = build(:user) + user2 = build(:user) + user3 = build(:user) + instance = model.new + + expect(instance).to receive(:foo).and_return(user2) + expect(instance).to receive(:bar).and_return(user3) + + expect(instance.participants(user1)).to eq([user2, user3]) + end + + context 'when using a Proc as an attribute' do + it 'calls the supplied Proc' do + user1 = build(:user) + user2 = build(:user) + + model.participant proc { user2 } + + expect(model.new.participants(user1)).to eq([user2]) + end + + it 'passes the current user to the Proc' do + user1 = build(:user) + + model.participant proc { |user| user } + + expect(model.new.participants(user1)).to eq([user1]) + end + end + end +end |