Enables RSpec/DescribedClass cop & fixes all issues

Autocorrection for existing issues, and stashing at .rubocop_todo.yml
the false positives

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
This commit is contained in:
Bertocq
2018-01-07 00:38:19 +01:00
parent 0c3dc56650
commit 265d4d0967
38 changed files with 327 additions and 316 deletions

View File

@@ -59,4 +59,7 @@ RSpec/DescribeMethod:
Enabled: true
RSpec/DescribeSymbol:
Enabled: true
RSpec/DescribedClass:
Enabled: true

View File

@@ -784,7 +784,7 @@ Style/WordArray:
EnforcedStyle: percent
MinSize: 8
# Offense count: 9
# Offense count: 10
RSpec/DescribeClass:
Exclude:
- 'spec/customization_engine_spec.rb'
@@ -796,4 +796,12 @@ RSpec/DescribeClass:
- 'spec/lib/tasks/dev_seed_spec.rb'
- 'spec/lib/tasks/settings_spec.rb'
- 'spec/models/abilities/organization_spec.rb'
- 'spec/views/welcome/index.html.erb_spec.rb'
- 'spec/views/welcome/index.html.erb_spec.rb'
# Offense count: 2
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/controllers/concerns/has_filters_spec.rb'
- 'spec/controllers/concerns/has_orders_spec.rb'

View File

@@ -3,56 +3,56 @@ require 'rails_helper'
describe Age do
describe '.in_years' do
it "handles nils" do
expect(Age.in_years(nil)).to be_nil
expect(described_class.in_years(nil)).to be_nil
end
it "calculates age correctly for common dates" do
d = Date.new(1980, 3, 13)
expect(Age.in_years(d, Date.new(2000, 3, 12))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 3, 13))).to eq(20)
expect(Age.in_years(d, Date.new(2000, 3, 14))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 3, 12))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 3, 13))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 3, 14))).to eq(20)
end
it "calculates age correctly for people born near a year's limit" do
d = Date.new(1980, 12, 31)
expect(Age.in_years(d, Date.new(2000, 12, 30))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 12, 31))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 1, 1))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 12, 30))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 12, 31))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 1, 1))).to eq(20)
d = Date.new(1980, 1, 1)
expect(Age.in_years(d, Date.new(2000, 12, 31))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 1, 1))).to eq(21)
expect(Age.in_years(d, Date.new(2001, 1, 2))).to eq(21)
expect(described_class.in_years(d, Date.new(2000, 12, 31))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 1, 1))).to eq(21)
expect(described_class.in_years(d, Date.new(2001, 1, 2))).to eq(21)
end
it "calculates age correctly for people born around February the 29th" do
# 1980 and 2000 are leap years. 2001 is a regular year
d = Date.new(1980, 2, 29)
expect(Age.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 2, 28))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 2, 29))).to eq(20)
expect(Age.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 28))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 3, 1))).to eq(21)
expect(described_class.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 2, 28))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 2, 29))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 28))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 3, 1))).to eq(21)
d = Date.new(1980, 2, 28)
expect(Age.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 2, 28))).to eq(20)
expect(Age.in_years(d, Date.new(2000, 2, 29))).to eq(20)
expect(Age.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 28))).to eq(21)
expect(Age.in_years(d, Date.new(2001, 3, 1))).to eq(21)
expect(described_class.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 2, 28))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 2, 29))).to eq(20)
expect(described_class.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 28))).to eq(21)
expect(described_class.in_years(d, Date.new(2001, 3, 1))).to eq(21)
d = Date.new(1980, 3, 1)
expect(Age.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 2, 28))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 2, 29))).to eq(19)
expect(Age.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 2, 28))).to eq(20)
expect(Age.in_years(d, Date.new(2001, 3, 1))).to eq(21)
expect(described_class.in_years(d, Date.new(2000, 2, 27))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 2, 28))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 2, 29))).to eq(19)
expect(described_class.in_years(d, Date.new(2000, 3, 1))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 27))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 2, 28))).to eq(20)
expect(described_class.in_years(d, Date.new(2001, 3, 1))).to eq(21)
end
end
end

View File

@@ -12,7 +12,7 @@ describe EmailDigest do
notification1 = create(:notification, notifiable: proposal_notification, user: user1)
notification2 = create(:notification, notifiable: proposal_notification, user: user2)
email_digest = EmailDigest.new(user1)
email_digest = described_class.new(user1)
expect(email_digest.notifications).to include(notification1)
expect(email_digest.notifications).to_not include(notification2)
@@ -27,7 +27,7 @@ describe EmailDigest do
notification1 = create(:notification, notifiable: proposal_notification, user: user)
notification2 = create(:notification, notifiable: comment, user: user)
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
expect(email_digest.notifications).to include(notification1)
expect(email_digest.notifications).to_not include(notification2)
@@ -43,7 +43,7 @@ describe EmailDigest do
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user)
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
expect(email_digest.pending_notifications?).to be
end
@@ -53,13 +53,13 @@ describe EmailDigest do
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
expect(email_digest.pending_notifications?).to_not be
end
it "returns false when there are no notifications for a user" do
user = create(:user)
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
expect(email_digest.pending_notifications?).to_not be
end
@@ -74,7 +74,7 @@ describe EmailDigest do
notification = create(:notification, notifiable: proposal_notification, user: user)
reset_mailer
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
email_digest.deliver
email = open_last_email
@@ -88,7 +88,7 @@ describe EmailDigest do
create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
reset_mailer
email_digest = EmailDigest.new(user)
email_digest = described_class.new(user)
email_digest.deliver
expect(all_emails.count).to eq(0)
@@ -111,7 +111,7 @@ describe EmailDigest do
expect(notification2.emailed_at).to_not be
expect(notification3.emailed_at).to_not be
email_digest = EmailDigest.new(user1)
email_digest = described_class.new(user1)
email_digest.mark_as_emailed
notification1.reload
@@ -126,8 +126,8 @@ describe EmailDigest do
user1 = create(:user, failed_email_digests_count: 0)
user2 = create(:user, failed_email_digests_count: 3)
email_digest_1 = EmailDigest.new(user1)
email_digest_2 = EmailDigest.new(user2)
email_digest_1 = described_class.new(user1)
email_digest_2 = described_class.new(user2)
email_digest_1.mark_as_emailed
email_digest_2.mark_as_emailed

View File

@@ -5,7 +5,7 @@ describe GraphQL::ApiTypesCreator do
describe "::create_type" do
it "creates fields for Int attributes" do
debate_type = GraphQL::ApiTypesCreator.create_type(Debate, { id: :integer }, created_types)
debate_type = described_class.create_type(Debate, { id: :integer }, created_types)
created_field = debate_type.fields['id']
expect(created_field).to be_a(GraphQL::Field)
@@ -14,7 +14,7 @@ describe GraphQL::ApiTypesCreator do
end
it "creates fields for String attributes" do
debate_type = GraphQL::ApiTypesCreator.create_type(Debate, { title: :string }, created_types)
debate_type = described_class.create_type(Debate, { title: :string }, created_types)
created_field = debate_type.fields['title']
expect(created_field).to be_a(GraphQL::Field)
@@ -23,8 +23,8 @@ describe GraphQL::ApiTypesCreator do
end
it "creates connections for :belongs_to associations" do
user_type = GraphQL::ApiTypesCreator.create_type(User, { id: :integer }, created_types)
debate_type = GraphQL::ApiTypesCreator.create_type(Debate, { author: User }, created_types)
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']
@@ -34,8 +34,8 @@ describe GraphQL::ApiTypesCreator do
end
it "creates connections for :has_one associations" do
user_type = GraphQL::ApiTypesCreator.create_type(User, { organization: Organization }, created_types)
organization_type = GraphQL::ApiTypesCreator.create_type(Organization, { id: :integer }, created_types)
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']
@@ -45,8 +45,8 @@ describe GraphQL::ApiTypesCreator do
end
it "creates connections for :has_many associations" do
comment_type = GraphQL::ApiTypesCreator.create_type(Comment, { id: :integer }, created_types)
debate_type = GraphQL::ApiTypesCreator.create_type(Debate, { comments: [Comment] }, created_types)
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']

View File

@@ -10,7 +10,7 @@ describe GraphQL::QueryTypeCreator do
let(:api_types) { GraphQL::ApiTypesCreator.create(api_type_definitions) }
describe "::create" do
let(:query_type) { GraphQL::QueryTypeCreator.create(api_types) }
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']

View File

@@ -1,21 +1,21 @@
require 'rails_helper'
describe ManagerAuthenticator do
let(:authenticator) { ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") }
let(:authenticator) { described_class.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") }
describe 'initialization params' do
it 'should cause auth to return false if blank login' do
blank_login_authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905")
blank_login_authenticator = described_class.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905")
expect(blank_login_authenticator.auth).to be false
end
it 'should cause auth to return false if blank user_key' do
blank_user_key_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905")
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 'should cause auth to return false if blank date' do
blank_date_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "")
blank_date_authenticator = described_class.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "")
expect(blank_date_authenticator.auth).to be false
end
end

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
describe MigrateSpendingProposalsToInvestments do
let(:importer) { MigrateSpendingProposalsToInvestments.new }
let(:importer) { described_class.new }
describe '#import' do

View File

@@ -14,9 +14,9 @@ describe TagSanitizer do
end
it 'sets up a max length for each tag' do
long_tag = '1' * (TagSanitizer.tag_max_length + 100)
long_tag = '1' * (described_class.tag_max_length + 100)
expect(subject.sanitize_tag(long_tag).size).to eq(TagSanitizer.tag_max_length)
expect(subject.sanitize_tag(long_tag).size).to eq(described_class.tag_max_length)
end
end

View File

@@ -7,7 +7,7 @@ describe DeviseMailer do
user = create(:user, locale: "es")
email = I18n.with_locale :en do
DeviseMailer.confirmation_instructions(user, "ABC")
described_class.confirmation_instructions(user, "ABC")
end
expect(email.subject).to include("confirmación")

View File

@@ -8,7 +8,7 @@ describe Mailer do
comment = create(:comment, commentable: proposal)
email = I18n.with_locale :en do
Mailer.comment(comment)
described_class.comment(comment)
end
expect(email.subject).to include("comentado")

View File

@@ -21,9 +21,9 @@ describe Activity do
user = create(:user)
proposal = create(:proposal)
expect{ Activity.log(user, :hide, proposal) }.to change { Activity.count }.by(1)
expect{ described_class.log(user, :hide, proposal) }.to change { described_class.count }.by(1)
activity = Activity.last
activity = described_class.last
expect(activity.user_id).to eq(user.id)
expect(activity.action).to eq("hide")
expect(activity.actionable).to eq(proposal)
@@ -41,9 +41,9 @@ describe Activity do
create(:activity, action: "hide", actionable: create(:comment))
create(:activity, action: "block", actionable: create(:user))
expect(Activity.on(proposal).size).to eq 3
expect(described_class.on(proposal).size).to eq 3
[activity1, activity2, activity3].each do |a|
expect(Activity.on(proposal)).to include(a)
expect(described_class.on(proposal)).to include(a)
end
end
end
@@ -59,10 +59,10 @@ describe Activity do
activity6 = create(:activity, user: user1, action: "valuate", actionable: create(:budget_investment))
create_list(:activity, 3)
expect(Activity.by(user1).size).to eq 6
expect(described_class.by(user1).size).to eq 6
[activity1, activity2, activity3, activity4, activity5, activity6].each do |a|
expect(Activity.by(user1)).to include(a)
expect(described_class.by(user1)).to include(a)
end
end
end
@@ -75,17 +75,17 @@ describe Activity do
on_user = create(:activity, actionable: create(:user))
on_investment = create(:activity, actionable: create(:budget_investment))
expect(Activity.on_proposals.size).to eq 1
expect(Activity.on_debates.size).to eq 1
expect(Activity.on_comments.size).to eq 1
expect(Activity.on_users.size).to eq 1
expect(Activity.on_budget_investments.size).to eq 1
expect(described_class.on_proposals.size).to eq 1
expect(described_class.on_debates.size).to eq 1
expect(described_class.on_comments.size).to eq 1
expect(described_class.on_users.size).to eq 1
expect(described_class.on_budget_investments.size).to eq 1
expect(Activity.on_proposals.first).to eq on_proposal
expect(Activity.on_debates.first).to eq on_debate
expect(Activity.on_comments.first).to eq on_comment
expect(Activity.on_users.first).to eq on_user
expect(Activity.on_budget_investments.first).to eq on_investment
expect(described_class.on_proposals.first).to eq on_proposal
expect(described_class.on_debates.first).to eq on_debate
expect(described_class.on_comments.first).to eq on_comment
expect(described_class.on_users.first).to eq on_user
expect(described_class.on_budget_investments.first).to eq on_investment
end
end

View File

@@ -16,18 +16,18 @@ describe Ahoy::DataSource do
end
it 'should work without data sources' do
ds = Ahoy::DataSource.new
ds = described_class.new
expect(ds.build).to eq x: []
end
it 'should work with single data sources' do
ds = Ahoy::DataSource.new
ds = described_class.new
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count
expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02"], "foo" => [2, 1]
end
it 'should combine data sources' do
ds = Ahoy::DataSource.new
ds = described_class.new
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count
ds.add 'bar', Ahoy::Event.where(name: 'bar').group_by_day(:time).count
expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"], "foo" => [2, 1, 0], "bar" => [1, 0, 2]

View File

@@ -60,7 +60,7 @@ describe Budget::Ballot::Line do
ballot_line2 = create(:budget_ballot_line, ballot: ballot2, investment: investment1)
ballot_line3 = create(:budget_ballot_line, ballot: ballot3, investment: investment2)
ballot_lines_by_investment = Budget::Ballot::Line.by_investment(investment1.id)
ballot_lines_by_investment = described_class.by_investment(investment1.id)
expect(ballot_lines_by_investment).to include ballot_line1
expect(ballot_lines_by_investment).to include ballot_line2

View File

@@ -232,7 +232,7 @@ describe Budget::Investment do
investment1 = create(:budget_investment, administrator_id: 33)
create(:budget_investment)
by_admin = Budget::Investment.by_admin(33)
by_admin = described_class.by_admin(33)
expect(by_admin.size).to eq(1)
expect(by_admin.first).to eq(investment1)
@@ -252,7 +252,7 @@ describe Budget::Investment do
investment2.valuators << valuator2
investment3.valuators << [valuator1, valuator2]
by_valuator = Budget::Investment.by_valuator(valuator1.id)
by_valuator = described_class.by_valuator(valuator1.id)
expect(by_valuator.size).to eq(2)
expect(by_valuator.sort).to eq([investment1, investment3].sort)
@@ -265,7 +265,7 @@ describe Budget::Investment do
investment1 = create(:budget_investment, valuation_finished: true)
investment2 = create(:budget_investment)
valuation_open = Budget::Investment.valuation_open
valuation_open = described_class.valuation_open
expect(valuation_open.size).to eq(1)
expect(valuation_open.first).to eq(investment2)
@@ -278,7 +278,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, administrator: create(:administrator))
investment3 = create(:budget_investment)
without_admin = Budget::Investment.without_admin
without_admin = described_class.without_admin
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(investment3)
@@ -292,7 +292,7 @@ describe Budget::Investment do
investment3 = create(:budget_investment, administrator: create(:administrator))
investment1.valuators << create(:valuator)
managed = Budget::Investment.managed
managed = described_class.managed
expect(managed.size).to eq(1)
expect(managed.first).to eq(investment3)
@@ -308,7 +308,7 @@ describe Budget::Investment do
investment2.valuators << create(:valuator)
investment3.valuators << create(:valuator)
valuating = Budget::Investment.valuating
valuating = described_class.valuating
expect(valuating.size).to eq(1)
expect(valuating.first).to eq(investment2)
@@ -324,7 +324,7 @@ describe Budget::Investment do
investment2.valuators << create(:valuator)
investment3.valuators << create(:valuator)
valuation_finished = Budget::Investment.valuation_finished
valuation_finished = described_class.valuation_finished
expect(valuation_finished.size).to eq(1)
expect(valuation_finished.first).to eq(investment3)
@@ -336,7 +336,7 @@ describe Budget::Investment do
feasible_investment = create(:budget_investment, :feasible)
create(:budget_investment)
expect(Budget::Investment.feasible).to eq [feasible_investment]
expect(described_class.feasible).to eq [feasible_investment]
end
end
@@ -345,7 +345,7 @@ describe Budget::Investment do
unfeasible_investment = create(:budget_investment, :unfeasible)
create(:budget_investment, :feasible)
expect(Budget::Investment.unfeasible).to eq [unfeasible_investment]
expect(described_class.unfeasible).to eq [unfeasible_investment]
end
end
@@ -355,7 +355,7 @@ describe Budget::Investment do
undecided_investment = create(:budget_investment, :undecided)
feasible_investment = create(:budget_investment, :feasible)
expect(Budget::Investment.not_unfeasible.sort).to eq [undecided_investment, feasible_investment].sort
expect(described_class.not_unfeasible.sort).to eq [undecided_investment, feasible_investment].sort
end
end
@@ -365,7 +365,7 @@ describe Budget::Investment do
undecided_investment = create(:budget_investment, :undecided)
feasible_investment = create(:budget_investment, :feasible)
expect(Budget::Investment.undecided).to eq [undecided_investment]
expect(described_class.undecided).to eq [undecided_investment]
end
end
@@ -374,7 +374,7 @@ describe Budget::Investment do
selected_investment = create(:budget_investment, :selected)
unselected_investment = create(:budget_investment, :unselected)
expect(Budget::Investment.selected).to eq [selected_investment]
expect(described_class.selected).to eq [selected_investment]
end
end
@@ -385,7 +385,7 @@ describe Budget::Investment do
unselected_undecided_investment = create(:budget_investment, :unselected, :undecided)
unselected_feasible_investment = create(:budget_investment, :unselected, :feasible)
expect(Budget::Investment.unselected.sort).to eq [unselected_undecided_investment, unselected_feasible_investment].sort
expect(described_class.unselected.sort).to eq [unselected_undecided_investment, unselected_feasible_investment].sort
end
end
end
@@ -399,7 +399,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, :feasible, budget: budget)
investment3 = create(:budget_investment, :unfeasible, budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, {}, :feasible)
results = described_class.apply_filters_and_search(budget, {}, :feasible)
expect(results).to include investment1
expect(results).to include investment2
@@ -411,7 +411,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, :unfeasible, budget: budget)
investment3 = create(:budget_investment, :feasible, budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, {}, :unfeasible)
results = described_class.apply_filters_and_search(budget, {}, :unfeasible)
expect(results).to include investment1
expect(results).to include investment2
@@ -425,7 +425,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, :feasible, :selected, budget: budget)
investment3 = create(:budget_investment, :feasible, :unselected, budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, {}, :selected)
results = described_class.apply_filters_and_search(budget, {}, :selected)
expect(results).to include investment1
expect(results).to include investment2
@@ -439,7 +439,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, :feasible, :unselected, budget: budget)
investment3 = create(:budget_investment, :feasible, :selected, budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, {}, :unselected)
results = described_class.apply_filters_and_search(budget, {}, :unselected)
expect(results).to include investment1
expect(results).to include investment2
@@ -456,7 +456,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, heading: heading1, budget: budget)
investment3 = create(:budget_investment, heading: heading2, budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, heading_id: heading1.id)
results = described_class.apply_filters_and_search(budget, heading_id: heading1.id)
expect(results).to include investment1
expect(results).to include investment2
@@ -468,7 +468,7 @@ describe Budget::Investment do
investment2 = create(:budget_investment, title: "improved health", budget: budget)
investment3 = create(:budget_investment, title: "finance", budget: budget)
results = Budget::Investment.apply_filters_and_search(budget, search: "health")
results = described_class.apply_filters_and_search(budget, search: "health")
expect(results).to include investment1
expect(results).to include investment2
@@ -482,10 +482,10 @@ describe Budget::Investment do
it "searches by tags" do
investment = create(:budget_investment, tag_list: 'Latina')
results = Budget::Investment.search('Latina')
results = described_class.search('Latina')
expect(results.first).to eq(investment)
results = Budget::Investment.search('Latin')
results = described_class.search('Latin')
expect(results.first).to eq(investment)
end
end
@@ -585,9 +585,9 @@ describe Budget::Investment do
most_voted = create(:budget_investment, cached_votes_up: 10)
some_votes = create(:budget_investment, cached_votes_up: 5)
expect(Budget::Investment.sort_by_confidence_score.first).to eq most_voted
expect(Budget::Investment.sort_by_confidence_score.second).to eq some_votes
expect(Budget::Investment.sort_by_confidence_score.third).to eq least_voted
expect(described_class.sort_by_confidence_score.first).to eq most_voted
expect(described_class.sort_by_confidence_score.second).to eq some_votes
expect(described_class.sort_by_confidence_score.third).to eq least_voted
end
it "should order by confidence_score and then by id" do
@@ -596,10 +596,10 @@ describe Budget::Investment do
most_voted2 = create(:budget_investment, cached_votes_up: 10)
least_voted2 = create(:budget_investment, cached_votes_up: 1)
expect(Budget::Investment.sort_by_confidence_score.first).to eq most_voted2
expect(Budget::Investment.sort_by_confidence_score.second).to eq most_voted
expect(Budget::Investment.sort_by_confidence_score.third).to eq least_voted2
expect(Budget::Investment.sort_by_confidence_score.fourth).to eq least_voted
expect(described_class.sort_by_confidence_score.first).to eq most_voted2
expect(described_class.sort_by_confidence_score.second).to eq most_voted
expect(described_class.sort_by_confidence_score.third).to eq least_voted2
expect(described_class.sort_by_confidence_score.fourth).to eq least_voted
end
end
end
@@ -642,8 +642,8 @@ describe Budget::Investment do
inv2 = create(:budget_investment)
create(:vote, votable: inv1)
expect(Budget::Investment.with_supports).to include(inv1)
expect(Budget::Investment.with_supports).to_not include(inv2)
expect(described_class.with_supports).to include(inv1)
expect(described_class.with_supports).to_not include(inv2)
end
end

View File

@@ -129,8 +129,8 @@ describe Comment do
create(:comment, administrator_id: create(:administrator).id)
create(:comment, moderator_id: create(:moderator).id)
expect(Comment.not_as_admin_or_moderator.size).to eq(1)
expect(Comment.not_as_admin_or_moderator.first).to eq(comment1)
expect(described_class.not_as_admin_or_moderator.size).to eq(1)
expect(described_class.not_as_admin_or_moderator.first).to eq(comment1)
end
end
@@ -138,54 +138,54 @@ describe Comment do
it "returns comments" do
comment = create(:comment)
expect(Comment.public_for_api).to include(comment)
expect(described_class.public_for_api).to include(comment)
end
it "does not return hidden comments" do
hidden_comment = create(:comment, :hidden)
expect(Comment.public_for_api).not_to include(hidden_comment)
expect(described_class.public_for_api).not_to include(hidden_comment)
end
it "returns comments on debates" do
debate = create(:debate)
comment = create(:comment, commentable: debate)
expect(Comment.public_for_api).to include(comment)
expect(described_class.public_for_api).to include(comment)
end
it "does not return comments on hidden debates" do
hidden_debate = create(:debate, :hidden)
comment = create(:comment, commentable: hidden_debate)
expect(Comment.public_for_api).not_to include(comment)
expect(described_class.public_for_api).not_to include(comment)
end
it "returns comments on proposals" do
proposal = create(:proposal)
comment = create(:comment, commentable: proposal)
expect(Comment.public_for_api).to include(comment)
expect(described_class.public_for_api).to include(comment)
end
it "does not return comments on hidden proposals" do
hidden_proposal = create(:proposal, :hidden)
comment = create(:comment, commentable: hidden_proposal)
expect(Comment.public_for_api).not_to include(comment)
expect(described_class.public_for_api).not_to include(comment)
end
it 'does not return comments on elements which are not debates or proposals' do
budget_investment = create(:budget_investment)
comment = create(:comment, commentable: budget_investment)
expect(Comment.public_for_api).not_to include(comment)
expect(described_class.public_for_api).not_to include(comment)
end
it 'does not return comments with no commentable' do
comment = build(:comment, commentable: nil).save!(validate: false)
expect(Comment.public_for_api).to_not include(comment)
expect(described_class.public_for_api).to_not include(comment)
end
end
end

View File

@@ -445,27 +445,27 @@ describe Debate do
it "searches by title" do
debate = create(:debate, title: 'save the world')
results = Debate.search('save the world')
results = described_class.search('save the world')
expect(results).to eq([debate])
end
it "searches by description" do
debate = create(:debate, description: 'in order to save the world one must think about...')
results = Debate.search('one must think')
results = described_class.search('one must think')
expect(results).to eq([debate])
end
it "searches by author name" do
author = create(:user, username: 'Danny Trejo')
debate = create(:debate, author: author)
results = Debate.search('Danny')
results = described_class.search('Danny')
expect(results).to eq([debate])
end
it "searches by geozone" do
geozone = create(:geozone, name: 'California')
debate = create(:debate, geozone: geozone)
results = Debate.search('California')
results = described_class.search('California')
expect(results).to eq([debate])
end
@@ -476,13 +476,13 @@ describe Debate do
it "searches word stems" do
debate = create(:debate, title: 'limpiar')
results = Debate.search('limpiará')
results = described_class.search('limpiará')
expect(results).to eq([debate])
results = Debate.search('limpiémos')
results = described_class.search('limpiémos')
expect(results).to eq([debate])
results = Debate.search('limpió')
results = described_class.search('limpió')
expect(results).to eq([debate])
end
@@ -493,15 +493,15 @@ describe Debate do
it "searches with accents" do
debate = create(:debate, title: 'difusión')
results = Debate.search('difusion')
results = described_class.search('difusion')
expect(results).to eq([debate])
debate2 = create(:debate, title: 'estadisticas')
results = Debate.search('estadísticas')
results = described_class.search('estadísticas')
expect(results).to eq([debate2])
debate3 = create(:debate, title: 'público')
results = Debate.search('publico')
results = described_class.search('publico')
expect(results).to eq([debate3])
end
@@ -511,11 +511,11 @@ describe Debate do
it "searches case insensite" do
debate = create(:debate, title: 'SHOUT')
results = Debate.search('shout')
results = described_class.search('shout')
expect(results).to eq([debate])
debate2 = create(:debate, title: "scream")
results = Debate.search("SCREAM")
results = described_class.search("SCREAM")
expect(results).to eq([debate2])
end
end
@@ -524,10 +524,10 @@ describe Debate do
it "searches by tags" do
debate = create(:debate, tag_list: 'Latina')
results = Debate.search('Latina')
results = described_class.search('Latina')
expect(results.first).to eq(debate)
results = Debate.search('Latin')
results = described_class.search('Latin')
expect(results.first).to eq(debate)
end
end
@@ -538,7 +538,7 @@ describe Debate do
debate_description = create(:debate, description: 'stop corruption')
debate_title = create(:debate, title: 'stop corruption')
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(debate_title)
expect(results.second).to eq(debate_description)
@@ -550,7 +550,7 @@ describe Debate do
title_most_voted = create(:debate, title: 'stop corruption', cached_votes_up: 10)
description_most_voted = create(:debate, description: 'stop corruption', cached_votes_up: 10)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(title_most_voted)
expect(results.second).to eq(title_some_votes)
@@ -562,7 +562,7 @@ describe Debate do
exact_title_few_votes = create(:debate, title: 'stop corruption', cached_votes_up: 5)
similar_title_many_votes = create(:debate, title: 'stop some of the corruption', cached_votes_up: 500)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(exact_title_few_votes)
expect(results.second).to eq(similar_title_many_votes)
@@ -581,7 +581,7 @@ describe Debate do
highest_score.update_column(:hot_score, 100)
average_score.update_column(:hot_score, 10)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(average_score)
expect(results.second).to eq(highest_score)
@@ -603,7 +603,7 @@ describe Debate do
highest_score.update_column(:confidence_score, 100)
average_score.update_column(:confidence_score, 10)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(average_score)
expect(results.second).to eq(highest_score)
@@ -621,7 +621,7 @@ describe Debate do
newest = create(:debate, title: 'stop corruption', cached_votes_up: 2, created_at: Time.current)
oldest = create(:debate, title: 'stop corruption', cached_votes_up: 3, created_at: 1.month.ago)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(oldest)
expect(results.second).to eq(newest)
@@ -639,7 +639,7 @@ describe Debate do
most_commented = create(:debate, title: 'stop corruption', cached_votes_up: 2, comments_count: 100)
some_comments = create(:debate, title: 'stop corruption', cached_votes_up: 3, comments_count: 10)
results = Debate.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(some_comments)
expect(results.second).to eq(most_commented)
@@ -659,28 +659,28 @@ describe Debate do
it "no words match" do
debate = create(:debate, title: 'save world')
results = Debate.search('destroy planet')
results = described_class.search('destroy planet')
expect(results).to eq([])
end
it "too many typos" do
debate = create(:debate, title: 'fantastic')
results = Debate.search('frantac')
results = described_class.search('frantac')
expect(results).to eq([])
end
it "too much stemming" do
debate = create(:debate, title: 'reloj')
results = Debate.search('superrelojimetro')
results = described_class.search('superrelojimetro')
expect(results).to eq([])
end
it "empty" do
debate = create(:debate, title: 'great')
results = Debate.search('')
results = described_class.search('')
expect(results).to eq([])
end
@@ -690,12 +690,12 @@ describe Debate do
describe "#last_week" do
it "should return debates created this week" do
debate = create(:debate)
expect(Debate.last_week.all).to include debate
expect(described_class.last_week.all).to include debate
end
it "should not show debates created more than a week ago" do
debate = create(:debate, created_at: 8.days.ago)
expect(Debate.last_week.all).to_not include debate
expect(described_class.last_week.all).to_not include debate
end
end
@@ -708,12 +708,12 @@ describe Debate do
describe 'public_for_api scope' do
it 'returns debates' do
debate = create(:debate)
expect(Debate.public_for_api).to include(debate)
expect(described_class.public_for_api).to include(debate)
end
it 'does not return hidden debates' do
debate = create(:debate, :hidden)
expect(Debate.public_for_api).to_not include(debate)
expect(described_class.public_for_api).to_not include(debate)
end
end
@@ -724,7 +724,7 @@ describe Debate do
it "Should not return any debates when user has not interests" do
create(:debate)
expect(Debate.recommendations(user).size).to eq 0
expect(described_class.recommendations(user).size).to eq 0
end
it "Should return debates ordered by cached_votes_total" do
@@ -734,7 +734,7 @@ describe Debate do
proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user)
result = Debate.recommendations(user).sort_by_recommendations
result = described_class.recommendations(user).sort_by_recommendations
expect(result.first).to eq debate3
expect(result.second).to eq debate2
@@ -747,7 +747,7 @@ describe Debate do
proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user)
result = Debate.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq 1
expect(result).to eq [debate1]
@@ -759,7 +759,7 @@ describe Debate do
proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user)
result = Debate.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq 1
expect(result).to eq [debate2]

View File

@@ -81,14 +81,14 @@ describe DirectMessage do
direct_message2 = create(:direct_message, created_at: Time.now.utc)
direct_message3 = create(:direct_message, created_at: Time.now.utc.end_of_day)
expect(DirectMessage.today.count).to eq 3
expect(described_class.today.count).to eq 3
end
it "should not return direct messages created another day" do
direct_message1 = create(:direct_message, created_at: 1.day.ago)
direct_message2 = create(:direct_message, created_at: 1.day.from_now)
expect(DirectMessage.today.count).to eq 0
expect(described_class.today.count).to eq 0
end
end

View File

@@ -8,15 +8,15 @@ describe Flag do
describe '.flag' do
it 'creates a flag when there is none' do
expect { described_class.flag(user, comment) }.to change{ Flag.count }.by(1)
expect(Flag.last.user).to eq(user)
expect(Flag.last.flaggable).to eq(comment)
expect { described_class.flag(user, comment) }.to change{ described_class.count }.by(1)
expect(described_class.last.user).to eq(user)
expect(described_class.last.flaggable).to eq(comment)
end
it 'does nothing if the flag already exists' do
described_class.flag(user, comment)
expect(described_class.flag(user, comment)).to eq(false)
expect(Flag.by_user_and_flaggable(user, comment).count).to eq(1)
expect(described_class.by_user_and_flaggable(user, comment).count).to eq(1)
end
it 'increases the flag count' do
@@ -33,7 +33,7 @@ describe Flag do
before(:each) { described_class.flag(user, comment) }
it 'removes an existing flag' do
expect { described_class.unflag(user, comment) }.to change{ Flag.count }.by(-1)
expect { described_class.unflag(user, comment) }.to change{ described_class.count }.by(-1)
end
it 'decreases the flag count' do

View File

@@ -17,7 +17,7 @@ describe Legislation::Question do
expect do
question.destroy
end.to change { Legislation::Question.count }.by(-1)
end.to change { described_class.count }.by(-1)
end
example "when it has options but no answers" do
@@ -26,7 +26,7 @@ describe Legislation::Question do
expect do
question.destroy
end.to change { Legislation::Question.count }.by(-1)
end.to change { described_class.count }.by(-1)
end
example "when it has options and answers" do
@@ -37,7 +37,7 @@ describe Legislation::Question do
expect do
question.destroy
end.to change { Legislation::Question.count }.by(-1)
end.to change { described_class.count }.by(-1)
end
end

View File

@@ -5,7 +5,7 @@ describe Notification do
describe "#unread (scope)" do
it "returns only unread notifications" do
2.times { create :notification }
expect(Notification.unread.size).to be 2
expect(described_class.unread.size).to be 2
end
end
@@ -14,7 +14,7 @@ describe Notification do
old_notification = create :notification
new_notification = create :notification
sorted_notifications = Notification.recent
sorted_notifications = described_class.recent
expect(sorted_notifications.size).to be 2
expect(sorted_notifications.first).to eq new_notification
expect(sorted_notifications.last).to eq old_notification
@@ -23,8 +23,8 @@ describe Notification do
describe "#for_render (scope)" do
it "returns notifications including notifiable and user" do
expect(Notification).to receive(:includes).with(:notifiable).exactly(:once)
Notification.for_render
expect(described_class).to receive(:includes).with(:notifiable).exactly(:once)
described_class.for_render
end
end
@@ -40,10 +40,10 @@ describe Notification do
describe "#mark_as_read" do
it "destroys notification" do
notification = create :notification
expect(Notification.unread.size).to eq 1
expect(described_class.unread.size).to eq 1
notification.mark_as_read
expect(Notification.unread.size).to eq 0
expect(described_class.unread.size).to eq 0
end
end

View File

@@ -28,13 +28,13 @@ describe Officing::Residence do
describe "allowed age" do
it "should not be valid if user is under allowed age" do
allow_any_instance_of(Officing::Residence).to receive(:date_of_birth).and_return(15.years.ago)
allow_any_instance_of(described_class).to receive(:date_of_birth).and_return(15.years.ago)
expect(residence).to_not be_valid
expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate")
end
it "should be valid if user is above allowed age" do
allow_any_instance_of(Officing::Residence).to receive(:date_of_birth).and_return(16.years.ago)
allow_any_instance_of(described_class).to receive(:date_of_birth).and_return(16.years.ago)
expect(residence).to be_valid
expect(residence.errors[:year_of_birth]).to be_empty
end
@@ -44,12 +44,12 @@ describe Officing::Residence do
describe "new" do
it "should upcase document number" do
residence = Officing::Residence.new(document_number: "x1234567z")
residence = described_class.new(document_number: "x1234567z")
expect(residence.document_number).to eq("X1234567Z")
end
it "should remove all characters except numbers and letters" do
residence = Officing::Residence.new(document_number: " 12.345.678 - B")
residence = described_class.new(document_number: " 12.345.678 - B")
expect(residence.document_number).to eq("12345678B")
end
end

View File

@@ -48,24 +48,24 @@ describe Organization do
let!(:organization) { create(:organization, name: "Watershed", user: create(:user, phone_number: "333")) }
it "returns no results if search term is empty" do
expect(Organization.search(" ").size).to eq(0)
expect(described_class.search(" ").size).to eq(0)
end
it "finds fuzzily by name" do
expect(Organization.search("Greenpeace").size).to eq 0
search = Organization.search("Tershe")
expect(described_class.search("Greenpeace").size).to eq 0
search = described_class.search("Tershe")
expect(search.size).to eq 1
expect(search.first).to eq organization
end
scenario "finds by users email" do
search = Organization.search(organization.user.email)
search = described_class.search(organization.user.email)
expect(search.size).to eq 1
expect(search.first).to eq organization
end
scenario "finds by users phone number" do
search = Organization.search(organization.user.phone_number)
search = described_class.search(organization.user.phone_number)
expect(search.size).to eq 1
expect(search.first).to eq organization
end

View File

@@ -18,9 +18,9 @@ describe Poll::Booth do
booth1 = create(:poll_booth, name: "Booth number 1", location: "City center")
booth2 = create(:poll_booth, name: "Central", location: "Town hall")
expect(Poll::Booth.search("number")).to eq([booth1])
expect(Poll::Booth.search("hall")).to eq([booth2])
expect(Poll::Booth.search("cen").size).to eq 2
expect(described_class.search("number")).to eq([booth1])
expect(described_class.search("hall")).to eq([booth2])
expect(described_class.search("cen").size).to eq 2
end
end
@@ -39,9 +39,9 @@ describe Poll::Booth do
create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll)
create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll)
expect(Poll::Booth.available).to include(booth_for_current_poll)
expect(Poll::Booth.available).to include(booth_for_incoming_poll)
expect(Poll::Booth.available).to_not include(booth_for_expired_poll)
expect(described_class.available).to include(booth_for_current_poll)
expect(described_class.available).to include(booth_for_incoming_poll)
expect(described_class.available).to_not include(booth_for_expired_poll)
end
end

View File

@@ -72,7 +72,7 @@ describe Poll do
incoming = create(:poll, :incoming)
expired = create(:poll, :expired)
current_or_incoming = Poll.current_or_incoming
current_or_incoming = described_class.current_or_incoming
expect(current_or_incoming).to include(current)
expect(current_or_incoming).to include(incoming)
@@ -87,7 +87,7 @@ describe Poll do
expired = create(:poll, :expired)
recounting = create(:poll, :recounting)
recounting_polls = Poll.recounting
recounting_polls = described_class.recounting
expect(recounting_polls).to_not include(current)
expect(recounting_polls).to_not include(incoming)
@@ -103,7 +103,7 @@ describe Poll do
expired = create(:poll, :expired)
recounting = create(:poll, :recounting)
current_or_recounting_or_incoming = Poll.current_or_recounting_or_incoming
current_or_recounting_or_incoming = described_class.current_or_recounting_or_incoming
expect(current_or_recounting_or_incoming).to include(current)
expect(current_or_recounting_or_incoming).to include(recounting)
@@ -159,16 +159,16 @@ describe Poll do
describe 'class method' do
it "returns no polls for non-users and level 1 users" do
expect(Poll.answerable_by(nil)).to be_empty
expect(Poll.answerable_by(level1)).to be_empty
expect(described_class.answerable_by(nil)).to be_empty
expect(described_class.answerable_by(level1)).to be_empty
end
it "returns unrestricted polls for level 2 users" do
expect(Poll.answerable_by(level2).to_a).to eq([current_poll])
expect(described_class.answerable_by(level2).to_a).to eq([current_poll])
end
it "returns restricted & unrestricted polls for level 2 users of the correct geozone" do
list = Poll.answerable_by(level2_from_geozone)
list = described_class.answerable_by(level2_from_geozone)
.order(:geozone_restricted)
expect(list.to_a).to eq([current_poll, current_restricted_poll])
end

View File

@@ -81,7 +81,7 @@ describe Poll::Shift do
create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment1, date: Date.tomorrow)
expect { Poll::Shift.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2)
expect { described_class.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2)
end
it "should create final officer_assignments" do

View File

@@ -11,7 +11,7 @@ describe Poll::Stats do
3.times {create(:poll_voter, poll: poll, origin: 'booth')}
create(:poll_voter, poll: poll)
create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id)
stats = Poll::Stats.new(poll).generate
stats = described_class.new(poll).generate
expect(stats[:total_participants]).to eq(5)
expect(stats[:total_participants_web]).to eq(2)

View File

@@ -117,7 +117,7 @@ describe Poll::Voter do
voter2 = create(:poll_voter, origin: "web")
voter3 = create(:poll_voter, origin: "booth")
web_voters = Poll::Voter.web
web_voters = described_class.web
expect(web_voters.count).to eq(2)
expect(web_voters).to include(voter1)
@@ -132,7 +132,7 @@ describe Poll::Voter do
voter2 = create(:poll_voter, origin: "booth")
voter3 = create(:poll_voter, origin: "web")
booth_voters = Poll::Voter.booth
booth_voters = described_class.booth
expect(booth_voters.count).to eq(2)
expect(booth_voters).to include(voter1)

View File

@@ -27,20 +27,20 @@ describe ProposalNotification do
proposal = create(:proposal)
notification = create(:proposal_notification, proposal: proposal)
expect(ProposalNotification.public_for_api).to include(notification)
expect(described_class.public_for_api).to include(notification)
end
it "blocks proposal notifications whose proposal is hidden" do
proposal = create(:proposal, :hidden)
notification = create(:proposal_notification, proposal: proposal)
expect(ProposalNotification.public_for_api).not_to include(notification)
expect(described_class.public_for_api).not_to include(notification)
end
it "blocks proposal notifications without proposal" do
proposal = build(:proposal_notification, proposal: nil).save!(validate: false)
expect(ProposalNotification.public_for_api).not_to include(notification)
expect(described_class.public_for_api).not_to include(notification)
end
end

View File

@@ -445,39 +445,39 @@ describe Proposal do
it "searches by title" do
proposal = create(:proposal, title: 'save the world')
results = Proposal.search('save the world')
results = described_class.search('save the world')
expect(results).to eq([proposal])
end
it "searches by summary" do
proposal = create(:proposal, summary: 'basically...')
results = Proposal.search('basically')
results = described_class.search('basically')
expect(results).to eq([proposal])
end
it "searches by description" do
proposal = create(:proposal, description: 'in order to save the world one must think about...')
results = Proposal.search('one must think')
results = described_class.search('one must think')
expect(results).to eq([proposal])
end
it "searches by question" do
proposal = create(:proposal, question: 'to be or not to be')
results = Proposal.search('to be or not to be')
results = described_class.search('to be or not to be')
expect(results).to eq([proposal])
end
it "searches by author name" do
author = create(:user, username: 'Danny Trejo')
proposal = create(:proposal, author: author)
results = Proposal.search('Danny')
results = described_class.search('Danny')
expect(results).to eq([proposal])
end
it "searches by geozone" do
geozone = create(:geozone, name: 'California')
proposal = create(:proposal, geozone: geozone)
results = Proposal.search('California')
results = described_class.search('California')
expect(results).to eq([proposal])
end
@@ -488,13 +488,13 @@ describe Proposal do
it "searches word stems" do
proposal = create(:proposal, summary: 'Economía')
results = Proposal.search('economía')
results = described_class.search('economía')
expect(results).to eq([proposal])
results = Proposal.search('econo')
results = described_class.search('econo')
expect(results).to eq([proposal])
results = Proposal.search('eco')
results = described_class.search('eco')
expect(results).to eq([proposal])
end
@@ -504,15 +504,15 @@ describe Proposal do
it "searches with accents" do
proposal = create(:proposal, summary: 'difusión')
results = Proposal.search('difusion')
results = described_class.search('difusion')
expect(results).to eq([proposal])
proposal2 = create(:proposal, summary: 'estadisticas')
results = Proposal.search('estadísticas')
results = described_class.search('estadísticas')
expect(results).to eq([proposal2])
proposal3 = create(:proposal, summary: 'público')
results = Proposal.search('publico')
results = described_class.search('publico')
expect(results).to eq([proposal3])
end
end
@@ -521,11 +521,11 @@ describe Proposal do
it "searches case insensite" do
proposal = create(:proposal, title: 'SHOUT')
results = Proposal.search('shout')
results = described_class.search('shout')
expect(results).to eq([proposal])
proposal2 = create(:proposal, title: "scream")
results = Proposal.search("SCREAM")
results = described_class.search("SCREAM")
expect(results).to eq([proposal2])
end
end
@@ -534,10 +534,10 @@ describe Proposal do
it "searches by tags" do
proposal = create(:proposal, tag_list: 'Latina')
results = Proposal.search('Latina')
results = described_class.search('Latina')
expect(results.first).to eq(proposal)
results = Proposal.search('Latin')
results = described_class.search('Latin')
expect(results.first).to eq(proposal)
end
end
@@ -550,7 +550,7 @@ describe Proposal do
proposal_description = create(:proposal, description: 'stop corruption')
proposal_summary = create(:proposal, summary: 'stop corruption')
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(proposal_title)
expect(results.second).to eq(proposal_question)
@@ -565,7 +565,7 @@ describe Proposal do
summary_most_voted = create(:proposal, summary: 'stop corruption', cached_votes_up: 10)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(title_most_voted)
expect(results.second).to eq(title_some_votes)
@@ -577,7 +577,7 @@ describe Proposal do
exact_title_few_votes = create(:proposal, title: 'stop corruption', cached_votes_up: 5)
similar_title_many_votes = create(:proposal, title: 'stop some of the corruption', cached_votes_up: 500)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(exact_title_few_votes)
expect(results.second).to eq(similar_title_many_votes)
@@ -596,7 +596,7 @@ describe Proposal do
highest_score.update_column(:hot_score, 100)
average_score.update_column(:hot_score, 10)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(average_score)
expect(results.second).to eq(highest_score)
@@ -618,7 +618,7 @@ describe Proposal do
highest_score.update_column(:confidence_score, 100)
average_score.update_column(:confidence_score, 10)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(average_score)
expect(results.second).to eq(highest_score)
@@ -636,7 +636,7 @@ describe Proposal do
newest = create(:proposal, title: 'stop corruption', cached_votes_up: 2, created_at: Time.current)
oldest = create(:proposal, title: 'stop corruption', cached_votes_up: 3, created_at: 1.month.ago)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(oldest)
expect(results.second).to eq(newest)
@@ -654,7 +654,7 @@ describe Proposal do
most_commented = create(:proposal, title: 'stop corruption', cached_votes_up: 2, comments_count: 100)
some_comments = create(:proposal, title: 'stop corruption', cached_votes_up: 3, comments_count: 10)
results = Proposal.search('stop corruption')
results = described_class.search('stop corruption')
expect(results.first).to eq(some_comments)
expect(results.second).to eq(most_commented)
@@ -674,28 +674,28 @@ describe Proposal do
it "no words match" do
create(:proposal, title: 'save world')
results = Proposal.search('destroy planet')
results = described_class.search('destroy planet')
expect(results).to eq([])
end
it "too many typos" do
create(:proposal, title: 'fantastic')
results = Proposal.search('frantac')
results = described_class.search('frantac')
expect(results).to eq([])
end
it "too much stemming" do
create(:proposal, title: 'reloj')
results = Proposal.search('superrelojimetro')
results = described_class.search('superrelojimetro')
expect(results).to eq([])
end
it "empty" do
create(:proposal, title: 'great')
results = Proposal.search('')
results = described_class.search('')
expect(results).to eq([])
end
@@ -705,12 +705,12 @@ describe Proposal do
describe "#last_week" do
it "should return proposals created this week" do
proposal = create(:proposal)
expect(Proposal.last_week).to include(proposal)
expect(described_class.last_week).to include(proposal)
end
it "should not return proposals created more than a week ago" do
proposal = create(:proposal, created_at: 8.days.ago)
expect(Proposal.last_week).to_not include(proposal)
expect(described_class.last_week).to_not include(proposal)
end
end
@@ -722,14 +722,14 @@ describe Proposal do
create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture')
expect(Proposal.for_summary.values.flatten).to include(proposal)
expect(described_class.for_summary.values.flatten).to include(proposal)
end
it "should not return proposals tagged without a category" do
create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'parks')
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
expect(described_class.for_summary.values.flatten).to_not include(proposal)
end
end
@@ -739,27 +739,27 @@ describe Proposal do
california = create(:geozone, name: 'california')
proposal = create(:proposal, geozone: california)
expect(Proposal.for_summary.values.flatten).to include(proposal)
expect(described_class.for_summary.values.flatten).to include(proposal)
end
it "should not return proposals without a geozone" do
create(:geozone, name: 'california')
proposal = create(:proposal)
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
expect(described_class.for_summary.values.flatten).to_not include(proposal)
end
end
it "should return proposals created this week" do
create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture')
expect(Proposal.for_summary.values.flatten).to include(proposal)
expect(described_class.for_summary.values.flatten).to include(proposal)
end
it "should not return proposals created more than a week ago" do
create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture', created_at: 8.days.ago)
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
expect(described_class.for_summary.values.flatten).to_not include(proposal)
end
it "should order proposals by votes" do
@@ -768,7 +768,7 @@ describe Proposal do
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10)
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 5)
results = Proposal.for_summary.values.flatten
results = described_class.for_summary.values.flatten
expect(results.first.confidence_score).to be(10)
expect(results.second.confidence_score).to be(5)
@@ -784,7 +784,7 @@ describe Proposal do
culture_proposal = create(:proposal, tag_list: 'culture')
social_proposal = create(:proposal, tag_list: 'social services')
results = Proposal.for_summary.values.flatten
results = described_class.for_summary.values.flatten
expect(results.first).to eq(culture_proposal)
expect(results.second).to eq(health_proposal)
@@ -803,7 +803,7 @@ describe Proposal do
proposal1.update_column(:confidence_score, 10)
proposal2.update_column(:confidence_score, 9)
expect(Proposal.for_summary).to include('culture' => [proposal1, proposal2], 'health' => [proposal3])
expect(described_class.for_summary).to include('culture' => [proposal1, proposal2], 'health' => [proposal3])
end
end
@@ -823,14 +823,14 @@ describe Proposal do
end
it "scope retired" do
retired = Proposal.retired
retired = described_class.retired
expect(retired.size).to eq(1)
expect(retired.first).to eq(proposal2)
end
it "scope not_retired" do
not_retired = Proposal.not_retired
not_retired = described_class.not_retired
expect(not_retired.size).to eq(1)
expect(not_retired.first).to eq(proposal1)
@@ -847,14 +847,14 @@ describe Proposal do
end
it "scope archived" do
archived = Proposal.archived
archived = described_class.archived
expect(archived.size).to eq(1)
expect(archived.first).to eq(archived_proposal)
end
it "scope archived" do
not_archived = Proposal.not_archived
not_archived = described_class.not_archived
expect(not_archived.size).to eq(1)
expect(not_archived.first).to eq(new_proposal)
@@ -864,12 +864,12 @@ describe Proposal do
describe 'public_for_api scope' do
it 'returns proposals' do
proposal = create(:proposal)
expect(Proposal.public_for_api).to include(proposal)
expect(described_class.public_for_api).to include(proposal)
end
it 'does not return hidden proposals' do
proposal = create(:proposal, :hidden)
expect(Proposal.public_for_api).to_not include(proposal)
expect(described_class.public_for_api).to_not include(proposal)
end
end
@@ -903,7 +903,7 @@ describe Proposal do
it "Should not return any proposals when user has not interests" do
create(:proposal)
expect(Proposal.recommendations(user).size).to eq 0
expect(described_class.recommendations(user).size).to eq 0
end
it "Should return proposals ordered by cached_votes_up" do
@@ -913,7 +913,7 @@ describe Proposal do
proposal4 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal4, user: user)
result = Proposal.recommendations(user).sort_by_recommendations
result = described_class.recommendations(user).sort_by_recommendations
expect(result.first).to eq proposal3
expect(result.second).to eq proposal2
@@ -926,7 +926,7 @@ describe Proposal do
proposal3 = create(:proposal, tag_list: "Politics")
create(:follow, followable: proposal1, user: user)
result = Proposal.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq 1
expect(result).to eq [proposal2]
@@ -936,7 +936,7 @@ describe Proposal do
proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user)
result = Proposal.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq 0
end
@@ -947,7 +947,7 @@ describe Proposal do
proposal3 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal3, user: user)
result = Proposal.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq 1
expect(result).to eq [proposal2]
@@ -959,7 +959,7 @@ describe Proposal do
archived_proposal = create(:proposal, :archived)
create(:follow, followable: proposal1, user: user)
result = Proposal.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq(1)
expect(result).to eq([proposal2])
end
@@ -971,7 +971,7 @@ describe Proposal do
create(:vote, votable: proposal1, voter: user)
create(:follow, followable: proposal2, user: user)
result = Proposal.recommendations(user)
result = described_class.recommendations(user)
expect(result.size).to eq(1)
expect(result).to eq([proposal3])
end

View File

@@ -29,7 +29,7 @@ describe RelatedContent do
let(:related_content) { build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) }
it 'creates an opposite related_content' do
expect { related_content.save }.to change { RelatedContent.count }.by(2)
expect { related_content.save }.to change { described_class.count }.by(2)
expect(related_content.opposite_related_content.child_relationable_id).to eq(parent_relationable.id)
expect(related_content.opposite_related_content.child_relationable_type).to eq(parent_relationable.class.name)
expect(related_content.opposite_related_content.parent_relationable_id).to eq(child_relationable.id)

View File

@@ -13,19 +13,19 @@ describe Verification::Residence do
describe "dates" do
it "should be valid with a valid date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980")
residence = described_class.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980")
expect(residence.errors[:date_of_birth].size).to eq(0)
end
it "should not be valid without a date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "", "date_of_birth(2i)" => "", "date_of_birth(1i)" => "")
residence = described_class.new("date_of_birth(3i)" => "", "date_of_birth(2i)" => "", "date_of_birth(1i)" => "")
expect(residence).to_not be_valid
expect(residence.errors[:date_of_birth]).to include("can't be blank")
end
end
it "should validate user has allowed age" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1",
residence = described_class.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => 5.years.ago.year.to_s)
expect(residence).to_not be_valid
@@ -52,12 +52,12 @@ describe Verification::Residence do
describe "new" do
it "should upcase document number" do
residence = Verification::Residence.new(document_number: "x1234567z")
residence = described_class.new(document_number: "x1234567z")
expect(residence.document_number).to eq("X1234567Z")
end
it "should remove all characters except numbers and letters" do
residence = Verification::Residence.new(document_number: " 12.345.678 - B")
residence = described_class.new(document_number: " 12.345.678 - B")
expect(residence.document_number).to eq("12345678B")
end
end

View File

@@ -2,36 +2,36 @@ require 'rails_helper'
describe Setting do
before do
Setting["official_level_1_name"] = 'Stormtrooper'
described_class["official_level_1_name"] = 'Stormtrooper'
end
it "should return the overriden setting" do
expect(Setting['official_level_1_name']).to eq('Stormtrooper')
expect(described_class['official_level_1_name']).to eq('Stormtrooper')
end
it "should should return nil" do
expect(Setting['undefined_key']).to eq(nil)
expect(described_class['undefined_key']).to eq(nil)
end
it "should persist a setting on the db" do
expect(Setting.where(key: 'official_level_1_name', value: 'Stormtrooper')).to exist
expect(described_class.where(key: 'official_level_1_name', value: 'Stormtrooper')).to exist
end
describe "#feature_flag?" do
it "should be true if key starts with 'feature.'" do
setting = Setting.create(key: 'feature.whatever')
setting = described_class.create(key: 'feature.whatever')
expect(setting.feature_flag?).to eq true
end
it "should be false if key does not start with 'feature.'" do
setting = Setting.create(key: 'whatever')
setting = described_class.create(key: 'whatever')
expect(setting.feature_flag?).to eq false
end
end
describe "#enabled?" do
it "should be true if feature_flag and value present" do
setting = Setting.create(key: 'feature.whatever', value: 1)
setting = described_class.create(key: 'feature.whatever', value: 1)
expect(setting.enabled?).to eq true
setting.value = "true"
@@ -42,7 +42,7 @@ describe Setting do
end
it "should be false if feature_flag and value blank" do
setting = Setting.create(key: 'feature.whatever')
setting = described_class.create(key: 'feature.whatever')
expect(setting.enabled?).to eq false
setting.value = ""
@@ -50,31 +50,31 @@ describe Setting do
end
it "should be false if not feature_flag" do
setting = Setting.create(key: 'whatever', value: "whatever")
setting = described_class.create(key: 'whatever', value: "whatever")
expect(setting.enabled?).to eq false
end
end
describe "#banner_style?" do
it "should be true if key starts with 'banner-style.'" do
setting = Setting.create(key: 'banner-style.whatever')
setting = described_class.create(key: 'banner-style.whatever')
expect(setting.banner_style?).to eq true
end
it "should be false if key does not start with 'banner-style.'" do
setting = Setting.create(key: 'whatever')
setting = described_class.create(key: 'whatever')
expect(setting.banner_style?).to eq false
end
end
describe "#banner_img?" do
it "should be true if key starts with 'banner-img.'" do
setting = Setting.create(key: 'banner-img.whatever')
setting = described_class.create(key: 'banner-img.whatever')
expect(setting.banner_img?).to eq true
end
it "should be false if key does not start with 'banner-img.'" do
setting = Setting.create(key: 'whatever')
setting = described_class.create(key: 'whatever')
expect(setting.banner_img?).to eq false
end
end

View File

@@ -8,7 +8,7 @@ describe Verification::Sms do
it "should validate uniqness of phone" do
create(:user, confirmed_phone: "699999999")
sms = Verification::Sms.new(phone: "699999999")
sms = described_class.new(phone: "699999999")
expect(sms).to_not be_valid
end

View File

@@ -8,7 +8,7 @@ describe TagCloud do
create(:proposal, tag_list: 'participation')
create(:debate, tag_list: 'world hunger')
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud)).to contain_exactly('participation')
end
@@ -17,7 +17,7 @@ describe TagCloud do
create(:proposal, tag_list: 'participation')
create(:debate, tag_list: 'world hunger')
tag_cloud = TagCloud.new(Debate)
tag_cloud = described_class.new(Debate)
expect(tag_names(tag_cloud)).to contain_exactly('world hunger')
end
@@ -26,7 +26,7 @@ describe TagCloud do
create(:budget_investment, tag_list: 'participation')
create(:debate, tag_list: 'world hunger')
tag_cloud = TagCloud.new(Budget::Investment)
tag_cloud = described_class.new(Budget::Investment)
expect(tag_names(tag_cloud)).to contain_exactly('participation')
end
@@ -35,7 +35,7 @@ describe TagCloud do
create(:proposal, tag_list: 'participation', created_at: 1.day.ago)
create(:proposal, tag_list: 'corruption', created_at: 2.weeks.ago)
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud)).to contain_exactly('participation')
end
@@ -47,7 +47,7 @@ describe TagCloud do
create(:proposal, tag_list: 'education, parks')
create(:proposal, tag_list: 'participation, water')
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud)).to contain_exactly('parks', 'water')
end
@@ -59,7 +59,7 @@ describe TagCloud do
create(:proposal, tag_list: 'parks, California')
create(:proposal, tag_list: 'water, New York')
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud)).to contain_exactly('parks', 'water')
end
@@ -71,7 +71,7 @@ describe TagCloud do
create(:proposal, tag_list: 'education, parks')
create(:proposal, tag_list: 'participation, water')
tag_cloud = TagCloud.new(Proposal, 'Education')
tag_cloud = described_class.new(Proposal, 'Education')
expect(tag_names(tag_cloud)).to contain_exactly('parks')
end
@@ -83,7 +83,7 @@ describe TagCloud do
create(:proposal, tag_list: 'parks, California')
create(:proposal, tag_list: 'water, New York')
tag_cloud = TagCloud.new(Proposal, 'California')
tag_cloud = described_class.new(Proposal, 'California')
expect(tag_names(tag_cloud)).to contain_exactly('parks')
end
@@ -95,7 +95,7 @@ describe TagCloud do
3.times { create(:proposal, tag_list: 'participation') }
create(:proposal, tag_list: 'corruption')
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud).first).to eq 'participation'
expect(tag_names(tag_cloud).second).to eq 'corruption'
@@ -106,7 +106,7 @@ describe TagCloud do
3.times { create(:proposal, tag_list: 'health') }
create(:proposal, tag_list: 'corruption')
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud).first).to eq 'health'
expect(tag_names(tag_cloud).second).to eq 'participation'
@@ -116,7 +116,7 @@ describe TagCloud do
it "returns a maximum of 10 tags" do
12.times { |i| create(:proposal, tag_list: "Tag #{i}") }
tag_cloud = TagCloud.new(Proposal)
tag_cloud = described_class.new(Proposal)
expect(tag_names(tag_cloud).count).to eq(10)
end

View File

@@ -278,7 +278,7 @@ describe User do
create(:user, official_position: "Manager", official_level: 5)
2.times { create(:user) }
officials = User.officials
officials = described_class.officials
expect(officials.size).to eq(4)
officials.each do |user|
expect(user.official_level).to be > 0
@@ -353,9 +353,9 @@ describe User do
user2 = create(:user, erased_at: nil)
user3 = create(:user, erased_at: Time.current)
expect(User.active).to include(user1)
expect(User.active).to include(user2)
expect(User.active).to_not include(user3)
expect(described_class.active).to include(user1)
expect(described_class.active).to include(user2)
expect(described_class.active).to_not include(user3)
end
it "returns users that have not been blocked" do
@@ -364,9 +364,9 @@ describe User do
user3 = create(:user)
user3.block
expect(User.active).to include(user1)
expect(User.active).to include(user2)
expect(User.active).to_not include(user3)
expect(described_class.active).to include(user1)
expect(described_class.active).to include(user2)
expect(described_class.active).to_not include(user3)
end
end
@@ -378,9 +378,9 @@ describe User do
user2 = create(:user, erased_at: Time.current)
user3 = create(:user, erased_at: nil)
expect(User.erased).to include(user1)
expect(User.erased).to include(user2)
expect(User.erased).to_not include(user3)
expect(described_class.erased).to include(user1)
expect(described_class.erased).to include(user2)
expect(described_class.erased).to_not include(user3)
end
end
@@ -390,7 +390,7 @@ describe User do
it "find users by email" do
user1 = create(:user, email: "larry@consul.dev")
create(:user, email: "bird@consul.dev")
search = User.search("larry@consul.dev")
search = described_class.search("larry@consul.dev")
expect(search.size).to eq(1)
expect(search.first).to eq(user1)
end
@@ -398,13 +398,13 @@ describe User do
it "find users by name" do
user1 = create(:user, username: "Larry Bird")
create(:user, username: "Robert Parish")
search = User.search("larry")
search = described_class.search("larry")
expect(search.size).to eq(1)
expect(search.first).to eq(user1)
end
it "returns no results if no search term provided" do
expect(User.search(" ").size).to eq(0)
expect(described_class.search(" ").size).to eq(0)
end
end
@@ -434,13 +434,13 @@ describe User do
describe "document_number" do
it "should upcase document number" do
user = User.new(document_number: "x1234567z")
user = described_class.new(document_number: "x1234567z")
user.valid?
expect(user.document_number).to eq("X1234567Z")
end
it "should remove all characters except numbers and letters" do
user = User.new(document_number: " 12.345.678 - B")
user = described_class.new(document_number: " 12.345.678 - B")
user.valid?
expect(user.document_number).to eq("12345678B")
end

View File

@@ -4,24 +4,24 @@ describe Verification::Management::Document do
describe "#valid_age?" do
it "returns false when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be false
expect(described_class.new.valid_age?(census_response)).to be false
end
it "returns true when the user has the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 16.years.ago.month, 16.years.ago.day))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
expect(described_class.new.valid_age?(census_response)).to be true
end
it "returns true when the user is older than the user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
expect(described_class.new.valid_age?(census_response)).to be true
end
end
describe "#under_age?" do
it "returns true when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be true
expect(described_class.new.under_age?(census_response)).to be true
end
it "returns false when the user is user's minimum required age" do
@@ -29,12 +29,12 @@ describe Verification::Management::Document do
User.minimum_required_age.years.ago.month,
User.minimum_required_age.years.ago.day)
census_response = double(date_of_birth: date_of_birth)
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
expect(described_class.new.under_age?(census_response)).to be false
end
it "returns false when the user is older than user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
expect(described_class.new.under_age?(census_response)).to be false
end
end
end

View File

@@ -8,7 +8,7 @@ describe Vote do
comment = create(:comment)
create(:vote, votable: comment)
expect(Vote.for_debates(debate).count).to eq(0)
expect(described_class.for_debates(debate).count).to eq(0)
end
it 'returns votes only for debates in parameters' do
@@ -16,8 +16,8 @@ describe Vote do
debate2 = create(:debate)
create(:vote, votable: debate1)
expect(Vote.for_debates(debate1).count).to eq(1)
expect(Vote.for_debates(debate2).count).to eq(0)
expect(described_class.for_debates(debate1).count).to eq(1)
expect(described_class.for_debates(debate2).count).to eq(0)
end
it 'accepts more than 1 debate' do
@@ -27,7 +27,7 @@ describe Vote do
create(:vote, votable: debate1)
create(:vote, votable: debate3)
expect(Vote.for_debates([debate1, debate2]).count).to eq(1)
expect(described_class.for_debates([debate1, debate2]).count).to eq(1)
end
end
@@ -46,42 +46,42 @@ describe Vote do
debate = create(:debate)
vote = create(:vote, votable: debate)
expect(Vote.public_for_api).to include(vote)
expect(described_class.public_for_api).to include(vote)
end
it 'blocks votes on hidden debates' do
debate = create(:debate, :hidden)
vote = create(:vote, votable: debate)
expect(Vote.public_for_api).not_to include(vote)
expect(described_class.public_for_api).not_to include(vote)
end
it 'returns votes on proposals' do
proposal = create(:proposal)
vote = create(:vote, votable: proposal)
expect(Vote.public_for_api).to include(vote)
expect(described_class.public_for_api).to include(vote)
end
it 'blocks votes on hidden proposals' do
proposal = create(:proposal, :hidden)
vote = create(:vote, votable: proposal)
expect(Vote.public_for_api).not_to include(vote)
expect(described_class.public_for_api).not_to include(vote)
end
it 'returns votes on comments' do
comment = create(:comment)
vote = create(:vote, votable: comment)
expect(Vote.public_for_api).to include(vote)
expect(described_class.public_for_api).to include(vote)
end
it 'blocks votes on hidden comments' do
comment = create(:comment, :hidden)
vote = create(:vote, votable: comment)
expect(Vote.public_for_api).not_to include(vote)
expect(described_class.public_for_api).not_to include(vote)
end
it 'blocks votes on comments on hidden proposals' do
@@ -89,7 +89,7 @@ describe Vote do
comment_on_hidden_proposal = create(:comment, commentable: hidden_proposal)
vote = create(:vote, votable: comment_on_hidden_proposal)
expect(Vote.public_for_api).to_not include(vote)
expect(described_class.public_for_api).to_not include(vote)
end
it 'blocks votes on comments on hidden debates' do
@@ -97,20 +97,20 @@ describe Vote do
comment_on_hidden_debate = create(:comment, commentable: hidden_debate)
vote = create(:vote, votable: comment_on_hidden_debate)
expect(Vote.public_for_api).to_not include(vote)
expect(described_class.public_for_api).to_not include(vote)
end
it 'blocks any other kind of votes' do
spending_proposal = create(:spending_proposal)
vote = create(:vote, votable: spending_proposal)
expect(Vote.public_for_api).not_to include(vote)
expect(described_class.public_for_api).not_to include(vote)
end
it 'blocks votes without votable' do
vote = build(:vote, votable: nil).save!(validate: false)
expect(Vote.public_for_api).not_to include(vote)
expect(described_class.public_for_api).not_to include(vote)
end
end
end