Merge branch 'master' into polling-views-plus

This commit is contained in:
Juanjo Bazán
2016-10-19 13:50:08 +02:00
68 changed files with 1063 additions and 136 deletions

View File

@@ -0,0 +1,22 @@
require 'rails_helper'
# This module tests functionality related with custom application files
# TODO test models, controllers, etc...
describe 'CustomizationEngine' do
let(:test_key) { I18n.t('account.show.change_credentials_link') }
it "should load custom and override original locales" do
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', 'custom', '*.{rb,yml}')]
I18n.reload!
expect(test_key).to eq 'Overriden string with custom locales'
end
it "should not override original locales" do
I18n.load_path.delete_if {|item| item =~ /spec\/support\/locales\/custom/ }
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', '**', '*.{rb,yml}')]
I18n.reload!
expect(test_key).to eq 'Not overriden string with custom locales'
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,57 @@
# coding: utf-8
require 'rails_helper'
feature 'Proposal ballots' do
scenario 'Banner shows in proposal index' do
create_featured_proposals
visit proposals_path
expect(page).to_not have_css("#next-voting")
expect(page).to have_css("#featured-proposals")
create_successfull_proposals
visit proposals_path
expect(page).to have_css("#next-voting")
expect(page).to_not have_css("#featured-proposals")
end
scenario 'Successfull proposals do not show support buttons in index' do
successfull_proposals = create_successfull_proposals
visit proposals_path
successfull_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 reached the required supports"
end
end
end
scenario 'Successfull proposals do not show support buttons in show' do
successfull_proposals = create_successfull_proposals
successfull_proposals.each do |proposal|
visit proposal_path(proposal)
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_css(".supports")
expect(page).to have_content "This proposal has reached the required supports"
end
end
end
scenario 'Successfull proposals are listed in the proposal ballots index' do
successfull_proposals = create_successfull_proposals
visit proposal_ballots_path
successfull_proposals.each do |proposal|
expect(page).to have_content(proposal.title)
end
end
end

View File

@@ -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,110 @@ 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
scenario "Order by votes" do
create(:proposal, :archived, title: "Least voted").update_column(:confidence_score, 10)
create(:proposal, :archived, title: "Most voted").update_column(:confidence_score, 50)
create(:proposal, :archived, title: "Some votes").update_column(:confidence_score, 25)
visit proposals_path
click_link 'Archived'
within("#proposals-list") do
expect(all(".proposal")[0].text).to match "Most voted"
expect(all(".proposal")[1].text).to match "Some votes"
expect(all(".proposal")[2].text).to match "Least voted"
end
end
end
context "Search" do
context "Basic search" do

View File

@@ -285,4 +285,59 @@ feature 'Users' do
expect(page).to have_content "Your password has been changed successfully."
end
scenario 'Sign in, admin with password expired' do
user = create(:user, password_changed_at: Time.now - 1.year)
admin = create(:administrator, user: user)
login_as(admin.user)
visit root_path
expect(page).to have_content "Your password is expired"
fill_in 'user_current_password', with: 'judgmentday'
fill_in 'user_password', with: '123456789'
fill_in 'user_password_confirmation', with: '123456789'
click_button 'Change your password'
expect(page).to have_content "Password successfully updated"
end
scenario 'Sign in, admin without password expired' do
user = create(:user, password_changed_at: Time.now - 360.days)
admin = create(:administrator, user: user)
login_as(admin.user)
visit root_path
expect(page).to_not have_content "Your password is expired"
end
scenario 'Sign in, user with password expired' do
user = create(:user, password_changed_at: Time.now - 1.year)
login_as(user)
visit root_path
expect(page).to_not have_content "Your password is expired"
end
scenario 'Admin with password expired trying to use same password' do
user = create(:user, password_changed_at: Time.now - 1.year, password: '123456789')
admin = create(:administrator, user: user)
login_as(admin.user)
visit root_path
expect(page).to have_content "Your password is expired"
fill_in 'user_current_password', with: 'judgmentday'
fill_in 'user_password', with: '123456789'
fill_in 'user_password_confirmation', with: '123456789'
click_button 'Change your password'
expect(page).to have_content "must be different than the current password."
end
end

View File

@@ -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

View File

@@ -192,6 +192,16 @@ module CommonActions
create(:debate, :with_confidence_score, cached_votes_up: 80)]
end
def create_successfull_proposals
[create(:proposal, title: "Winter is coming", question: "Do you speak it?", cached_votes_up: Proposal.votes_needed_for_success + 100),
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

View File

@@ -0,0 +1,5 @@
---
en:
account:
show:
change_credentials_link: Overriden string with custom locales

View File

@@ -0,0 +1,5 @@
---
en:
account:
show:
change_credentials_link: Not overriden string with custom locales