Fixed 4903 and not render vote form when user is not logged
This commit is contained in:
parent
c634aba267
commit
2ae4d41db3
5 changed files with 38 additions and 4 deletions
|
|
@ -10,6 +10,16 @@ app.views.Poll = app.views.Base.extend({
|
|||
this.model.bind('change', this.render, this);
|
||||
},
|
||||
|
||||
presenter: function(){
|
||||
var defaultPresenter = this.defaultPresenter();
|
||||
var show_form = defaultPresenter.loggedIn &&
|
||||
!this.model.attributes.already_participated_in_poll;
|
||||
|
||||
return _.extend(defaultPresenter, {
|
||||
show_form: show_form
|
||||
});
|
||||
},
|
||||
|
||||
postRenderTemplate: function() {
|
||||
this.poll = this.model.attributes.poll;
|
||||
this.setProgressBar();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row-fluid poll_content">
|
||||
{{#unless already_participated_in_poll}}
|
||||
{{#if show_form}}
|
||||
<form action="/posts/{{poll.post_id}}/poll_participations" method="POST">
|
||||
{{#poll.poll_answers}}
|
||||
<label class="radio result-row">
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{{/poll.poll_answers}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class PostPresenter
|
|||
private
|
||||
|
||||
def already_participated_in_poll
|
||||
if @post.poll
|
||||
if @post.poll && user_signed_in?
|
||||
@post.poll.already_participated?(current_user)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,5 +33,21 @@ describe("app.views.Poll", function(){
|
|||
expect(obj.poll_id).toBe(poll.poll_id);
|
||||
expect(obj.poll_answer_id).toBe(answer.id);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
describe("vote form", function(){
|
||||
it('show vote form when user is logged in and not voted before', function(){
|
||||
expect(this.view.$('form').length).toBe(1);
|
||||
});
|
||||
it('hide vote form when user voted before', function(){
|
||||
this.view.model.attributes.already_participated_in_poll = true;
|
||||
this.view.render();
|
||||
expect(this.view.$('form').length).toBe(0);
|
||||
});
|
||||
it("hide vote form when user not logged in", function(){
|
||||
logout();
|
||||
this.view.render();
|
||||
expect(this.view.$('form').length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
|||
describe PostPresenter do
|
||||
before do
|
||||
@sm = FactoryGirl.create(:status_message, :public => true)
|
||||
@sm_with_poll = FactoryGirl.create(:status_message_with_poll, public: true)
|
||||
@presenter = PostPresenter.new(@sm, bob)
|
||||
@unauthenticated_presenter = PostPresenter.new(@sm)
|
||||
end
|
||||
|
|
@ -96,4 +97,11 @@ describe PostPresenter do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#poll' do
|
||||
it 'works without a user' do
|
||||
presenter = PostPresenter.new(@sm_with_poll)
|
||||
presenter.as_json.should be_a(Hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue