Merge branch 'master' into voting-proposals
Conflicts: app/models/proposal.rb app/views/proposals/_proposal.html.erb app/views/proposals/index.html.erb app/views/proposals/show.html.erb spec/support/common_actions.rb
This commit is contained in:
@@ -163,6 +163,10 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
trait :archived do
|
||||
created_at 25.months.ago
|
||||
end
|
||||
|
||||
trait :with_hot_score do
|
||||
before(:save) { |d| d.calculate_hot_score }
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ feature 'Official positions' do
|
||||
@proposal1 = create(:proposal, author: @user1)
|
||||
@proposal2 = create(:proposal, author: @user2)
|
||||
|
||||
featured_proposals = 3.times { create(:proposal) }
|
||||
create_featured_proposals
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
|
||||
@@ -3,48 +3,50 @@ require 'rails_helper'
|
||||
|
||||
feature 'Proposals' do
|
||||
|
||||
scenario 'Index' do
|
||||
featured_proposals = create_featured_proposals
|
||||
proposals = [create(:proposal), create(:proposal), create(:proposal)]
|
||||
context 'Index' do
|
||||
scenario 'Lists featured and regular proposals' do
|
||||
featured_proposals = create_featured_proposals
|
||||
proposals = [create(:proposal), create(:proposal), create(:proposal)]
|
||||
|
||||
visit proposals_path
|
||||
visit proposals_path
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal-featured', count: 3)
|
||||
featured_proposals.each do |featured_proposal|
|
||||
within('#featured-proposals') do
|
||||
expect(page).to have_content featured_proposal.title
|
||||
expect(page).to have_css("a[href='#{proposal_path(featured_proposal)}']")
|
||||
expect(page).to have_selector('#proposals .proposal-featured', count: 3)
|
||||
featured_proposals.each do |featured_proposal|
|
||||
within('#featured-proposals') do
|
||||
expect(page).to have_content featured_proposal.title
|
||||
expect(page).to have_css("a[href='#{proposal_path(featured_proposal)}']")
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: 3)
|
||||
proposals.each do |proposal|
|
||||
within('#proposals') do
|
||||
expect(page).to have_content proposal.title
|
||||
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.title)
|
||||
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.summary)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: 3)
|
||||
proposals.each do |proposal|
|
||||
within('#proposals') do
|
||||
expect(page).to have_content proposal.title
|
||||
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.title)
|
||||
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.summary)
|
||||
scenario 'Pagination' do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 5).times { create(:proposal) }
|
||||
|
||||
visit proposals_path
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: per_page)
|
||||
|
||||
within("ul.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
expect(page).to have_content("2")
|
||||
expect(page).to_not have_content("3")
|
||||
click_link "Next", exact: false
|
||||
end
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Paginated Index' do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 5).times { create(:proposal) }
|
||||
|
||||
visit proposals_path
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: per_page)
|
||||
|
||||
within("ul.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
expect(page).to have_content("2")
|
||||
expect(page).to_not have_content("3")
|
||||
click_link "Next", exact: false
|
||||
end
|
||||
|
||||
expect(page).to have_selector('#proposals .proposal', count: 2)
|
||||
end
|
||||
|
||||
scenario 'Show' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
@@ -676,6 +678,95 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
feature 'Archived proposals' do
|
||||
|
||||
scenario 'show on archived tab' do
|
||||
create_featured_proposals
|
||||
archived_proposals = create_archived_proposals
|
||||
|
||||
visit proposals_path
|
||||
click_link 'Archived'
|
||||
|
||||
within("#proposals-list") do
|
||||
archived_proposals.each do |proposal|
|
||||
expect(page).to have_content(proposal.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'do not show in other index tabs' do
|
||||
create_featured_proposals
|
||||
archived_proposal = create(:proposal, :archived)
|
||||
|
||||
visit proposals_path
|
||||
|
||||
within("#proposals-list") do
|
||||
expect(page).to_not have_content archived_proposal.title
|
||||
end
|
||||
|
||||
orders = %w{hot_score confidence_score created_at relevance}
|
||||
orders.each do |order|
|
||||
visit proposals_path(order: order)
|
||||
|
||||
within("#proposals-list") do
|
||||
expect(page).to_not have_content archived_proposal.title
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'do not show support buttons in index' do
|
||||
create_featured_proposals
|
||||
archived_proposals = create_archived_proposals
|
||||
|
||||
visit proposals_path(order: 'archival_date')
|
||||
|
||||
within("#proposals-list") do
|
||||
archived_proposals.each do |proposal|
|
||||
within("#proposal_#{proposal.id}_votes") do
|
||||
expect(page).to_not have_css(".supports")
|
||||
expect(page).to have_content "This proposal has been archived and can't collect supports"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'do not show support buttons in show' do
|
||||
archived_proposal = create(:proposal, :archived)
|
||||
|
||||
visit proposal_path(archived_proposal)
|
||||
expect(page).to_not have_css(".supports")
|
||||
expect(page).to have_content "This proposal has been archived and can't collect supports"
|
||||
end
|
||||
|
||||
scenario 'do not show in featured proposals section' do
|
||||
featured_proposal = create(:proposal, :with_confidence_score, cached_votes_up: 100)
|
||||
archived_proposal = create(:proposal, :archived, :with_confidence_score, cached_votes_up: 10000)
|
||||
|
||||
visit proposals_path
|
||||
|
||||
within("#featured-proposals") do
|
||||
expect(page).to have_content(featured_proposal.title)
|
||||
expect(page).to_not have_content(archived_proposal.title)
|
||||
end
|
||||
within("#proposals-list") do
|
||||
expect(page).to_not have_content(featured_proposal.title)
|
||||
expect(page).to_not have_content(archived_proposal.title)
|
||||
end
|
||||
|
||||
click_link "Archived"
|
||||
|
||||
within("#featured-proposals") do
|
||||
expect(page).to have_content(featured_proposal.title)
|
||||
expect(page).to_not have_content(archived_proposal.title)
|
||||
end
|
||||
within("#proposals-list") do
|
||||
expect(page).to_not have_content(featured_proposal.title)
|
||||
expect(page).to have_content(archived_proposal.title)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Search" do
|
||||
|
||||
context "Basic search" do
|
||||
|
||||
@@ -204,6 +204,13 @@ describe Proposal do
|
||||
expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "should not register vote for archived proposals" do
|
||||
user = create(:user, verified_at: Time.now)
|
||||
archived_proposal = create(:proposal, :archived)
|
||||
|
||||
expect {archived_proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#cached_votes_up' do
|
||||
@@ -811,4 +818,30 @@ describe Proposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "archived" do
|
||||
before(:each) do
|
||||
@new_proposal = create(:proposal)
|
||||
@archived_proposal = create(:proposal, :archived)
|
||||
end
|
||||
|
||||
it "archived? is true only for proposals created more than n (configured months) ago" do
|
||||
expect(@new_proposal.archived?).to eq false
|
||||
expect(@archived_proposal.archived?).to eq true
|
||||
end
|
||||
|
||||
it "scope archived" do
|
||||
archived = Proposal.archived
|
||||
|
||||
expect(archived.size).to eq(1)
|
||||
expect(archived.first).to eq(@archived_proposal)
|
||||
end
|
||||
|
||||
it "scope archived" do
|
||||
not_archived = Proposal.not_archived
|
||||
|
||||
expect(not_archived.size).to eq(1)
|
||||
expect(not_archived.first).to eq(@new_proposal)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -197,6 +197,11 @@ module CommonActions
|
||||
create(:proposal, title: "Fire and blood", question: "You talking to me?", cached_votes_up: Proposal.votes_needed_for_success + 1)]
|
||||
end
|
||||
|
||||
def create_archived_proposals
|
||||
[create(:proposal, title: "This is an expired proposal", created_at: Setting["months_to_archive_proposals"].to_i.months.ago),
|
||||
create(:proposal, title: "This is an oldest expired proposal", created_at: (Setting["months_to_archive_proposals"].to_i + 2).months.ago)]
|
||||
end
|
||||
|
||||
def tag_names(tag_cloud)
|
||||
tag_cloud.tags.map(&:name)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user