Remove instance variables in RSpec

Instance variables might lead to hard-to-detect issues, since using a
nonexistent instance variable will return `nil` instead of raising an
error.
This commit is contained in:
Javi Martín
2019-09-29 14:01:55 +02:00
parent f70e10fe9f
commit 91c21b0982
39 changed files with 639 additions and 667 deletions

View File

@@ -57,9 +57,6 @@ Rails/SaveBang:
Rails/SkipsModelValidations: Rails/SkipsModelValidations:
Enabled: true Enabled: true
RSpec/InstanceVariable:
Enabled: true
Security/Eval: Security/Eval:
Enabled: true Enabled: true

View File

@@ -199,6 +199,9 @@ RSpec/Focus:
RSpec/HookArgument: RSpec/HookArgument:
Enabled: true Enabled: true
RSpec/InstanceVariable:
Enabled: true
RSpec/LetBeforeExamples: RSpec/LetBeforeExamples:
Enabled: true Enabled: true

View File

@@ -3,17 +3,20 @@ require "rails_helper"
describe RemoteTranslationsController do describe RemoteTranslationsController do
describe "POST create", :delay_jobs do describe "POST create", :delay_jobs do
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
let(:remote_translations_params) do
[{ remote_translatable_id: debate.id.to_s,
remote_translatable_type: debate.class.to_s,
locale: :es }].to_json
end
before do before do
@remote_translations_params = [{ remote_translatable_id: debate.id.to_s,
remote_translatable_type: debate.class.to_s,
locale: :es }].to_json
request.env["HTTP_REFERER"] = "any_path" request.env["HTTP_REFERER"] = "any_path"
end end
it "create correctly remote translation" do it "create correctly remote translation" do
post :create, params: { remote_translations: @remote_translations_params } post :create, params: { remote_translations: remote_translations_params }
expect(RemoteTranslation.count).to eq(1) expect(RemoteTranslation.count).to eq(1)
end end
@@ -21,7 +24,7 @@ describe RemoteTranslationsController do
it "create remote translation when same remote translation with error_message is enqueued" do it "create remote translation when same remote translation with error_message is enqueued" do
create(:remote_translation, remote_translatable: debate, locale: :es, error_message: "Has errors") create(:remote_translation, remote_translatable: debate, locale: :es, error_message: "Has errors")
post :create, params: { remote_translations: @remote_translations_params } post :create, params: { remote_translations: remote_translations_params }
expect(RemoteTranslation.count).to eq(2) expect(RemoteTranslation.count).to eq(2)
end end
@@ -29,13 +32,13 @@ describe RemoteTranslationsController do
it "not create remote translation when same remote translation is enqueued" do it "not create remote translation when same remote translation is enqueued" do
create(:remote_translation, remote_translatable: debate, locale: :es) create(:remote_translation, remote_translatable: debate, locale: :es)
post :create, params: { remote_translations: @remote_translations_params } post :create, params: { remote_translations: remote_translations_params }
expect(RemoteTranslation.count).to eq(1) expect(RemoteTranslation.count).to eq(1)
end end
it "redirect_to request referer after create" do it "redirect_to request referer after create" do
post :create, params: { remote_translations: @remote_translations_params } post :create, params: { remote_translations: remote_translations_params }
expect(subject).to redirect_to("any_path") expect(subject).to redirect_to("any_path")
end end

View File

@@ -2,7 +2,7 @@ require "rails_helper"
describe Users::ConfirmationsController do describe Users::ConfirmationsController do
before do before do
@request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
end end
describe "GET show" do describe "GET show" do

View File

@@ -5,7 +5,7 @@ describe Users::RegistrationsController do
describe "POST check_username" do describe "POST check_username" do
before do before do
@request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
end end
context "when username is available" do context "when username is available" do

View File

@@ -1,10 +1,10 @@
require "rails_helper" require "rails_helper"
describe "Account" do describe "Account" do
let(:user) { create(:user, username: "Manuela Colau") }
before do before do
@user = create(:user, username: "Manuela Colau") login_as(user)
login_as(@user)
end end
scenario "Show" do scenario "Show" do
@@ -19,7 +19,7 @@ describe "Account" do
end end
scenario "Show organization" do scenario "Show organization" do
create(:organization, user: @user, name: "Manuela Corp") create(:organization, user: user, name: "Manuela Corp")
visit account_path visit account_path
@@ -85,7 +85,7 @@ describe "Account" do
end end
scenario "Edit Organization" do scenario "Edit Organization" do
create(:organization, user: @user, name: "Manuela Corp") create(:organization, user: user, name: "Manuela Corp")
visit account_path visit account_path
fill_in "account_organization_attributes_name", with: "Google" fill_in "account_organization_attributes_name", with: "Google"
@@ -170,7 +170,7 @@ describe "Account" do
expect(page).to have_content "Goodbye! Your account has been cancelled. We hope to see you again soon." expect(page).to have_content "Goodbye! Your account has been cancelled. We hope to see you again soon."
login_through_form_as(@user) login_through_form_as(user)
expect(page).to have_content "Invalid Email or username or password" expect(page).to have_content "Invalid Email or username or password"
end end
@@ -203,10 +203,10 @@ describe "Account" do
expect(find("#account_recommended_debates")).not_to be_checked expect(find("#account_recommended_debates")).not_to be_checked
expect(find("#account_recommended_proposals")).not_to be_checked expect(find("#account_recommended_proposals")).not_to be_checked
@user.reload user.reload
expect(@user.recommended_debates).to be(false) expect(user.recommended_debates).to be(false)
expect(@user.recommended_proposals).to be(false) expect(user.recommended_proposals).to be(false)
end end
end end

View File

@@ -1,10 +1,10 @@
require "rails_helper" require "rails_helper"
describe "Admin activity" do describe "Admin activity" do
let(:admin) { create(:administrator) }
before do before do
@admin = create(:administrator) login_as(admin.user)
login_as(@admin.user)
end end
context "Proposals" do context "Proposals" do
@@ -23,7 +23,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.title)
expect(page).to have_content("Hidden") expect(page).to have_content("Hidden")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
@@ -65,7 +65,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.title)
expect(page).to have_content("Restored") expect(page).to have_content("Restored")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
end end
@@ -86,7 +86,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(debate.title) expect(page).to have_content(debate.title)
expect(page).to have_content("Hidden") expect(page).to have_content("Hidden")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
@@ -128,7 +128,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(debate.title) expect(page).to have_content(debate.title)
expect(page).to have_content("Restored") expect(page).to have_content("Restored")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
end end
@@ -150,7 +150,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
expect(page).to have_content("Hidden") expect(page).to have_content("Hidden")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
@@ -192,7 +192,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
expect(page).to have_content("Restored") expect(page).to have_content("Restored")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
end end
@@ -215,7 +215,7 @@ describe "Admin activity" do
expect(page).to have_content("Blocked") expect(page).to have_content("Blocked")
expect(page).to have_content(proposal.author.username) expect(page).to have_content(proposal.author.username)
expect(page).to have_content(proposal.author.email) expect(page).to have_content(proposal.author.email)
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
expect(page).not_to have_content(proposal.title) expect(page).not_to have_content(proposal.title)
end end
end end
@@ -234,7 +234,7 @@ describe "Admin activity" do
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(user.username) expect(page).to have_content(user.username)
expect(page).to have_content(user.email) expect(page).to have_content(user.email)
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
@@ -331,7 +331,7 @@ describe "Admin activity" do
expect(page).to have_content(user.username) expect(page).to have_content(user.username)
expect(page).to have_content(user.email) expect(page).to have_content(user.email)
expect(page).to have_content("Restored") expect(page).to have_content("Restored")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
end end
@@ -342,14 +342,14 @@ describe "Admin activity" do
proposal_notification = create(:proposal_notification, proposal: proposal, proposal_notification = create(:proposal_notification, proposal: proposal,
title: "Proposal A Title", title: "Proposal A Title",
body: "Proposal A Notification Body") body: "Proposal A Notification Body")
proposal_notification.moderate_system_email(@admin.user) proposal_notification.moderate_system_email(admin.user)
visit admin_activity_path visit admin_activity_path
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
expect(page).to have_content(proposal_notification.title) expect(page).to have_content(proposal_notification.title)
expect(page).to have_content("Hidden") expect(page).to have_content("Hidden")
expect(page).to have_content(@admin.user.username) expect(page).to have_content(admin.user.username)
end end
end end
end end

View File

@@ -12,8 +12,7 @@ describe "Admin budget investments" do
"admin_budget_budget_investment_path" "admin_budget_budget_investment_path"
before do before do
@admin = create(:administrator) login_as(create(:administrator).user)
login_as(@admin.user)
end end
context "Feature flag" do context "Feature flag" do

View File

@@ -7,10 +7,8 @@ describe "Admin change log" do
end end
context "Investments Participatory Budgets" do context "Investments Participatory Budgets" do
before do before do
@admin = create(:administrator) login_as(create(:administrator).user)
login_as(@admin.user)
end end
scenario "No changes" do scenario "No changes" do

View File

@@ -1,28 +1,28 @@
require "rails_helper" require "rails_helper"
describe "Admin managers" do describe "Admin managers" do
let!(:user) { create(:user) }
let!(:manager) { create(:manager) }
before do before do
@admin = create(:administrator) login_as(create(:administrator).user)
@user = create(:user)
@manager = create(:manager)
login_as(@admin.user)
visit admin_managers_path visit admin_managers_path
end end
scenario "Index" do scenario "Index" do
expect(page).to have_content @manager.name expect(page).to have_content manager.name
expect(page).to have_content @manager.email expect(page).to have_content manager.email
expect(page).not_to have_content @user.name expect(page).not_to have_content user.name
end end
scenario "Create Manager", :js do scenario "Create Manager", :js do
fill_in "name_or_email", with: @user.email fill_in "name_or_email", with: user.email
click_button "Search" click_button "Search"
expect(page).to have_content @user.name expect(page).to have_content user.name
click_link "Add" click_link "Add"
within("#managers") do within("#managers") do
expect(page).to have_content @user.name expect(page).to have_content user.name
end end
end end
@@ -30,55 +30,55 @@ describe "Admin managers" do
click_link "Delete" click_link "Delete"
within("#managers") do within("#managers") do
expect(page).not_to have_content @manager.name expect(page).not_to have_content manager.name
end end
end end
context "Search" do context "Search" do
let(:user) { create(:user, username: "Taylor Swift", email: "taylor@swift.com") }
let(:user2) { create(:user, username: "Stephanie Corneliussen", email: "steph@mrrobot.com") }
let!(:manager1) { create(:manager, user: user) }
let!(:manager2) { create(:manager, user: user2) }
before do before do
user = create(:user, username: "Taylor Swift", email: "taylor@swift.com")
user2 = create(:user, username: "Stephanie Corneliussen", email: "steph@mrrobot.com")
@manager1 = create(:manager, user: user)
@manager2 = create(:manager, user: user2)
visit admin_managers_path visit admin_managers_path
end end
scenario "returns no results if search term is empty" do scenario "returns no results if search term is empty" do
expect(page).to have_content(@manager1.name) expect(page).to have_content(manager1.name)
expect(page).to have_content(@manager2.name) expect(page).to have_content(manager2.name)
fill_in "name_or_email", with: " " fill_in "name_or_email", with: " "
click_button "Search" click_button "Search"
expect(page).to have_content("Managers: User search") expect(page).to have_content("Managers: User search")
expect(page).to have_content("No results found") expect(page).to have_content("No results found")
expect(page).not_to have_content(@manager1.name) expect(page).not_to have_content(manager1.name)
expect(page).not_to have_content(@manager2.name) expect(page).not_to have_content(manager2.name)
end end
scenario "search by name" do scenario "search by name" do
expect(page).to have_content(@manager1.name) expect(page).to have_content(manager1.name)
expect(page).to have_content(@manager2.name) expect(page).to have_content(manager2.name)
fill_in "name_or_email", with: "Taylor" fill_in "name_or_email", with: "Taylor"
click_button "Search" click_button "Search"
expect(page).to have_content("Managers: User search") expect(page).to have_content("Managers: User search")
expect(page).to have_content(@manager1.name) expect(page).to have_content(manager1.name)
expect(page).not_to have_content(@manager2.name) expect(page).not_to have_content(manager2.name)
end end
scenario "search by email" do scenario "search by email" do
expect(page).to have_content(@manager1.email) expect(page).to have_content(manager1.email)
expect(page).to have_content(@manager2.email) expect(page).to have_content(manager2.email)
fill_in "name_or_email", with: @manager2.email fill_in "name_or_email", with: manager2.email
click_button "Search" click_button "Search"
expect(page).to have_content("Managers: User search") expect(page).to have_content("Managers: User search")
expect(page).to have_content(@manager2.email) expect(page).to have_content(manager2.email)
expect(page).not_to have_content(@manager1.email) expect(page).not_to have_content(manager1.email)
end end
end end

View File

@@ -1,28 +1,28 @@
require "rails_helper" require "rails_helper"
describe "Admin moderators" do describe "Admin moderators" do
let!(:user) { create(:user, username: "Jose Luis Balbin") }
let!(:moderator) { create(:moderator) }
before do before do
@admin = create(:administrator) login_as(create(:administrator).user)
@user = create(:user, username: "Jose Luis Balbin")
@moderator = create(:moderator)
login_as(@admin.user)
visit admin_moderators_path visit admin_moderators_path
end end
scenario "Index" do scenario "Index" do
expect(page).to have_content @moderator.name expect(page).to have_content moderator.name
expect(page).to have_content @moderator.email expect(page).to have_content moderator.email
expect(page).not_to have_content @user.name expect(page).not_to have_content user.name
end end
scenario "Create Moderator", :js do scenario "Create Moderator", :js do
fill_in "name_or_email", with: @user.email fill_in "name_or_email", with: user.email
click_button "Search" click_button "Search"
expect(page).to have_content @user.name expect(page).to have_content user.name
click_link "Add" click_link "Add"
within("#moderators") do within("#moderators") do
expect(page).to have_content @user.name expect(page).to have_content user.name
end end
end end
@@ -30,55 +30,55 @@ describe "Admin moderators" do
click_link "Delete" click_link "Delete"
within("#moderators") do within("#moderators") do
expect(page).not_to have_content @moderator.name expect(page).not_to have_content moderator.name
end end
end end
context "Search" do context "Search" do
let(:user) { create(:user, username: "Elizabeth Bathory", email: "elizabeth@bathory.com") }
let(:user2) { create(:user, username: "Ada Lovelace", email: "ada@lovelace.com") }
let!(:moderator1) { create(:moderator, user: user) }
let!(:moderator2) { create(:moderator, user: user2) }
before do before do
user = create(:user, username: "Elizabeth Bathory", email: "elizabeth@bathory.com")
user2 = create(:user, username: "Ada Lovelace", email: "ada@lovelace.com")
@moderator1 = create(:moderator, user: user)
@moderator2 = create(:moderator, user: user2)
visit admin_moderators_path visit admin_moderators_path
end end
scenario "returns no results if search term is empty" do scenario "returns no results if search term is empty" do
expect(page).to have_content(@moderator1.name) expect(page).to have_content(moderator1.name)
expect(page).to have_content(@moderator2.name) expect(page).to have_content(moderator2.name)
fill_in "name_or_email", with: " " fill_in "name_or_email", with: " "
click_button "Search" click_button "Search"
expect(page).to have_content("Moderators: User search") expect(page).to have_content("Moderators: User search")
expect(page).to have_content("No results found") expect(page).to have_content("No results found")
expect(page).not_to have_content(@moderator1.name) expect(page).not_to have_content(moderator1.name)
expect(page).not_to have_content(@moderator2.name) expect(page).not_to have_content(moderator2.name)
end end
scenario "search by name" do scenario "search by name" do
expect(page).to have_content(@moderator1.name) expect(page).to have_content(moderator1.name)
expect(page).to have_content(@moderator2.name) expect(page).to have_content(moderator2.name)
fill_in "name_or_email", with: "Eliz" fill_in "name_or_email", with: "Eliz"
click_button "Search" click_button "Search"
expect(page).to have_content("Moderators: User search") expect(page).to have_content("Moderators: User search")
expect(page).to have_content(@moderator1.name) expect(page).to have_content(moderator1.name)
expect(page).not_to have_content(@moderator2.name) expect(page).not_to have_content(moderator2.name)
end end
scenario "search by email" do scenario "search by email" do
expect(page).to have_content(@moderator1.email) expect(page).to have_content(moderator1.email)
expect(page).to have_content(@moderator2.email) expect(page).to have_content(moderator2.email)
fill_in "name_or_email", with: @moderator2.email fill_in "name_or_email", with: moderator2.email
click_button "Search" click_button "Search"
expect(page).to have_content("Moderators: User search") expect(page).to have_content("Moderators: User search")
expect(page).to have_content(@moderator2.email) expect(page).to have_content(moderator2.email)
expect(page).not_to have_content(@moderator1.email) expect(page).not_to have_content(moderator1.email)
end end
end end

View File

@@ -1,32 +1,31 @@
require "rails_helper" require "rails_helper"
describe "Admin officials" do describe "Admin officials" do
let!(:citizen) { create(:user, username: "Citizen Kane") }
let!(:official) { create(:user, official_position: "Mayor", official_level: 5) }
before do before do
@citizen = create(:user, username: "Citizen Kane") login_as(create(:administrator).user)
@official = create(:user, official_position: "Mayor", official_level: 5)
@admin = create(:administrator)
login_as(@admin.user)
end end
scenario "Index" do scenario "Index" do
visit admin_officials_path visit admin_officials_path
expect(page).to have_content @official.name expect(page).to have_content official.name
expect(page).not_to have_content @citizen.name expect(page).not_to have_content citizen.name
expect(page).to have_content @official.official_position expect(page).to have_content official.official_position
expect(page).to have_content @official.official_level expect(page).to have_content official.official_level
end end
scenario "Edit an official" do scenario "Edit an official" do
visit admin_officials_path visit admin_officials_path
click_link @official.name click_link official.name
expect(page).to have_current_path(edit_admin_official_path(@official)) expect(page).to have_current_path(edit_admin_official_path(official))
expect(page).not_to have_content @citizen.name expect(page).not_to have_content citizen.name
expect(page).to have_content @official.name expect(page).to have_content official.name
expect(page).to have_content @official.email expect(page).to have_content official.email
fill_in "user_official_position", with: "School Teacher" fill_in "user_official_position", with: "School Teacher"
select "3", from: "user_official_level", exact: false select "3", from: "user_official_level", exact: false
@@ -36,20 +35,20 @@ describe "Admin officials" do
visit admin_officials_path visit admin_officials_path
expect(page).to have_content @official.name expect(page).to have_content official.name
expect(page).to have_content "School Teacher" expect(page).to have_content "School Teacher"
expect(page).to have_content "3" expect(page).to have_content "3"
end end
scenario "Create an official" do scenario "Create an official" do
visit admin_officials_path visit admin_officials_path
fill_in "name_or_email", with: @citizen.email fill_in "name_or_email", with: citizen.email
click_button "Search" click_button "Search"
expect(page).to have_current_path(search_admin_officials_path, ignore_query: true) expect(page).to have_current_path(search_admin_officials_path, ignore_query: true)
expect(page).not_to have_content @official.name expect(page).not_to have_content official.name
click_link @citizen.name click_link citizen.name
fill_in "user_official_position", with: "Hospital manager" fill_in "user_official_position", with: "Hospital manager"
select "4", from: "user_official_level", exact: false select "4", from: "user_official_level", exact: false
@@ -59,20 +58,20 @@ describe "Admin officials" do
visit admin_officials_path visit admin_officials_path
expect(page).to have_content @official.name expect(page).to have_content official.name
expect(page).to have_content @citizen.name expect(page).to have_content citizen.name
expect(page).to have_content "Hospital manager" expect(page).to have_content "Hospital manager"
expect(page).to have_content "4" expect(page).to have_content "4"
end end
scenario "Destroy" do scenario "Destroy" do
visit edit_admin_official_path(@official) visit edit_admin_official_path(official)
click_link 'Remove "Official" status' click_link 'Remove "Official" status'
expect(page).to have_content "Details saved: the user is no longer an official" expect(page).to have_content "Details saved: the user is no longer an official"
expect(page).to have_current_path(admin_officials_path, ignore_query: true) expect(page).to have_current_path(admin_officials_path, ignore_query: true)
expect(page).not_to have_content @citizen.name expect(page).not_to have_content citizen.name
expect(page).not_to have_content @official.name expect(page).not_to have_content official.name
end end
end end

View File

@@ -27,10 +27,10 @@ describe "Admin::Organizations" do
end end
context "Search" do context "Search" do
let(:user) { create(:user, email: "marley@humanrights.com", phone_number: "6764440002") }
before do before do
@user = create(:user, email: "marley@humanrights.com", phone_number: "6764440002") create(:organization, user: user, name: "Get up, Stand up")
create(:organization, user: @user, name: "Get up, Stand up")
end end
scenario "returns no results if search term is empty" do scenario "returns no results if search term is empty" do
@@ -62,7 +62,7 @@ describe "Admin::Organizations" do
visit search_admin_organizations_path visit search_admin_organizations_path
expect(page).not_to have_content("Get up, Stand up") expect(page).not_to have_content("Get up, Stand up")
fill_in "term", with: @user.email fill_in "term", with: user.email
click_button "Search" click_button "Search"
within("#search-results") do within("#search-results") do
@@ -74,7 +74,7 @@ describe "Admin::Organizations" do
visit search_admin_organizations_path visit search_admin_organizations_path
expect(page).not_to have_content("Get up, Stand up") expect(page).not_to have_content("Get up, Stand up")
fill_in "term", with: @user.phone_number fill_in "term", with: user.phone_number
click_button "Search" click_button "Search"
within("#search-results") do within("#search-results") do

View File

@@ -1,29 +1,28 @@
require "rails_helper" require "rails_helper"
describe "Admin poll officers" do describe "Admin poll officers" do
let!(:user) { create(:user, username: "Pedro Jose Garcia") }
let!(:officer) { create(:poll_officer) }
before do before do
@admin = create(:administrator) login_as(create(:administrator).user)
@user = create(:user, username: "Pedro Jose Garcia")
@officer = create(:poll_officer)
login_as(@admin.user)
visit admin_officers_path visit admin_officers_path
end end
scenario "Index" do scenario "Index" do
expect(page).to have_content @officer.name expect(page).to have_content officer.name
expect(page).to have_content @officer.email expect(page).to have_content officer.email
expect(page).not_to have_content @user.name expect(page).not_to have_content user.name
end end
scenario "Create", :js do scenario "Create", :js do
fill_in "email", with: @user.email fill_in "email", with: user.email
click_button "Search" click_button "Search"
expect(page).to have_content @user.name expect(page).to have_content user.name
click_link "Add" click_link "Add"
within("#officers") do within("#officers") do
expect(page).to have_content @user.name expect(page).to have_content user.name
end end
end end

View File

@@ -100,21 +100,19 @@ describe "Stats" do
describe "Budget investments" do describe "Budget investments" do
context "Supporting phase" do context "Supporting phase" do
before do let(:budget) { create(:budget) }
@budget = create(:budget) let(:group_all_city) { create(:budget_group, budget: budget) }
@group_all_city = create(:budget_group, budget: @budget) let!(:heading_all_city) { create(:budget_heading, group: group_all_city) }
@heading_all_city = create(:budget_heading, group: @group_all_city)
end
scenario "Number of supports in investment projects" do scenario "Number of supports in investment projects" do
group_2 = create(:budget_group, budget: @budget) group_2 = create(:budget_group, budget: budget)
create(:budget_investment, heading: create(:budget_heading, group: group_2), voters: [create(:user)]) create(:budget_investment, heading: create(:budget_heading, group: group_2), voters: [create(:user)])
create(:budget_investment, heading: @heading_all_city, voters: [create(:user), create(:user)]) create(:budget_investment, heading: heading_all_city, voters: [create(:user), create(:user)])
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do within("#budget_#{budget.id}") do
click_link "Supporting phase" click_link "Supporting phase"
end end
@@ -122,9 +120,9 @@ describe "Stats" do
end end
scenario "Number of users that have supported an investment project" do scenario "Number of users that have supported an investment project" do
group_2 = create(:budget_group, budget: @budget) group_2 = create(:budget_group, budget: budget)
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city) investment2 = create(:budget_investment, heading: heading_all_city)
create(:user, :level_two, votables: [investment1, investment2]) create(:user, :level_two, votables: [investment1, investment2])
create(:user, :level_two, votables: [investment1]) create(:user, :level_two, votables: [investment1])
@@ -132,7 +130,7 @@ describe "Stats" do
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do within("#budget_#{budget.id}") do
click_link "Supporting phase" click_link "Supporting phase"
end end
@@ -179,35 +177,33 @@ describe "Stats" do
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do within("#budget_#{budget.id}") do
expect(page).not_to have_link "Final voting" expect(page).not_to have_link "Final voting"
end end
end end
scenario "show message when accessing final voting stats" do scenario "show message when accessing final voting stats" do
visit budget_balloting_admin_stats_path(budget_id: @budget.id) visit budget_balloting_admin_stats_path(budget_id: budget.id)
expect(page).to have_content "There isn't any data to show before the balloting phase." expect(page).to have_content "There isn't any data to show before the balloting phase."
end end
end end
context "Balloting phase" do context "Balloting phase" do
before do let(:budget) { create(:budget, :balloting) }
@budget = create(:budget, :balloting) let(:group) { create(:budget_group, budget: budget) }
@group = create(:budget_group, budget: @budget) let(:heading) { create(:budget_heading, group: group) }
@heading = create(:budget_heading, group: @group) let!(:investment) { create(:budget_investment, :feasible, :selected, heading: heading) }
@investment = create(:budget_investment, :feasible, :selected, heading: @heading)
end
scenario "Number of votes in investment projects" do scenario "Number of votes in investment projects" do
investment_2 = create(:budget_investment, :feasible, :selected, budget: @budget) investment_2 = create(:budget_investment, :feasible, :selected, budget: budget)
create(:user, ballot_lines: [@investment, investment_2]) create(:user, ballot_lines: [investment, investment_2])
create(:user, ballot_lines: [investment_2]) create(:user, ballot_lines: [investment_2])
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do within("#budget_#{budget.id}") do
click_link "Final voting" click_link "Final voting"
end end
@@ -215,13 +211,13 @@ describe "Stats" do
end end
scenario "Number of users that have voted a investment project" do scenario "Number of users that have voted a investment project" do
create(:user, ballot_lines: [@investment]) create(:user, ballot_lines: [investment])
create(:user, ballot_lines: [@investment]) create(:user, ballot_lines: [investment])
create(:user) create(:user)
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do within("#budget_#{budget.id}") do
click_link "Final voting" click_link "Final voting"
end end

View File

@@ -1,33 +1,34 @@
require "rails_helper" require "rails_helper"
describe "Admin users" do describe "Admin users" do
let(:admin) { create(:administrator) }
let!(:user) { create(:user, username: "Jose Luis Balbin") }
before do before do
@admin = create(:administrator) login_as(admin.user)
@user = create(:user, username: "Jose Luis Balbin")
login_as(@admin.user)
visit admin_users_path visit admin_users_path
end end
scenario "Index" do scenario "Index" do
expect(page).to have_link @user.name expect(page).to have_link user.name
expect(page).to have_content @user.email expect(page).to have_content user.email
expect(page).to have_content @admin.name expect(page).to have_content admin.name
expect(page).to have_content @admin.email expect(page).to have_content admin.email
end end
scenario "The username links to their public profile" do scenario "The username links to their public profile" do
click_link @user.name click_link user.name
expect(page).to have_current_path(user_path(@user)) expect(page).to have_current_path(user_path(user))
end end
scenario "Search" do scenario "Search" do
fill_in :search, with: "Luis" fill_in :search, with: "Luis"
click_button "Search" click_button "Search"
expect(page).to have_content @user.name expect(page).to have_content user.name
expect(page).to have_content @user.email expect(page).to have_content user.email
expect(page).not_to have_content @admin.name expect(page).not_to have_content admin.name
expect(page).not_to have_content @admin.email expect(page).not_to have_content admin.email
end end
end end

View File

@@ -1,42 +1,40 @@
require "rails_helper" require "rails_helper"
describe "Email campaigns" do describe "Email campaigns" do
let(:campaign1) { create(:campaign) }
let(:campaign2) { create(:campaign) }
before do before do
@campaign1 = create(:campaign) login_as(create(:administrator).user)
@campaign2 = create(:campaign)
admin = create(:administrator)
login_as(admin.user)
end end
scenario "Track email templates" do scenario "Track email templates" do
3.times { visit root_url(track_id: @campaign1.track_id) } 3.times { visit root_url(track_id: campaign1.track_id) }
5.times { visit root_url(track_id: @campaign2.track_id) } 5.times { visit root_url(track_id: campaign2.track_id) }
visit admin_stats_path visit admin_stats_path
click_link @campaign1.name click_link campaign1.name
expect(page).to have_content "#{@campaign1.name} (3)" expect(page).to have_content "#{campaign1.name} (3)"
click_link "Go back" click_link "Go back"
click_link @campaign2.name click_link campaign2.name
expect(page).to have_content "#{@campaign2.name} (5)" expect(page).to have_content "#{campaign2.name} (5)"
end end
scenario "Do not track erroneous track_ids" do scenario "Do not track erroneous track_ids" do
visit root_url(track_id: @campaign1.track_id) visit root_url(track_id: campaign1.track_id)
visit root_url(track_id: "999") visit root_url(track_id: "999")
visit admin_stats_path visit admin_stats_path
click_link @campaign1.name click_link campaign1.name
expect(page).to have_content "#{@campaign1.name} (1)" expect(page).to have_content "#{campaign1.name} (1)"
click_link "Go back" click_link "Go back"
expect(page).not_to have_content @campaign2.name.to_s expect(page).not_to have_content campaign2.name.to_s
end end
end end

View File

@@ -500,24 +500,24 @@ describe "Commenting Budget::Investments" do
end end
describe "Voting comments" do describe "Voting comments" do
let(:verified) { create(:user, verified_at: Time.current) }
let(:unverified) { create(:user) }
let(:budget) { create(:budget) }
let(:investment) { create(:budget_investment, budget: budget) }
let!(:comment) { create(:comment, commentable: investment) }
before do before do
@manuela = create(:user, verified_at: Time.current)
@pablo = create(:user)
@investment = create(:budget_investment)
@comment = create(:comment, commentable: @investment)
@budget = @investment.budget
login_as(@manuela) login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit budget_investment_path(@budget, @budget, @investment) visit budget_investment_path(budget, investment)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -531,9 +531,9 @@ describe "Commenting Budget::Investments" do
end end
scenario "Create", :js do scenario "Create", :js do
visit budget_investment_path(@budget, @investment) visit budget_investment_path(budget, investment)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -549,9 +549,9 @@ describe "Commenting Budget::Investments" do
end end
scenario "Update", :js do scenario "Update", :js do
visit budget_investment_path(@budget, @investment) visit budget_investment_path(budget, investment)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -573,9 +573,9 @@ describe "Commenting Budget::Investments" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit budget_investment_path(@budget, @investment) visit budget_investment_path(budget, investment)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
find(".in_favor a").click find(".in_favor a").click

View File

@@ -445,22 +445,22 @@ describe "Commenting debates" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:debate) { create(:debate) }
@debate = create(:debate) let!(:comment) { create(:comment, commentable: debate) }
@comment = create(:comment, commentable: @debate)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit debate_path(@debate) visit debate_path(debate)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -474,9 +474,9 @@ describe "Commenting debates" do
end end
scenario "Create", :js do scenario "Create", :js do
visit debate_path(@debate) visit debate_path(debate)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -492,9 +492,9 @@ describe "Commenting debates" do
end end
scenario "Update", :js do scenario "Update", :js do
visit debate_path(@debate) visit debate_path(debate)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -516,9 +516,9 @@ describe "Commenting debates" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit debate_path(@debate) visit debate_path(debate)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -517,24 +517,24 @@ describe "Commenting legislation questions" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:annotation) { create(:legislation_annotation) }
@legislation_annotation = create(:legislation_annotation) let!(:comment) { create(:comment, commentable: annotation) }
@comment = create(:comment, commentable: @legislation_annotation)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, visit legislation_process_draft_version_annotation_path(annotation.draft_version.process,
@legislation_annotation.draft_version, annotation.draft_version,
@legislation_annotation) annotation)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -548,11 +548,11 @@ describe "Commenting legislation questions" do
end end
scenario "Create", :js do scenario "Create", :js do
visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, visit legislation_process_draft_version_annotation_path(annotation.draft_version.process,
@legislation_annotation.draft_version, annotation.draft_version,
@legislation_annotation) annotation)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -568,11 +568,11 @@ describe "Commenting legislation questions" do
end end
scenario "Update", :js do scenario "Update", :js do
visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, visit legislation_process_draft_version_annotation_path(annotation.draft_version.process,
@legislation_annotation.draft_version, annotation.draft_version,
@legislation_annotation) annotation)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -594,11 +594,11 @@ describe "Commenting legislation questions" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, visit legislation_process_draft_version_annotation_path(annotation.draft_version.process,
@legislation_annotation.draft_version, annotation.draft_version,
@legislation_annotation) annotation)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -468,22 +468,23 @@ describe "Commenting legislation questions" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:question) { create(:legislation_question) }
@legislation_question = create(:legislation_question) let!(:comment) { create(:comment, commentable: question) }
@comment = create(:comment, commentable: @legislation_question)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit legislation_process_question_path(@legislation_question.process, @legislation_question) visit legislation_process_question_path(question.process, question)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -497,9 +498,9 @@ describe "Commenting legislation questions" do
end end
scenario "Create", :js do scenario "Create", :js do
visit legislation_process_question_path(@legislation_question.process, @legislation_question) visit legislation_process_question_path(question.process, question)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -515,9 +516,9 @@ describe "Commenting legislation questions" do
end end
scenario "Update", :js do scenario "Update", :js do
visit legislation_process_question_path(@legislation_question.process, @legislation_question) visit legislation_process_question_path(question.process, question)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -539,9 +540,9 @@ describe "Commenting legislation questions" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit legislation_process_question_path(@legislation_question.process, @legislation_question) visit legislation_process_question_path(question.process, question)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -453,23 +453,22 @@ describe "Commenting polls" do
end end
describe "Voting comments" do describe "Voting comments" do
let(:verified) { create(:user, verified_at: Time.current) }
let(:unverified) { create(:user) }
let(:poll) { create(:poll) }
let!(:comment) { create(:comment, commentable: poll) }
before do before do
@manuela = create(:user, verified_at: Time.current) login_as(verified)
@pablo = create(:user)
@poll = create(:poll)
@comment = create(:comment, commentable: @poll)
login_as(@manuela)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit poll_path(@poll) visit poll_path(poll)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -483,9 +482,9 @@ describe "Commenting polls" do
end end
scenario "Create", :js do scenario "Create", :js do
visit poll_path(@poll) visit poll_path(poll)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -501,9 +500,9 @@ describe "Commenting polls" do
end end
scenario "Update", :js do scenario "Update", :js do
visit poll_path(@poll) visit poll_path(poll)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -525,9 +524,9 @@ describe "Commenting polls" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit poll_path(@poll) visit poll_path(poll)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
find(".in_favor a").click find(".in_favor a").click

View File

@@ -432,22 +432,22 @@ describe "Commenting proposals" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:proposal) { create(:proposal) }
@proposal = create(:proposal) let!(:comment) { create(:comment, commentable: proposal) }
@comment = create(:comment, commentable: @proposal)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit proposal_path(@proposal) visit proposal_path(proposal)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -461,9 +461,9 @@ describe "Commenting proposals" do
end end
scenario "Create", :js do scenario "Create", :js do
visit proposal_path(@proposal) visit proposal_path(proposal)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -479,9 +479,9 @@ describe "Commenting proposals" do
end end
scenario "Update", :js do scenario "Update", :js do
visit proposal_path(@proposal) visit proposal_path(proposal)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -503,9 +503,9 @@ describe "Commenting proposals" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit proposal_path(@proposal) visit proposal_path(proposal)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
find(".in_favor a").click find(".in_favor a").click

View File

@@ -481,23 +481,23 @@ describe "Commenting topics from proposals" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:proposal) { create(:proposal) }
@proposal = create(:proposal) let(:topic) { create(:topic, community: proposal.community) }
@topic = create(:topic, community: @proposal.community) let!(:comment) { create(:comment, commentable: topic) }
@comment = create(:comment, commentable: @topic)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit community_topic_path(@proposal.community, @topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -511,9 +511,9 @@ describe "Commenting topics from proposals" do
end end
scenario "Create", :js do scenario "Create", :js do
visit community_topic_path(@proposal.community, @topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -529,9 +529,9 @@ describe "Commenting topics from proposals" do
end end
scenario "Update", :js do scenario "Update", :js do
visit community_topic_path(@proposal.community, @topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -553,9 +553,9 @@ describe "Commenting topics from proposals" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit community_topic_path(@proposal.community, @topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
find(".in_favor a").click find(".in_favor a").click
@@ -1032,23 +1032,23 @@ describe "Commenting topics from budget investments" do
end end
describe "Voting comments" do describe "Voting comments" do
before do let(:verified) { create(:user, verified_at: Time.current) }
@manuela = create(:user, verified_at: Time.current) let(:unverified) { create(:user) }
@pablo = create(:user) let(:investment) { create(:budget_investment) }
@investment = create(:budget_investment) let(:topic) { create(:topic, community: investment.community) }
@topic = create(:topic, community: @investment.community) let!(:comment) { create(:comment, commentable: topic) }
@comment = create(:comment, commentable: @topic)
login_as(@manuela) before do
login_as(verified)
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: @pablo, votable: @comment, vote_flag: false) create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit community_topic_path(@investment.community, @topic) visit community_topic_path(investment.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
@@ -1062,9 +1062,9 @@ describe "Commenting topics from budget investments" do
end end
scenario "Create", :js do scenario "Create", :js do
visit community_topic_path(@investment.community, @topic) visit community_topic_path(investment.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -1080,9 +1080,9 @@ describe "Commenting topics from budget investments" do
end end
scenario "Update", :js do scenario "Update", :js do
visit community_topic_path(@investment.community, @topic) visit community_topic_path(investment.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
within(".in_favor") do within(".in_favor") do
@@ -1104,9 +1104,9 @@ describe "Commenting topics from budget investments" do
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit community_topic_path(@investment.community, @topic) visit community_topic_path(investment.community, topic)
within("#comment_#{@comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click find(".in_favor a").click
find(".in_favor a").click find(".in_favor a").click

View File

@@ -299,12 +299,13 @@ describe "Legislation Draft Versions" do
before do before do
create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum", create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum",
ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }])
@annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
end end
scenario "See one annotation with replies for a draft version" do scenario "See one annotation with replies for a draft version" do
visit legislation_process_draft_version_annotation_path(draft_version.process, draft_version, @annotation) annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
visit legislation_process_draft_version_annotation_path(draft_version.process, draft_version, annotation)
expect(page).not_to have_content "ipsum" expect(page).not_to have_content "ipsum"
expect(page).not_to have_content "my annotation" expect(page).not_to have_content "my annotation"

View File

@@ -2,15 +2,20 @@ require "rails_helper"
describe "Legislation" do describe "Legislation" do
context "process debate page" do context "process debate page" do
let(:process) do
create(:legislation_process,
debate_start_date: Date.current - 3.days,
debate_end_date: Date.current + 2.days)
end
before do before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days) create(:legislation_question, process: process, title: "Question 1")
create(:legislation_question, process: @process, title: "Question 1") create(:legislation_question, process: process, title: "Question 2")
create(:legislation_question, process: @process, title: "Question 2") create(:legislation_question, process: process, title: "Question 3")
create(:legislation_question, process: @process, title: "Question 3")
end end
scenario "shows question list" do scenario "shows question list" do
visit legislation_process_path(@process) visit legislation_process_path(process)
expect(page).to have_content("Participate in the debate") expect(page).to have_content("Participate in the debate")
@@ -35,14 +40,14 @@ describe "Legislation" do
end end
scenario "shows question page" do scenario "shows question page" do
visit legislation_process_question_path(@process, @process.questions.first) visit legislation_process_question_path(process, process.questions.first)
expect(page).to have_content("Question 1") expect(page).to have_content("Question 1")
expect(page).to have_content("Open answers (0)") expect(page).to have_content("Open answers (0)")
end end
scenario "shows next question link in question page" do scenario "shows next question link in question page" do
visit legislation_process_question_path(@process, @process.questions.first) visit legislation_process_question_path(process, process.questions.first)
expect(page).to have_content("Question 1") expect(page).to have_content("Question 1")
expect(page).to have_content("Next question") expect(page).to have_content("Next question")
@@ -59,7 +64,7 @@ describe "Legislation" do
end end
scenario "answer question" do scenario "answer question" do
question = @process.questions.first question = process.questions.first
create(:legislation_question_option, question: question, value: "Yes") create(:legislation_question_option, question: question, value: "Yes")
create(:legislation_question_option, question: question, value: "No") create(:legislation_question_option, question: question, value: "No")
option = create(:legislation_question_option, question: question, value: "I don't know") option = create(:legislation_question_option, question: question, value: "I don't know")
@@ -67,7 +72,7 @@ describe "Legislation" do
login_as(user) login_as(user)
visit legislation_process_question_path(@process, question) visit legislation_process_question_path(process, question)
expect(page).to have_selector(:radio_button, "Yes") expect(page).to have_selector(:radio_button, "Yes")
expect(page).to have_selector(:radio_button, "No") expect(page).to have_selector(:radio_button, "No")
@@ -89,8 +94,8 @@ describe "Legislation" do
end end
scenario "cannot answer question when phase not open" do scenario "cannot answer question when phase not open" do
@process.update_attribute(:debate_end_date, Date.current - 1.day) process.update_attribute(:debate_end_date, Date.current - 1.day)
question = @process.questions.first question = process.questions.first
create(:legislation_question_option, question: question, value: "Yes") create(:legislation_question_option, question: question, value: "Yes")
create(:legislation_question_option, question: question, value: "No") create(:legislation_question_option, question: question, value: "No")
create(:legislation_question_option, question: question, value: "I don't know") create(:legislation_question_option, question: question, value: "I don't know")
@@ -98,7 +103,7 @@ describe "Legislation" do
login_as(user) login_as(user)
visit legislation_process_question_path(@process, question) visit legislation_process_question_path(process, question)
expect(page).to have_selector(:radio_button, "Yes", disabled: true) expect(page).to have_selector(:radio_button, "Yes", disabled: true)
expect(page).to have_selector(:radio_button, "No", disabled: true) expect(page).to have_selector(:radio_button, "No", disabled: true)

View File

@@ -17,37 +17,33 @@ describe "Legislation" do
end end
context "process empty" do context "process empty" do
before do let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
scenario "warning empty" do scenario "warning empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.") expect(page).to have_content("The process have no phases.")
end end
end end
context "phases empty" do context "phases empty" do
before do let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
@process = create(:legislation_process, end_date: Date.current - 1.day)
end
scenario "debates empty" do scenario "debates empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase") expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates") expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions") expect(page).to have_content("There aren't any questions")
end end
scenario "proposals empty" do scenario "proposals empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase") expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals") expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals") expect(page).to have_content("There are no proposals")
end end
scenario "text comments empty" do scenario "text comments empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase") expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments") expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments") expect(page).to have_content("There are no text comments")
@@ -55,31 +51,29 @@ describe "Legislation" do
end end
context "process empty" do context "process empty" do
before do let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
scenario "warning empty" do scenario "warning empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.") expect(page).to have_content("The process have no phases.")
end end
end end
context "only debates exist" do context "only debates exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do before do
user = create(:user, :level_two) user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day) @debate = create(:legislation_question, process: process, title: "Question 1")
@debate = create(:legislation_question, process: @process, title: "Question 1")
create(:comment, user: user, commentable: @debate, body: "Answer 1") create(:comment, user: user, commentable: @debate, body: "Answer 1")
create(:comment, user: user, commentable: @debate, body: "Answer 2") create(:comment, user: user, commentable: @debate, body: "Answer 2")
@debate = create(:legislation_question, process: @process, title: "Question 2") @debate = create(:legislation_question, process: process, title: "Question 2")
create(:comment, user: user, commentable: @debate, body: "Answer 3") create(:comment, user: user, commentable: @debate, body: "Answer 3")
create(:comment, user: user, commentable: @debate, body: "Answer 4") create(:comment, user: user, commentable: @debate, body: "Answer 4")
end end
scenario "show debates list" do scenario "show debates list" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase") expect(page).to have_content("Debates phase")
expect(page).to have_content("2 debates") expect(page).to have_content("2 debates")
@@ -97,7 +91,7 @@ describe "Legislation" do
expect(page).not_to have_content("Answer 3") expect(page).not_to have_content("Answer 3")
expect(page).not_to have_content("Answer 4") expect(page).not_to have_content("Answer 4")
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
click_link "Question 2" click_link "Question 2"
expect(page).to have_content("Question 2") expect(page).to have_content("Question 2")
expect(page).not_to have_content("Answer 1") expect(page).not_to have_content("Answer 1")
@@ -108,14 +102,14 @@ describe "Legislation" do
end end
scenario "proposals empty" do scenario "proposals empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase") expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals") expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals") expect(page).to have_content("There are no proposals")
end end
scenario "text comments empty" do scenario "text comments empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase") expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments") expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments") expect(page).to have_content("There are no text comments")
@@ -123,27 +117,28 @@ describe "Legislation" do
end end
context "only proposals exist" do context "only proposals exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do before do
@process = create(:legislation_process, end_date: Date.current - 1.day) create(:legislation_proposal, legislation_process_id: process.id,
create(:legislation_proposal, legislation_process_id: @process.id,
title: "Legislation proposal 1", selected: true) title: "Legislation proposal 1", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id, create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 2", selected: false) title: "Legislation proposal 2", selected: false)
create(:legislation_proposal, legislation_process_id: @process.id, create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 3", selected: true) title: "Legislation proposal 3", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id, create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 4", selected: false) title: "Legislation proposal 4", selected: false)
end end
scenario "debates empty" do scenario "debates empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase") expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates") expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions") expect(page).to have_content("There aren't any questions")
end end
scenario "proposals empty" do scenario "proposals empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase") expect(page).to have_content("Proposal phase")
expect(page).to have_content("2 proposals") expect(page).to have_content("2 proposals")
@@ -155,14 +150,14 @@ describe "Legislation" do
click_link "Legislation proposal 1" click_link "Legislation proposal 1"
expect(page).to have_content("Legislation proposal 1") expect(page).to have_content("Legislation proposal 1")
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
click_link "Legislation proposal 3" click_link "Legislation proposal 3"
expect(page).to have_content("Legislation proposal 3") expect(page).to have_content("Legislation proposal 3")
end end
scenario "text comments empty" do scenario "text comments empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase") expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments") expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments") expect(page).to have_content("There are no text comments")
@@ -170,13 +165,14 @@ describe "Legislation" do
end end
context "only text comments exist" do context "only text comments exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do before do
user = create(:user, :level_two) user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day) draft_version_1 = create(:legislation_draft_version, process: process,
draft_version_1 = create(:legislation_draft_version, process: @process,
title: "Version 1", body: "Body of the first version", title: "Version 1", body: "Body of the first version",
status: "published") status: "published")
draft_version_2 = create(:legislation_draft_version, process: @process, draft_version_2 = create(:legislation_draft_version, process: process,
title: "Version 2", body: "Body of the second version and that's it all of it", title: "Version 2", body: "Body of the second version and that's it all of it",
status: "published") status: "published")
annotation0 = create(:legislation_annotation, annotation0 = create(:legislation_annotation,
@@ -196,21 +192,21 @@ describe "Legislation" do
end end
scenario "debates empty" do scenario "debates empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase") expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates") expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions") expect(page).to have_content("There aren't any questions")
end end
scenario "proposals empty" do scenario "proposals empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase") expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals") expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals") expect(page).to have_content("There are no proposals")
end end
scenario "text comments empty" do scenario "text comments empty" do
visit resume_legislation_process_path(@process) visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase (version Version 2") expect(page).to have_content("Text comment phase (version Version 2")
expect(page).to have_content("5 comments") expect(page).to have_content("5 comments")
expect(page).not_to have_content("Comment 0") expect(page).not_to have_content("Comment 0")
@@ -223,7 +219,7 @@ describe "Legislation" do
end end
# scenario "excel download" do # scenario "excel download" do
# visit resume_legislation_process_path(@process) # visit resume_legislation_process_path(process)
# click_link "Download" # click_link "Download"
# page.response_headers['Content-Type'].should eq "application/xlsx" # page.response_headers['Content-Type'].should eq "application/xlsx"
# end # end
@@ -234,9 +230,9 @@ describe "Legislation" do
before do before do
user = create(:user, :level_two) user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day) @process = create(:legislation_process, end_date: Date.current - 1.day)
@debate = create(:legislation_question, process: @process, title: "Question 1") debate = create(:legislation_question, process: @process, title: "Question 1")
create(:comment, user: user, commentable: @debate, body: "Answer 1") create(:comment, user: user, commentable: debate, body: "Answer 1")
create(:comment, user: user, commentable: @debate, body: "Answer 2") create(:comment, user: user, commentable: debate, body: "Answer 2")
end end
it "download execl file test" do it "download execl file test" do

View File

@@ -2,24 +2,21 @@ require "rails_helper"
describe "Moderate budget investments" do describe "Moderate budget investments" do
let(:budget) { create(:budget) } let(:budget) { create(:budget) }
let(:heading) { create(:budget_heading, budget: budget, price: 666666) } let(:heading) { create(:budget_heading, budget: budget, price: 666666) }
let(:mod) { create(:moderator) }
before do let!(:investment) { create(:budget_investment, heading: heading, author: create(:user)) }
@mod = create(:moderator)
@investment = create(:budget_investment, heading: heading, author: create(:user))
end
scenario "Disabled with a feature flag" do scenario "Disabled with a feature flag" do
Setting["process.budgets"] = nil Setting["process.budgets"] = nil
login_as(@mod.user) login_as(mod.user)
expect { visit moderation_budget_investments_path }.to raise_exception(FeatureFlags::FeatureDisabled) expect { visit moderation_budget_investments_path }.to raise_exception(FeatureFlags::FeatureDisabled)
end end
scenario "Hiding an investment", :js do scenario "Hiding an investment", :js do
login_as(@mod.user) login_as(mod.user)
visit budget_investment_path(budget, @investment) visit budget_investment_path(budget, investment)
accept_confirm { click_link "Hide" } accept_confirm { click_link "Hide" }
@@ -27,12 +24,12 @@ describe "Moderate budget investments" do
visit budget_investments_path(budget.id, heading_id: heading.id) visit budget_investments_path(budget.id, heading_id: heading.id)
expect(page).not_to have_content(@investment.title) expect(page).not_to have_content(investment.title)
end end
scenario "Hiding an investment's author", :js do scenario "Hiding an investment's author", :js do
login_as(@mod.user) login_as(mod.user)
visit budget_investment_path(budget, @investment) visit budget_investment_path(budget, investment)
accept_confirm { click_link "Hide author" } accept_confirm { click_link "Hide author" }
@@ -40,16 +37,16 @@ describe "Moderate budget investments" do
visit budget_investments_path(budget.id, heading_id: heading.id) visit budget_investments_path(budget.id, heading_id: heading.id)
expect(page).not_to have_content(@investment.title) expect(page).not_to have_content(investment.title)
end end
scenario "Can not hide own investment" do scenario "Can not hide own investment" do
@investment.update(author: @mod.user) investment.update(author: mod.user)
login_as(@mod.user) login_as(mod.user)
visit budget_investment_path(budget, @investment) visit budget_investment_path(budget, investment)
within "#budget_investment_#{@investment.id}" do within "#budget_investment_#{investment.id}" do
expect(page).not_to have_link("Hide") expect(page).not_to have_link("Hide")
expect(page).not_to have_link("Hide author") expect(page).not_to have_link("Hide author")
end end
@@ -58,7 +55,7 @@ describe "Moderate budget investments" do
describe "/moderation/ screen" do describe "/moderation/ screen" do
before do before do
login_as(@mod.user) login_as(mod.user)
end end
describe "moderate in bulk" do describe "moderate in bulk" do
@@ -71,40 +68,40 @@ describe "Moderate budget investments" do
click_link "All" click_link "All"
end end
within("#investment_#{@investment.id}") do within("#investment_#{investment.id}") do
check "budget_investment_#{@investment.id}_check" check "budget_investment_#{investment.id}_check"
end end
expect(page).not_to have_css("investment#{@investment.id}") expect(page).not_to have_css("investment#{investment.id}")
end end
scenario "Hide the investment" do scenario "Hide the investment" do
click_button "Hide budget investments" click_button "Hide budget investments"
expect(page).not_to have_css("investment_#{@investment.id}") expect(page).not_to have_css("investment_#{investment.id}")
@investment.reload investment.reload
expect(@investment.author).not_to be_hidden expect(investment.author).not_to be_hidden
end end
scenario "Block the author" do scenario "Block the author" do
click_button "Block authors" click_button "Block authors"
expect(page).not_to have_css("investment_#{@investment.id}") expect(page).not_to have_css("investment_#{investment.id}")
@investment.reload investment.reload
expect(@investment.author).to be_hidden expect(investment.author).to be_hidden
end end
scenario "Ignore the investment" do scenario "Ignore the investment" do
click_button "Mark as viewed" click_button "Mark as viewed"
expect(page).not_to have_css("investment_#{@investment.id}") expect(page).not_to have_css("investment_#{investment.id}")
@investment.reload investment.reload
expect(@investment).to be_ignored_flag expect(investment).to be_ignored_flag
expect(@investment).not_to be_hidden expect(investment).not_to be_hidden
expect(@investment.author).not_to be_hidden expect(investment.author).not_to be_hidden
end end
end end

View File

@@ -72,40 +72,41 @@ describe "Moderate comments" do
describe "moderate in bulk" do describe "moderate in bulk" do
describe "When a comment has been selected for moderation" do describe "When a comment has been selected for moderation" do
let!(:comment) { create(:comment) }
before do before do
@comment = create(:comment)
visit moderation_comments_path visit moderation_comments_path
within(".menu.simple") do within(".menu.simple") do
click_link "All" click_link "All"
end end
within("#comment_#{@comment.id}") do within("#comment_#{comment.id}") do
check "comment_#{@comment.id}_check" check "comment_#{comment.id}_check"
end end
expect(page).not_to have_css("comment_#{@comment.id}") expect(page).not_to have_css("comment_#{comment.id}")
end end
scenario "Hide the comment" do scenario "Hide the comment" do
click_on "Hide comments" click_on "Hide comments"
expect(page).not_to have_css("comment_#{@comment.id}") expect(page).not_to have_css("comment_#{comment.id}")
expect(@comment.reload).to be_hidden expect(comment.reload).to be_hidden
expect(@comment.user).not_to be_hidden expect(comment.user).not_to be_hidden
end end
scenario "Block the user" do scenario "Block the user" do
click_on "Block authors" click_on "Block authors"
expect(page).not_to have_css("comment_#{@comment.id}") expect(page).not_to have_css("comment_#{comment.id}")
expect(@comment.reload).to be_hidden expect(comment.reload).to be_hidden
expect(@comment.user).to be_hidden expect(comment.user).to be_hidden
end end
scenario "Ignore the comment" do scenario "Ignore the comment" do
click_on "Mark as viewed" click_on "Mark as viewed"
expect(page).not_to have_css("comment_#{@comment.id}") expect(page).not_to have_css("comment_#{comment.id}")
expect(@comment.reload).to be_ignored_flag expect(comment.reload).to be_ignored_flag
expect(@comment.reload).not_to be_hidden expect(comment.reload).not_to be_hidden
expect(@comment.user).not_to be_hidden expect(comment.user).not_to be_hidden
end end
end end

View File

@@ -53,40 +53,41 @@ describe "Moderate debates" do
describe "moderate in bulk" do describe "moderate in bulk" do
describe "When a debate has been selected for moderation" do describe "When a debate has been selected for moderation" do
let!(:debate) { create(:debate) }
before do before do
@debate = create(:debate)
visit moderation_debates_path visit moderation_debates_path
within(".menu.simple") do within(".menu.simple") do
click_link "All" click_link "All"
end end
within("#debate_#{@debate.id}") do within("#debate_#{debate.id}") do
check "debate_#{@debate.id}_check" check "debate_#{debate.id}_check"
end end
expect(page).not_to have_css("debate_#{@debate.id}") expect(page).not_to have_css("debate_#{debate.id}")
end end
scenario "Hide the debate" do scenario "Hide the debate" do
click_on "Hide debates" click_on "Hide debates"
expect(page).not_to have_css("debate_#{@debate.id}") expect(page).not_to have_css("debate_#{debate.id}")
expect(@debate.reload).to be_hidden expect(debate.reload).to be_hidden
expect(@debate.author).not_to be_hidden expect(debate.author).not_to be_hidden
end end
scenario "Block the author" do scenario "Block the author" do
click_on "Block authors" click_on "Block authors"
expect(page).not_to have_css("debate_#{@debate.id}") expect(page).not_to have_css("debate_#{debate.id}")
expect(@debate.reload).to be_hidden expect(debate.reload).to be_hidden
expect(@debate.author).to be_hidden expect(debate.author).to be_hidden
end end
scenario "Ignore the debate" do scenario "Ignore the debate" do
click_on "Mark as viewed" click_on "Mark as viewed"
expect(page).not_to have_css("debate_#{@debate.id}") expect(page).not_to have_css("debate_#{debate.id}")
expect(@debate.reload).to be_ignored_flag expect(debate.reload).to be_ignored_flag
expect(@debate.reload).not_to be_hidden expect(debate.reload).not_to be_hidden
expect(@debate.author).not_to be_hidden expect(debate.author).not_to be_hidden
end end
end end

View File

@@ -48,41 +48,41 @@ describe "Moderate proposal notifications" do
describe "moderate in bulk" do describe "moderate in bulk" do
describe "When a proposal has been selected for moderation" do describe "When a proposal has been selected for moderation" do
let!(:proposal_notification) { create(:proposal_notification, created_at: Date.current - 4.days) }
before do before do
proposal = create(:proposal)
@proposal_notification = create(:proposal_notification, proposal: proposal, created_at: Date.current - 4.days)
visit moderation_proposal_notifications_path visit moderation_proposal_notifications_path
within(".menu.simple") do within(".menu.simple") do
click_link "All" click_link "All"
end end
within("#proposal_notification_#{@proposal_notification.id}") do within("#proposal_notification_#{proposal_notification.id}") do
check "proposal_notification_#{@proposal_notification.id}_check" check "proposal_notification_#{proposal_notification.id}_check"
end end
end end
scenario "Hide the proposal" do scenario "Hide the proposal" do
click_on "Hide proposals" click_on "Hide proposals"
expect(page).not_to have_css("#proposal_notification_#{@proposal_notification.id}") expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}")
expect(@proposal_notification.reload).to be_hidden expect(proposal_notification.reload).to be_hidden
expect(@proposal_notification.author).not_to be_hidden expect(proposal_notification.author).not_to be_hidden
end end
scenario "Block the author" do scenario "Block the author" do
author = create(:user) author = create(:user)
@proposal_notification.update(author: author) proposal_notification.update(author: author)
click_on "Block authors" click_on "Block authors"
expect(page).not_to have_css("#proposal_notification_#{@proposal_notification.id}") expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}")
expect(@proposal_notification.reload).to be_hidden expect(proposal_notification.reload).to be_hidden
expect(author.reload).to be_hidden expect(author.reload).to be_hidden
end end
scenario "Ignore the proposal" do scenario "Ignore the proposal" do
click_button "Mark as viewed" click_button "Mark as viewed"
expect(@proposal_notification.reload).to be_ignored expect(proposal_notification.reload).to be_ignored
expect(@proposal_notification.reload).not_to be_hidden expect(proposal_notification.reload).not_to be_hidden
expect(@proposal_notification.author).not_to be_hidden expect(proposal_notification.author).not_to be_hidden
end end
end end

View File

@@ -51,41 +51,42 @@ describe "Moderate proposals" do
end end
describe "moderate in bulk" do describe "moderate in bulk" do
let!(:proposal) { create(:proposal) }
describe "When a proposal has been selected for moderation" do describe "When a proposal has been selected for moderation" do
before do before do
@proposal = create(:proposal)
visit moderation_proposals_path visit moderation_proposals_path
within(".menu.simple") do within(".menu.simple") do
click_link "All" click_link "All"
end end
within("#proposal_#{@proposal.id}") do within("#proposal_#{proposal.id}") do
check "proposal_#{@proposal.id}_check" check "proposal_#{proposal.id}_check"
end end
expect(page).not_to have_css("proposal_#{@proposal.id}") expect(page).not_to have_css("proposal_#{proposal.id}")
end end
scenario "Hide the proposal" do scenario "Hide the proposal" do
click_on "Hide proposals" click_on "Hide proposals"
expect(page).not_to have_css("proposal_#{@proposal.id}") expect(page).not_to have_css("proposal_#{proposal.id}")
expect(@proposal.reload).to be_hidden expect(proposal.reload).to be_hidden
expect(@proposal.author).not_to be_hidden expect(proposal.author).not_to be_hidden
end end
scenario "Block the author" do scenario "Block the author" do
click_on "Block authors" click_on "Block authors"
expect(page).not_to have_css("proposal_#{@proposal.id}") expect(page).not_to have_css("proposal_#{proposal.id}")
expect(@proposal.reload).to be_hidden expect(proposal.reload).to be_hidden
expect(@proposal.author).to be_hidden expect(proposal.author).to be_hidden
end end
scenario "Ignore the proposal" do scenario "Ignore the proposal" do
click_button "Mark as viewed" click_button "Mark as viewed"
expect(page).not_to have_css("proposal_#{@proposal.id}") expect(page).not_to have_css("proposal_#{proposal.id}")
expect(@proposal.reload).to be_ignored_flag expect(proposal.reload).to be_ignored_flag
expect(@proposal.reload).not_to be_hidden expect(proposal.reload).not_to be_hidden
expect(@proposal.author).not_to be_hidden expect(proposal.author).not_to be_hidden
end end
end end

View File

@@ -3,16 +3,13 @@ require "rails_helper"
describe "Official positions" do describe "Official positions" do
context "Badge" do context "Badge" do
let(:user1) { create(:user, official_level: 1, official_position: "Employee", official_position_badge: true) }
before do let(:user2) { create(:user, official_level: 0, official_position: "") }
@user1 = create(:user, official_level: 1, official_position: "Employee", official_position_badge: true)
@user2 = create(:user, official_level: 0, official_position: "")
end
scenario "Comments" do scenario "Comments" do
proposal = create(:proposal) proposal = create(:proposal)
comment1 = create(:comment, commentable: proposal, user: @user1) comment1 = create(:comment, commentable: proposal, user: user1)
comment2 = create(:comment, commentable: proposal, user: @user2) comment2 = create(:comment, commentable: proposal, user: user2)
visit proposal_path(proposal) visit proposal_path(proposal)
@@ -21,49 +18,43 @@ describe "Official positions" do
end end
context "Debates" do context "Debates" do
let!(:debate1) { create(:debate, author: user1) }
before do let!(:debate2) { create(:debate, author: user2) }
@debate1 = create(:debate, author: @user1)
@debate2 = create(:debate, author: @user2)
end
scenario "Index" do scenario "Index" do
visit debates_path visit debates_path
expect_badge_for("debate", @debate1) expect_badge_for("debate", debate1)
expect_no_badge_for("debate", @debate2) expect_no_badge_for("debate", debate2)
end end
scenario "Show" do scenario "Show" do
visit debate_path(@debate1) visit debate_path(debate1)
expect_badge_for("debate", @debate1) expect_badge_for("debate", debate1)
visit debate_path(@debate2) visit debate_path(debate2)
expect_no_badge_for("debate", @debate2) expect_no_badge_for("debate", debate2)
end end
end end
context "Proposals" do context "Proposals" do
let!(:proposal1) { create(:proposal, author: user1) }
before do let!(:proposal2) { create(:proposal, author: user2) }
@proposal1 = create(:proposal, author: @user1)
@proposal2 = create(:proposal, author: @user2)
end
scenario "Index" do scenario "Index" do
visit proposals_path visit proposals_path
expect_badge_for("proposal", @proposal1) expect_badge_for("proposal", proposal1)
expect_no_badge_for("proposal", @proposal2) expect_no_badge_for("proposal", proposal2)
end end
scenario "Show" do scenario "Show" do
visit proposal_path(@proposal1) visit proposal_path(proposal1)
expect_badge_for("proposal", @proposal1) expect_badge_for("proposal", proposal1)
visit proposal_path(@proposal2) visit proposal_path(proposal2)
expect_no_badge_for("proposal", @proposal2) expect_no_badge_for("proposal", proposal2)
end end
end end

View File

@@ -4,15 +4,16 @@ describe "Officing Results", :with_frozen_time do
let(:poll) { create(:poll, ends_at: 1.day.ago) } let(:poll) { create(:poll, ends_at: 1.day.ago) }
let(:booth) { create(:poll_booth, polls: [poll]) } let(:booth) { create(:poll_booth, polls: [poll]) }
let(:poll_officer) { create(:poll_officer) } let(:poll_officer) { create(:poll_officer) }
let(:question_1) { create(:poll_question, poll: poll) }
let(:question_2) { create(:poll_question, poll: poll) }
before do before do
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current)
@question_1 = create(:poll_question, poll: poll) create(:poll_question_answer, title: "Yes", question: question_1, given_order: 1)
create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1) create(:poll_question_answer, title: "No", question: question_1, given_order: 2)
create(:poll_question_answer, title: "No", question: @question_1, given_order: 2)
@question_2 = create(:poll_question, poll: poll) create(:poll_question_answer, title: "Today", question: question_2, given_order: 1)
create(:poll_question_answer, title: "Today", question: @question_2, given_order: 1) create(:poll_question_answer, title: "Tomorrow", question: question_2, given_order: 2)
create(:poll_question_answer, title: "Tomorrow", question: @question_2, given_order: 2)
login_as(poll_officer.user) login_as(poll_officer.user)
set_officing_booth(booth) set_officing_booth(booth)
@@ -57,11 +58,11 @@ describe "Officing Results", :with_frozen_time do
select booth.name, from: "officer_assignment_id" select booth.name, from: "officer_assignment_id"
fill_in "questions[#{@question_1.id}][0]", with: "100" fill_in "questions[#{question_1.id}][0]", with: "100"
fill_in "questions[#{@question_1.id}][1]", with: "200" fill_in "questions[#{question_1.id}][1]", with: "200"
fill_in "questions[#{@question_2.id}][0]", with: "333" fill_in "questions[#{question_2.id}][0]", with: "333"
fill_in "questions[#{@question_2.id}][1]", with: "444" fill_in "questions[#{question_2.id}][1]", with: "444"
fill_in "whites", with: "66" fill_in "whites", with: "66"
fill_in "nulls", with: "77" fill_in "nulls", with: "77"
@@ -82,22 +83,22 @@ describe "Officing Results", :with_frozen_time do
officer_assignment: poll_officer.officer_assignments.first, officer_assignment: poll_officer.officer_assignments.first,
booth_assignment: poll_officer.officer_assignments.first.booth_assignment, booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
date: Date.current, date: Date.current,
question: @question_1, question: question_1,
answer: @question_1.question_answers.first.title, answer: question_1.question_answers.first.title,
author: poll_officer.user, author: poll_officer.user,
amount: 7777) amount: 7777)
visit officing_poll_results_path(poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id) visit officing_poll_results_path(poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id)
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content("7777") } within("#question_#{question_1.id}_0_result") { expect(page).to have_content("7777") }
visit new_officing_poll_result_path(poll) visit new_officing_poll_result_path(poll)
booth_name = partial_result.booth_assignment.booth.name booth_name = partial_result.booth_assignment.booth.name
select booth_name, from: "officer_assignment_id" select booth_name, from: "officer_assignment_id"
fill_in "questions[#{@question_1.id}][0]", with: "5555" fill_in "questions[#{question_1.id}][0]", with: "5555"
fill_in "questions[#{@question_1.id}][1]", with: "200" fill_in "questions[#{question_1.id}][1]", with: "200"
fill_in "whites", with: "6" fill_in "whites", with: "6"
fill_in "nulls", with: "7" fill_in "nulls", with: "7"
fill_in "total", with: "8" fill_in "total", with: "8"
@@ -114,8 +115,8 @@ describe "Officing Results", :with_frozen_time do
within("#white_results") { expect(page).to have_content("6") } within("#white_results") { expect(page).to have_content("6") }
within("#null_results") { expect(page).to have_content("7") } within("#null_results") { expect(page).to have_content("7") }
within("#total_results") { expect(page).to have_content("8") } within("#total_results") { expect(page).to have_content("8") }
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content("5555") } within("#question_#{question_1.id}_0_result") { expect(page).to have_content("5555") }
within("#question_#{@question_1.id}_1_result") { expect(page).to have_content("200") } within("#question_#{question_1.id}_1_result") { expect(page).to have_content("200") }
end end
scenario "Index lists all questions and answers" do scenario "Index lists all questions and answers" do
@@ -123,7 +124,7 @@ describe "Officing Results", :with_frozen_time do
officer_assignment: poll_officer.officer_assignments.first, officer_assignment: poll_officer.officer_assignments.first,
booth_assignment: poll_officer.officer_assignments.first.booth_assignment, booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
date: poll.ends_at, date: poll.ends_at,
question: @question_1, question: question_1,
amount: 33) amount: 33)
create(:poll_recount, create(:poll_recount,
@@ -141,14 +142,14 @@ describe "Officing Results", :with_frozen_time do
expect(page).to have_content(I18n.l(poll.ends_at.to_date, format: :long)) expect(page).to have_content(I18n.l(poll.ends_at.to_date, format: :long))
expect(page).to have_content(poll_officer.officer_assignments.first.booth_assignment.booth.name) expect(page).to have_content(poll_officer.officer_assignments.first.booth_assignment.booth.name)
expect(page).to have_content(@question_1.title) expect(page).to have_content(question_1.title)
@question_1.question_answers.each_with_index do |answer, i| question_1.question_answers.each_with_index do |answer, i|
within("#question_#{@question_1.id}_#{i}_result") { expect(page).to have_content(answer.title) } within("#question_#{question_1.id}_#{i}_result") { expect(page).to have_content(answer.title) }
end end
expect(page).to have_content(@question_2.title) expect(page).to have_content(question_2.title)
@question_2.question_answers.each_with_index do |answer, i| question_2.question_answers.each_with_index do |answer, i|
within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer.title) } within("#question_#{question_2.id}_#{i}_result") { expect(page).to have_content(answer.title) }
end end
within("#white_results") { expect(page).to have_content("21") } within("#white_results") { expect(page).to have_content("21") }

View File

@@ -3,9 +3,9 @@ require "rails_helper"
describe "Tracking budgets" do describe "Tracking budgets" do
before do before do
@tracker = create(:tracker, user: create(:user, username: "Rachel", tracker = create(:tracker, user: create(:user, username: "Rachel",
email: "rachel@trackers.org")) email: "rachel@trackers.org"))
login_as(@tracker.user) login_as(tracker.user)
end end
scenario "Disabled with a feature flag" do scenario "Disabled with a feature flag" do

View File

@@ -3,15 +3,15 @@ require "rails_helper"
describe "Users" do describe "Users" do
describe "Show (public page)" do describe "Show (public page)" do
let(:user) { create(:user) }
before do before do
@user = create(:user) 1.times { create(:debate, author: user) }
1.times { create(:debate, author: @user) } 2.times { create(:proposal, author: user) }
2.times { create(:proposal, author: @user) } 3.times { create(:budget_investment, author: user) }
3.times { create(:budget_investment, author: @user) } 4.times { create(:comment, user: user) }
4.times { create(:comment, user: @user) }
visit user_path(@user) visit user_path(user)
end end
scenario "shows user public activity" do scenario "shows user public activity" do
@@ -22,7 +22,7 @@ describe "Users" do
end end
scenario "shows only items where user has activity" do scenario "shows only items where user has activity" do
@user.proposals.destroy_all user.proposals.destroy_all
expect(page).not_to have_content("0 Proposals") expect(page).not_to have_content("0 Proposals")
expect(page).to have_content("1 Debate") expect(page).to have_content("1 Debate")
@@ -31,41 +31,41 @@ describe "Users" do
end end
scenario "default filter is proposals" do scenario "default filter is proposals" do
@user.proposals.each do |proposal| user.proposals.each do |proposal|
expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.title)
end end
@user.debates.each do |debate| user.debates.each do |debate|
expect(page).not_to have_content(debate.title) expect(page).not_to have_content(debate.title)
end end
@user.comments.each do |comment| user.comments.each do |comment|
expect(page).not_to have_content(comment.body) expect(page).not_to have_content(comment.body)
end end
end end
scenario "shows debates by default if user has no proposals" do scenario "shows debates by default if user has no proposals" do
@user.proposals.destroy_all user.proposals.destroy_all
visit user_path(@user) visit user_path(user)
expect(page).to have_content(@user.debates.first.title) expect(page).to have_content(user.debates.first.title)
end end
scenario "shows investments by default if user has no proposals nor debates" do scenario "shows investments by default if user has no proposals nor debates" do
@user.proposals.destroy_all user.proposals.destroy_all
@user.debates.destroy_all user.debates.destroy_all
visit user_path(@user) visit user_path(user)
expect(page).to have_content(@user.budget_investments.first.title) expect(page).to have_content(user.budget_investments.first.title)
end end
scenario "shows comments by default if user has no proposals nor debates nor investments" do scenario "shows comments by default if user has no proposals nor debates nor investments" do
@user.proposals.destroy_all user.proposals.destroy_all
@user.debates.destroy_all user.debates.destroy_all
@user.budget_investments.destroy_all user.budget_investments.destroy_all
visit user_path(@user) visit user_path(user)
@user.comments.each do |comment| user.comments.each do |comment|
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
end end
end end
@@ -73,43 +73,43 @@ describe "Users" do
scenario "filters" do scenario "filters" do
click_link "1 Debate" click_link "1 Debate"
@user.debates.each do |debate| user.debates.each do |debate|
expect(page).to have_content(debate.title) expect(page).to have_content(debate.title)
end end
@user.proposals.each do |proposal| user.proposals.each do |proposal|
expect(page).not_to have_content(proposal.title) expect(page).not_to have_content(proposal.title)
end end
@user.comments.each do |comment| user.comments.each do |comment|
expect(page).not_to have_content(comment.body) expect(page).not_to have_content(comment.body)
end end
click_link "4 Comments" click_link "4 Comments"
@user.comments.each do |comment| user.comments.each do |comment|
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
end end
@user.proposals.each do |proposal| user.proposals.each do |proposal|
expect(page).not_to have_content(proposal.title) expect(page).not_to have_content(proposal.title)
end end
@user.debates.each do |debate| user.debates.each do |debate|
expect(page).not_to have_content(debate.title) expect(page).not_to have_content(debate.title)
end end
click_link "2 Proposals" click_link "2 Proposals"
@user.proposals.each do |proposal| user.proposals.each do |proposal|
expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.title)
end end
@user.comments.each do |comment| user.comments.each do |comment|
expect(page).not_to have_content(comment.body) expect(page).not_to have_content(comment.body)
end end
@user.debates.each do |debate| user.debates.each do |debate|
expect(page).not_to have_content(debate.title) expect(page).not_to have_content(debate.title)
end end
end end
@@ -138,19 +138,17 @@ describe "Users" do
end end
describe "Public activity" do describe "Public activity" do
before do let(:user) { create(:user) }
@user = create(:user)
end
scenario "visible by default" do scenario "visible by default" do
visit user_path(@user) visit user_path(user)
expect(page).to have_content(@user.username) expect(page).to have_content(user.username)
expect(page).not_to have_content("activity list private") expect(page).not_to have_content("activity list private")
end end
scenario "user can hide public page" do scenario "user can hide public page" do
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_activity" uncheck "account_public_activity"
@@ -158,23 +156,23 @@ describe "Users" do
logout logout
visit user_path(@user) visit user_path(user)
expect(page).to have_content("activity list private") expect(page).to have_content("activity list private")
end end
scenario "is always visible for the owner" do scenario "is always visible for the owner" do
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_activity" uncheck "account_public_activity"
click_button "Save changes" click_button "Save changes"
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content("activity list private") expect(page).not_to have_content("activity list private")
end end
scenario "is always visible for admins" do scenario "is always visible for admins" do
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_activity" uncheck "account_public_activity"
@@ -183,12 +181,12 @@ describe "Users" do
logout logout
login_as(create(:administrator).user) login_as(create(:administrator).user)
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content("activity list private") expect(page).not_to have_content("activity list private")
end end
scenario "is always visible for moderators" do scenario "is always visible for moderators" do
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_activity" uncheck "account_public_activity"
@@ -197,51 +195,46 @@ describe "Users" do
logout logout
login_as(create(:moderator).user) login_as(create(:moderator).user)
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content("activity list private") expect(page).not_to have_content("activity list private")
end end
describe "User email" do describe "User email" do
let(:user) { create(:user) }
before do
@user = create(:user)
end
scenario "is not shown if no user logged in" do scenario "is not shown if no user logged in" do
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content(@user.email) expect(page).not_to have_content(user.email)
end end
scenario "is not shown if logged in user is a regular user" do scenario "is not shown if logged in user is a regular user" do
login_as(create(:user)) login_as(create(:user))
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content(@user.email) expect(page).not_to have_content(user.email)
end end
scenario "is not shown if logged in user is moderator" do scenario "is not shown if logged in user is moderator" do
login_as(create(:moderator).user) login_as(create(:moderator).user)
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content(@user.email) expect(page).not_to have_content(user.email)
end end
scenario "is shown if logged in user is admin" do scenario "is shown if logged in user is admin" do
login_as(create(:administrator).user) login_as(create(:administrator).user)
visit user_path(@user) visit user_path(user)
expect(page).to have_content(@user.email) expect(page).to have_content(user.email)
end end
end end
end end
describe "Public interests" do describe "Public interests" do
before do let(:user) { create(:user) }
@user = create(:user)
end
scenario "Display interests" do scenario "Display interests" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
login_as(@user) login_as(user)
visit account_path visit account_path
check "account_public_interests" check "account_public_interests"
@@ -249,15 +242,15 @@ describe "Users" do
logout logout
visit user_path(@user) visit user_path(user)
expect(page).to have_content("Sport") expect(page).to have_content("Sport")
end end
scenario "Not display interests when proposal has been destroyed" do scenario "Not display interests when proposal has been destroyed" do
proposal = create(:proposal, tag_list: "Sport", followers: [@user]) proposal = create(:proposal, tag_list: "Sport", followers: [user])
proposal.destroy proposal.destroy
login_as(@user) login_as(user)
visit account_path visit account_path
check "account_public_interests" check "account_public_interests"
@@ -265,21 +258,21 @@ describe "Users" do
logout logout
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content("Sport") expect(page).not_to have_content("Sport")
end end
scenario "No visible by default" do scenario "No visible by default" do
visit user_path(@user) visit user_path(user)
expect(page).to have_content(@user.username) expect(page).to have_content(user.username)
expect(page).not_to have_css("#public_interests") expect(page).not_to have_css("#public_interests")
end end
scenario "User can display public page" do scenario "User can display public page" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
login_as(@user) login_as(user)
visit account_path visit account_path
check "account_public_interests" check "account_public_interests"
@@ -287,28 +280,28 @@ describe "Users" do
logout logout
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_css("#public_interests") expect(page).to have_css("#public_interests")
end end
scenario "Is always visible for the owner" do scenario "Is always visible for the owner" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_interests" uncheck "account_public_interests"
click_button "Save changes" click_button "Save changes"
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_css("#public_interests") expect(page).to have_css("#public_interests")
end end
scenario "Is always visible for admins" do scenario "Is always visible for admins" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_interests" uncheck "account_public_interests"
@@ -317,14 +310,14 @@ describe "Users" do
logout logout
login_as(create(:administrator).user) login_as(create(:administrator).user)
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_css("#public_interests") expect(page).to have_css("#public_interests")
end end
scenario "Is always visible for moderators" do scenario "Is always visible for moderators" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
login_as(@user) login_as(user)
visit account_path visit account_path
uncheck "account_public_interests" uncheck "account_public_interests"
@@ -333,25 +326,25 @@ describe "Users" do
logout logout
login_as(create(:moderator).user) login_as(create(:moderator).user)
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_css("#public_interests") expect(page).to have_css("#public_interests")
end end
scenario "Should display generic interests title" do scenario "Should display generic interests title" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
@user.update(public_interests: true) user.update(public_interests: true)
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_content("Tags of elements this user follows") expect(page).to have_content("Tags of elements this user follows")
end end
scenario "Should display custom interests title when user is visiting own user page" do scenario "Should display custom interests title when user is visiting own user page" do
create(:proposal, tag_list: "Sport", followers: [@user]) create(:proposal, tag_list: "Sport", followers: [user])
@user.update(public_interests: true) user.update(public_interests: true)
login_as(@user) login_as(user)
visit user_path(@user, filter: "follows", page: "1") visit user_path(user, filter: "follows", page: "1")
expect(page).to have_content("Tags of elements you follow") expect(page).to have_content("Tags of elements you follow")
end end
@@ -411,30 +404,27 @@ describe "Users" do
end end
describe "Following (public page)" do describe "Following (public page)" do
let(:user) { create(:user) }
before do
@user = create(:user)
end
scenario "Do not display follows' tab when user is not following any followables" do scenario "Do not display follows' tab when user is not following any followables" do
visit user_path(@user) visit user_path(user)
expect(page).not_to have_content("0 Following") expect(page).not_to have_content("0 Following")
end end
scenario "Active following tab by default when follows filters selected", :js do scenario "Active following tab by default when follows filters selected", :js do
create(:proposal, author: @user, followers: [@user]) create(:proposal, author: user, followers: [user])
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
expect(page).to have_selector(".activity li.is-active", text: "1 Following") expect(page).to have_selector(".activity li.is-active", text: "1 Following")
end end
scenario "Gracefully handle followables that have been hidden" do scenario "Gracefully handle followables that have been hidden" do
create(:proposal, followers: [@user]) create(:proposal, followers: [user])
create(:proposal, followers: [@user]) { |proposal| proposal.hide } create(:proposal, followers: [user]) { |proposal| proposal.hide }
visit user_path(@user) visit user_path(user)
expect(page).to have_content("1 Following") expect(page).to have_content("1 Following")
end end
@@ -442,43 +432,43 @@ describe "Users" do
describe "Proposals" do describe "Proposals" do
scenario "Display following tab when user is following one proposal at least" do scenario "Display following tab when user is following one proposal at least" do
create(:proposal, followers: [@user]) create(:proposal, followers: [user])
visit user_path(@user) visit user_path(user)
expect(page).to have_content("1 Following") expect(page).to have_content("1 Following")
end end
scenario "Display proposal tab when user is following one proposal at least" do scenario "Display proposal tab when user is following one proposal at least" do
create(:proposal, followers: [@user]) create(:proposal, followers: [user])
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
expect(page).to have_link("Citizen proposals", href: "#citizen_proposals") expect(page).to have_link("Citizen proposals", href: "#citizen_proposals")
end end
scenario "Do not display proposals' tab when user is not following any proposal" do scenario "Do not display proposals' tab when user is not following any proposal" do
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
expect(page).not_to have_link("Citizen proposals", href: "#citizen_proposals") expect(page).not_to have_link("Citizen proposals", href: "#citizen_proposals")
end end
scenario "Display proposals with link to proposal" do scenario "Display proposals with link to proposal" do
proposal = create(:proposal, author: @user, followers: [@user]) proposal = create(:proposal, author: user, followers: [user])
login_as @user login_as user
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
click_link "Citizen proposals" click_link "Citizen proposals"
expect(page).to have_content proposal.title expect(page).to have_content proposal.title
end end
scenario "Retired proposals do not have a link to the dashboard", js: true do scenario "Retired proposals do not have a link to the dashboard", js: true do
proposal = create(:proposal, :retired, author: @user) proposal = create(:proposal, :retired, author: user)
login_as @user login_as user
visit user_path(@user) visit user_path(user)
expect(page).to have_content proposal.title expect(page).to have_content proposal.title
expect(page).not_to have_link "Dashboard" expect(page).not_to have_link "Dashboard"
@@ -486,10 +476,10 @@ describe "Users" do
end end
scenario "Published proposals have a link to the dashboard" do scenario "Published proposals have a link to the dashboard" do
proposal = create(:proposal, :published, author: @user) proposal = create(:proposal, :published, author: user)
login_as @user login_as user
visit user_path(@user) visit user_path(user)
expect(page).to have_content proposal.title expect(page).to have_content proposal.title
expect(page).to have_link "Dashboard" expect(page).to have_link "Dashboard"
@@ -499,23 +489,23 @@ describe "Users" do
describe "Budget Investments" do describe "Budget Investments" do
scenario "Display following tab when user is following one budget investment at least" do scenario "Display following tab when user is following one budget investment at least" do
create(:budget_investment, followers: [@user]) create(:budget_investment, followers: [user])
visit user_path(@user) visit user_path(user)
expect(page).to have_content("1 Following") expect(page).to have_content("1 Following")
end end
scenario "Display budget investment tab when user is following one budget investment at least" do scenario "Display budget investment tab when user is following one budget investment at least" do
create(:budget_investment, followers: [@user]) create(:budget_investment, followers: [user])
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
expect(page).to have_link("Investments", href: "#investments") expect(page).to have_link("Investments", href: "#investments")
end end
scenario "Not display budget investment tab when user is not following any budget investment" do scenario "Not display budget investment tab when user is not following any budget investment" do
visit user_path(@user, filter: "follows") visit user_path(user, filter: "follows")
expect(page).not_to have_link("Investments", href: "#investments") expect(page).not_to have_link("Investments", href: "#investments")
end end

View File

@@ -3,8 +3,8 @@ require "rails_helper"
describe "Valuation budgets" do describe "Valuation budgets" do
before do before do
@valuator = create(:valuator, user: create(:user, username: "Rachel", email: "rachel@valuators.org")) valuator = create(:valuator, user: create(:user, username: "Rachel", email: "rachel@valuators.org"))
login_as(@valuator.user) login_as(valuator.user)
end end
scenario "Disabled with a feature flag" do scenario "Disabled with a feature flag" do

View File

@@ -1,22 +1,22 @@
require "rails_helper" require "rails_helper"
describe "Votes" do describe "Votes" do
let!(:verified) { create(:user, verified_at: Time.current) }
let!(:unverified) { create(:user) }
before do before do
@manuela = create(:user, verified_at: Time.current)
@pablo = create(:user)
end end
describe "Debates" do describe "Debates" do
before { login_as(@manuela) } before { login_as(verified) }
scenario "Index shows user votes on debates" do scenario "Index shows user votes on debates" do
debate1 = create(:debate) debate1 = create(:debate)
debate2 = create(:debate) debate2 = create(:debate)
debate3 = create(:debate) debate3 = create(:debate)
create(:vote, voter: @manuela, votable: debate1, vote_flag: true) create(:vote, voter: verified, votable: debate1, vote_flag: true)
create(:vote, voter: @manuela, votable: debate3, vote_flag: false) create(:vote, voter: verified, votable: debate3, vote_flag: false)
visit debates_path visit debates_path
@@ -123,8 +123,8 @@ describe "Votes" do
scenario "Show" do scenario "Show" do
debate = create(:debate) debate = create(:debate)
create(:vote, voter: @manuela, votable: debate, vote_flag: true) create(:vote, voter: verified, votable: debate, vote_flag: true)
create(:vote, voter: @pablo, votable: debate, vote_flag: false) create(:vote, voter: unverified, votable: debate, vote_flag: false)
visit debate_path(debate) visit debate_path(debate)
@@ -185,10 +185,10 @@ describe "Votes" do
end end
describe "Proposals" do describe "Proposals" do
before { login_as(@manuela) } before { login_as(verified) }
scenario "Index shows user votes on proposals" do scenario "Index shows user votes on proposals" do
proposal1 = create(:proposal, voters: [@manuela]) proposal1 = create(:proposal, voters: [verified])
proposal2 = create(:proposal) proposal2 = create(:proposal)
proposal3 = create(:proposal) proposal3 = create(:proposal)
@@ -210,17 +210,15 @@ describe "Votes" do
end end
describe "Single proposal" do describe "Single proposal" do
before do let!(:proposal) { create(:proposal) }
@proposal = create(:proposal)
end
scenario "Show no votes" do scenario "Show no votes" do
visit proposal_path(@proposal) visit proposal_path(proposal)
expect(page).to have_content "No supports" expect(page).to have_content "No supports"
end end
scenario "Trying to vote multiple times", :js do scenario "Trying to vote multiple times", :js do
visit proposal_path(@proposal) visit proposal_path(proposal)
within(".supports") do within(".supports") do
find(".in-favor a").click find(".in-favor a").click
@@ -231,10 +229,10 @@ describe "Votes" do
end end
scenario "Show" do scenario "Show" do
create(:vote, voter: @manuela, votable: @proposal, vote_flag: true) create(:vote, voter: verified, votable: proposal, vote_flag: true)
create(:vote, voter: @pablo, votable: @proposal, vote_flag: true) create(:vote, voter: unverified, votable: proposal, vote_flag: true)
visit proposal_path(@proposal) visit proposal_path(proposal)
within(".supports") do within(".supports") do
expect(page).to have_content "2 supports" expect(page).to have_content "2 supports"
@@ -242,7 +240,7 @@ describe "Votes" do
end end
scenario "Create from proposal show", :js do scenario "Create from proposal show", :js do
visit proposal_path(@proposal) visit proposal_path(proposal)
within(".supports") do within(".supports") do
find(".in-favor a").click find(".in-favor a").click
@@ -255,7 +253,7 @@ describe "Votes" do
scenario "Create in listed proposal in index", :js do scenario "Create in listed proposal in index", :js do
visit proposals_path visit proposals_path
within("#proposal_#{@proposal.id}") do within("#proposal_#{proposal.id}") do
find(".in-favor a").click find(".in-favor a").click
expect(page).to have_content "1 support" expect(page).to have_content "1 support"
@@ -267,7 +265,7 @@ describe "Votes" do
scenario "Create in featured proposal in index", :js do scenario "Create in featured proposal in index", :js do
visit proposals_path visit proposals_path
within("#proposal_#{@proposal.id}") do within("#proposal_#{proposal.id}") do
find(".in-favor a").click find(".in-favor a").click
expect(page).to have_content "You have already supported this proposal. Share it!" expect(page).to have_content "You have already supported this proposal. Share it!"

View File

@@ -1,29 +1,26 @@
require "rails_helper" require "rails_helper"
describe "rake sitemap:create", type: :feature do describe "rake sitemap:create", type: :feature do
before do let(:file) { Rails.root.join("public", "sitemap.xml") }
@file ||= Rails.root.join("public", "sitemap.xml")
# To avoid spec failures if file does not exist before do
# Useful on CI environments or if file was created File.delete(file) if File.exist?(file)
# previous to the specs (to ensure a clean state)
File.delete(@file) if File.exist?(@file)
Rake::Task["sitemap:create"].reenable Rake::Task["sitemap:create"].reenable
Rake.application.invoke_task("sitemap:create") Rake.application.invoke_task("sitemap:create")
end end
it "generates a sitemap" do it "generates a sitemap" do
expect(@file).to exist expect(file).to exist
end end
it "generates a valid sitemap" do it "generates a valid sitemap" do
sitemap = Nokogiri::XML(File.open(@file)) sitemap = Nokogiri::XML(File.open(file))
expect(sitemap.errors).to be_empty expect(sitemap.errors).to be_empty
end end
it "generates a sitemap with expected and valid URLs" do it "generates a sitemap with expected and valid URLs" do
sitemap = File.read(@file) sitemap = File.read(file)
# Static pages # Static pages
expect(sitemap).to include(faq_path) expect(sitemap).to include(faq_path)