Merge pull request #3089 from consul/backport-polls-show
Polls voted by
This commit is contained in:
@@ -90,6 +90,10 @@ class Poll < ActiveRecord::Base
|
||||
Poll::Voter.where(poll: self, user: user, origin: "web").exists?
|
||||
end
|
||||
|
||||
def voted_by?(user)
|
||||
Poll::Voter.where(poll: self, user: user).exists?
|
||||
end
|
||||
|
||||
def date_range
|
||||
unless starts_at.present? && ends_at.present? && starts_at <= ends_at
|
||||
errors.add(:starts_at, I18n.t('errors.messages.invalid_date_range'))
|
||||
|
||||
@@ -17,8 +17,16 @@
|
||||
class: "button secondary hollow js-question-answer" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% elsif !user_signed_in? %>
|
||||
<% question.question_answers.order(id: :desc).each do |answer| %>
|
||||
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
|
||||
<% end %>
|
||||
<% elsif !current_user.level_two_or_three_verified? %>
|
||||
<% question.question_answers.order(id: :desc).each do |answer| %>
|
||||
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% question.question_answers.each do |answer| %>
|
||||
<% question.question_answers.order(id: :desc).each do |answer| %>
|
||||
<span class="button secondary hollow disabled"><%= answer.title %></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -179,12 +179,9 @@ feature 'Polls' do
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('Han Solo')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
expect(page).to have_content('You must Sign in or Sign up to participate')
|
||||
|
||||
expect(page).not_to have_link('Han Solo')
|
||||
expect(page).not_to have_link('Chewbacca')
|
||||
expect(page).to have_link('Han Solo', href: new_user_session_path)
|
||||
expect(page).to have_link('Chewbacca', href: new_user_session_path)
|
||||
end
|
||||
|
||||
scenario 'Level 1 users' do
|
||||
@@ -203,11 +200,8 @@ feature 'Polls' do
|
||||
|
||||
expect(page).to have_content('You must verify your account in order to answer')
|
||||
|
||||
expect(page).to have_content('Han Solo')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
|
||||
expect(page).not_to have_link('Han Solo')
|
||||
expect(page).not_to have_link('Chewbacca')
|
||||
expect(page).to have_link('Han Solo', href: verification_path)
|
||||
expect(page).to have_link('Chewbacca', href: verification_path)
|
||||
end
|
||||
|
||||
scenario 'Level 2 users in an incoming poll' do
|
||||
|
||||
@@ -175,6 +175,24 @@ describe Poll do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#voted_by?" do
|
||||
it "return false if the user has not voted for this poll" do
|
||||
user = create(:user, :level_two)
|
||||
poll = create(:poll)
|
||||
|
||||
expect(poll.voted_by?(user)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if the user has voted for this poll" do
|
||||
user = create(:user, :level_two)
|
||||
poll = create(:poll)
|
||||
|
||||
voter = create(:poll_voter, user: user, poll: poll)
|
||||
|
||||
expect(poll.voted_by?(user)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#voted_in_booth?" do
|
||||
|
||||
it "returns true if the user has already voted in booth" do
|
||||
|
||||
Reference in New Issue
Block a user