Merge branch 'master' into dashboard

This commit is contained in:
decabeza
2019-03-26 16:45:48 +01:00
2476 changed files with 62613 additions and 84405 deletions

View File

@@ -1,49 +0,0 @@
require 'rails_helper'
require 'rake'
describe 'Communities Rake' do
describe '#associate_community' do
before do
Rake.application.rake_require "tasks/communities"
Rake::Task.define_task(:environment)
end
let :run_rake_task do
Rake::Task['communities:associate_community'].reenable
Rake.application.invoke_task 'communities:associate_community'
end
context 'Associate community to Proposal' do
it 'When proposal has not community_id' do
proposal = create(:proposal)
proposal.update(community_id: nil)
expect(proposal.community).to be_nil
run_rake_task
proposal.reload
expect(proposal.community).to be_present
end
end
context 'Associate community to Budget Investment' do
it 'When budget investment has not community_id' do
investment = create(:budget_investment)
investment.update(community_id: nil)
expect(investment.community).to be_nil
run_rake_task
investment.reload
expect(investment.community).to be_present
end
end
end
end

15
spec/lib/tasks/db_spec.rb Normal file
View File

@@ -0,0 +1,15 @@
require "rails_helper"
describe "rake db:pages" do
let :run_rake_task do
Rake.application.invoke_task("db:pages")
end
it "seeds the database with the default custom pages" do
SiteCustomization::Page.destroy_all
expect(SiteCustomization::Page.count).to be 0
run_rake_task
expect(SiteCustomization::Page.count).to be 7
end
end

View File

@@ -1,14 +1,11 @@
require 'rake'
require 'rails_helper'
Rake::Task.define_task(:environment)
Rake.application.rake_require('tasks/db')
require "rails_helper"
describe 'rake db:dev_seed' do
describe "rake db:dev_seed" do
let :run_rake_task do
Rake.application.invoke_task('db:dev_seed[avoid_log]')
Rake.application.invoke_task("db:dev_seed[avoid_log]")
end
it 'seeds the database without errors' do
it "seeds the database without errors" do
expect { run_rake_task }.not_to raise_error
end
end

View File

@@ -1,22 +0,0 @@
require 'rake'
require 'rails_helper'
Rails.application.load_tasks
describe 'rake map_locations:destroy' do
before do
create(:map_location, :proposal_map_location)
empty_location = create(:map_location, :proposal_map_location)
empty_location.attributes = { longitude: nil, latitude: nil, zoom: nil }
empty_location.save(validate: false)
end
let :run_rake_task do
Rake.application.invoke_task('map_locations:destroy')
end
it 'destroys empty locations' do
expect(MapLocation.all.size).to eq(2)
run_rake_task
expect(MapLocation.all.size).to eq(1)
end
end

View File

@@ -0,0 +1,66 @@
require "rails_helper"
describe Proposals do
describe "Move external_url to description" do
let :run_rake_task do
Rake::Task["proposals:move_external_url_to_description"].reenable
Rake.application.invoke_task "proposals:move_external_url_to_description"
end
context "Move external_url to description for Proposals" do
it "When proposal has external_url" do
proposal = create(:proposal, description: "<p>Lorem ipsum dolor sit amet</p>",
external_url: "http://consul.dev")
run_rake_task
proposal.reload
expect(proposal.description).to eq "<p>Lorem ipsum dolor sit amet</p> "\
'<p><a href="http://consul.dev" '\
'target="_blank" rel="nofollow">'\
"http://consul.dev</a></p>"
expect(proposal.external_url).to eq ""
end
it "When proposal has not external_url" do
proposal = create(:proposal, description: "<p>Lorem ipsum dolor sit amet</p>",
external_url: "")
run_rake_task
proposal.reload
expect(proposal.description).to eq "<p>Lorem ipsum dolor sit amet</p>"
expect(proposal.external_url).to eq ""
end
end
context "Move external_url to description for Legislation proposals" do
it "When legislation proposal has external_url" do
legislation_proposal = create(:legislation_proposal, description: "<p>Ut enim ad minim</p>",
external_url: "http://consulproject.org")
run_rake_task
legislation_proposal.reload
expect(legislation_proposal.description).to eq "<p>Ut enim ad minim</p> "\
'<p><a href="http://consulproject.org" '\
'target="_blank" rel="nofollow">'\
"http://consulproject.org</a></p>"
expect(legislation_proposal.external_url).to eq ""
end
it "When legislation proposal has not external_url" do
legislation_proposal = create(:legislation_proposal, description: "<p>Ut enim ad minim</p>",
external_url: "")
run_rake_task
legislation_proposal.reload
expect(legislation_proposal.description).to eq "<p>Ut enim ad minim</p>"
expect(legislation_proposal.external_url).to eq ""
end
end
end
end

View File

@@ -1,73 +1,109 @@
require 'rails_helper'
require 'rake'
require "rails_helper"
describe 'Settings Rake' do
describe Setting do
describe '#per_page_code_migration' do
context "Remove deprecated settings" do
let :run_remove_deprecated_settings_task do
Rake::Task["settings:remove_deprecated_settings"].reenable
Rake.application.invoke_task "settings:remove_deprecated_settings"
end
before do
Rake.application.rake_require "tasks/settings"
Rake::Task.define_task(:environment)
Setting.create(key: "place_name", value: "City")
Setting.create(key: "banner-style.banner-style-one", value: "Style one")
Setting.create(key: "banner-style.banner-style-two", value: "Style two")
Setting.create(key: "banner-style.banner-style-three", value: "Style three")
Setting.create(key: "banner-img.banner-img-one", value: "Image 1")
Setting.create(key: "banner-img.banner-img-two", value: "Image 2")
Setting.create(key: "banner-img.banner-img-three", value: "Image 3")
Setting.create(key: "verification_offices_url", value: "http://offices.url")
Setting.create(key: "not_deprecated", value: "Setting not deprecated")
run_remove_deprecated_settings_task
end
it "Rake only removes deprecated settings" do
expect(Setting.where(key: "place_name").count).to eq(0)
expect(Setting.where(key: "banner-style.banner-style-one").count).to eq(0)
expect(Setting.where(key: "banner-style.banner-style-two").count).to eq(0)
expect(Setting.where(key: "banner-style.banner-style-three").count).to eq(0)
expect(Setting.where(key: "banner-img.banner-img-one").count).to eq(0)
expect(Setting.where(key: "banner-img.banner-img-two").count).to eq(0)
expect(Setting.where(key: "banner-img.banner-img-three").count).to eq(0)
expect(Setting.where(key: "verification_offices_url").count).to eq(0)
expect(Setting.where(key: "not_deprecated").count).to eq(1)
end
end
describe "#rename_setting_keys" do
let :run_rake_task do
Rake::Task['settings:per_page_code_migration'].reenable
Rake.application.invoke_task 'settings:per_page_code_migration'
Rake::Task["settings:rename_setting_keys"].reenable
Rake.application.invoke_task "settings:rename_setting_keys"
end
context 'Neither per_page_code_head or per_page_code Settings exist' do
before do
Setting.where(key: 'per_page_code').first&.destroy
Setting.where(key: 'per_page_code_head').first&.destroy
run_rake_task
end
let :old_keys do
%w[map_latitude map_longitude map_zoom feature.debates feature.proposals feature.polls
feature.budgets feature.legislation per_page_code_head per_page_code_body
feature.homepage.widgets.feeds.proposals feature.homepage.widgets.feeds.debates
feature.homepage.widgets.feeds.processes]
end
it 'has per_page_code_head setting present and no per_page_code' do
expect(Setting.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq(nil)
expect(Setting.where(key: 'per_page_code').count).to eq(0)
let :new_keys do
%w[map.latitude map.longitude map.zoom process.debates process.proposals process.polls
process.budgets process.legislation html.per_page_code_head html.per_page_code_body
homepage.widgets.feeds.proposals homepage.widgets.feeds.debates
homepage.widgets.feeds.processes]
end
context "with existing old settings" do
it "rename all settings keys keeping the same value" do
Setting.destroy_all
old_keys.each { |old_key| Setting[old_key] = "old value" }
run_rake_task
new_keys.each do |new_key|
expect(Setting[new_key]).to eq "old value"
end
old_keys.each do |old_key|
expect(Setting.where(key: old_key)).not_to exist
end
end
end
context 'Both per_page_code_head or per_page_code Settings exist' do
before do
Setting['per_page_code'] = 'per_page_code'
Setting['per_page_code_head'] = 'per_page_code_head'
run_rake_task
end
context "without existing old settings" do
it "initializes all settings with null value" do
Setting.destroy_all
it 'has per_page_code_head setting present and no per_page_code' do
expect(Setting.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code_head')
expect(Setting.where(key: 'per_page_code').count).to eq(0)
run_rake_task
new_keys.each do |new_key|
expect(Setting[new_key]).to eq nil
end
old_keys.each do |old_key|
expect(Setting.where(key: old_key)).not_to exist
end
end
end
context 'per_page_code_head exists, but per_page_code does not' do
before do
Setting.where(key: 'per_page_code').first&.destroy
Setting['per_page_code_head'] = 'per_page_code_head'
context "with already existing new settings" do
it "does not change the value of the new settings even if the old setting exist" do
Setting.destroy_all
old_keys.each { |old_key| Setting[old_key] = "old value" }
new_keys.each { |new_key| Setting[new_key] = "new value" }
run_rake_task
end
it 'has per_page_code_head setting present and no per_page_code' do
expect(Setting.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code_head')
expect(Setting.where(key: 'per_page_code').count).to eq(0)
end
end
new_keys.each do |new_key|
expect(Setting[new_key]).to eq "new value"
end
context 'per_page_code_head does not exist, but per_page_code does' do
before do
Setting['per_page_code'] = 'per_page_code'
Setting.where(key: 'per_page_code_head').first&.destroy
run_rake_task
end
it 'has per_page_code_head setting present and no per_page_code' do
expect(Setting.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code')
expect(Setting.where(key: 'per_page_code').count).to eq(0)
old_keys.each do |old_key|
expect(Setting.where(key: old_key)).not_to exist
end
end
end

View File

@@ -1,38 +1,34 @@
require 'rake'
require 'rails_helper'
Rails.application.load_tasks
Rake::Task.define_task(:environment)
require "rails_helper"
feature 'rake sitemap:create' do
feature "rake sitemap:create" do
before do
@file ||= Rails.root.join('public', 'sitemap.xml')
@file ||= Rails.root.join("public", "sitemap.xml")
# To avoid spec failures if file does not exist
# Useful on CI environments or if file was created
# previous to the specs (to ensure a clean state)
File.delete(@file) if File.exist?(@file)
Rake::Task['sitemap:create'].reenable
Rake.application.invoke_task('sitemap:create')
Rake::Task["sitemap:create"].reenable
Rake.application.invoke_task("sitemap:create")
end
it 'generates a sitemap' do
it "generates a sitemap" do
expect(@file).to exist
end
it 'generates a valid sitemap' do
it "generates a valid sitemap" do
sitemap = Nokogiri::XML(File.open(@file))
expect(sitemap.errors).to be_empty
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)
# Static pages
expect(sitemap).to include(faq_path)
expect(sitemap).to include(help_path)
expect(sitemap).to include(how_to_use_path)
expect(sitemap).to include(page_path(id: 'general_terms'))
# Dynamic URLs
expect(sitemap).to include(polls_path)
@@ -41,7 +37,7 @@ feature 'rake sitemap:create' do
expect(sitemap).to include(proposals_path)
expect(sitemap).to include(legislation_processes_path)
expect(sitemap).to have_content('0.7', count: 5)
expect(sitemap).to have_content('daily', count: 5)
expect(sitemap).to have_content("0.7", count: 5)
expect(sitemap).to have_content("daily", count: 5)
end
end