Merge branch 'master' into dashboard
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe 'Paranoid methods' do
|
||||
describe "Paranoid methods" do
|
||||
|
||||
describe '.hide_all' do
|
||||
it 'hides all instances in the id list' do
|
||||
describe ".hide_all" do
|
||||
it "hides all instances in the id list" do
|
||||
debate1 = create(:debate)
|
||||
debate2 = create(:debate)
|
||||
debate3 = create(:debate)
|
||||
@@ -17,8 +17,8 @@ describe 'Paranoid methods' do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.restore_all' do
|
||||
it 'restores all instances in the id list' do
|
||||
describe ".restore_all" do
|
||||
it "restores all instances in the id list" do
|
||||
debate1 = create(:debate)
|
||||
debate2 = create(:debate)
|
||||
debate3 = create(:debate)
|
||||
@@ -34,8 +34,8 @@ describe 'Paranoid methods' do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#restore' do
|
||||
it 'resets the confirmed_hide_at attribute' do
|
||||
describe "#restore" do
|
||||
it "resets the confirmed_hide_at attribute" do
|
||||
debate = create(:debate, :hidden, :with_confirmed_hide)
|
||||
|
||||
debate.restore
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe ActsAsTaggableOn do
|
||||
|
||||
describe 'Tagging' do
|
||||
describe "Tagging" do
|
||||
describe "when tagging debates or proposals" do
|
||||
let(:proposal) { create(:proposal) }
|
||||
let(:debate) { create(:debate) }
|
||||
@@ -44,7 +44,7 @@ describe ActsAsTaggableOn do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Tag' do
|
||||
describe "Tag" do
|
||||
describe "#recalculate_custom_counter_for" do
|
||||
it "updates the counters of proposals and debates, taking into account hidden ones" do
|
||||
tag = ActsAsTaggableOn::Tag.create(name: "foo")
|
||||
@@ -57,10 +57,10 @@ describe ActsAsTaggableOn do
|
||||
|
||||
tag.update(debates_count: 0, proposals_count: 0)
|
||||
|
||||
tag.recalculate_custom_counter_for('Debate')
|
||||
tag.recalculate_custom_counter_for("Debate")
|
||||
expect(tag.debates_count).to eq(1)
|
||||
|
||||
tag.recalculate_custom_counter_for('Proposal')
|
||||
tag.recalculate_custom_counter_for("Proposal")
|
||||
expect(tag.proposals_count).to eq(1)
|
||||
end
|
||||
end
|
||||
@@ -86,7 +86,7 @@ describe ActsAsTaggableOn do
|
||||
end
|
||||
|
||||
it "blocks other kinds of tags" do
|
||||
tag = create(:tag, kind: 'foo')
|
||||
tag = create(:tag, kind: "foo")
|
||||
proposal = create(:proposal)
|
||||
proposal.tag_list.add(tag)
|
||||
proposal.save
|
||||
@@ -100,7 +100,7 @@ describe ActsAsTaggableOn do
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).not_to include(tag)
|
||||
end
|
||||
|
||||
it 'only permits tags on proposals or debates' do
|
||||
it "only permits tags on proposals or debates" do
|
||||
tag_1 = create(:tag)
|
||||
tag_2 = create(:tag)
|
||||
tag_3 = create(:tag)
|
||||
@@ -120,7 +120,7 @@ describe ActsAsTaggableOn do
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to match_array([tag_1, tag_3])
|
||||
end
|
||||
|
||||
it 'blocks tags after its taggings became hidden' do
|
||||
it "blocks tags after its taggings became hidden" do
|
||||
tag = create(:tag)
|
||||
proposal = create(:proposal)
|
||||
proposal.tag_list.add(tag)
|
||||
@@ -136,15 +136,15 @@ describe ActsAsTaggableOn do
|
||||
|
||||
describe "search" do
|
||||
it "containing the word in the name" do
|
||||
create(:tag, name: 'Familia')
|
||||
create(:tag, name: 'Cultura')
|
||||
create(:tag, name: 'Salud')
|
||||
create(:tag, name: 'Famosos')
|
||||
create(:tag, name: "Familia")
|
||||
create(:tag, name: "Cultura")
|
||||
create(:tag, name: "Salud")
|
||||
create(:tag, name: "Famosos")
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.pg_search('f').length).to eq(2)
|
||||
expect(ActsAsTaggableOn::Tag.search('cultura').first.name).to eq('Cultura')
|
||||
expect(ActsAsTaggableOn::Tag.search('sal').first.name).to eq('Salud')
|
||||
expect(ActsAsTaggableOn::Tag.search('fami').first.name).to eq('Familia')
|
||||
expect(ActsAsTaggableOn::Tag.pg_search("f").length).to eq(2)
|
||||
expect(ActsAsTaggableOn::Tag.search("cultura").first.name).to eq("Cultura")
|
||||
expect(ActsAsTaggableOn::Tag.search("sal").first.name).to eq("Salud")
|
||||
expect(ActsAsTaggableOn::Tag.search("fami").first.name).to eq("Familia")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe AdminWYSIWYGSanitizer do
|
||||
let(:sanitizer) { AdminWYSIWYGSanitizer.new }
|
||||
|
||||
describe '#sanitize' do
|
||||
it 'allows images' do
|
||||
describe "#sanitize" do
|
||||
|
||||
it "allows images" do
|
||||
html = 'Dangerous<img src="/smile.png" alt="Smile" style="width: 10px;"> image'
|
||||
expect(sanitizer.sanitize(html)).to eq(html)
|
||||
end
|
||||
|
||||
it "allows tables" do
|
||||
html = '<table align="center" border="2" cellpadding="2" cellspacing="2" dir="ltr" ' \
|
||||
'id="table_id" class="stylesheet_classes" style="height:200px;width:500px;" ' \
|
||||
'summary="summary">
|
||||
<caption>caption</caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">header 1</th>
|
||||
<td>cell 1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">header 2</th>
|
||||
<td>cell 2</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>'
|
||||
expect(sanitizer.sanitize(html)).to eq(html)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe Age do
|
||||
describe '.in_years' do
|
||||
describe ".in_years" do
|
||||
it "handles nils" do
|
||||
expect(described_class.in_years(nil)).to be_nil
|
||||
end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe 'Cache flow' do
|
||||
describe "Cache flow" do
|
||||
|
||||
describe 'Tag destroy' do
|
||||
it 'invalidates Debate cache keys' do
|
||||
describe "Tag destroy" do
|
||||
it "invalidates Debate cache keys" do
|
||||
debate = create(:debate, tag_list: "Good, Bad")
|
||||
tag = ActsAsTaggableOn::Tag.find_by(name: "Bad")
|
||||
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe CensusApi do
|
||||
let(:api) { described_class.new }
|
||||
|
||||
describe '#get_document_number_variants' do
|
||||
describe "#get_document_number_variants" do
|
||||
it "trims and cleans up entry" do
|
||||
expect(api.get_document_number_variants(2, ' 1 2@ 34')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(2, " 1 2@ 34")).to eq(["1234"])
|
||||
end
|
||||
|
||||
it "returns only one try for passports & residence cards" do
|
||||
expect(api.get_document_number_variants(2, '1234')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(3, '1234')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(2, "1234")).to eq(["1234"])
|
||||
expect(api.get_document_number_variants(3, "1234")).to eq(["1234"])
|
||||
end
|
||||
|
||||
it 'takes only the last 8 digits for dnis and resicence cards' do
|
||||
expect(api.get_document_number_variants(1, '543212345678')).to eq(['12345678'])
|
||||
it "takes only the last 8 digits for dnis and resicence cards" do
|
||||
expect(api.get_document_number_variants(1, "543212345678")).to eq(["12345678"])
|
||||
end
|
||||
|
||||
it 'tries all the dni variants padding with zeroes' do
|
||||
expect(api.get_document_number_variants(1, '0123456')).to eq(['123456', '0123456', '00123456'])
|
||||
expect(api.get_document_number_variants(1, '00123456')).to eq(['123456', '0123456', '00123456'])
|
||||
it "tries all the dni variants padding with zeroes" do
|
||||
expect(api.get_document_number_variants(1, "0123456")).to eq(["123456", "0123456", "00123456"])
|
||||
expect(api.get_document_number_variants(1, "00123456")).to eq(["123456", "0123456", "00123456"])
|
||||
end
|
||||
|
||||
it 'adds upper and lowercase letter when the letter is present' do
|
||||
expect(api.get_document_number_variants(1, '1234567A')).to eq(%w(1234567 01234567 1234567a 1234567A 01234567a 01234567A))
|
||||
it "adds upper and lowercase letter when the letter is present" do
|
||||
expect(api.get_document_number_variants(1, "1234567A")).to eq(%w(1234567 01234567 1234567a 1234567A 01234567a 01234567A))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
describe "#call" do
|
||||
let(:invalid_body) { {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {}}}} }
|
||||
let(:valid_body) do
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe CensusCaller do
|
||||
let(:api) { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
it 'returns data from local_census_records if census API is not available' do
|
||||
describe "#call" do
|
||||
it "returns data from local_census_records if census API is not available" do
|
||||
census_api_response = CensusApi::Response.new(get_habita_datos_response: {
|
||||
get_habita_datos_return: { datos_habitante: {}, datos_vivienda: {} }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe EmailDigest do
|
||||
|
||||
@@ -140,14 +140,14 @@ describe EmailDigest do
|
||||
describe "#valid_email?" do
|
||||
|
||||
it "returns a MatchData if email is valid" do
|
||||
user = create(:user, email: 'valid_email@email.com')
|
||||
user = create(:user, email: "valid_email@email.com")
|
||||
|
||||
email_digest = described_class.new(user)
|
||||
expect(email_digest.valid_email?).to be_a(MatchData)
|
||||
end
|
||||
|
||||
it "returns nil if email is invalid" do
|
||||
user = create(:user, email: 'invalid_email@email..com')
|
||||
user = create(:user, email: "invalid_email@email..com")
|
||||
|
||||
email_digest = described_class.new(user)
|
||||
expect(email_digest.valid_email?).to be(nil)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe GraphQL::ApiTypesCreator do
|
||||
let(:created_types) { {} }
|
||||
@@ -6,53 +6,53 @@ describe GraphQL::ApiTypesCreator do
|
||||
describe "::create_type" do
|
||||
it "creates fields for Int attributes" do
|
||||
debate_type = described_class.create_type(Debate, { id: :integer }, created_types)
|
||||
created_field = debate_type.fields['id']
|
||||
created_field = debate_type.fields["id"]
|
||||
|
||||
expect(created_field).to be_a(GraphQL::Field)
|
||||
expect(created_field.type).to be_a(GraphQL::ScalarType)
|
||||
expect(created_field.type.name).to eq('Int')
|
||||
expect(created_field.type.name).to eq("Int")
|
||||
end
|
||||
|
||||
it "creates fields for String attributes" do
|
||||
debate_type = described_class.create_type(Debate, { title: :string }, created_types)
|
||||
created_field = debate_type.fields['title']
|
||||
created_field = debate_type.fields["title"]
|
||||
|
||||
expect(created_field).to be_a(GraphQL::Field)
|
||||
expect(created_field.type).to be_a(GraphQL::ScalarType)
|
||||
expect(created_field.type.name).to eq('String')
|
||||
expect(created_field.type.name).to eq("String")
|
||||
end
|
||||
|
||||
it "creates connections for :belongs_to associations" do
|
||||
user_type = described_class.create_type(User, { id: :integer }, created_types)
|
||||
debate_type = described_class.create_type(Debate, { author: User }, created_types)
|
||||
|
||||
connection = debate_type.fields['author']
|
||||
connection = debate_type.fields["author"]
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
expect(connection.type).to eq(user_type)
|
||||
expect(connection.name).to eq('author')
|
||||
expect(connection.name).to eq("author")
|
||||
end
|
||||
|
||||
it "creates connections for :has_one associations" do
|
||||
user_type = described_class.create_type(User, { organization: Organization }, created_types)
|
||||
organization_type = described_class.create_type(Organization, { id: :integer }, created_types)
|
||||
|
||||
connection = user_type.fields['organization']
|
||||
connection = user_type.fields["organization"]
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
expect(connection.type).to eq(organization_type)
|
||||
expect(connection.name).to eq('organization')
|
||||
expect(connection.name).to eq("organization")
|
||||
end
|
||||
|
||||
it "creates connections for :has_many associations" do
|
||||
comment_type = described_class.create_type(Comment, { id: :integer }, created_types)
|
||||
debate_type = described_class.create_type(Debate, { comments: [Comment] }, created_types)
|
||||
|
||||
connection = debate_type.fields['comments']
|
||||
connection = debate_type.fields["comments"]
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
expect(connection.type).to eq(comment_type.connection_type)
|
||||
expect(connection.name).to eq('comments')
|
||||
expect(connection.name).to eq("comments")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe GraphQL::QueryTypeCreator do
|
||||
let(:api_type_definitions) do
|
||||
@@ -12,24 +12,24 @@ describe GraphQL::QueryTypeCreator do
|
||||
describe "::create" do
|
||||
let(:query_type) { described_class.create(api_types) }
|
||||
|
||||
it 'creates a QueryType with fields to retrieve single objects whose model fields included an ID' do
|
||||
field = query_type.fields['proposal']
|
||||
it "creates a QueryType with fields to retrieve single objects whose model fields included an ID" do
|
||||
field = query_type.fields["proposal"]
|
||||
|
||||
expect(field).to be_a(GraphQL::Field)
|
||||
expect(field.type).to eq(api_types[Proposal])
|
||||
expect(field.name).to eq('proposal')
|
||||
expect(field.name).to eq("proposal")
|
||||
end
|
||||
|
||||
it 'creates a QueryType without fields to retrieve single objects whose model fields did not include an ID' do
|
||||
expect(query_type.fields['proposal_notification']).to be_nil
|
||||
it "creates a QueryType without fields to retrieve single objects whose model fields did not include an ID" do
|
||||
expect(query_type.fields["proposal_notification"]).to be_nil
|
||||
end
|
||||
|
||||
it "creates a QueryType with connections to retrieve collections of objects" do
|
||||
connection = query_type.fields['proposals']
|
||||
connection = query_type.fields["proposals"]
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
expect(connection.type).to eq(api_types[Proposal].connection_type)
|
||||
expect(connection.name).to eq('proposals')
|
||||
expect(connection.name).to eq("proposals")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
api_types = GraphQL::ApiTypesCreator.create(API_TYPE_DEFINITIONS)
|
||||
query_type = GraphQL::QueryTypeCreator.create(api_types)
|
||||
@@ -12,213 +12,213 @@ def execute(query_string, context = {}, variables = {})
|
||||
end
|
||||
|
||||
def dig(response, path)
|
||||
response.dig(*path.split('.'))
|
||||
response.dig(*path.split("."))
|
||||
end
|
||||
|
||||
def hidden_field?(response, field_name)
|
||||
data_is_empty = response['data'].nil?
|
||||
error_is_present = ((response['errors'].first['message'] =~ /Field '#{field_name}' doesn't exist on type '[[:alnum:]]*'/) == 0)
|
||||
data_is_empty = response["data"].nil?
|
||||
error_is_present = ((response["errors"].first["message"] =~ /Field '#{field_name}' doesn't exist on type '[[:alnum:]]*'/) == 0)
|
||||
data_is_empty && error_is_present
|
||||
end
|
||||
|
||||
def extract_fields(response, collection_name, field_chain)
|
||||
fields = field_chain.split('.')
|
||||
fields = field_chain.split(".")
|
||||
dig(response, "data.#{collection_name}.edges").collect do |node|
|
||||
begin
|
||||
if fields.size > 1
|
||||
node['node'][fields.first][fields.second]
|
||||
node["node"][fields.first][fields.second]
|
||||
else
|
||||
node['node'][fields.first]
|
||||
node["node"][fields.first]
|
||||
end
|
||||
rescue NoMethodError
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
describe 'Consul Schema' do
|
||||
describe "Consul Schema" do
|
||||
let(:user) { create(:user) }
|
||||
let(:proposal) { create(:proposal, author: user) }
|
||||
|
||||
it 'returns fields of Int type' do
|
||||
it "returns fields of Int type" do
|
||||
response = execute("{ proposal(id: #{proposal.id}) { id } }")
|
||||
expect(dig(response, 'data.proposal.id')).to eq(proposal.id)
|
||||
expect(dig(response, "data.proposal.id")).to eq(proposal.id)
|
||||
end
|
||||
|
||||
it 'returns fields of String type' do
|
||||
it "returns fields of String type" do
|
||||
response = execute("{ proposal(id: #{proposal.id}) { title } }")
|
||||
expect(dig(response, 'data.proposal.title')).to eq(proposal.title)
|
||||
expect(dig(response, "data.proposal.title")).to eq(proposal.title)
|
||||
end
|
||||
|
||||
xit 'returns has_one associations' do
|
||||
xit "returns has_one associations" do
|
||||
organization = create(:organization)
|
||||
response = execute("{ user(id: #{organization.user_id}) { organization { name } } }")
|
||||
expect(dig(response, 'data.user.organization.name')).to eq(organization.name)
|
||||
expect(dig(response, "data.user.organization.name")).to eq(organization.name)
|
||||
end
|
||||
|
||||
it 'returns belongs_to associations' do
|
||||
it "returns belongs_to associations" do
|
||||
response = execute("{ proposal(id: #{proposal.id}) { public_author { username } } }")
|
||||
expect(dig(response, 'data.proposal.public_author.username')).to eq(proposal.public_author.username)
|
||||
expect(dig(response, "data.proposal.public_author.username")).to eq(proposal.public_author.username)
|
||||
end
|
||||
|
||||
it 'returns has_many associations' do
|
||||
it "returns has_many associations" do
|
||||
comments_author = create(:user)
|
||||
comment_1 = create(:comment, author: comments_author, commentable: proposal)
|
||||
comment_2 = create(:comment, author: comments_author, commentable: proposal)
|
||||
|
||||
response = execute("{ proposal(id: #{proposal.id}) { comments { edges { node { body } } } } }")
|
||||
comments = dig(response, 'data.proposal.comments.edges').collect { |edge| edge['node'] }
|
||||
comment_bodies = comments.collect { |comment| comment['body'] }
|
||||
comments = dig(response, "data.proposal.comments.edges").collect { |edge| edge["node"] }
|
||||
comment_bodies = comments.collect { |comment| comment["body"] }
|
||||
|
||||
expect(comment_bodies).to match_array([comment_1.body, comment_2.body])
|
||||
end
|
||||
|
||||
xit 'executes deeply nested queries' do
|
||||
xit "executes deeply nested queries" do
|
||||
org_user = create(:user)
|
||||
organization = create(:organization, user: org_user)
|
||||
org_proposal = create(:proposal, author: org_user)
|
||||
response = execute("{ proposal(id: #{org_proposal.id}) { public_author { organization { name } } } }")
|
||||
|
||||
expect(dig(response, 'data.proposal.public_author.organization.name')).to eq(organization.name)
|
||||
expect(dig(response, "data.proposal.public_author.organization.name")).to eq(organization.name)
|
||||
end
|
||||
|
||||
it 'hides confidential fields of Int type' do
|
||||
it "hides confidential fields of Int type" do
|
||||
response = execute("{ user(id: #{user.id}) { failed_census_calls_count } }")
|
||||
expect(hidden_field?(response, 'failed_census_calls_count')).to be_truthy
|
||||
expect(hidden_field?(response, "failed_census_calls_count")).to be_truthy
|
||||
end
|
||||
|
||||
it 'hides confidential fields of String type' do
|
||||
it "hides confidential fields of String type" do
|
||||
response = execute("{ user(id: #{user.id}) { encrypted_password } }")
|
||||
expect(hidden_field?(response, 'encrypted_password')).to be_truthy
|
||||
expect(hidden_field?(response, "encrypted_password")).to be_truthy
|
||||
end
|
||||
|
||||
it 'hides confidential has_one associations' do
|
||||
it "hides confidential has_one associations" do
|
||||
user.administrator = create(:administrator)
|
||||
response = execute("{ user(id: #{user.id}) { administrator { id } } }")
|
||||
expect(hidden_field?(response, 'administrator')).to be_truthy
|
||||
expect(hidden_field?(response, "administrator")).to be_truthy
|
||||
end
|
||||
|
||||
it 'hides confidential belongs_to associations' do
|
||||
it "hides confidential belongs_to associations" do
|
||||
create(:failed_census_call, user: user)
|
||||
response = execute("{ user(id: #{user.id}) { failed_census_calls { id } } }")
|
||||
expect(hidden_field?(response, 'failed_census_calls')).to be_truthy
|
||||
expect(hidden_field?(response, "failed_census_calls")).to be_truthy
|
||||
end
|
||||
|
||||
it 'hides confidential has_many associations' do
|
||||
it "hides confidential has_many associations" do
|
||||
create(:direct_message, sender: user)
|
||||
response = execute("{ user(id: #{user.id}) { direct_messages_sent { id } } }")
|
||||
expect(hidden_field?(response, 'direct_messages_sent')).to be_truthy
|
||||
expect(hidden_field?(response, "direct_messages_sent")).to be_truthy
|
||||
end
|
||||
|
||||
it 'hides confidential fields inside deeply nested queries' do
|
||||
it "hides confidential fields inside deeply nested queries" do
|
||||
response = execute("{ proposals(first: 1) { edges { node { public_author { encrypted_password } } } } }")
|
||||
expect(hidden_field?(response, 'encrypted_password')).to be_truthy
|
||||
expect(hidden_field?(response, "encrypted_password")).to be_truthy
|
||||
end
|
||||
|
||||
describe 'Users' do
|
||||
describe "Users" do
|
||||
let(:user) { create(:user, public_activity: false) }
|
||||
|
||||
it 'does not link debates if activity is not public' do
|
||||
it "does not link debates if activity is not public" do
|
||||
create(:debate, author: user)
|
||||
|
||||
response = execute("{ user(id: #{user.id}) { public_debates { edges { node { title } } } } }")
|
||||
received_debates = dig(response, 'data.user.public_debates.edges')
|
||||
received_debates = dig(response, "data.user.public_debates.edges")
|
||||
|
||||
expect(received_debates).to eq []
|
||||
end
|
||||
|
||||
it 'does not link proposals if activity is not public' do
|
||||
it "does not link proposals if activity is not public" do
|
||||
create(:proposal, author: user)
|
||||
|
||||
response = execute("{ user(id: #{user.id}) { public_proposals { edges { node { title } } } } }")
|
||||
received_proposals = dig(response, 'data.user.public_proposals.edges')
|
||||
received_proposals = dig(response, "data.user.public_proposals.edges")
|
||||
|
||||
expect(received_proposals).to eq []
|
||||
end
|
||||
|
||||
it 'does not link comments if activity is not public' do
|
||||
it "does not link comments if activity is not public" do
|
||||
create(:comment, author: user)
|
||||
|
||||
response = execute("{ user(id: #{user.id}) { public_comments { edges { node { body } } } } }")
|
||||
received_comments = dig(response, 'data.user.public_comments.edges')
|
||||
received_comments = dig(response, "data.user.public_comments.edges")
|
||||
|
||||
expect(received_comments).to eq []
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'Proposals' do
|
||||
it 'does not include hidden proposals' do
|
||||
describe "Proposals" do
|
||||
it "does not include hidden proposals" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
response = execute('{ proposals { edges { node { title } } } }')
|
||||
received_titles = extract_fields(response, 'proposals', 'title')
|
||||
response = execute("{ proposals { edges { node { title } } } }")
|
||||
received_titles = extract_fields(response, "proposals", "title")
|
||||
|
||||
expect(received_titles).to match_array [visible_proposal.title]
|
||||
end
|
||||
|
||||
xit 'only returns proposals of the Human Rights proceeding' do
|
||||
xit "only returns proposals of the Human Rights proceeding" do
|
||||
proposal = create(:proposal)
|
||||
human_rights_proposal = create(:proposal, proceeding: 'Derechos Humanos', sub_proceeding: 'Right to have a job')
|
||||
human_rights_proposal = create(:proposal, proceeding: "Derechos Humanos", sub_proceeding: "Right to have a job")
|
||||
other_proceeding_proposal = create(:proposal)
|
||||
other_proceeding_proposal.update_attribute(:proceeding, 'Another proceeding')
|
||||
other_proceeding_proposal.update_attribute(:proceeding, "Another proceeding")
|
||||
|
||||
response = execute('{ proposals { edges { node { title } } } }')
|
||||
received_titles = extract_fields(response, 'proposals', 'title')
|
||||
response = execute("{ proposals { edges { node { title } } } }")
|
||||
received_titles = extract_fields(response, "proposals", "title")
|
||||
|
||||
expect(received_titles).to match_array [proposal.title, human_rights_proposal.title]
|
||||
end
|
||||
|
||||
it 'includes proposals of authors even if public activity is set to false' do
|
||||
it "includes proposals of authors even if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_proposal = create(:proposal, author: visible_author)
|
||||
hidden_proposal = create(:proposal, author: hidden_author)
|
||||
|
||||
response = execute('{ proposals { edges { node { title } } } }')
|
||||
received_titles = extract_fields(response, 'proposals', 'title')
|
||||
response = execute("{ proposals { edges { node { title } } } }")
|
||||
received_titles = extract_fields(response, "proposals", "title")
|
||||
|
||||
expect(received_titles).to match_array [visible_proposal.title, hidden_proposal.title]
|
||||
end
|
||||
|
||||
it 'does not link author if public activity is set to false' do
|
||||
it "does not link author if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_proposal = create(:proposal, author: visible_author)
|
||||
hidden_proposal = create(:proposal, author: hidden_author)
|
||||
|
||||
response = execute('{ proposals { edges { node { public_author { username } } } } }')
|
||||
received_authors = extract_fields(response, 'proposals', 'public_author.username')
|
||||
response = execute("{ proposals { edges { node { public_author { username } } } } }")
|
||||
received_authors = extract_fields(response, "proposals", "public_author.username")
|
||||
|
||||
expect(received_authors).to match_array [visible_author.username]
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
it "only returns date and hour for created_at" do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:proposal, created_at: created_at)
|
||||
|
||||
response = execute('{ proposals { edges { node { public_created_at } } } }')
|
||||
received_timestamps = extract_fields(response, 'proposals', 'public_created_at')
|
||||
response = execute("{ proposals { edges { node { public_created_at } } } }")
|
||||
received_timestamps = extract_fields(response, "proposals", "public_created_at")
|
||||
|
||||
expect(Time.zone.parse(received_timestamps.first)).to eq Time.zone.parse("2017-12-31 9:00:00")
|
||||
end
|
||||
|
||||
it 'only retruns tags with kind nil or category' do
|
||||
tag = create(:tag, name: 'Parks')
|
||||
category_tag = create(:tag, :category, name: 'Health')
|
||||
admin_tag = create(:tag, name: 'Admin tag', kind: 'admin')
|
||||
it "only retruns tags with kind nil or category" do
|
||||
tag = create(:tag, name: "Parks")
|
||||
category_tag = create(:tag, :category, name: "Health")
|
||||
admin_tag = create(:tag, name: "Admin tag", kind: "admin")
|
||||
|
||||
proposal = create(:proposal, tag_list: 'Parks, Health, Admin tag')
|
||||
proposal = create(:proposal, tag_list: "Parks, Health, Admin tag")
|
||||
|
||||
response = execute("{ proposal(id: #{proposal.id}) { tags { edges { node { name } } } } }")
|
||||
received_tags = dig(response, 'data.proposal.tags.edges').map { |node| node['node']['name'] }
|
||||
received_tags = dig(response, "data.proposal.tags.edges").map { |node| node["node"]["name"] }
|
||||
|
||||
expect(received_tags).to match_array ['Parks', 'Health']
|
||||
expect(received_tags).to match_array ["Parks", "Health"]
|
||||
end
|
||||
|
||||
it 'returns nested votes for a proposal' do
|
||||
it "returns nested votes for a proposal" do
|
||||
proposal = create(:proposal)
|
||||
2.times { create(:vote, votable: proposal) }
|
||||
|
||||
@@ -230,357 +230,357 @@ describe 'Consul Schema' do
|
||||
|
||||
end
|
||||
|
||||
describe 'Debates' do
|
||||
it 'does not include hidden debates' do
|
||||
describe "Debates" do
|
||||
it "does not include hidden debates" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, :hidden)
|
||||
|
||||
response = execute('{ debates { edges { node { title } } } }')
|
||||
received_titles = extract_fields(response, 'debates', 'title')
|
||||
response = execute("{ debates { edges { node { title } } } }")
|
||||
received_titles = extract_fields(response, "debates", "title")
|
||||
|
||||
expect(received_titles).to match_array [visible_debate.title]
|
||||
end
|
||||
|
||||
it 'includes debates of authors even if public activity is set to false' do
|
||||
it "includes debates of authors even if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_debate = create(:debate, author: visible_author)
|
||||
hidden_debate = create(:debate, author: hidden_author)
|
||||
|
||||
response = execute('{ debates { edges { node { title } } } }')
|
||||
received_titles = extract_fields(response, 'debates', 'title')
|
||||
response = execute("{ debates { edges { node { title } } } }")
|
||||
received_titles = extract_fields(response, "debates", "title")
|
||||
|
||||
expect(received_titles).to match_array [visible_debate.title, hidden_debate.title]
|
||||
end
|
||||
|
||||
it 'does not link author if public activity is set to false' do
|
||||
it "does not link author if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_debate = create(:debate, author: visible_author)
|
||||
hidden_debate = create(:debate, author: hidden_author)
|
||||
|
||||
response = execute('{ debates { edges { node { public_author { username } } } } }')
|
||||
received_authors = extract_fields(response, 'debates', 'public_author.username')
|
||||
response = execute("{ debates { edges { node { public_author { username } } } } }")
|
||||
received_authors = extract_fields(response, "debates", "public_author.username")
|
||||
|
||||
expect(received_authors).to match_array [visible_author.username]
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
it "only returns date and hour for created_at" do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:debate, created_at: created_at)
|
||||
|
||||
response = execute('{ debates { edges { node { public_created_at } } } }')
|
||||
received_timestamps = extract_fields(response, 'debates', 'public_created_at')
|
||||
response = execute("{ debates { edges { node { public_created_at } } } }")
|
||||
received_timestamps = extract_fields(response, "debates", "public_created_at")
|
||||
|
||||
expect(Time.zone.parse(received_timestamps.first)).to eq Time.zone.parse("2017-12-31 9:00:00")
|
||||
end
|
||||
|
||||
it 'only retruns tags with kind nil or category' do
|
||||
tag = create(:tag, name: 'Parks')
|
||||
category_tag = create(:tag, :category, name: 'Health')
|
||||
admin_tag = create(:tag, name: 'Admin tag', kind: 'admin')
|
||||
it "only retruns tags with kind nil or category" do
|
||||
tag = create(:tag, name: "Parks")
|
||||
category_tag = create(:tag, :category, name: "Health")
|
||||
admin_tag = create(:tag, name: "Admin tag", kind: "admin")
|
||||
|
||||
debate = create(:debate, tag_list: 'Parks, Health, Admin tag')
|
||||
debate = create(:debate, tag_list: "Parks, Health, Admin tag")
|
||||
|
||||
response = execute("{ debate(id: #{debate.id}) { tags { edges { node { name } } } } }")
|
||||
received_tags = dig(response, 'data.debate.tags.edges').map { |node| node['node']['name'] }
|
||||
received_tags = dig(response, "data.debate.tags.edges").map { |node| node["node"]["name"] }
|
||||
|
||||
expect(received_tags).to match_array ['Parks', 'Health']
|
||||
expect(received_tags).to match_array ["Parks", "Health"]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Comments' do
|
||||
it 'only returns comments from proposals, debates and polls' do
|
||||
describe "Comments" do
|
||||
it "only returns comments from proposals, debates and polls" do
|
||||
proposal_comment = create(:comment, commentable: create(:proposal))
|
||||
debate_comment = create(:comment, commentable: create(:debate))
|
||||
poll_comment = create(:comment, commentable: create(:poll))
|
||||
spending_proposal_comment = build(:comment, commentable: create(:spending_proposal)).save(skip_validation: true)
|
||||
|
||||
response = execute('{ comments { edges { node { commentable_type } } } }')
|
||||
received_commentables = extract_fields(response, 'comments', 'commentable_type')
|
||||
response = execute("{ comments { edges { node { commentable_type } } } }")
|
||||
received_commentables = extract_fields(response, "comments", "commentable_type")
|
||||
|
||||
expect(received_commentables).to match_array ['Proposal', 'Debate', 'Poll']
|
||||
expect(received_commentables).to match_array ["Proposal", "Debate", "Poll"]
|
||||
end
|
||||
|
||||
it 'displays comments of authors even if public activity is set to false' do
|
||||
it "displays comments of authors even if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_comment = create(:comment, user: visible_author)
|
||||
hidden_comment = create(:comment, user: hidden_author)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).to match_array [visible_comment.body, hidden_comment.body]
|
||||
end
|
||||
|
||||
it 'does not link author if public activity is set to false' do
|
||||
it "does not link author if public activity is set to false" do
|
||||
visible_author = create(:user, public_activity: true)
|
||||
hidden_author = create(:user, public_activity: false)
|
||||
|
||||
visible_comment = create(:comment, author: visible_author)
|
||||
hidden_comment = create(:comment, author: hidden_author)
|
||||
|
||||
response = execute('{ comments { edges { node { public_author { username } } } } }')
|
||||
received_authors = extract_fields(response, 'comments', 'public_author.username')
|
||||
response = execute("{ comments { edges { node { public_author { username } } } } }")
|
||||
received_authors = extract_fields(response, "comments", "public_author.username")
|
||||
|
||||
expect(received_authors).to match_array [visible_author.username]
|
||||
end
|
||||
|
||||
it 'does not include hidden comments' do
|
||||
it "does not include hidden comments" do
|
||||
visible_comment = create(:comment)
|
||||
hidden_comment = create(:comment, hidden_at: Time.current)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).to match_array [visible_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments from hidden proposals' do
|
||||
it "does not include comments from hidden proposals" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, hidden_at: Time.current)
|
||||
|
||||
visible_proposal_comment = create(:comment, commentable: visible_proposal)
|
||||
hidden_proposal_comment = create(:comment, commentable: hidden_proposal)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).to match_array [visible_proposal_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments from hidden debates' do
|
||||
it "does not include comments from hidden debates" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, hidden_at: Time.current)
|
||||
|
||||
visible_debate_comment = create(:comment, commentable: visible_debate)
|
||||
hidden_debate_comment = create(:comment, commentable: hidden_debate)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).to match_array [visible_debate_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments from hidden polls' do
|
||||
it "does not include comments from hidden polls" do
|
||||
visible_poll = create(:poll)
|
||||
hidden_poll = create(:poll, hidden_at: Time.current)
|
||||
|
||||
visible_poll_comment = create(:comment, commentable: visible_poll)
|
||||
hidden_poll_comment = create(:comment, commentable: hidden_poll)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).to match_array [visible_poll_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments of debates that are not public' do
|
||||
it "does not include comments of debates that are not public" do
|
||||
not_public_debate = create(:debate, :hidden)
|
||||
not_public_debate_comment = create(:comment, commentable: not_public_debate)
|
||||
allow(Comment).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).not_to include(not_public_debate_comment.body)
|
||||
end
|
||||
|
||||
it 'does not include comments of proposals that are not public' do
|
||||
it "does not include comments of proposals that are not public" do
|
||||
not_public_proposal = create(:proposal)
|
||||
not_public_proposal_comment = create(:comment, commentable: not_public_proposal)
|
||||
allow(Comment).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).not_to include(not_public_proposal_comment.body)
|
||||
end
|
||||
|
||||
it 'does not include comments of polls that are not public' do
|
||||
it "does not include comments of polls that are not public" do
|
||||
not_public_poll = create(:poll)
|
||||
not_public_poll_comment = create(:comment, commentable: not_public_poll)
|
||||
allow(Comment).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).not_to include(not_public_poll_comment.body)
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
it "only returns date and hour for created_at" do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:comment, created_at: created_at)
|
||||
|
||||
response = execute('{ comments { edges { node { public_created_at } } } }')
|
||||
received_timestamps = extract_fields(response, 'comments', 'public_created_at')
|
||||
response = execute("{ comments { edges { node { public_created_at } } } }")
|
||||
received_timestamps = extract_fields(response, "comments", "public_created_at")
|
||||
|
||||
expect(Time.zone.parse(received_timestamps.first)).to eq Time.zone.parse("2017-12-31 9:00:00")
|
||||
end
|
||||
|
||||
it 'does not include valuation comments' do
|
||||
it "does not include valuation comments" do
|
||||
visible_comment = create(:comment)
|
||||
valuation_comment = create(:comment, :valuation)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
response = execute("{ comments { edges { node { body } } } }")
|
||||
received_comments = extract_fields(response, "comments", "body")
|
||||
|
||||
expect(received_comments).not_to include(valuation_comment.body)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Geozones' do
|
||||
it 'returns geozones' do
|
||||
describe "Geozones" do
|
||||
it "returns geozones" do
|
||||
geozone_names = [ create(:geozone), create(:geozone) ].map { |geozone| geozone.name }
|
||||
|
||||
response = execute('{ geozones { edges { node { name } } } }')
|
||||
received_names = extract_fields(response, 'geozones', 'name')
|
||||
response = execute("{ geozones { edges { node { name } } } }")
|
||||
received_names = extract_fields(response, "geozones", "name")
|
||||
|
||||
expect(received_names).to match_array geozone_names
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Proposal notifications' do
|
||||
describe "Proposal notifications" do
|
||||
|
||||
it 'does not include proposal notifications for hidden proposals' do
|
||||
it "does not include proposal notifications for hidden proposals" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
visible_proposal_notification = create(:proposal_notification, proposal: visible_proposal)
|
||||
hidden_proposal_notification = create(:proposal_notification, proposal: hidden_proposal)
|
||||
|
||||
response = execute('{ proposal_notifications { edges { node { title } } } }')
|
||||
received_notifications = extract_fields(response, 'proposal_notifications', 'title')
|
||||
response = execute("{ proposal_notifications { edges { node { title } } } }")
|
||||
received_notifications = extract_fields(response, "proposal_notifications", "title")
|
||||
|
||||
expect(received_notifications).to match_array [visible_proposal_notification.title]
|
||||
end
|
||||
|
||||
it 'does not include proposal notifications for proposals that are not public' do
|
||||
it "does not include proposal notifications for proposals that are not public" do
|
||||
not_public_proposal = create(:proposal)
|
||||
not_public_proposal_notification = create(:proposal_notification, proposal: not_public_proposal)
|
||||
allow(ProposalNotification).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ proposal_notifications { edges { node { title } } } }')
|
||||
received_notifications = extract_fields(response, 'proposal_notifications', 'title')
|
||||
response = execute("{ proposal_notifications { edges { node { title } } } }")
|
||||
received_notifications = extract_fields(response, "proposal_notifications", "title")
|
||||
|
||||
expect(received_notifications).not_to include(not_public_proposal_notification.title)
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
it "only returns date and hour for created_at" do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:proposal_notification, created_at: created_at)
|
||||
|
||||
response = execute('{ proposal_notifications { edges { node { public_created_at } } } }')
|
||||
received_timestamps = extract_fields(response, 'proposal_notifications', 'public_created_at')
|
||||
response = execute("{ proposal_notifications { edges { node { public_created_at } } } }")
|
||||
received_timestamps = extract_fields(response, "proposal_notifications", "public_created_at")
|
||||
|
||||
expect(Time.zone.parse(received_timestamps.first)).to eq Time.zone.parse("2017-12-31 9:00:00")
|
||||
end
|
||||
|
||||
it 'only links proposal if public' do
|
||||
it "only links proposal if public" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
visible_proposal_notification = create(:proposal_notification, proposal: visible_proposal)
|
||||
hidden_proposal_notification = create(:proposal_notification, proposal: hidden_proposal)
|
||||
|
||||
response = execute('{ proposal_notifications { edges { node { proposal { title } } } } }')
|
||||
received_proposals = extract_fields(response, 'proposal_notifications', 'proposal.title')
|
||||
response = execute("{ proposal_notifications { edges { node { proposal { title } } } } }")
|
||||
received_proposals = extract_fields(response, "proposal_notifications", "proposal.title")
|
||||
|
||||
expect(received_proposals).to match_array [visible_proposal.title]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'Tags' do
|
||||
it 'only display tags with kind nil or category' do
|
||||
tag = create(:tag, name: 'Parks')
|
||||
category_tag = create(:tag, :category, name: 'Health')
|
||||
admin_tag = create(:tag, name: 'Admin tag', kind: 'admin')
|
||||
describe "Tags" do
|
||||
it "only display tags with kind nil or category" do
|
||||
tag = create(:tag, name: "Parks")
|
||||
category_tag = create(:tag, :category, name: "Health")
|
||||
admin_tag = create(:tag, name: "Admin tag", kind: "admin")
|
||||
|
||||
proposal = create(:proposal, tag_list: 'Parks')
|
||||
proposal = create(:proposal, tag_list: 'Health')
|
||||
proposal = create(:proposal, tag_list: 'Admin tag')
|
||||
proposal = create(:proposal, tag_list: "Parks")
|
||||
proposal = create(:proposal, tag_list: "Health")
|
||||
proposal = create(:proposal, tag_list: "Admin tag")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Parks', 'Health']
|
||||
expect(received_tags).to match_array ["Parks", "Health"]
|
||||
end
|
||||
|
||||
it 'uppercase and lowercase tags work ok together for proposals' do
|
||||
create(:tag, name: 'Health')
|
||||
create(:tag, name: 'health')
|
||||
create(:proposal, tag_list: 'health')
|
||||
create(:proposal, tag_list: 'Health')
|
||||
it "uppercase and lowercase tags work ok together for proposals" do
|
||||
create(:tag, name: "Health")
|
||||
create(:tag, name: "health")
|
||||
create(:proposal, tag_list: "health")
|
||||
create(:proposal, tag_list: "Health")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Health', 'health']
|
||||
expect(received_tags).to match_array ["Health", "health"]
|
||||
end
|
||||
|
||||
it 'uppercase and lowercase tags work ok together for debates' do
|
||||
create(:tag, name: 'Health')
|
||||
create(:tag, name: 'health')
|
||||
create(:debate, tag_list: 'Health')
|
||||
create(:debate, tag_list: 'health')
|
||||
it "uppercase and lowercase tags work ok together for debates" do
|
||||
create(:tag, name: "Health")
|
||||
create(:tag, name: "health")
|
||||
create(:debate, tag_list: "Health")
|
||||
create(:debate, tag_list: "health")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Health', 'health']
|
||||
expect(received_tags).to match_array ["Health", "health"]
|
||||
end
|
||||
|
||||
it 'does not display tags for hidden proposals' do
|
||||
proposal = create(:proposal, tag_list: 'Health')
|
||||
hidden_proposal = create(:proposal, :hidden, tag_list: 'SPAM')
|
||||
it "does not display tags for hidden proposals" do
|
||||
proposal = create(:proposal, tag_list: "Health")
|
||||
hidden_proposal = create(:proposal, :hidden, tag_list: "SPAM")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Health']
|
||||
expect(received_tags).to match_array ["Health"]
|
||||
end
|
||||
|
||||
it 'does not display tags for hidden debates' do
|
||||
debate = create(:debate, tag_list: 'Health, Transportation')
|
||||
hidden_debate = create(:debate, :hidden, tag_list: 'SPAM')
|
||||
it "does not display tags for hidden debates" do
|
||||
debate = create(:debate, tag_list: "Health, Transportation")
|
||||
hidden_debate = create(:debate, :hidden, tag_list: "SPAM")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Health', 'Transportation']
|
||||
expect(received_tags).to match_array ["Health", "Transportation"]
|
||||
end
|
||||
|
||||
xit "does not display tags for proceeding's proposals" do
|
||||
valid_proceeding_proposal = create(:proposal, proceeding: 'Derechos Humanos', sub_proceeding: 'Right to a Home', tag_list: 'Health')
|
||||
invalid_proceeding_proposal = create(:proposal, tag_list: 'Animals')
|
||||
invalid_proceeding_proposal.update_attribute('proceeding', 'Random')
|
||||
valid_proceeding_proposal = create(:proposal, proceeding: "Derechos Humanos", sub_proceeding: "Right to a Home", tag_list: "Health")
|
||||
invalid_proceeding_proposal = create(:proposal, tag_list: "Animals")
|
||||
invalid_proceeding_proposal.update_attribute("proceeding", "Random")
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).to match_array ['Health']
|
||||
expect(received_tags).to match_array ["Health"]
|
||||
end
|
||||
|
||||
it 'does not display tags for taggings that are not public' do
|
||||
proposal = create(:proposal, tag_list: 'Health')
|
||||
it "does not display tags for taggings that are not public" do
|
||||
proposal = create(:proposal, tag_list: "Health")
|
||||
allow(ActsAsTaggableOn::Tag).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ tags { edges { node { name } } } }')
|
||||
received_tags = extract_fields(response, 'tags', 'name')
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
expect(received_tags).not_to include('Health')
|
||||
expect(received_tags).not_to include("Health")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'Votes' do
|
||||
describe "Votes" do
|
||||
|
||||
it 'only returns votes from proposals, debates and comments' do
|
||||
it "only returns votes from proposals, debates and comments" do
|
||||
proposal = create(:proposal)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment)
|
||||
@@ -591,52 +591,52 @@ describe 'Consul Schema' do
|
||||
comment_vote = create(:vote, votable: comment)
|
||||
spending_proposal_vote = create(:vote, votable: spending_proposal)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_type } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_type')
|
||||
response = execute("{ votes { edges { node { votable_type } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_type")
|
||||
|
||||
expect(received_votables).to match_array ['Proposal', 'Debate', 'Comment']
|
||||
expect(received_votables).to match_array ["Proposal", "Debate", "Comment"]
|
||||
end
|
||||
|
||||
it 'does not include votes from hidden debates' do
|
||||
it "does not include votes from hidden debates" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, :hidden)
|
||||
|
||||
visible_debate_vote = create(:vote, votable: visible_debate)
|
||||
hidden_debate_vote = create(:vote, votable: hidden_debate)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_debates = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_debates = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_debates).to match_array [visible_debate.id]
|
||||
end
|
||||
|
||||
it 'does not include votes of hidden proposals' do
|
||||
it "does not include votes of hidden proposals" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, hidden_at: Time.current)
|
||||
|
||||
visible_proposal_vote = create(:vote, votable: visible_proposal)
|
||||
hidden_proposal_vote = create(:vote, votable: hidden_proposal)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_proposals = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_proposals = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_proposals).to match_array [visible_proposal.id]
|
||||
end
|
||||
|
||||
it 'does not include votes of hidden comments' do
|
||||
it "does not include votes of hidden comments" do
|
||||
visible_comment = create(:comment)
|
||||
hidden_comment = create(:comment, hidden_at: Time.current)
|
||||
|
||||
visible_comment_vote = create(:vote, votable: visible_comment)
|
||||
hidden_comment_vote = create(:vote, votable: hidden_comment)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_comments = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_comments = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_comments).to match_array [visible_comment.id]
|
||||
end
|
||||
|
||||
it 'does not include votes of comments from a hidden proposal' do
|
||||
it "does not include votes of comments from a hidden proposal" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
@@ -646,13 +646,13 @@ describe 'Consul Schema' do
|
||||
visible_proposal_comment_vote = create(:vote, votable: visible_proposal_comment)
|
||||
hidden_proposal_comment_vote = create(:vote, votable: hidden_proposal_comment)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_votables).to match_array [visible_proposal_comment.id]
|
||||
end
|
||||
|
||||
it 'does not include votes of comments from a hidden debate' do
|
||||
it "does not include votes of comments from a hidden debate" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, :hidden)
|
||||
|
||||
@@ -662,54 +662,54 @@ describe 'Consul Schema' do
|
||||
visible_debate_comment_vote = create(:vote, votable: visible_debate_comment)
|
||||
hidden_debate_comment_vote = create(:vote, votable: hidden_debate_comment)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_votables).to match_array [visible_debate_comment.id]
|
||||
end
|
||||
|
||||
it 'does not include votes of debates that are not public' do
|
||||
it "does not include votes of debates that are not public" do
|
||||
not_public_debate = create(:debate)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_debate_vote = create(:vote, votable: not_public_debate)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_votables).not_to include(not_public_debate.id)
|
||||
end
|
||||
|
||||
it 'does not include votes of a hidden proposals' do
|
||||
it "does not include votes of a hidden proposals" do
|
||||
not_public_proposal = create(:proposal)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_proposal_vote = create(:vote, votable: not_public_proposal)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_votables).not_to include(not_public_proposal.id)
|
||||
end
|
||||
|
||||
it 'does not include votes of a hidden comments' do
|
||||
it "does not include votes of a hidden comments" do
|
||||
not_public_comment = create(:comment)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_comment_vote = create(:vote, votable: not_public_comment)
|
||||
|
||||
response = execute('{ votes { edges { node { votable_id } } } }')
|
||||
received_votables = extract_fields(response, 'votes', 'votable_id')
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
expect(received_votables).not_to include(not_public_comment.id)
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
it "only returns date and hour for created_at" do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:vote, created_at: created_at)
|
||||
|
||||
response = execute('{ votes { edges { node { public_created_at } } } }')
|
||||
received_timestamps = extract_fields(response, 'votes', 'public_created_at')
|
||||
response = execute("{ votes { edges { node { public_created_at } } } }")
|
||||
received_timestamps = extract_fields(response, "votes", "public_created_at")
|
||||
|
||||
expect(Time.zone.parse(received_timestamps.first)).to eq Time.zone.parse("2017-12-31 9:00:00")
|
||||
end
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe LocalCensus do
|
||||
let(:api) { described_class.new }
|
||||
|
||||
describe '#get_document_number_variants' do
|
||||
describe "#get_document_number_variants" do
|
||||
it "trims and cleans up entry" do
|
||||
expect(api.get_document_number_variants(2, ' 1 2@ 34')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(2, " 1 2@ 34")).to eq(["1234"])
|
||||
end
|
||||
|
||||
it "returns only one try for passports & residence cards" do
|
||||
expect(api.get_document_number_variants(2, '1234')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(3, '1234')).to eq(['1234'])
|
||||
expect(api.get_document_number_variants(2, "1234")).to eq(["1234"])
|
||||
expect(api.get_document_number_variants(3, "1234")).to eq(["1234"])
|
||||
end
|
||||
|
||||
it 'takes only the last 8 digits for dnis and resicence cards' do
|
||||
expect(api.get_document_number_variants(1, '543212345678')).to eq(['12345678'])
|
||||
it "takes only the last 8 digits for dnis and resicence cards" do
|
||||
expect(api.get_document_number_variants(1, "543212345678")).to eq(["12345678"])
|
||||
end
|
||||
|
||||
it 'tries all the dni variants padding with zeroes' do
|
||||
expect(api.get_document_number_variants(1, '0123456')).to eq(['123456', '0123456', '00123456'])
|
||||
expect(api.get_document_number_variants(1, '00123456')).to eq(['123456', '0123456', '00123456'])
|
||||
it "tries all the dni variants padding with zeroes" do
|
||||
expect(api.get_document_number_variants(1, "0123456")).to eq(["123456", "0123456", "00123456"])
|
||||
expect(api.get_document_number_variants(1, "00123456")).to eq(["123456", "0123456", "00123456"])
|
||||
end
|
||||
|
||||
it 'adds upper and lowercase letter when the letter is present' do
|
||||
expect(api.get_document_number_variants(1, '1234567A')).to eq(['1234567', '01234567', '1234567a', '1234567A', '01234567a', '01234567A'])
|
||||
it "adds upper and lowercase letter when the letter is present" do
|
||||
expect(api.get_document_number_variants(1, "1234567A")).to eq(["1234567", "01234567", "1234567a", "1234567A", "01234567a", "01234567A"])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
describe "#call" do
|
||||
let(:invalid_body) { nil }
|
||||
let(:valid_body) { create(:local_census_record) }
|
||||
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe ManagerAuthenticator do
|
||||
let(:authenticator) { described_class.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") }
|
||||
|
||||
describe 'initialization params' do
|
||||
it 'causes auth to return false if blank login' do
|
||||
describe "initialization params" do
|
||||
it "causes auth to return false if blank login" do
|
||||
blank_login_authenticator = described_class.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905")
|
||||
expect(blank_login_authenticator.auth).to be false
|
||||
end
|
||||
|
||||
it 'causes auth to return false if blank user_key' do
|
||||
it "causes auth to return false if blank user_key" do
|
||||
blank_user_key_authenticator = described_class.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905")
|
||||
expect(blank_user_key_authenticator.auth).to be false
|
||||
end
|
||||
|
||||
it 'causes auth to return false if blank date' do
|
||||
it "causes auth to return false if blank date" do
|
||||
blank_date_authenticator = described_class.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "")
|
||||
expect(blank_date_authenticator.auth).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#auth' do
|
||||
it 'returns false if not manager_exists' do
|
||||
describe "#auth" do
|
||||
it "returns false if not manager_exists" do
|
||||
allow(authenticator).to receive(:manager_exists?).and_return(false)
|
||||
allow(authenticator).to receive(:application_authorized?).and_return(true)
|
||||
|
||||
expect(authenticator.auth).to be false
|
||||
end
|
||||
|
||||
it 'returns false if not application_authorized' do
|
||||
it "returns false if not application_authorized" do
|
||||
allow(authenticator).to receive(:manager_exists?).and_return(true)
|
||||
allow(authenticator).to receive(:application_authorized?).and_return(false)
|
||||
|
||||
expect(authenticator.auth).to be false
|
||||
end
|
||||
|
||||
it 'returns ok if manager_exists and application_authorized' do
|
||||
it "returns ok if manager_exists and application_authorized" do
|
||||
allow(authenticator).to receive(:manager_exists?).and_return(true)
|
||||
allow(authenticator).to receive(:application_authorized?).and_return(true)
|
||||
|
||||
@@ -43,15 +43,15 @@ describe ManagerAuthenticator do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'SOAP' do
|
||||
it 'calls the verification user method' do
|
||||
describe "SOAP" do
|
||||
it "calls the verification user method" do
|
||||
message = { ub: {user_key: "31415926", date: "20151031135905"} }
|
||||
allow(authenticator).to receive(:application_authorized?).and_return(true)
|
||||
allow(authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message)
|
||||
authenticator.auth
|
||||
end
|
||||
|
||||
it 'calls the permissions check method' do
|
||||
it "calls the permissions check method" do
|
||||
allow(authenticator).to receive(:manager_exists?).and_return(true)
|
||||
allow(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} })
|
||||
authenticator.auth
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe MigrateSpendingProposalsToInvestments do
|
||||
|
||||
let(:importer) { described_class.new }
|
||||
|
||||
describe '#import' do
|
||||
describe "#import" do
|
||||
|
||||
it "Creates the budget if it doesn't exist" do
|
||||
sp = create(:spending_proposal)
|
||||
@@ -57,9 +57,9 @@ describe MigrateSpendingProposalsToInvestments do
|
||||
feasible = create(:spending_proposal, feasible: true)
|
||||
unfeasible = create(:spending_proposal, feasible: false)
|
||||
|
||||
expect(importer.import(sp).feasibility).to eq('undecided')
|
||||
expect(importer.import(feasible).feasibility).to eq('feasible')
|
||||
expect(importer.import(unfeasible).feasibility).to eq('unfeasible')
|
||||
expect(importer.import(sp).feasibility).to eq("undecided")
|
||||
expect(importer.import(feasible).feasibility).to eq("feasible")
|
||||
expect(importer.import(unfeasible).feasibility).to eq("unfeasible")
|
||||
end
|
||||
|
||||
it "Imports valuation assignments" do
|
||||
|
||||
57
spec/lib/reply_email_spec.rb
Normal file
57
spec/lib/reply_email_spec.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe ReplyEmail do
|
||||
|
||||
let(:author) { create(:user) }
|
||||
let(:debate) { create(:debate, author: author) }
|
||||
let(:commenter) { create(:user, email: "email@commenter.org") }
|
||||
let(:comment) { create(:comment, commentable: debate, user: commenter) }
|
||||
let(:replier) { create(:user) }
|
||||
let(:reply) { create(:comment, commentable: debate, parent: comment, user: replier) }
|
||||
let(:reply_email) { ReplyEmail.new(reply) }
|
||||
|
||||
describe "#commentable" do
|
||||
it "returns the commentable object that contains the replied comment" do
|
||||
expect(reply_email.commentable).to eq debate
|
||||
end
|
||||
end
|
||||
|
||||
describe "#recipient" do
|
||||
it "returns the author of the replied comment" do
|
||||
expect(reply_email.recipient).to eq commenter
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to" do
|
||||
it "returns the author's email of the replied comment" do
|
||||
expect(reply_email.to).to eq "email@commenter.org"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#subject" do
|
||||
it "returns the translation for a reply email subject" do
|
||||
expect(reply_email.subject).to eq "Someone has responded to your comment"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#can_be_sent?" do
|
||||
|
||||
it "returns true if comment and recipient exist" do
|
||||
expect(reply_email.can_be_sent?).to be true
|
||||
end
|
||||
|
||||
it "returns false if the comment doesn't exist" do
|
||||
reply.update(commentable: nil)
|
||||
|
||||
expect(reply_email.can_be_sent?).to be false
|
||||
end
|
||||
|
||||
it "returns false if the recipient doesn't exist" do
|
||||
reply.parent.author.really_destroy!
|
||||
|
||||
expect(reply_email.can_be_sent?).to be false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,27 +1,27 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe TagSanitizer do
|
||||
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#sanitize_tag' do
|
||||
it 'allows regular text, even spaces' do
|
||||
expect(subject.sanitize_tag('hello there')).to eq('hello there')
|
||||
describe "#sanitize_tag" do
|
||||
it "allows regular text, even spaces" do
|
||||
expect(subject.sanitize_tag("hello there")).to eq("hello there")
|
||||
end
|
||||
|
||||
it 'filters out dangerous strings' do
|
||||
expect(subject.sanitize_tag('user_id=1')).to eq('user_id1')
|
||||
it "filters out dangerous strings" do
|
||||
expect(subject.sanitize_tag("user_id=1")).to eq("user_id1")
|
||||
end
|
||||
|
||||
it 'sets up a max length for each tag' do
|
||||
long_tag = '1' * (described_class.tag_max_length + 100)
|
||||
it "sets up a max length for each tag" do
|
||||
long_tag = "1" * (described_class.tag_max_length + 100)
|
||||
|
||||
expect(subject.sanitize_tag(long_tag).size).to eq(described_class.tag_max_length)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sanitize_tag_list' do
|
||||
it 'returns a new tag list with sanitized tags' do
|
||||
describe "#sanitize_tag_list" do
|
||||
it "returns a new tag list with sanitized tags" do
|
||||
expect(subject.sanitize_tag_list(%w{x=1 y?z})).to eq(%w(x1 yz))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
15
spec/lib/tasks/db_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
66
spec/lib/tasks/proposals_spec.rb
Normal file
66
spec/lib/tasks/proposals_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe UserSegments do
|
||||
let(:user1) { create(:user) }
|
||||
@@ -178,8 +178,8 @@ describe UserSegments do
|
||||
investment1 = create(:budget_investment)
|
||||
investment2 = create(:budget_investment)
|
||||
budget = create(:budget)
|
||||
investment1.vote_by(voter: user1, vote: 'yes')
|
||||
investment2.vote_by(voter: user2, vote: 'yes')
|
||||
investment1.vote_by(voter: user1, vote: "yes")
|
||||
investment2.vote_by(voter: user2, vote: "yes")
|
||||
investment1.update(budget: budget)
|
||||
investment2.update(budget: budget)
|
||||
|
||||
@@ -190,4 +190,15 @@ describe UserSegments do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#user_segment_emails" do
|
||||
it "returns list of emails sorted by user creation date" do
|
||||
create(:user, email: "first@email.com", created_at: 1.day.ago)
|
||||
create(:user, email: "last@email.com")
|
||||
|
||||
emails = described_class.user_segment_emails(:all_users)
|
||||
expect(emails.first).to eq "first@email.com"
|
||||
expect(emails.last).to eq "last@email.com"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
describe WYSIWYGSanitizer do
|
||||
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#sanitize' do
|
||||
describe "#sanitize" do
|
||||
|
||||
it 'returns an html_safe string' do
|
||||
expect(subject.sanitize('hello')).to be_html_safe
|
||||
it "returns an html_safe string" do
|
||||
expect(subject.sanitize("hello")).to be_html_safe
|
||||
end
|
||||
|
||||
it 'allows basic html formatting' do
|
||||
html = '<p>This is <strong>a paragraph</strong></p>'
|
||||
it "allows basic html formatting" do
|
||||
html = "<p>This is <strong>a paragraph</strong></p>"
|
||||
expect(subject.sanitize(html)).to eq(html)
|
||||
end
|
||||
|
||||
it 'allows links' do
|
||||
it "allows links" do
|
||||
html = '<p><a href="/">Home</a></p>'
|
||||
expect(subject.sanitize(html)).to eq(html)
|
||||
end
|
||||
|
||||
it 'allows headings' do
|
||||
html = '<h2>Objectives</h2><p>Fix flaky specs</p><h3>Explain why the test is flaky</h3>'
|
||||
it "allows headings" do
|
||||
html = "<h2>Objectives</h2><p>Fix flaky specs</p><h3>Explain why the test is flaky</h3>"
|
||||
expect(subject.sanitize(html)).to eq(html)
|
||||
end
|
||||
|
||||
it 'filters out dangerous tags' do
|
||||
html = '<p>This is <script>alert("dangerous");</script></p>'
|
||||
expect(subject.sanitize(html)).to eq('<p>This is alert("dangerous");</p>')
|
||||
it "filters out dangerous tags" do
|
||||
html = "<p>This is <script>alert('dangerous');</script></p>"
|
||||
expect(subject.sanitize(html)).to eq("<p>This is alert('dangerous');</p>")
|
||||
end
|
||||
|
||||
it 'filters images' do
|
||||
html = 'Dangerous<img src="/smile.png" alt="Smile" style="width: 10px";> image'
|
||||
expect(subject.sanitize(html)).to eq('Dangerous image')
|
||||
it "filters images" do
|
||||
html = "Dangerous<img src='/smile.png' alt='Smile' style='width: 10px';> image"
|
||||
expect(subject.sanitize(html)).to eq("Dangerous image")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user