From 5d560609e40505cda4cb90f34292bd4b291c7b4a Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Fri, 21 Mar 2014 12:20:01 +0100 Subject: [PATCH] poll_participation_spec no longer fails, added poll_participation factory --- app/models/poll.rb | 7 ++--- spec/factories.rb | 17 +++++++++++ spec/models/poll_participation_spec.rb | 41 ++++++++++++++------------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 896908b50..586e18154 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -6,10 +6,7 @@ class Poll < ActiveRecord::Base has_many :poll_answers has_many :poll_participations - delegate :author, :author_id, :subscribers, to: :status_message + #forward some requests to status message, because a poll is just attached to a status message and is not sharable itself + delegate :author, :author_id, :public?, :subscribers, to: :status_message - #forward subscribers request to status message, because a poll is just attached to a status message and is not sharable itself - #def subscribers(user) - # status_message.subscribers(user) - #end end diff --git a/spec/factories.rb b/spec/factories.rb index fcede7e1b..232e3a15b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -92,6 +92,12 @@ FactoryGirl.define do end end + factory(:status_message_with_poll, :parent => :status_message) do + after(:build) do |sm| + FactoryGirl.create(:poll, :status_message => sm) + end + end + factory(:status_message_with_photo, :parent => :status_message) do sequence(:text) { |n| "There are #{n} ninjas in this photo." } after(:build) do |sm| @@ -107,6 +113,17 @@ FactoryGirl.define do end end + factory(:poll) do + sequence(:question) { |n| "What do you think about #{n} ninjas?" } + after(:build) do |p| + FactoryGirl.create(:poll_answer, :poll => p) + end + end + + factory(:poll_answer) do + sequence(:answer) { |n| "#{n} questionmarks" } + end + factory(:photo) do sequence(:random_string) {|n| SecureRandom.hex(10) } association :author, :factory => :person diff --git a/spec/models/poll_participation_spec.rb b/spec/models/poll_participation_spec.rb index ee25b378a..68c3fcfdf 100644 --- a/spec/models/poll_participation_spec.rb +++ b/spec/models/poll_participation_spec.rb @@ -6,6 +6,10 @@ describe PollParticipation do before do @alices_aspect = alice.aspects.first @status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id) + @poll = Poll.new(:question => 'Who is in charge?') + @poll.poll_answers.build(:answer => "a") + @poll.poll_answers.build(:answer => "b") + @status.poll = @poll end describe 'xml' do @@ -53,26 +57,25 @@ describe PollParticipation do end end - # describe 'it is relayable' do - # before do - # @poll = Poll.new - # @poll_answer = PollAnswer.new(:answer => '1') - # @poll_answer2 = PollAnswer.new(:answer => '1') - # @poll.answers << [poll_answer, poll_answer2] - # @status.poll = @poll + describe 'it is relayable' do + before do + @local_luke, @local_leia, @remote_raphael = set_up_friends + @remote_parent = FactoryGirl.build(:status_message_with_poll, :author => @remote_raphael) + + @local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first + @poll2 = Poll.new(:question => 'Who is now in charge?') + @poll2.poll_answers.build(:answer => "a") + @poll2.poll_answers.build(:answer => "b") + @local_parent.poll = @poll2 - # @local_luke, @local_leia, @remote_raphael = set_up_friends - # @remote_parent = FactoryGirl.build(:status_message, :author => @remote_raphael) - # @local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first + @object_by_parent_author = @local_luke.participate_in_poll!(@local_parent, @poll.poll_answers.first) + @object_by_recipient = @local_leia.participate_in_poll!(@local_parent, @poll.poll_answers.first) + @dup_object_by_parent_author = @object_by_parent_author.dup - # @object_by_parent_author = @local_luke.vote!(@local_parent, @poll_answer) - # @object_by_recipient = @local_leia.vote!(@local_parent, @poll_answer) - # @dup_object_by_parent_author = @object_by_parent_author.dup + @object_on_remote_parent = @local_luke.participate_in_poll!(@remote_parent, @poll.poll_answers.first) + end - # @object_on_remote_parent = @local_luke.comment!(@remote_parent, "Yeah, it was great") - # end - - # let(:build_object) { alice.build_poll_participation(:poll => @poll, :poll_answer => @poll_answer) } - # it_should_behave_like 'it is relayable' - # end + let(:build_object) { PollParticipation::Generator.new(alice, @status, @poll.poll_answers.first).build } + it_should_behave_like 'it is relayable' + end end