disable poll voting for reshared post

This commit is contained in:
Hincu Petru 2014-04-14 09:46:34 +00:00 committed by Steffen van Bergerem
parent c3bf9dd831
commit 9589cb2e0f
6 changed files with 47 additions and 4 deletions

View file

@ -14,11 +14,14 @@ app.views.Poll = app.views.Base.extend({
presenter: function(){ presenter: function(){
var defaultPresenter = this.defaultPresenter(); var defaultPresenter = this.defaultPresenter();
var isResharePost = (this.model.get('post_type') == 'Reshare');
var show_form = defaultPresenter.loggedIn && var show_form = defaultPresenter.loggedIn &&
!this.model.attributes.already_participated_in_poll; !isResharePost &&
!this.model.get('already_participated_in_poll');
return _.extend(defaultPresenter, { return _.extend(defaultPresenter, {
show_form: show_form show_form: show_form,
is_reshare_post: isResharePost
}); });
}, },

View file

@ -37,6 +37,13 @@
</div> </div>
{{/poll.poll_answers}} {{/poll.poll_answers}}
{{/if}} {{/if}}
{{#if is_reshare_post }}
<div class="poll_footer">
<a class="root_post_link" href="/posts/{{root.id}}">{{t "poll.vote_original_post" }}</a>
</div>
{{/if}}
</div> </div>
</div> </div>
{{/if}} {{/if}}

View file

@ -49,6 +49,10 @@ class Reshare < Post
absolute_root.try(:location).try(:address) absolute_root.try(:location).try(:address)
end end
def poll
absolute_root.try(:poll) || super
end
def receive(recipient, sender) def receive(recipient, sender)
local_reshare = Reshare.where(:guid => self.guid).first local_reshare = Reshare.where(:guid => self.guid).first
if local_reshare && local_reshare.root.author_id == recipient.person.id if local_reshare && local_reshare.root.author_id == recipient.person.id

View file

@ -227,6 +227,7 @@ en:
poll: poll:
vote: "Vote" vote: "Vote"
vote_original_post: 'Vote original post'
result: "Result" result: "Result"
count: count:
one: "1 vote so far" one: "1 vote so far"

View file

@ -44,6 +44,23 @@ describe("app.views.Poll", function(){
}); });
}); });
describe('reshared post', function(){
beforeEach(function(){
this.view.model.set('post_type', 'Reshare');
this.view.model.set('root', {id: 1});
this.view.render();
});
it('hide vote form', function(){
expect(this.view.$('form').length).toBe(0);
});
it("show a.root_post_link", function(){
var id = this.view.model.get('root').id;
expect(this.view.$('a.root_post_link').attr('href')).toBe('/posts/'+id);
});
});
describe("vote form", function(){ describe("vote form", function(){
it('show vote form when user is logged in and not voted before', function(){ it('show vote form when user is logged in and not voted before', function(){
expect(this.view.$('form').length).toBe(1); expect(this.view.$('form').length).toBe(1);

View file

@ -63,6 +63,17 @@ describe Reshare, :type => :model do
end end
end end
describe '#poll' do
before do
@root_post = FactoryGirl.create(:status_message_with_poll, public: true)
@reshare = FactoryGirl.create(:reshare, root: @root_post)
end
it 'contains root poll' do
@reshare.poll == @root_post.poll
end
end
describe '#notification_type' do describe '#notification_type' do
before do before do
sm = FactoryGirl.build(:status_message, :author => alice.person, :public => true) sm = FactoryGirl.build(:status_message, :author => alice.person, :public => true)