Enables RSpec/ExampleWording and fixes all issues

Both avoiding 'should' and repiting 'it' on the tests description
improves reading them and also makes all descriptions consistent.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording
This commit is contained in:
Bertocq
2018-01-07 00:57:50 +01:00
parent 971f2e308a
commit ed16a78f42
73 changed files with 482 additions and 479 deletions

View File

@@ -71,4 +71,7 @@ RSpec/EmptyLineAfterSubject:
Enabled: true Enabled: true
RSpec/ExampleLength: RSpec/ExampleLength:
Enabled: false Enabled: false
RSpec/ExampleWording:
Enabled: true

View File

@@ -6,7 +6,7 @@ describe Admin::Api::StatsController do
let(:user) { create(:administrator).user } let(:user) { create(:administrator).user }
context 'events or visits not present' do context 'events or visits not present' do
it 'should respond with bad_request' do it 'responds with bad_request' do
sign_in user sign_in user
get :show get :show
@@ -29,7 +29,7 @@ describe Admin::Api::StatsController do
create :ahoy_event, name: 'bar', time: time_3 create :ahoy_event, name: 'bar', time: time_3
end end
it 'should return single events formated for working with c3.js' do it 'returns single events formated for working with c3.js' do
sign_in user sign_in user
get :show, events: 'foo' get :show, events: 'foo'
@@ -39,7 +39,7 @@ describe Admin::Api::StatsController do
expect(data).to eq "x" => ["2015-01-01", "2015-01-02"], "Foo" => [2, 1] expect(data).to eq "x" => ["2015-01-01", "2015-01-02"], "Foo" => [2, 1]
end end
it 'should return combined comma separated events formated for working with c3.js' do it 'returns combined comma separated events formated for working with c3.js' do
sign_in user sign_in user
get :show, events: 'foo,bar' get :show, events: 'foo,bar'
@@ -51,7 +51,7 @@ describe Admin::Api::StatsController do
end end
context 'visits present' do context 'visits present' do
it 'should return visits formated for working with c3.js' do it 'returns visits formated for working with c3.js' do
time_1 = DateTime.parse("2015-01-01").in_time_zone time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone time_2 = DateTime.parse("2015-01-02").in_time_zone
@@ -70,7 +70,7 @@ describe Admin::Api::StatsController do
end end
context 'visits and events present' do context 'visits and events present' do
it 'should return combined events and visits formated for working with c3.js' do it 'returns combined events and visits formated for working with c3.js' do
time_1 = DateTime.parse("2015-01-01").in_time_zone time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone time_2 = DateTime.parse("2015-01-02").in_time_zone
@@ -93,7 +93,7 @@ describe Admin::Api::StatsController do
end end
context 'budget investments present' do context 'budget investments present' do
it 'should return budget investments formated for working with c3.js' do it 'returns budget investments formated for working with c3.js' do
time_1 = DateTime.parse("2017-04-01").in_time_zone time_1 = DateTime.parse("2017-04-01").in_time_zone
time_2 = DateTime.parse("2017-04-02").in_time_zone time_2 = DateTime.parse("2017-04-02").in_time_zone

View File

@@ -10,7 +10,7 @@ describe CommentsController do
@unverified_user = create(:user) @unverified_user = create(:user)
end end
it 'should create an comment if the comments are open' do it 'creates an comment if the comments are open' do
sign_in @user sign_in @user
expect do expect do
@@ -18,7 +18,7 @@ describe CommentsController do
end.to change { @question.reload.comments_count }.by(1) end.to change { @question.reload.comments_count }.by(1)
end end
it 'should not create a comment if the comments are closed' do it 'does not create a comment if the comments are closed' do
sign_in @user sign_in @user
@process.update_attribute(:debate_end_date, Date.current - 1.day) @process.update_attribute(:debate_end_date, Date.current - 1.day)
@@ -27,7 +27,7 @@ describe CommentsController do
end.to_not change { @question.reload.comments_count } end.to_not change { @question.reload.comments_count }
end end
it 'should not create a comment for unverified users when the commentable requires it' do it 'does not create a comment for unverified users when the commentable requires it' do
sign_in @unverified_user sign_in @unverified_user
expect do expect do

View File

@@ -11,7 +11,7 @@ describe DebatesController do
InvisibleCaptcha.timestamp_enabled = true InvisibleCaptcha.timestamp_enabled = true
end end
it 'should create an ahoy event' do it 'creates an ahoy event' do
sign_in create(:user) sign_in create(:user)
@@ -26,7 +26,7 @@ describe DebatesController do
Setting['max_ratio_anon_votes_on_debates'] = 50 Setting['max_ratio_anon_votes_on_debates'] = 50
end end
it 'should allow vote if user is allowed' do it 'allows vote if user is allowed' do
Setting["max_ratio_anon_votes_on_debates"] = 100 Setting["max_ratio_anon_votes_on_debates"] = 100
debate = create(:debate) debate = create(:debate)
sign_in create(:user) sign_in create(:user)
@@ -36,7 +36,7 @@ describe DebatesController do
end.to change { debate.reload.votes_for.size }.by(1) end.to change { debate.reload.votes_for.size }.by(1)
end end
it 'should not allow vote if user is not allowed' do it 'does not allow vote if user is not allowed' do
Setting["max_ratio_anon_votes_on_debates"] = 0 Setting["max_ratio_anon_votes_on_debates"] = 0
debate = create(:debate, cached_votes_total: 1000) debate = create(:debate, cached_votes_total: 1000)
sign_in create(:user) sign_in create(:user)

View File

@@ -10,7 +10,7 @@ describe Legislation::AnnotationsController do
@user = create(:user, :level_two) @user = create(:user, :level_two)
end end
it 'should create an ahoy event' do it 'creates an ahoy event' do
sign_in @user sign_in @user
post :create, process_id: @process.id, post :create, process_id: @process.id,
@@ -24,7 +24,7 @@ describe Legislation::AnnotationsController do
expect(Ahoy::Event.last.properties['legislation_annotation_id']).to eq Legislation::Annotation.last.id expect(Ahoy::Event.last.properties['legislation_annotation_id']).to eq Legislation::Annotation.last.id
end end
it 'should not create an annotation if the draft version is a final version' do it 'does not create an annotation if the draft version is a final version' do
sign_in @user sign_in @user
post :create, process_id: @process.id, post :create, process_id: @process.id,
@@ -38,7 +38,7 @@ describe Legislation::AnnotationsController do
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
it 'should create an annotation if the process allegations phase is open' do it 'creates an annotation if the process allegations phase is open' do
sign_in @user sign_in @user
expect do expect do
@@ -52,7 +52,7 @@ describe Legislation::AnnotationsController do
end.to change { @draft_version.annotations.count }.by(1) end.to change { @draft_version.annotations.count }.by(1)
end end
it 'should not create an annotation if the process allegations phase is not open' do it 'does not create an annotation if the process allegations phase is not open' do
sign_in @user sign_in @user
@process.update_attribute(:allegations_end_date, Date.current - 1.day) @process.update_attribute(:allegations_end_date, Date.current - 1.day)
@@ -67,7 +67,7 @@ describe Legislation::AnnotationsController do
end.to_not change { @draft_version.annotations.count } end.to_not change { @draft_version.annotations.count }
end end
it 'should create an annotation by parsing parameters in JSON' do it 'creates an annotation by parsing parameters in JSON' do
sign_in @user sign_in @user
expect do expect do
@@ -81,7 +81,7 @@ describe Legislation::AnnotationsController do
end.to change { @draft_version.annotations.count }.by(1) end.to change { @draft_version.annotations.count }.by(1)
end end
it 'should create a new comment on an existing annotation when range is the same' do it 'creates a new comment on an existing annotation when range is the same' do
annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation",
ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}],
range_start: "/p[1]", range_start_offset: 6, range_end: "/p[1]", range_end_offset: 11) range_start: "/p[1]", range_start_offset: 6, range_end: "/p[1]", range_end_offset: 11)

View File

@@ -10,7 +10,7 @@ describe Legislation::AnswersController do
@user = create(:user, :level_two) @user = create(:user, :level_two)
end end
it 'should create an ahoy event' do it 'creates an ahoy event' do
sign_in @user sign_in @user
post :create, process_id: @process.id, question_id: @question.id, post :create, process_id: @process.id, question_id: @question.id,
@@ -19,7 +19,7 @@ describe Legislation::AnswersController do
expect(Ahoy::Event.last.properties['legislation_answer_id']).to eq Legislation::Answer.last.id expect(Ahoy::Event.last.properties['legislation_answer_id']).to eq Legislation::Answer.last.id
end end
it 'should create an answer if the process debate phase is open' do it 'creates an answer if the process debate phase is open' do
sign_in @user sign_in @user
expect do expect do
@@ -28,7 +28,7 @@ describe Legislation::AnswersController do
end.to change { @question.reload.answers_count }.by(1) end.to change { @question.reload.answers_count }.by(1)
end end
it 'should not create an answer if the process debate phase is not open' do it 'does not create an answer if the process debate phase is not open' do
sign_in @user sign_in @user
@process.update_attribute(:debate_end_date, Date.current - 1.day) @process.update_attribute(:debate_end_date, Date.current - 1.day)

View File

@@ -4,7 +4,7 @@ describe Management::BaseController do
describe 'managed_user' do describe 'managed_user' do
it "should return existent user with session document info if present" do it "returns existent user with session document info if present" do
session[:document_type] = "1" session[:document_type] = "1"
session[:document_number] = "333333333E" session[:document_number] = "333333333E"
user = create(:user, :level_two, document_number: "333333333E") user = create(:user, :level_two, document_number: "333333333E")
@@ -13,7 +13,7 @@ describe Management::BaseController do
expect(managed_user).to eq user expect(managed_user).to eq user
end end
it "should return new user if no user have the session document info" do it "returns new user if no user have the session document info" do
session[:document_type] = "1" session[:document_type] = "1"
session[:document_number] = "333333333E" session[:document_number] = "333333333E"
managed_user = subject.send(:managed_user) managed_user = subject.send(:managed_user)

View File

@@ -3,13 +3,13 @@ require 'rails_helper'
describe Management::SessionsController do describe Management::SessionsController do
describe 'Sign in' do describe 'Sign in' do
it "should deny access if wrong manager credentials" do it "denies access if wrong manager credentials" do
allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(false) allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(false)
expect { get :create, login: "nonexistent", clave_usuario: "wrong"}.to raise_error CanCan::AccessDenied expect { get :create, login: "nonexistent", clave_usuario: "wrong"}.to raise_error CanCan::AccessDenied
expect(session[:manager]).to be_nil expect(session[:manager]).to be_nil
end end
it "should redirect to management root path if authorized manager with right credentials" do it "redirects to management root path if authorized manager with right credentials" do
manager = {login: "JJB033", user_key: "31415926", date: "20151031135905"} manager = {login: "JJB033", user_key: "31415926", date: "20151031135905"}
allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(manager) allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(manager)
@@ -18,7 +18,7 @@ describe Management::SessionsController do
expect(session[:manager][:login]).to eq "JJB033" expect(session[:manager][:login]).to eq "JJB033"
end end
it "should redirect to management root path if user is admin" do it "redirects to management root path if user is admin" do
user = create(:administrator).user user = create(:administrator).user
sign_in user sign_in user
get :create get :create
@@ -26,7 +26,7 @@ describe Management::SessionsController do
expect(session[:manager][:login]).to eq "admin_user_#{user.id}" expect(session[:manager][:login]).to eq "admin_user_#{user.id}"
end end
it "should redirect to management root path if user is manager" do it "redirects to management root path if user is manager" do
user = create(:manager).user user = create(:manager).user
sign_in user sign_in user
get :create get :create
@@ -34,7 +34,7 @@ describe Management::SessionsController do
expect(session[:manager][:login]).to eq "manager_user_#{user.id}" expect(session[:manager][:login]).to eq "manager_user_#{user.id}"
end end
it "should deny access if user is not admin or manager" do it "denies access if user is not admin or manager" do
sign_in create(:user) sign_in create(:user)
expect { get :create}.to raise_error CanCan::AccessDenied expect { get :create}.to raise_error CanCan::AccessDenied
expect(session[:manager]).to be_nil expect(session[:manager]).to be_nil
@@ -42,7 +42,7 @@ describe Management::SessionsController do
end end
describe 'Sign out' do describe 'Sign out' do
it "should destroy the session data and redirect" do it "destroys the session data and redirect" do
session[:manager] = {user_key: "31415926", date: "20151031135905", login: "JJB033"} session[:manager] = {user_key: "31415926", date: "20151031135905", login: "JJB033"}
session[:document_type] = "1" session[:document_type] = "1"
session[:document_number] = "12345678Z" session[:document_number] = "12345678Z"

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Management::UsersController do describe Management::UsersController do
describe 'logout' do describe 'logout' do
it "should remove user data from the session" do it "removes user data from the session" do
session[:manager] = {user_key: "31415926", date: "20151031135905", login: "JJB033"} session[:manager] = {user_key: "31415926", date: "20151031135905", login: "JJB033"}
session[:document_type] = "1" session[:document_type] = "1"
session[:document_number] = "12345678Z" session[:document_number] = "12345678Z"

View File

@@ -3,27 +3,27 @@ require 'rails_helper'
describe PagesController do describe PagesController do
describe 'Static pages' do describe 'Static pages' do
it 'should include a privacy page' do it 'includes a privacy page' do
get :show, id: :privacy get :show, id: :privacy
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a conditions page' do it 'includes a conditions page' do
get :show, id: :conditions get :show, id: :conditions
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a general terms page' do it 'includes a general terms page' do
get :show, id: :general_terms get :show, id: :general_terms
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a terms page' do it 'includes a terms page' do
get :show, id: :census_terms get :show, id: :census_terms
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a accessibility page' do it 'includes a accessibility page' do
get :show, id: :accessibility get :show, id: :accessibility
expect(response).to be_ok expect(response).to be_ok
end end
@@ -31,24 +31,24 @@ describe PagesController do
describe 'More info pages' do describe 'More info pages' do
it 'should include a more info page' do it 'includes a more info page' do
get :show, id: 'more_info/index' get :show, id: 'more_info/index'
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a how_to_use page' do it 'includes a how_to_use page' do
get :show, id: 'more_info/how_to_use/index' get :show, id: 'more_info/how_to_use/index'
expect(response).to be_ok expect(response).to be_ok
end end
it 'should include a faq page' do it 'includes a faq page' do
get :show, id: 'more_info/faq/index' get :show, id: 'more_info/faq/index'
expect(response).to be_ok expect(response).to be_ok
end end
end end
describe 'Not found pages' do describe 'Not found pages' do
it 'should return a 404 message' do it 'returns a 404 message' do
get :show, id: "nonExistentPage" get :show, id: "nonExistentPage"
expect(response).to be_missing expect(response).to be_missing
end end

View File

@@ -9,7 +9,7 @@ describe Users::RegistrationsController do
end end
context "when username is available" do context "when username is available" do
it "should return true with no error message" do it "returns true with no error message" do
get :check_username, username: "available username" get :check_username, username: "available username"
data = JSON.parse response.body, symbolize_names: true data = JSON.parse response.body, symbolize_names: true
@@ -19,7 +19,7 @@ describe Users::RegistrationsController do
end end
context "when username is not available" do context "when username is not available" do
it "should return false with an error message" do it "returns false with an error message" do
user = create(:user) user = create(:user)
get :check_username, username: user.username get :check_username, username: user.username

View File

@@ -8,13 +8,13 @@ describe 'Customization Engine' do
let(:test_key) { I18n.t('account.show.change_credentials_link') } let(:test_key) { I18n.t('account.show.change_credentials_link') }
let!(:default_path) { I18n.load_path } let!(:default_path) { I18n.load_path }
it "should load custom and override original locales" do it "loads custom and override original locales" do
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', 'custom', '*.{rb,yml}')] I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', 'custom', '*.{rb,yml}')]
I18n.reload! I18n.reload!
expect(test_key).to eq 'Overriden string with custom locales' expect(test_key).to eq 'Overriden string with custom locales'
end end
it "should not override original locales" do it "does not override original locales" do
I18n.load_path.delete_if {|item| item =~ /spec\/support\/locales\/custom/ } I18n.load_path.delete_if {|item| item =~ /spec\/support\/locales\/custom/ }
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', '**', '*.{rb,yml}')] I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', '**', '*.{rb,yml}')]
I18n.reload! I18n.reload!

View File

@@ -3,19 +3,19 @@ require 'rails_helper'
describe ApplicationHelper do describe ApplicationHelper do
describe "#author_of?" do describe "#author_of?" do
it "should be true if user is the author" do it "is true if user is the author" do
user = create(:user) user = create(:user)
proposal = create(:proposal, author: user) proposal = create(:proposal, author: user)
expect(author_of?(proposal, user)).to eq true expect(author_of?(proposal, user)).to eq true
end end
it "should be false if user is not the author" do it "is false if user is not the author" do
user = create(:user) user = create(:user)
proposal = create(:proposal) proposal = create(:proposal)
expect(author_of?(proposal, user)).to eq false expect(author_of?(proposal, user)).to eq false
end end
it "should be false if user or authorable is nil" do it "is false if user or authorable is nil" do
user = create(:user) user = create(:user)
proposal = create(:proposal) proposal = create(:proposal)

View File

@@ -3,43 +3,43 @@ require 'rails_helper'
describe ProposalsHelper do describe ProposalsHelper do
describe "#progress_bar_percentage" do describe "#progress_bar_percentage" do
it "should be 0 if no votes" do it "is 0 if no votes" do
proposal = create(:proposal) proposal = create(:proposal)
expect(progress_bar_percentage(proposal)).to eq 0 expect(progress_bar_percentage(proposal)).to eq 0
end end
it "should be a between 1 and 100 if there are votes but less than needed" do it "is between 1 and 100 if there are votes but less than needed" do
proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success / 2) proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success / 2)
expect(progress_bar_percentage(proposal)).to eq 50 expect(progress_bar_percentage(proposal)).to eq 50
end end
it "should be 100 if there are more votes than needed" do it "is 100 if there are more votes than needed" do
proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success * 2) proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success * 2)
expect(progress_bar_percentage(proposal)).to eq 100 expect(progress_bar_percentage(proposal)).to eq 100
end end
end end
describe "#supports_percentage" do describe "#supports_percentage" do
it "should be 0 if no votes" do it "is 0 if no votes" do
proposal = create(:proposal) proposal = create(:proposal)
expect(supports_percentage(proposal)).to eq "0%" expect(supports_percentage(proposal)).to eq "0%"
end end
it "should be a between 0.1 from 1 to 0.1% of needed votes" do it "is between 0.1 from 1 to 0.1% of needed votes" do
proposal = create(:proposal, cached_votes_up: 1) proposal = create(:proposal, cached_votes_up: 1)
expect(supports_percentage(proposal)).to eq "0.1%" expect(supports_percentage(proposal)).to eq "0.1%"
end end
it "should be a between 1 and 100 if there are votes but less than needed" do it "is between 1 and 100 if there are votes but less than needed" do
proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success / 2) proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success / 2)
expect(supports_percentage(proposal)).to eq "50%" expect(supports_percentage(proposal)).to eq "50%"
end end
it "should be 100 if there are more votes than needed" do it "is 100 if there are more votes than needed" do
proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success * 2) proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success * 2)
expect(supports_percentage(proposal)).to eq "100%" expect(supports_percentage(proposal)).to eq "100%"
end end
end end
end end

View File

@@ -3,12 +3,12 @@ require 'rails_helper'
describe TextHelper do describe TextHelper do
describe "#first_paragraph" do describe "#first_paragraph" do
it "should return the first paragraph of a text" do it "returns the first paragraph of a text" do
text = "\n\nThis is the first paragraph\n\nThis is the second paragraph\n" text = "\n\nThis is the first paragraph\n\nThis is the second paragraph\n"
expect(first_paragraph(text)).to eq("This is the first paragraph") expect(first_paragraph(text)).to eq("This is the first paragraph")
end end
it "should return blank if the text is blank" do it "returns blank if the text is blank" do
expect(first_paragraph("")).to eq("") expect(first_paragraph("")).to eq("")
expect(first_paragraph(nil)).to eq("") expect(first_paragraph(nil)).to eq("")
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe UsersHelper do describe UsersHelper do
describe '#humanize_document_type' do describe '#humanize_document_type' do
it "should return a humanized document type" do it "returns a humanized document type" do
expect(humanize_document_type("1")).to eq "DNI" expect(humanize_document_type("1")).to eq "DNI"
expect(humanize_document_type("2")).to eq "Passport" expect(humanize_document_type("2")).to eq "Passport"
expect(humanize_document_type("3")).to eq "Residence card" expect(humanize_document_type("3")).to eq "Residence card"
@@ -11,7 +11,7 @@ describe UsersHelper do
end end
describe '#deleted_commentable_text' do describe '#deleted_commentable_text' do
it "should return the appropriate message for deleted debates" do it "returns the appropriate message for deleted debates" do
debate = create(:debate) debate = create(:debate)
comment = create(:comment, commentable: debate) comment = create(:comment, commentable: debate)
@@ -21,7 +21,7 @@ describe UsersHelper do
'</del> <span class="small">(This debate has been deleted)</span>') '</del> <span class="small">(This debate has been deleted)</span>')
end end
it "should return the appropriate message for deleted proposals" do it "returns the appropriate message for deleted proposals" do
proposal = create(:proposal) proposal = create(:proposal)
comment = create(:comment, commentable: proposal) comment = create(:comment, commentable: proposal)
@@ -31,7 +31,7 @@ describe UsersHelper do
'</del> <span class="small">(This proposal has been deleted)</span>') '</del> <span class="small">(This proposal has been deleted)</span>')
end end
it "should return the appropriate message for deleted budget investment" do it "returns the appropriate message for deleted budget investment" do
investment = create(:budget_investment) investment = create(:budget_investment)
comment = create(:comment, commentable: investment) comment = create(:comment, commentable: investment)
@@ -43,12 +43,12 @@ describe UsersHelper do
end end
describe '#comment_commentable_title' do describe '#comment_commentable_title' do
it "should return a link to the comment" do it "returns a link to the comment" do
comment = create(:comment) comment = create(:comment)
expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment
end end
it "should return a hint if the commentable has been deleted" do it "returns a hint if the commentable has been deleted" do
comment = create(:comment) comment = create(:comment)
comment.commentable.hide comment.commentable.hide
expect(comment_commentable_title(comment)).to eq('<del>' + comment.commentable.title + expect(comment_commentable_title(comment)).to eq('<del>' + comment.commentable.title +

View File

@@ -3,18 +3,18 @@ require 'rails_helper'
describe VerificationHelper do describe VerificationHelper do
describe "#mask_phone" do describe "#mask_phone" do
it "should mask a phone" do it "masks a phone" do
expect(mask_phone("612345678")).to eq("******678") expect(mask_phone("612345678")).to eq("******678")
end end
end end
describe "#mask_email" do describe "#mask_email" do
it "should mask a long email address" do it "masks a long email address" do
expect(mask_email("isabel@example.com")).to eq("isa***@example.com") expect(mask_email("isabel@example.com")).to eq("isa***@example.com")
expect(mask_email("antonio.perez@example.com")).to eq("ant**********@example.com") expect(mask_email("antonio.perez@example.com")).to eq("ant**********@example.com")
end end
it "should mask a short email address" do it "masks a short email address" do
expect(mask_email("an@example.com")).to eq("an@example.com") expect(mask_email("an@example.com")).to eq("an@example.com")
expect(mask_email("ana@example.com")).to eq("ana@example.com") expect(mask_email("ana@example.com")).to eq("ana@example.com")
expect(mask_email("aina@example.com")).to eq("ain*@example.com") expect(mask_email("aina@example.com")).to eq("ain*@example.com")

View File

@@ -3,14 +3,14 @@ require 'rails_helper'
describe VotesHelper do describe VotesHelper do
describe "#voted_for?" do describe "#voted_for?" do
it "should return true if voted for a proposal" do it "returns true if voted for a proposal" do
proposal = create(:proposal) proposal = create(:proposal)
votes = {proposal.id => true} votes = {proposal.id => true}
expect(voted_for?(votes, proposal)).to eq(true) expect(voted_for?(votes, proposal)).to eq(true)
end end
it "should return false if not voted for a proposals" do it "returns false if not voted for a proposals" do
proposal = create(:proposal) proposal = create(:proposal)
votes = {proposal.id => nil} votes = {proposal.id => nil}
@@ -19,7 +19,7 @@ describe VotesHelper do
end end
describe "#votes_percentage" do describe "#votes_percentage" do
it "should always sum 100%" do it "alwayses sum 100%" do
debate = create(:debate) debate = create(:debate)
create_list(:vote, 8, votable: debate, vote_flag: true) create_list(:vote, 8, votable: debate, vote_flag: true)
create_list(:vote, 3, votable: debate, vote_flag: false) create_list(:vote, 3, votable: debate, vote_flag: false)

View File

@@ -4,38 +4,38 @@ describe ManagerAuthenticator do
let(:authenticator) { described_class.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 describe 'initialization params' do
it 'should cause auth to return false if blank login' do it 'causes auth to return false if blank login' do
blank_login_authenticator = described_class.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 expect(blank_login_authenticator.auth).to be false
end end
it 'should cause 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") blank_user_key_authenticator = described_class.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905")
expect(blank_user_key_authenticator.auth).to be false expect(blank_user_key_authenticator.auth).to be false
end end
it 'should cause 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: "") blank_date_authenticator = described_class.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "")
expect(blank_date_authenticator.auth).to be false expect(blank_date_authenticator.auth).to be false
end end
end end
describe '#auth' do describe '#auth' do
it 'should return false if not manager_exists' do it 'returns false if not manager_exists' do
allow(authenticator).to receive(:manager_exists?).and_return(false) allow(authenticator).to receive(:manager_exists?).and_return(false)
allow(authenticator).to receive(:application_authorized?).and_return(true) allow(authenticator).to receive(:application_authorized?).and_return(true)
expect(authenticator.auth).to be false expect(authenticator.auth).to be false
end end
it 'should return 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(:manager_exists?).and_return(true)
allow(authenticator).to receive(:application_authorized?).and_return(false) allow(authenticator).to receive(:application_authorized?).and_return(false)
expect(authenticator.auth).to be false expect(authenticator.auth).to be false
end end
it 'should return 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(:manager_exists?).and_return(true)
allow(authenticator).to receive(:application_authorized?).and_return(true) allow(authenticator).to receive(:application_authorized?).and_return(true)
@@ -44,14 +44,14 @@ describe ManagerAuthenticator do
end end
describe 'SOAP' do describe 'SOAP' do
it 'should call the verification user method' do it 'calls the verification user method' do
message = { ub: {user_key: "31415926", date: "20151031135905"} } message = { ub: {user_key: "31415926", date: "20151031135905"} }
allow(authenticator).to receive(:application_authorized?).and_return(true) allow(authenticator).to receive(:application_authorized?).and_return(true)
expect(authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message) expect(authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message)
authenticator.auth authenticator.auth
end end
it 'should call the permissions check method' do it 'calls the permissions check method' do
allow(authenticator).to receive(:manager_exists?).and_return(true) allow(authenticator).to receive(:manager_exists?).and_return(true)
expect(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} }) expect(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} })
authenticator.auth authenticator.auth

View File

@@ -22,7 +22,7 @@ describe 'Settings Rake' do
run_rake_task run_rake_task
end end
it 'should have per_page_code_head setting present and no per_page_code' do 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.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq(nil) expect(Setting['per_page_code_head']).to eq(nil)
expect(Setting.where(key: 'per_page_code').count).to eq(0) expect(Setting.where(key: 'per_page_code').count).to eq(0)
@@ -36,7 +36,7 @@ describe 'Settings Rake' do
run_rake_task run_rake_task
end end
it 'should have per_page_code_head setting present and no per_page_code' do 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.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code_head') expect(Setting['per_page_code_head']).to eq('per_page_code_head')
expect(Setting.where(key: 'per_page_code').count).to eq(0) expect(Setting.where(key: 'per_page_code').count).to eq(0)
@@ -50,7 +50,7 @@ describe 'Settings Rake' do
run_rake_task run_rake_task
end end
it 'should have per_page_code_head setting present and no per_page_code' do 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.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code_head') expect(Setting['per_page_code_head']).to eq('per_page_code_head')
expect(Setting.where(key: 'per_page_code').count).to eq(0) expect(Setting.where(key: 'per_page_code').count).to eq(0)
@@ -64,7 +64,7 @@ describe 'Settings Rake' do
run_rake_task run_rake_task
end end
it 'should have per_page_code_head setting present and no per_page_code' do 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.where(key: 'per_page_code_head').count).to eq(1)
expect(Setting['per_page_code_head']).to eq('per_page_code') expect(Setting['per_page_code_head']).to eq('per_page_code')
expect(Setting.where(key: 'per_page_code').count).to eq(0) expect(Setting.where(key: 'per_page_code').count).to eq(0)

View File

@@ -2,14 +2,14 @@ require 'rails_helper'
describe Activity do describe Activity do
it "should be valid for different actionables" do it "is valid for different actionables" do
expect(build(:activity, actionable: create(:proposal))).to be_valid expect(build(:activity, actionable: create(:proposal))).to be_valid
expect(build(:activity, actionable: create(:debate))).to be_valid expect(build(:activity, actionable: create(:debate))).to be_valid
expect(build(:activity, actionable: create(:comment))).to be_valid expect(build(:activity, actionable: create(:comment))).to be_valid
expect(build(:activity, actionable: create(:user))).to be_valid expect(build(:activity, actionable: create(:user))).to be_valid
end end
it "should be a valid only with allowed actions" do it "is a valid only with allowed actions" do
expect(build(:activity, action: "hide")).to be_valid expect(build(:activity, action: "hide")).to be_valid
expect(build(:activity, action: "block")).to be_valid expect(build(:activity, action: "block")).to be_valid
expect(build(:activity, action: "restore")).to be_valid expect(build(:activity, action: "restore")).to be_valid
@@ -17,7 +17,7 @@ describe Activity do
end end
describe "log" do describe "log" do
it "should create an activity entry" do it "creates an activity entry" do
user = create(:user) user = create(:user)
proposal = create(:proposal) proposal = create(:proposal)
@@ -31,7 +31,7 @@ describe Activity do
end end
describe "on" do describe "on" do
it "should list all activity on an actionable object" do it "lists all activity on an actionable object" do
proposal = create(:proposal) proposal = create(:proposal)
activity1 = create(:activity, action: "hide", actionable: proposal) activity1 = create(:activity, action: "hide", actionable: proposal)
activity2 = create(:activity, action: "restore", actionable: proposal) activity2 = create(:activity, action: "restore", actionable: proposal)
@@ -49,7 +49,7 @@ describe Activity do
end end
describe "by" do describe "by" do
it "should list all activity of a user" do it "lists all activity of a user" do
user1 = create(:user) user1 = create(:user)
activity1 = create(:activity, user: user1) activity1 = create(:activity, user: user1)
activity2 = create(:activity, user: user1, action: "restore", actionable: create(:debate)) activity2 = create(:activity, user: user1, action: "restore", actionable: create(:debate))
@@ -68,7 +68,7 @@ describe Activity do
end end
describe "scopes by actionable" do describe "scopes by actionable" do
it "should filter by actionable type" do it "filters by actionable type" do
on_proposal = create(:activity, actionable: create(:proposal)) on_proposal = create(:activity, actionable: create(:proposal))
on_debate = create(:activity, actionable: create(:debate)) on_debate = create(:activity, actionable: create(:debate))
on_comment = create(:activity, actionable: create(:comment)) on_comment = create(:activity, actionable: create(:comment))

View File

@@ -15,18 +15,18 @@ describe Ahoy::DataSource do
create :ahoy_event, name: 'bar', time: time_3 create :ahoy_event, name: 'bar', time: time_3
end end
it 'should work without data sources' do it 'works without data sources' do
ds = described_class.new ds = described_class.new
expect(ds.build).to eq x: [] expect(ds.build).to eq x: []
end end
it 'should work with single data sources' do it 'works with single data sources' do
ds = described_class.new ds = described_class.new
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count 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] expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02"], "foo" => [2, 1]
end end
it 'should combine data sources' do it 'combines data sources' do
ds = described_class.new ds = described_class.new
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count 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 ds.add 'bar', Ahoy::Event.where(name: 'bar').group_by_day(:time).count

View File

@@ -11,7 +11,7 @@ describe Budget::Ballot::Line do
describe 'Validations' do describe 'Validations' do
it "should be valid and automatically denormallyze budget, group and heading when validated" do it "is valid and automatically denormallyze budget, group and heading when validated" do
expect(ballot_line).to be_valid expect(ballot_line).to be_valid
expect(ballot_line.budget).to eq(budget) expect(ballot_line.budget).to eq(budget)
expect(ballot_line.group).to eq(group) expect(ballot_line.group).to eq(group)
@@ -19,24 +19,24 @@ describe Budget::Ballot::Line do
end end
describe 'Money' do describe 'Money' do
it "should not be valid if insufficient funds" do it "is not valid if insufficient funds" do
investment.update(price: heading.price + 1) investment.update(price: heading.price + 1)
expect(ballot_line).to_not be_valid expect(ballot_line).to_not be_valid
end end
it "should be valid if sufficient funds" do it "is valid if sufficient funds" do
investment.update(price: heading.price - 1) investment.update(price: heading.price - 1)
expect(ballot_line).to be_valid expect(ballot_line).to be_valid
end end
end end
describe 'Selectibility' do describe 'Selectibility' do
it "should not be valid if investment is unselected" do it "is not valid if investment is unselected" do
investment.update(selected: false) investment.update(selected: false)
expect(ballot_line).to_not be_valid expect(ballot_line).to_not be_valid
end end
it "should be valid if investment is selected" do it "is valid if investment is selected" do
investment.update(selected: true, price: 20000) investment.update(selected: true, price: 20000)
expect(ballot_line).to be_valid expect(ballot_line).to be_valid
end end
@@ -48,7 +48,7 @@ describe Budget::Ballot::Line do
describe "by_investment" do describe "by_investment" do
it "should return ballot lines for an investment" do it "returns ballot lines for an investment" do
investment1 = create(:budget_investment, :selected, heading: heading) investment1 = create(:budget_investment, :selected, heading: heading)
investment2 = create(:budget_investment, :selected, heading: heading) investment2 = create(:budget_investment, :selected, heading: heading)

View File

@@ -4,14 +4,14 @@ describe Budget::Ballot do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
budget = create(:budget) budget = create(:budget)
ballot = create(:budget_ballot, budget: budget) ballot = create(:budget_ballot, budget: budget)
expect(ballot).to be_valid expect(ballot).to be_valid
end end
it "should not be valid with the same investment twice" do it "is not valid with the same investment twice" do
budget = create(:budget) budget = create(:budget)
group = create(:budget_group, budget: budget) group = create(:budget_group, budget: budget)
heading = create(:budget_heading, group: group) heading = create(:budget_heading, group: group)

View File

@@ -5,21 +5,21 @@ describe Budget::Investment::Milestone do
describe "Validations" do describe "Validations" do
let(:milestone) { build(:budget_investment_milestone) } let(:milestone) { build(:budget_investment_milestone) }
it "Should be valid" do it "is valid" do
expect(milestone).to be_valid expect(milestone).to be_valid
end end
it "Should not be valid without a title" do it "is not valid without a title" do
milestone.title = nil milestone.title = nil
expect(milestone).to_not be_valid expect(milestone).to_not be_valid
end end
it "Should not be valid without a description" do it "is not valid without a description" do
milestone.description = nil milestone.description = nil
expect(milestone).to_not be_valid expect(milestone).to_not be_valid
end end
it "Should not be valid without an investment" do it "is not valid without an investment" do
milestone.investment_id = nil milestone.investment_id = nil
expect(milestone).to_not be_valid expect(milestone).to_not be_valid
end end

View File

@@ -7,27 +7,27 @@ describe Budget::Investment do
it_behaves_like "notifiable" it_behaves_like "notifiable"
end end
it "should be valid" do it "is valid" do
expect(investment).to be_valid expect(investment).to be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
investment.author = nil investment.author = nil
expect(investment).to_not be_valid expect(investment).to_not be_valid
end end
describe "#title" do describe "#title" do
it "should not be valid without a title" do it "is not valid without a title" do
investment.title = nil investment.title = nil
expect(investment).to_not be_valid expect(investment).to_not be_valid
end end
it "should not be valid when very short" do it "is not valid when very short" do
investment.title = "abc" investment.title = "abc"
expect(investment).to_not be_valid expect(investment).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
investment.title = "a" * 81 investment.title = "a" * 81
expect(investment).to_not be_valid expect(investment).to_not be_valid
end end
@@ -61,20 +61,20 @@ describe Budget::Investment do
end end
describe "#unfeasibility_explanation blank" do describe "#unfeasibility_explanation blank" do
it "should be valid if valuation not finished" do it "is valid if valuation not finished" do
investment.unfeasibility_explanation = "" investment.unfeasibility_explanation = ""
investment.valuation_finished = false investment.valuation_finished = false
expect(investment).to be_valid expect(investment).to be_valid
end end
it "should be valid if valuation finished and feasible" do it "is valid if valuation finished and feasible" do
investment.unfeasibility_explanation = "" investment.unfeasibility_explanation = ""
investment.feasibility = "feasible" investment.feasibility = "feasible"
investment.valuation_finished = true investment.valuation_finished = true
expect(investment).to be_valid expect(investment).to be_valid
end end
it "should not be valid if valuation finished and unfeasible" do it "is not valid if valuation finished and unfeasible" do
investment.unfeasibility_explanation = "" investment.unfeasibility_explanation = ""
investment.feasibility = "unfeasible" investment.feasibility = "unfeasible"
investment.valuation_finished = true investment.valuation_finished = true
@@ -83,13 +83,13 @@ describe Budget::Investment do
end end
describe "#price blank" do describe "#price blank" do
it "should be valid if valuation not finished" do it "is valid if valuation not finished" do
investment.price = "" investment.price = ""
investment.valuation_finished = false investment.valuation_finished = false
expect(investment).to be_valid expect(investment).to be_valid
end end
it "should be valid if valuation finished and unfeasible" do it "is valid if valuation finished and unfeasible" do
investment.price = "" investment.price = ""
investment.unfeasibility_explanation = "reason" investment.unfeasibility_explanation = "reason"
investment.feasibility = "unfeasible" investment.feasibility = "unfeasible"
@@ -97,7 +97,7 @@ describe Budget::Investment do
expect(investment).to be_valid expect(investment).to be_valid
end end
it "should not be valid if valuation finished and feasible" do it "is not valid if valuation finished and feasible" do
investment.price = "" investment.price = ""
investment.feasibility = "feasible" investment.feasibility = "feasible"
investment.valuation_finished = true investment.valuation_finished = true
@@ -228,7 +228,7 @@ describe Budget::Investment do
end end
describe "by_admin" do describe "by_admin" do
it "should return investments assigned to specific administrator" do it "returns investments assigned to specific administrator" do
investment1 = create(:budget_investment, administrator_id: 33) investment1 = create(:budget_investment, administrator_id: 33)
create(:budget_investment) create(:budget_investment)
@@ -240,7 +240,7 @@ describe Budget::Investment do
end end
describe "by_valuator" do describe "by_valuator" do
it "should return investments assigned to specific valuator" do it "returns investments assigned to specific valuator" do
investment1 = create(:budget_investment) investment1 = create(:budget_investment)
investment2 = create(:budget_investment) investment2 = create(:budget_investment)
investment3 = create(:budget_investment) investment3 = create(:budget_investment)
@@ -261,7 +261,7 @@ describe Budget::Investment do
describe "scopes" do describe "scopes" do
describe "valuation_open" do describe "valuation_open" do
it "should return all investments with false valuation_finished" do it "returns all investments with false valuation_finished" do
investment1 = create(:budget_investment, valuation_finished: true) investment1 = create(:budget_investment, valuation_finished: true)
investment2 = create(:budget_investment) investment2 = create(:budget_investment)
@@ -273,7 +273,7 @@ describe Budget::Investment do
end end
describe "without_admin" do describe "without_admin" do
it "should return all open investments without assigned admin" do it "returns all open investments without assigned admin" do
investment1 = create(:budget_investment, valuation_finished: true) investment1 = create(:budget_investment, valuation_finished: true)
investment2 = create(:budget_investment, administrator: create(:administrator)) investment2 = create(:budget_investment, administrator: create(:administrator))
investment3 = create(:budget_investment) investment3 = create(:budget_investment)
@@ -286,7 +286,7 @@ describe Budget::Investment do
end end
describe "managed" do describe "managed" do
it "should return all open investments with assigned admin but without assigned valuators" do it "returns all open investments with assigned admin but without assigned valuators" do
investment1 = create(:budget_investment, administrator: create(:administrator)) investment1 = create(:budget_investment, administrator: create(:administrator))
investment2 = create(:budget_investment, administrator: create(:administrator), valuation_finished: true) investment2 = create(:budget_investment, administrator: create(:administrator), valuation_finished: true)
investment3 = create(:budget_investment, administrator: create(:administrator)) investment3 = create(:budget_investment, administrator: create(:administrator))
@@ -300,7 +300,7 @@ describe Budget::Investment do
end end
describe "valuating" do describe "valuating" do
it "should return all investments with assigned valuator but valuation not finished" do it "returns all investments with assigned valuator but valuation not finished" do
investment1 = create(:budget_investment) investment1 = create(:budget_investment)
investment2 = create(:budget_investment) investment2 = create(:budget_investment)
investment3 = create(:budget_investment, valuation_finished: true) investment3 = create(:budget_investment, valuation_finished: true)
@@ -316,7 +316,7 @@ describe Budget::Investment do
end end
describe "valuation_finished" do describe "valuation_finished" do
it "should return all investments with valuation finished" do it "returns all investments with valuation finished" do
investment1 = create(:budget_investment) investment1 = create(:budget_investment)
investment2 = create(:budget_investment) investment2 = create(:budget_investment)
investment3 = create(:budget_investment, valuation_finished: true) investment3 = create(:budget_investment, valuation_finished: true)
@@ -332,7 +332,7 @@ describe Budget::Investment do
end end
describe "feasible" do describe "feasible" do
it "should return all feasible investments" do it "returns all feasible investments" do
feasible_investment = create(:budget_investment, :feasible) feasible_investment = create(:budget_investment, :feasible)
create(:budget_investment) create(:budget_investment)
@@ -341,7 +341,7 @@ describe Budget::Investment do
end end
describe "unfeasible" do describe "unfeasible" do
it "should return all unfeasible investments" do it "returns all unfeasible investments" do
unfeasible_investment = create(:budget_investment, :unfeasible) unfeasible_investment = create(:budget_investment, :unfeasible)
create(:budget_investment, :feasible) create(:budget_investment, :feasible)
@@ -350,7 +350,7 @@ describe Budget::Investment do
end end
describe "not_unfeasible" do describe "not_unfeasible" do
it "should return all feasible and undecided investments" do it "returns all feasible and undecided investments" do
unfeasible_investment = create(:budget_investment, :unfeasible) unfeasible_investment = create(:budget_investment, :unfeasible)
undecided_investment = create(:budget_investment, :undecided) undecided_investment = create(:budget_investment, :undecided)
feasible_investment = create(:budget_investment, :feasible) feasible_investment = create(:budget_investment, :feasible)
@@ -360,7 +360,7 @@ describe Budget::Investment do
end end
describe "undecided" do describe "undecided" do
it "should return all undecided investments" do it "returns all undecided investments" do
unfeasible_investment = create(:budget_investment, :unfeasible) unfeasible_investment = create(:budget_investment, :unfeasible)
undecided_investment = create(:budget_investment, :undecided) undecided_investment = create(:budget_investment, :undecided)
feasible_investment = create(:budget_investment, :feasible) feasible_investment = create(:budget_investment, :feasible)
@@ -370,7 +370,7 @@ describe Budget::Investment do
end end
describe "selected" do describe "selected" do
it "should return all selected investments" do it "returns all selected investments" do
selected_investment = create(:budget_investment, :selected) selected_investment = create(:budget_investment, :selected)
unselected_investment = create(:budget_investment, :unselected) unselected_investment = create(:budget_investment, :unselected)
@@ -379,7 +379,7 @@ describe Budget::Investment do
end end
describe "unselected" do describe "unselected" do
it "should return all unselected not_unfeasible investments" do it "returns all unselected not_unfeasible investments" do
selected_investment = create(:budget_investment, :selected) selected_investment = create(:budget_investment, :selected)
unselected_unfeasible_investment = create(:budget_investment, :unselected, :unfeasible) unselected_unfeasible_investment = create(:budget_investment, :unselected, :unfeasible)
unselected_undecided_investment = create(:budget_investment, :unselected, :undecided) unselected_undecided_investment = create(:budget_investment, :unselected, :undecided)
@@ -580,7 +580,7 @@ describe Budget::Investment do
describe "Order" do describe "Order" do
describe "#sort_by_confidence_score" do describe "#sort_by_confidence_score" do
it "should order by confidence_score" do it "orders by confidence_score" do
least_voted = create(:budget_investment, cached_votes_up: 1) least_voted = create(:budget_investment, cached_votes_up: 1)
most_voted = create(:budget_investment, cached_votes_up: 10) most_voted = create(:budget_investment, cached_votes_up: 10)
some_votes = create(:budget_investment, cached_votes_up: 5) some_votes = create(:budget_investment, cached_votes_up: 5)
@@ -590,7 +590,7 @@ describe Budget::Investment do
expect(described_class.sort_by_confidence_score.third).to eq least_voted expect(described_class.sort_by_confidence_score.third).to eq least_voted
end end
it "should order by confidence_score and then by id" do it "orders by confidence_score and then by id" do
least_voted = create(:budget_investment, cached_votes_up: 1) least_voted = create(:budget_investment, cached_votes_up: 1)
most_voted = create(:budget_investment, cached_votes_up: 10) most_voted = create(:budget_investment, cached_votes_up: 10)
most_voted2 = create(:budget_investment, cached_votes_up: 10) most_voted2 = create(:budget_investment, cached_votes_up: 10)
@@ -637,7 +637,7 @@ describe Budget::Investment do
end end
describe "#with_supports" do describe "#with_supports" do
it "should return proposals with supports" do it "returns proposals with supports" do
inv1 = create(:budget_investment) inv1 = create(:budget_investment)
inv2 = create(:budget_investment) inv2 = create(:budget_investment)
create(:vote, votable: inv1) create(:vote, votable: inv1)

View File

@@ -5,21 +5,21 @@ describe Budget::ReclassifiedVote do
describe "Validations" do describe "Validations" do
let(:reclassified_vote) { build(:budget_reclassified_vote) } let(:reclassified_vote) { build(:budget_reclassified_vote) }
it "should be valid" do it "is valid" do
expect(reclassified_vote).to be_valid expect(reclassified_vote).to be_valid
end end
it "should not be valid without a user" do it "is not valid without a user" do
reclassified_vote.user_id = nil reclassified_vote.user_id = nil
expect(reclassified_vote).to_not be_valid expect(reclassified_vote).to_not be_valid
end end
it "should not be valid without an investment" do it "is not valid without an investment" do
reclassified_vote.investment_id = nil reclassified_vote.investment_id = nil
expect(reclassified_vote).to_not be_valid expect(reclassified_vote).to_not be_valid
end end
it "should not be valid without a valid reason" do it "is not valid without a valid reason" do
reclassified_vote.reason = nil reclassified_vote.reason = nil
expect(reclassified_vote).to_not be_valid expect(reclassified_vote).to_not be_valid

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe Community, type: :model do RSpec.describe Community, type: :model do
it "should be valid when create proposal" do it "is valid when create proposal" do
proposal = create(:proposal) proposal = create(:proposal)
expect(proposal.community).to be_valid expect(proposal.community).to be_valid
@@ -10,7 +10,7 @@ RSpec.describe Community, type: :model do
describe "#participants" do describe "#participants" do
it "should return participants without duplicates" do it "returns participants without duplicates" do
proposal = create(:proposal) proposal = create(:proposal)
community = proposal.community community = proposal.community
user1 = create(:user) user1 = create(:user)

View File

@@ -7,7 +7,7 @@ describe Verification::Residence do
describe "verification" do describe "verification" do
describe "postal code" do describe "postal code" do
it "should be valid with postal codes starting with 280" do it "is valid with postal codes starting with 280" do
residence.postal_code = "28012" residence.postal_code = "28012"
residence.valid? residence.valid?
expect(residence.errors[:postal_code].size).to eq(0) expect(residence.errors[:postal_code].size).to eq(0)
@@ -17,7 +17,7 @@ describe Verification::Residence do
expect(residence.errors[:postal_code].size).to eq(0) expect(residence.errors[:postal_code].size).to eq(0)
end end
it "should not be valid with postal codes not starting with 280" do it "is not valid with postal codes not starting with 280" do
residence.postal_code = "12345" residence.postal_code = "12345"
residence.valid? residence.valid?
expect(residence.errors[:postal_code].size).to eq(1) expect(residence.errors[:postal_code].size).to eq(1)

View File

@@ -9,79 +9,79 @@ describe Debate do
it_behaves_like "notifiable" it_behaves_like "notifiable"
end end
it "should be valid" do it "is valid" do
expect(debate).to be_valid expect(debate).to be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
debate.author = nil debate.author = nil
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
describe "#title" do describe "#title" do
it "should not be valid without a title" do it "is not valid without a title" do
debate.title = nil debate.title = nil
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
it "should not be valid when very short" do it "is not valid when very short" do
debate.title = "abc" debate.title = "abc"
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
debate.title = "a" * 81 debate.title = "a" * 81
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
end end
describe "#description" do describe "#description" do
it "should not be valid without a description" do it "is not valid without a description" do
debate.description = nil debate.description = nil
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
it "should be sanitized" do it "is sanitized" do
debate.description = "<script>alert('danger');</script>" debate.description = "<script>alert('danger');</script>"
debate.valid? debate.valid?
expect(debate.description).to eq("alert('danger');") expect(debate.description).to eq("alert('danger');")
end end
it "should be html_safe" do it "is html_safe" do
debate.description = "<script>alert('danger');</script>" debate.description = "<script>alert('danger');</script>"
expect(debate.description).to be_html_safe expect(debate.description).to be_html_safe
end end
it "should not be valid when very short" do it "is not valid when very short" do
debate.description = "abc" debate.description = "abc"
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
debate.description = "a" * 6001 debate.description = "a" * 6001
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
end end
describe "#tag_list" do describe "#tag_list" do
it "should sanitize the tag list" do it "sanitizes the tag list" do
debate.tag_list = "user_id=1" debate.tag_list = "user_id=1"
debate.valid? debate.valid?
expect(debate.tag_list).to eq(['user_id1']) expect(debate.tag_list).to eq(['user_id1'])
end end
it "should not be valid with a tag list of more than 6 elements" do it "is not valid with a tag list of more than 6 elements" do
debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"]
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
it "should be valid with a tag list of 6 elements" do it "is valid with a tag list of 6 elements" do
debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
expect(debate).to be_valid expect(debate).to be_valid
end end
end end
it "should not be valid without accepting terms of service" do it "is not valid without accepting terms of service" do
debate.terms_of_service = nil debate.terms_of_service = nil
expect(debate).to_not be_valid expect(debate).to_not be_valid
end end
@@ -92,18 +92,18 @@ describe Debate do
before(:each) { Setting["max_votes_for_debate_edit"] = 3 } before(:each) { Setting["max_votes_for_debate_edit"] = 3 }
after(:each) { Setting["max_votes_for_debate_edit"] = 1000 } after(:each) { Setting["max_votes_for_debate_edit"] = 1000 }
it "should be true if debate has no votes yet" do it "is true if debate has no votes yet" do
expect(debate.total_votes).to eq(0) expect(debate.total_votes).to eq(0)
expect(debate.editable?).to be true expect(debate.editable?).to be true
end end
it "should be true if debate has less than limit votes" do it "is true if debate has less than limit votes" do
create_list(:vote, 2, votable: debate) create_list(:vote, 2, votable: debate)
expect(debate.total_votes).to eq(2) expect(debate.total_votes).to eq(2)
expect(debate.editable?).to be true expect(debate.editable?).to be true
end end
it "should be false if debate has more than limit votes" do it "is false if debate has more than limit votes" do
create_list(:vote, 4, votable: debate) create_list(:vote, 4, votable: debate)
expect(debate.total_votes).to eq(4) expect(debate.total_votes).to eq(4)
expect(debate.editable?).to be false expect(debate.editable?).to be false
@@ -116,16 +116,16 @@ describe Debate do
before(:each) { Setting["max_votes_for_debate_edit"] = 1 } before(:each) { Setting["max_votes_for_debate_edit"] = 1 }
after(:each) { Setting["max_votes_for_debate_edit"] = 1000 } after(:each) { Setting["max_votes_for_debate_edit"] = 1000 }
it "should be true if user is the author and debate is editable" do it "is true if user is the author and debate is editable" do
expect(debate.editable_by?(debate.author)).to be true expect(debate.editable_by?(debate.author)).to be true
end end
it "should be false if debate is not editable" do it "is false if debate is not editable" do
create_list(:vote, 2, votable: debate) create_list(:vote, 2, votable: debate)
expect(debate.editable_by?(debate.author)).to be false expect(debate.editable_by?(debate.author)).to be false
end end
it "should be false if user is not the author" do it "is false if user is not the author" do
expect(debate.editable_by?(create(:user))).to be false expect(debate.editable_by?(create(:user))).to be false
end end
end end
@@ -137,29 +137,29 @@ describe Debate do
Setting["max_ratio_anon_votes_on_debates"] = 50 Setting["max_ratio_anon_votes_on_debates"] = 50
end end
it "should be true for level two verified users" do it "is true for level two verified users" do
user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111")
expect(debate.votable_by?(user)).to be true expect(debate.votable_by?(user)).to be true
end end
it "should be true for level three verified users" do it "is true for level three verified users" do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
expect(debate.votable_by?(user)).to be true expect(debate.votable_by?(user)).to be true
end end
it "should be true for anonymous users if allowed anonymous votes" do it "is true for anonymous users if allowed anonymous votes" do
debate.update(cached_anonymous_votes_total: 420, cached_votes_total: 1000) debate.update(cached_anonymous_votes_total: 420, cached_votes_total: 1000)
user = create(:user) user = create(:user)
expect(debate.votable_by?(user)).to be true expect(debate.votable_by?(user)).to be true
end end
it "should be true for anonymous users if less than 100 votes" do it "is true for anonymous users if less than 100 votes" do
debate.update(cached_anonymous_votes_total: 90, cached_votes_total: 92) debate.update(cached_anonymous_votes_total: 90, cached_votes_total: 92)
user = create(:user) user = create(:user)
expect(debate.votable_by?(user)).to be true expect(debate.votable_by?(user)).to be true
end end
it "should be false for anonymous users if too many anonymous votes" do it "is false for anonymous users if too many anonymous votes" do
debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000) debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
user = create(:user) user = create(:user)
expect(debate.votable_by?(user)).to be false expect(debate.votable_by?(user)).to be false
@@ -174,24 +174,24 @@ describe Debate do
end end
describe "from level two verified users" do describe "from level two verified users" do
it "should register vote" do it "registers vote" do
user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111")
expect {debate.register_vote(user, 'yes')}.to change{debate.reload.votes_for.size}.by(1) expect {debate.register_vote(user, 'yes')}.to change{debate.reload.votes_for.size}.by(1)
end end
it "should not increase anonymous votes counter " do it "does not increase anonymous votes counter " do
user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111")
expect {debate.register_vote(user, 'yes')}.to_not change{debate.reload.cached_anonymous_votes_total} expect {debate.register_vote(user, 'yes')}.to_not change{debate.reload.cached_anonymous_votes_total}
end end
end end
describe "from level three verified users" do describe "from level three verified users" do
it "should register vote" do it "registers vote" do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
expect {debate.register_vote(user, 'yes')}.to change{debate.reload.votes_for.size}.by(1) expect {debate.register_vote(user, 'yes')}.to change{debate.reload.votes_for.size}.by(1)
end end
it "should not increase anonymous votes counter " do it "does not increase anonymous votes counter " do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
expect {debate.register_vote(user, 'yes')}.to_not change{debate.reload.cached_anonymous_votes_total} expect {debate.register_vote(user, 'yes')}.to_not change{debate.reload.cached_anonymous_votes_total}
end end
@@ -200,12 +200,12 @@ describe Debate do
describe "from anonymous users when anonymous votes are allowed" do describe "from anonymous users when anonymous votes are allowed" do
before(:each) {debate.update(cached_anonymous_votes_total: 42, cached_votes_total: 100)} before(:each) {debate.update(cached_anonymous_votes_total: 42, cached_votes_total: 100)}
it "should register vote " do it "registers vote" do
user = create(:user) user = create(:user)
expect {debate.register_vote(user, 'yes')}.to change {debate.reload.votes_for.size}.by(1) expect {debate.register_vote(user, 'yes')}.to change {debate.reload.votes_for.size}.by(1)
end end
it "should increase anonymous votes counter " do it "increases anonymous votes counter" do
user = create(:user) user = create(:user)
expect {debate.register_vote(user, 'yes')}.to change {debate.reload.cached_anonymous_votes_total}.by(1) expect {debate.register_vote(user, 'yes')}.to change {debate.reload.cached_anonymous_votes_total}.by(1)
end end
@@ -214,12 +214,12 @@ describe Debate do
describe "from anonymous users when there are too many anonymous votes" do describe "from anonymous users when there are too many anonymous votes" do
before(:each) {debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)} before(:each) {debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)}
it "should not register vote " do it "does not register vote " do
user = create(:user) user = create(:user)
expect {debate.register_vote(user, 'yes')}.to_not change {debate.reload.votes_for.size} expect {debate.register_vote(user, 'yes')}.to_not change {debate.reload.votes_for.size}
end end
it "should not increase anonymous votes counter " do it "does not increase anonymous votes counter " do
user = create(:user) user = create(:user)
expect {debate.register_vote(user, 'yes')}.to_not change {debate.reload.cached_anonymous_votes_total} expect {debate.register_vote(user, 'yes')}.to_not change {debate.reload.cached_anonymous_votes_total}
end end
@@ -334,47 +334,47 @@ describe Debate do
describe "cache" do describe "cache" do
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
it "should expire cache when it has a new comment" do it "expires cache when it has a new comment" do
expect { create(:comment, commentable: debate) } expect { create(:comment, commentable: debate) }
.to change { debate.updated_at } .to change { debate.updated_at }
end end
it "should expire cache when it has a new vote" do it "expires cache when it has a new vote" do
expect { create(:vote, votable: debate) } expect { create(:vote, votable: debate) }
.to change { debate.updated_at } .to change { debate.updated_at }
end end
it "should expire cache when it has a new flag" do it "expires cache when it has a new flag" do
expect { create(:flag, flaggable: debate) } expect { create(:flag, flaggable: debate) }
.to change { debate.reload.updated_at } .to change { debate.reload.updated_at }
end end
it "should expire cache when it has a new tag" do it "expires cache when it has a new tag" do
expect { debate.update(tag_list: "new tag") } expect { debate.update(tag_list: "new tag") }
.to change { debate.updated_at } .to change { debate.updated_at }
end end
it "should expire cache when hidden" do it "expires cache when hidden" do
expect { debate.hide } expect { debate.hide }
.to change { debate.updated_at } .to change { debate.updated_at }
end end
it "should expire cache when the author is hidden" do it "expires cache when the author is hidden" do
expect { debate.author.hide } expect { debate.author.hide }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.updated_at, debate.author.updated_at] }
end end
it "should expire cache when the author is erased" do it "expires cache when the author is erased" do
expect { debate.author.erase } expect { debate.author.erase }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.updated_at, debate.author.updated_at] }
end end
it "should expire cache when its author changes" do it "expires cache when its author changes" do
expect { debate.author.update(username: "Eva") } expect { debate.author.update(username: "Eva") }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.updated_at, debate.author.updated_at] }
end end
it "should expire cache when the author's organization get verified" do it "expires cache when the author's organization get verified" do
create(:organization, user: debate.author) create(:organization, user: debate.author)
expect { debate.author.organization.verify } expect { debate.author.organization.verify }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.updated_at, debate.author.updated_at] }
@@ -397,7 +397,7 @@ describe Debate do
describe "conflictive debates" do describe "conflictive debates" do
it "should return true when it has more than 1 flag for 5 positive votes" do it "returns true when it has more than 1 flag for 5 positive votes" do
debate.update(cached_votes_up: 4) debate.update(cached_votes_up: 4)
debate.update(flags_count: 1) debate.update(flags_count: 1)
expect(debate).to be_conflictive expect(debate).to be_conflictive
@@ -415,7 +415,7 @@ describe Debate do
expect(debate).to be_conflictive expect(debate).to be_conflictive
end end
it "should return false when it has less than or equal to 1 flag for 5 positive votes" do it "returns false when it has less than or equal to 1 flag for 5 positive votes" do
debate.update(cached_votes_up: 5) debate.update(cached_votes_up: 5)
debate.update(flags_count: 1) debate.update(flags_count: 1)
expect(debate).to_not be_conflictive expect(debate).to_not be_conflictive
@@ -429,12 +429,12 @@ describe Debate do
expect(debate).to_not be_conflictive expect(debate).to_not be_conflictive
end end
it "should return false when it has no flags" do it "returns false when it has no flags" do
debate.update(flags_count: 0) debate.update(flags_count: 0)
expect(debate).to_not be_conflictive expect(debate).to_not be_conflictive
end end
it "should return false when it has not votes up" do it "returns false when it has not votes up" do
debate.update(cached_votes_up: 0) debate.update(cached_votes_up: 0)
expect(debate).to_not be_conflictive expect(debate).to_not be_conflictive
end end
@@ -574,7 +574,7 @@ describe Debate do
context "reorder" do context "reorder" do
it "should be able to reorder by hot_score after searching" do it "is able to reorder by hot_score after searching" do
lowest_score = create(:debate, title: 'stop corruption', cached_votes_up: 1) lowest_score = create(:debate, title: 'stop corruption', cached_votes_up: 1)
highest_score = create(:debate, title: 'stop corruption', cached_votes_up: 2) highest_score = create(:debate, title: 'stop corruption', cached_votes_up: 2)
average_score = create(:debate, title: 'stop corruption', cached_votes_up: 3) average_score = create(:debate, title: 'stop corruption', cached_votes_up: 3)
@@ -596,7 +596,7 @@ describe Debate do
expect(results.third).to eq(lowest_score) expect(results.third).to eq(lowest_score)
end end
it "should be able to reorder by confidence_score after searching" do it "is able to reorder by confidence_score after searching" do
lowest_score = create(:debate, title: 'stop corruption', cached_votes_up: 1) lowest_score = create(:debate, title: 'stop corruption', cached_votes_up: 1)
highest_score = create(:debate, title: 'stop corruption', cached_votes_up: 2) highest_score = create(:debate, title: 'stop corruption', cached_votes_up: 2)
average_score = create(:debate, title: 'stop corruption', cached_votes_up: 3) average_score = create(:debate, title: 'stop corruption', cached_votes_up: 3)
@@ -618,7 +618,7 @@ describe Debate do
expect(results.third).to eq(lowest_score) expect(results.third).to eq(lowest_score)
end end
it "should be able to reorder by created_at after searching" do it "is able to reorder by created_at after searching" do
recent = create(:debate, title: 'stop corruption', cached_votes_up: 1, created_at: 1.week.ago) recent = create(:debate, title: 'stop corruption', cached_votes_up: 1, created_at: 1.week.ago)
newest = create(:debate, title: 'stop corruption', cached_votes_up: 2, created_at: Time.current) 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) oldest = create(:debate, title: 'stop corruption', cached_votes_up: 3, created_at: 1.month.ago)
@@ -636,7 +636,7 @@ describe Debate do
expect(results.third).to eq(oldest) expect(results.third).to eq(oldest)
end end
it "should be able to reorder by most commented after searching" do it "is able to reorder by most commented after searching" do
least_commented = create(:debate, title: 'stop corruption', cached_votes_up: 1, comments_count: 1) least_commented = create(:debate, title: 'stop corruption', cached_votes_up: 1, comments_count: 1)
most_commented = create(:debate, title: 'stop corruption', cached_votes_up: 2, comments_count: 100) 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) some_comments = create(:debate, title: 'stop corruption', cached_votes_up: 3, comments_count: 10)
@@ -690,19 +690,19 @@ describe Debate do
end end
describe "#last_week" do describe "#last_week" do
it "should return debates created this week" do it "returns debates created this week" do
debate = create(:debate) debate = create(:debate)
expect(described_class.last_week.all).to include debate expect(described_class.last_week.all).to include debate
end end
it "should not show debates created more than a week ago" do it "does not show debates created more than a week ago" do
debate = create(:debate, created_at: 8.days.ago) debate = create(:debate, created_at: 8.days.ago)
expect(described_class.last_week.all).to_not include debate expect(described_class.last_week.all).to_not include debate
end end
end end
describe "#to_param" do describe "#to_param" do
it "should return a friendly url" do it "returns a friendly url" do
expect(debate.to_param).to eq "#{debate.id} #{debate.title}".parameterize expect(debate.to_param).to eq "#{debate.id} #{debate.title}".parameterize
end end
end end
@@ -723,13 +723,13 @@ describe Debate do
let(:user) { create(:user) } let(:user) { create(:user) }
it "Should not return any debates when user has not interests" do it "does not return any debates when user has not interests" do
create(:debate) create(:debate)
expect(described_class.recommendations(user).size).to eq 0 expect(described_class.recommendations(user).size).to eq 0
end end
it "Should return debates ordered by cached_votes_total" do it "returns debates ordered by cached_votes_total" do
debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport") debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport")
debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport") debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport")
debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport") debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport")
@@ -743,7 +743,7 @@ describe Debate do
expect(result.third).to eq debate1 expect(result.third).to eq debate1
end end
it "Should return debates related with user interests" do it "returns debates related with user interests" do
debate1 = create(:debate, tag_list: "Sport") debate1 = create(:debate, tag_list: "Sport")
debate2 = create(:debate, tag_list: "Politics") debate2 = create(:debate, tag_list: "Politics")
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
@@ -755,7 +755,7 @@ describe Debate do
expect(result).to eq [debate1] expect(result).to eq [debate1]
end end
it "Should not return debates when user is the author" do it "does not return debates when user is the author" do
debate1 = create(:debate, author: user, tag_list: "Sport") debate1 = create(:debate, author: user, tag_list: "Sport")
debate2 = create(:debate, tag_list: "Sport") debate2 = create(:debate, tag_list: "Sport")
proposal = create(:proposal, tag_list: "Sport") proposal = create(:proposal, tag_list: "Sport")

View File

@@ -4,26 +4,26 @@ describe DirectMessage do
let(:direct_message) { build(:direct_message) } let(:direct_message) { build(:direct_message) }
it "should be valid" do it "is valid" do
expect(direct_message).to be_valid expect(direct_message).to be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
direct_message.title = nil direct_message.title = nil
expect(direct_message).to_not be_valid expect(direct_message).to_not be_valid
end end
it "should not be valid without a body" do it "is not valid without a body" do
direct_message.body = nil direct_message.body = nil
expect(direct_message).to_not be_valid expect(direct_message).to_not be_valid
end end
it "should not be valid without an associated sender" do it "is not valid without an associated sender" do
direct_message.sender = nil direct_message.sender = nil
expect(direct_message).to_not be_valid expect(direct_message).to_not be_valid
end end
it "should not be valid without an associated receiver" do it "is not valid without an associated receiver" do
direct_message.receiver = nil direct_message.receiver = nil
expect(direct_message).to_not be_valid expect(direct_message).to_not be_valid
end end
@@ -34,7 +34,7 @@ describe DirectMessage do
Setting[:direct_message_max_per_day] = 3 Setting[:direct_message_max_per_day] = 3
end end
it "should not be valid if above maximum" do it "is not valid if above maximum" do
sender = create(:user) sender = create(:user)
direct_message1 = create(:direct_message, sender: sender) direct_message1 = create(:direct_message, sender: sender)
direct_message2 = create(:direct_message, sender: sender) direct_message2 = create(:direct_message, sender: sender)
@@ -44,7 +44,7 @@ describe DirectMessage do
expect(direct_message4).to_not be_valid expect(direct_message4).to_not be_valid
end end
it "should be valid if below maximum" do it "is valid if below maximum" do
sender = create(:user) sender = create(:user)
direct_message1 = create(:direct_message, sender: sender) direct_message1 = create(:direct_message, sender: sender)
direct_message2 = create(:direct_message, sender: sender) direct_message2 = create(:direct_message, sender: sender)
@@ -53,7 +53,7 @@ describe DirectMessage do
expect(direct_message).to be_valid expect(direct_message).to be_valid
end end
it "should be valid if no direct_messages sent" do it "is valid if no direct_messages sent" do
direct_message = build(:direct_message) direct_message = build(:direct_message)
expect(direct_message).to be_valid expect(direct_message).to be_valid
@@ -65,7 +65,7 @@ describe DirectMessage do
Setting[:direct_message_max_per_day] = nil Setting[:direct_message_max_per_day] = nil
end end
it "should be valid" do it "is valid" do
direct_message = build(:direct_message) direct_message = build(:direct_message)
expect(direct_message).to be_valid expect(direct_message).to be_valid
@@ -76,7 +76,7 @@ describe DirectMessage do
describe "scopes" do describe "scopes" do
describe "today" do describe "today" do
it "should return direct messages created today" do it "returns direct messages created today" do
direct_message1 = create(:direct_message, created_at: Time.now.utc.beginning_of_day + 3.hours) direct_message1 = create(:direct_message, created_at: Time.now.utc.beginning_of_day + 3.hours)
direct_message2 = create(:direct_message, created_at: Time.now.utc) direct_message2 = create(:direct_message, created_at: Time.now.utc)
direct_message3 = create(:direct_message, created_at: Time.now.utc.end_of_day) direct_message3 = create(:direct_message, created_at: Time.now.utc.end_of_day)
@@ -84,7 +84,7 @@ describe DirectMessage do
expect(described_class.today.count).to eq 3 expect(described_class.today.count).to eq 3
end end
it "should not return direct messages created another day" do it "does not return direct messages created another day" do
direct_message1 = create(:direct_message, created_at: 1.day.ago) direct_message1 = create(:direct_message, created_at: 1.day.ago)
direct_message2 = create(:direct_message, created_at: 1.day.from_now) direct_message2 = create(:direct_message, created_at: 1.day.from_now)

View File

@@ -4,40 +4,40 @@ describe DirectUpload do
context "configurations" do context "configurations" do
it "should be valid for different kind of combinations when attachment is valid" do it "is valid for different kind of combinations when attachment is valid" do
expect(build(:direct_upload, :proposal, :documents)).to be_valid expect(build(:direct_upload, :proposal, :documents)).to be_valid
expect(build(:direct_upload, :proposal, :image)).to be_valid expect(build(:direct_upload, :proposal, :image)).to be_valid
expect(build(:direct_upload, :budget_investment, :documents)).to be_valid expect(build(:direct_upload, :budget_investment, :documents)).to be_valid
expect(build(:direct_upload, :budget_investment, :image)).to be_valid expect(build(:direct_upload, :budget_investment, :image)).to be_valid
end end
it "should not be valid for different kind of combinations with invalid atttachment content types" do it "is not valid for different kind of combinations with invalid atttachment content types" do
expect(build(:direct_upload, :proposal, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid expect(build(:direct_upload, :proposal, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
expect(build(:direct_upload, :proposal, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid expect(build(:direct_upload, :proposal, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
expect(build(:direct_upload, :budget_investment, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid expect(build(:direct_upload, :budget_investment, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
end end
it "should not be valid without resource_type" do it "is not valid without resource_type" do
expect(build(:direct_upload, :proposal, :documents, resource_type: nil)).not_to be_valid expect(build(:direct_upload, :proposal, :documents, resource_type: nil)).not_to be_valid
end end
it "should not be valid without resource_relation" do it "is not valid without resource_relation" do
expect(build(:direct_upload, :proposal, :documents, resource_relation: nil)).not_to be_valid expect(build(:direct_upload, :proposal, :documents, resource_relation: nil)).not_to be_valid
end end
it "should not be valid without attachment" do it "is not valid without attachment" do
expect(build(:direct_upload, :proposal, :documents, attachment: nil)).not_to be_valid expect(build(:direct_upload, :proposal, :documents, attachment: nil)).not_to be_valid
end end
it "should not be valid without user" do it "is not valid without user" do
expect(build(:direct_upload, :proposal, :documents, user: nil)).not_to be_valid expect(build(:direct_upload, :proposal, :documents, user: nil)).not_to be_valid
end end
end end
context "save_attachment" do context "save_attachment" do
it "should save uploaded file" do it "saves uploaded file" do
proposal_document_direct_upload = build(:direct_upload, :proposal, :documents) proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)
proposal_document_direct_upload.save_attachment proposal_document_direct_upload.save_attachment
@@ -50,7 +50,7 @@ describe DirectUpload do
context "destroy_attachment" do context "destroy_attachment" do
it "should remove uploaded file" do it "removes uploaded file" do
proposal_document_direct_upload = build(:direct_upload, :proposal, :documents) proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)
proposal_document_direct_upload.save_attachment proposal_document_direct_upload.save_attachment

View File

@@ -4,21 +4,21 @@ describe Follow do
let(:follow) { build(:follow, :followed_proposal) } let(:follow) { build(:follow, :followed_proposal) }
it "should be valid" do it "is valid" do
expect(follow).to be_valid expect(follow).to be_valid
end end
it "should not be valid without a user_id" do it "is not valid without a user_id" do
follow.user_id = nil follow.user_id = nil
expect(follow).to_not be_valid expect(follow).to_not be_valid
end end
it "should not be valid without a followable_id" do it "is not valid without a followable_id" do
follow.followable_id = nil follow.followable_id = nil
expect(follow).to_not be_valid expect(follow).to_not be_valid
end end
it "should not be valid without a followable_type" do it "is not valid without a followable_type" do
follow.followable_type = nil follow.followable_type = nil
expect(follow).to_not be_valid expect(follow).to_not be_valid
end end

View File

@@ -3,11 +3,11 @@ require 'rails_helper'
describe Geozone do describe Geozone do
let(:geozone) { build(:geozone) } let(:geozone) { build(:geozone) }
it "should be valid" do it "is valid" do
expect(geozone).to be_valid expect(geozone).to be_valid
end end
it "should not be valid without a name" do it "is not valid without a name" do
geozone.name = nil geozone.name = nil
expect(geozone).to_not be_valid expect(geozone).to_not be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe Identity, type: :model do RSpec.describe Identity, type: :model do
let(:identity) { build(:identity) } let(:identity) { build(:identity) }
it "should be valid" do it "is valid" do
expect(identity).to be_valid expect(identity).to be_valid
end end
end end

View File

@@ -4,7 +4,7 @@ RSpec.describe Legislation::Annotation, type: :model do
let(:draft_version) { create(:legislation_draft_version) } let(:draft_version) { create(:legislation_draft_version) }
let(:annotation) { create(:legislation_annotation, draft_version: draft_version) } let(:annotation) { create(:legislation_annotation, draft_version: draft_version) }
it "should be valid" do it "is valid" do
expect(draft_version).to be_valid expect(draft_version).to be_valid
expect(annotation).to be_valid expect(annotation).to be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe Legislation::Answer, type: :model do RSpec.describe Legislation::Answer, type: :model do
let(:legislation_answer) { build(:legislation_answer) } let(:legislation_answer) { build(:legislation_answer) }
it "should be valid" do it "is valid" do
expect(legislation_answer).to be_valid expect(legislation_answer).to be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe Legislation::DraftVersion, type: :model do RSpec.describe Legislation::DraftVersion, type: :model do
let(:legislation_draft_version) { build(:legislation_draft_version) } let(:legislation_draft_version) { build(:legislation_draft_version) }
it "should be valid" do it "is valid" do
expect(legislation_draft_version).to be_valid expect(legislation_draft_version).to be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Legislation::Process do describe Legislation::Process do
let(:process) { create(:legislation_process) } let(:process) { create(:legislation_process) }
it "should be valid" do it "is valid" do
expect(process).to be_valid expect(process).to be_valid
end end
@@ -101,17 +101,17 @@ describe Legislation::Process do
end end
describe "#status" do describe "#status" do
it "should detect planned phase" do it "detects planned phase" do
process.update_attributes(start_date: Date.current + 2.days) process.update_attributes(start_date: Date.current + 2.days)
expect(process.status).to eq(:planned) expect(process.status).to eq(:planned)
end end
it "should detect closed phase" do it "detects closed phase" do
process.update_attributes(end_date: Date.current - 2.days) process.update_attributes(end_date: Date.current - 2.days)
expect(process.status).to eq(:closed) expect(process.status).to eq(:closed)
end end
it "should detect open phase" do it "detects open phase" do
expect(process.status).to eq(:open) expect(process.status).to eq(:open)
end end
end end

View File

@@ -3,26 +3,26 @@ require 'rails_helper'
describe Legislation::Proposal do describe Legislation::Proposal do
let(:proposal) { build(:legislation_proposal) } let(:proposal) { build(:legislation_proposal) }
it "should be valid" do it "is valid" do
expect(proposal).to be_valid expect(proposal).to be_valid
end end
it "should not be valid without a process" do it "is not valid without a process" do
proposal.process = nil proposal.process = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
proposal.author = nil proposal.author = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
proposal.title = nil proposal.title = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid without a summary" do it "is not valid without a summary" do
proposal.summary = nil proposal.summary = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end

View File

@@ -3,11 +3,11 @@ require 'rails_helper'
RSpec.describe Legislation::QuestionOption, type: :model do RSpec.describe Legislation::QuestionOption, type: :model do
let(:legislation_question_option) { build(:legislation_question_option) } let(:legislation_question_option) { build(:legislation_question_option) }
it "should be valid" do it "is valid" do
expect(legislation_question_option).to be_valid expect(legislation_question_option).to be_valid
end end
it "should be unique per question" do it "is unique per question" do
question = create(:legislation_question) question = create(:legislation_question)
valid_question_option = create(:legislation_question_option, question: question, value: "uno") valid_question_option = create(:legislation_question_option, question: question, value: "uno")

View File

@@ -7,7 +7,7 @@ describe Legislation::Question do
it_behaves_like "notifiable" it_behaves_like "notifiable"
end end
it "should be valid" do it "is valid" do
expect(question).to be_valid expect(question).to be_valid
end end
@@ -45,11 +45,11 @@ describe Legislation::Question do
let!(:question1) { create(:legislation_question) } let!(:question1) { create(:legislation_question) }
let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) } let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) }
it "should return the next question" do it "returns the next question" do
expect(question1.next_question_id).to eq(question2.id) expect(question1.next_question_id).to eq(question2.id)
end end
it "should return nil" do it "returns nil" do
expect(question2.next_question_id).to be_nil expect(question2.next_question_id).to be_nil
end end
end end
@@ -58,7 +58,7 @@ describe Legislation::Question do
let!(:question1) { create(:legislation_question) } let!(:question1) { create(:legislation_question) }
let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) } let!(:question2) { create(:legislation_question, legislation_process_id: question1.legislation_process_id) }
it "should return the first question" do it "returns the first question" do
expect(question1.first_question_id).to eq(question1.id) expect(question1.first_question_id).to eq(question1.id)
expect(question2.first_question_id).to eq(question1.id) expect(question2.first_question_id).to eq(question1.id)
end end

View File

@@ -8,11 +8,11 @@ describe Verification::Letter do
let(:letter) { build(:verification_letter) } let(:letter) { build(:verification_letter) }
it "should be valid" do it "is valid" do
expect(letter).to be_valid expect(letter).to be_valid
end end
it "should not be valid without a user" do it "is not valid without a user" do
letter.user = nil letter.user = nil
expect(letter).to_not be_valid expect(letter).to_not be_valid
end end
@@ -21,7 +21,7 @@ describe Verification::Letter do
describe "save" do describe "save" do
it "should update letter_requested" do it "updates letter_requested" do
letter = build(:verification_letter) letter = build(:verification_letter)
letter.save letter.save
expect(letter.user.letter_requested_at).to be expect(letter.user.letter_requested_at).to be

View File

@@ -4,29 +4,29 @@ describe MapLocation do
let(:map_location) { build(:map_location, :proposal_map_location) } let(:map_location) { build(:map_location, :proposal_map_location) }
it "should be valid" do it "is valid" do
expect(map_location).to be_valid expect(map_location).to be_valid
end end
context "#available?" do context "#available?" do
it "should return true when latitude, longitude and zoom defined" do it "returns true when latitude, longitude and zoom defined" do
expect(map_location.available?).to be(true) expect(map_location.available?).to be(true)
end end
it "should return false when longitude is nil" do it "returns false when longitude is nil" do
map_location.longitude = nil map_location.longitude = nil
expect(map_location.available?).to be(false) expect(map_location.available?).to be(false)
end end
it "should return false when latitude is nil" do it "returns false when latitude is nil" do
map_location.latitude = nil map_location.latitude = nil
expect(map_location.available?).to be(false) expect(map_location.available?).to be(false)
end end
it "should return false when zoom is nil" do it "returns false when zoom is nil" do
map_location.zoom = nil map_location.zoom = nil
expect(map_location.available?).to be(false) expect(map_location.available?).to be(false)

View File

@@ -7,33 +7,33 @@ describe Officing::Residence do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(residence).to be_valid expect(residence).to be_valid
end end
it "should not be valid without a document number" do it "is not valid without a document number" do
residence.document_number = nil residence.document_number = nil
expect(residence).to_not be_valid expect(residence).to_not be_valid
end end
it "should not be valid without a document type" do it "is not valid without a document type" do
residence.document_type = nil residence.document_type = nil
expect(residence).to_not be_valid expect(residence).to_not be_valid
end end
it "should not be valid without a year of birth" do it "is not valid without a year of birth" do
residence.year_of_birth = nil residence.year_of_birth = nil
expect(residence).to_not be_valid expect(residence).to_not be_valid
end end
describe "allowed age" do describe "allowed age" do
it "should not be valid if user is under allowed age" do it "is not valid if user is under allowed age" do
allow_any_instance_of(described_class).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).to_not be_valid
expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate") expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate")
end end
it "should be valid if user is above allowed age" do it "is valid if user is above allowed age" do
allow_any_instance_of(described_class).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).to be_valid
expect(residence.errors[:year_of_birth]).to be_empty expect(residence.errors[:year_of_birth]).to be_empty
@@ -43,12 +43,12 @@ describe Officing::Residence do
end end
describe "new" do describe "new" do
it "should upcase document number" do it "upcases document number" do
residence = described_class.new(document_number: "x1234567z") residence = described_class.new(document_number: "x1234567z")
expect(residence.document_number).to eq("X1234567Z") expect(residence.document_number).to eq("X1234567Z")
end end
it "should remove all characters except numbers and letters" do it "removes all characters except numbers and letters" do
residence = described_class.new(document_number: " 12.345.678 - B") residence = described_class.new(document_number: " 12.345.678 - B")
expect(residence.document_number).to eq("12345678B") expect(residence.document_number).to eq("12345678B")
end end
@@ -56,7 +56,7 @@ describe Officing::Residence do
describe "save" do describe "save" do
it "should store document number, document type, geozone, date of birth and gender" do it "stores document number, document type, geozone, date of birth and gender" do
residence.save residence.save
user = residence.user user = residence.user
@@ -69,7 +69,7 @@ describe Officing::Residence do
expect(user.geozone).to eq(geozone) expect(user.geozone).to eq(geozone)
end end
it "should find existing user and use demographic information" do it "finds existing user and use demographic information" do
geozone = create(:geozone) geozone = create(:geozone)
create(:user, document_number: "12345678Z", create(:user, document_number: "12345678Z",
document_type: "1", document_type: "1",

View File

@@ -6,26 +6,26 @@ describe Poll::Answer do
let(:answer) { build(:poll_answer) } let(:answer) { build(:poll_answer) }
it "should be valid" do it "is valid" do
expect(answer).to be_valid expect(answer).to be_valid
end end
it "should not be valid wihout a question" do it "is not valid wihout a question" do
answer.question = nil answer.question = nil
expect(answer).to_not be_valid expect(answer).to_not be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
answer.author = nil answer.author = nil
expect(answer).to_not be_valid expect(answer).to_not be_valid
end end
it "should not be valid without an answer" do it "is not valid without an answer" do
answer.answer = nil answer.answer = nil
expect(answer).to_not be_valid expect(answer).to_not be_valid
end end
it "should be valid for answers included in the Poll::Question's question_answers list" do it "is valid for answers included in the Poll::Question's question_answers list" do
question = create(:poll_question) question = create(:poll_question)
create(:poll_question_answer, title: 'One', question: question) create(:poll_question_answer, title: 'One', question: question)
create(:poll_question_answer, title: 'Two', question: question) create(:poll_question_answer, title: 'Two', question: question)

View File

@@ -5,7 +5,7 @@ describe Poll::BoothAssignment do
let(:booth){create(:poll_booth)} let(:booth){create(:poll_booth)}
let(:booth1){create(:poll_booth)} let(:booth1){create(:poll_booth)}
it "should check if there are shifts" do it "checks if there are shifts" do
assignment_with_shifts = create(:poll_booth_assignment, poll: poll, booth: booth) assignment_with_shifts = create(:poll_booth_assignment, poll: poll, booth: booth)
assignment_without_shifts = create(:poll_booth_assignment, poll: poll, booth: booth1) assignment_without_shifts = create(:poll_booth_assignment, poll: poll, booth: booth1)
officer = create(:poll_officer) officer = create(:poll_officer)
@@ -16,7 +16,7 @@ describe Poll::BoothAssignment do
expect(assignment_without_shifts.shifts?).to eq(false) expect(assignment_without_shifts.shifts?).to eq(false)
end end
it "should delete shifts associated to booth assignments" do it "deletes shifts associated to booth assignments" do
assignment = create(:poll_booth_assignment, poll: poll, booth: booth) assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer = create(:poll_officer) officer = create(:poll_officer)
create(:poll_officer_assignment, officer: officer, booth_assignment: assignment) create(:poll_officer_assignment, officer: officer, booth_assignment: assignment)

View File

@@ -4,17 +4,17 @@ describe Poll::Booth do
let(:booth) { build(:poll_booth) } let(:booth) { build(:poll_booth) }
it "should be valid" do it "is valid" do
expect(booth).to be_valid expect(booth).to be_valid
end end
it "should not be valid without a name" do it "is not valid without a name" do
booth.name = nil booth.name = nil
expect(booth).to_not be_valid expect(booth).to_not be_valid
end end
describe "#search" do describe "#search" do
it "should find booths searching by name or location" do it "finds booths searching by name or location" do
booth1 = create(:poll_booth, name: "Booth number 1", location: "City center") booth1 = create(:poll_booth, name: "Booth number 1", location: "City center")
booth2 = create(:poll_booth, name: "Central", location: "Town hall") booth2 = create(:poll_booth, name: "Central", location: "Town hall")

View File

@@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
describe Poll::OfficerAssignment do describe Poll::OfficerAssignment do
it "should log user data on creation" do it "logs user data on creation" do
user = create(:user, username: "Larry Bird", email: "larry@lege.nd") user = create(:user, username: "Larry Bird", email: "larry@lege.nd")
officer = create(:poll_officer, user: user) officer = create(:poll_officer, user: user)

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Poll::Officer do describe Poll::Officer do
describe "#voting_days_assigned_polls" do describe "#voting_days_assigned_polls" do
it "should return all polls with this officer assigned during voting days" do it "returns all polls with this officer assigned during voting days" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll) poll_1 = create(:poll)
@@ -25,7 +25,7 @@ describe Poll::Officer do
expect(assigned_polls.include?(poll_3)).to eq(false) expect(assigned_polls.include?(poll_3)).to eq(false)
end end
it "should not return polls with this officer assigned for final recount/results" do it "does not return polls with this officer assigned for final recount/results" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll) poll_1 = create(:poll)
@@ -43,7 +43,7 @@ describe Poll::Officer do
expect(assigned_polls.include?(poll_2)).to eq(false) expect(assigned_polls.include?(poll_2)).to eq(false)
end end
it "should return polls ordered by end date (desc)" do it "returns polls ordered by end date (desc)" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll, ends_at: 1.day.ago) poll_1 = create(:poll, ends_at: 1.day.ago)
@@ -63,7 +63,7 @@ describe Poll::Officer do
end end
describe "#final_days_assigned_polls" do describe "#final_days_assigned_polls" do
it "should return all polls with this officer assigned for final recount/results" do it "returns all polls with this officer assigned for final recount/results" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll) poll_1 = create(:poll)
@@ -85,7 +85,7 @@ describe Poll::Officer do
expect(assigned_polls.include?(poll_3)).to eq(false) expect(assigned_polls.include?(poll_3)).to eq(false)
end end
it "should not return polls with this officer assigned for voting days" do it "does not return polls with this officer assigned for voting days" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll) poll_1 = create(:poll)
@@ -103,7 +103,7 @@ describe Poll::Officer do
expect(assigned_polls.include?(poll_2)).to eq(true) expect(assigned_polls.include?(poll_2)).to eq(true)
end end
it "should return polls ordered by end date (desc)" do it "returns polls ordered by end date (desc)" do
officer = create(:poll_officer) officer = create(:poll_officer)
poll_1 = create(:poll, ends_at: 1.day.ago) poll_1 = create(:poll, ends_at: 1.day.ago)

View File

@@ -18,7 +18,7 @@ describe Poll::PartialResult do
end end
describe "logging changes" do describe "logging changes" do
it "should update amount_log if amount changes" do it "updates amount_log if amount changes" do
partial_result = create(:poll_partial_result, amount: 33) partial_result = create(:poll_partial_result, amount: 33)
expect(partial_result.amount_log).to eq("") expect(partial_result.amount_log).to eq("")
@@ -33,7 +33,7 @@ describe Poll::PartialResult do
expect(partial_result.amount_log).to eq(":33:32") expect(partial_result.amount_log).to eq(":33:32")
end end
it "should update officer_assignment_id_log if amount changes" do it "updates officer_assignment_id_log if amount changes" do
partial_result = create(:poll_partial_result, amount: 33) partial_result = create(:poll_partial_result, amount: 33)
expect(partial_result.amount_log).to eq("") expect(partial_result.amount_log).to eq("")
@@ -55,7 +55,7 @@ describe Poll::PartialResult do
expect(partial_result.officer_assignment_id_log).to eq(":10:20") expect(partial_result.officer_assignment_id_log).to eq(":10:20")
end end
it "should update author_id if amount changes" do it "updates author_id if amount changes" do
partial_result = create(:poll_partial_result, amount: 33) partial_result = create(:poll_partial_result, amount: 33)
expect(partial_result.amount_log).to eq("") expect(partial_result.amount_log).to eq("")

View File

@@ -9,26 +9,26 @@ describe Poll do
end end
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(poll).to be_valid expect(poll).to be_valid
end end
it "should not be valid without a name" do it "is not valid without a name" do
poll.name = nil poll.name = nil
expect(poll).to_not be_valid expect(poll).to_not be_valid
end end
it "should not be valid without a start date" do it "is not valid without a start date" do
poll.starts_at = nil poll.starts_at = nil
expect(poll).to_not be_valid expect(poll).to_not be_valid
end end
it "should not be valid without an end date" do it "is not valid without an end date" do
poll.ends_at = nil poll.ends_at = nil
expect(poll).to_not be_valid expect(poll).to_not be_valid
end end
it "should not be valid without a proper start/end date range" do it "is not valid without a proper start/end date range" do
poll.starts_at = 1.week.ago poll.starts_at = 1.week.ago
poll.ends_at = 2.months.ago poll.ends_at = 2.months.ago
expect(poll).to_not be_valid expect(poll).to_not be_valid

View File

@@ -4,12 +4,12 @@ RSpec.describe Poll::Question, type: :model do
let(:poll_question) { build(:poll_question) } let(:poll_question) { build(:poll_question) }
describe "#poll_question_id" do describe "#poll_question_id" do
it "should be invalid if a poll is not selected" do it "is invalid if a poll is not selected" do
poll_question.poll_id = nil poll_question.poll_id = nil
expect(poll_question).to_not be_valid expect(poll_question).to_not be_valid
end end
it "should be valid if a poll is selected" do it "is valid if a poll is selected" do
poll_question.poll_id = 1 poll_question.poll_id = 1
expect(poll_question).to be_valid expect(poll_question).to be_valid
end end

View File

@@ -7,7 +7,7 @@ describe Poll::Recount do
let(:officer_assignment) { create(:poll_officer_assignment) } let(:officer_assignment) { create(:poll_officer_assignment) }
let(:poll_recount) { create(:poll_recount, author: author, officer_assignment: officer_assignment) } let(:poll_recount) { create(:poll_recount, author: author, officer_assignment: officer_assignment) }
it "should update white_amount_log if white_amount changes" do it "updates white_amount_log if white_amount changes" do
poll_recount.white_amount = 33 poll_recount.white_amount = 33
expect(poll_recount.white_amount_log).to eq("") expect(poll_recount.white_amount_log).to eq("")
@@ -22,7 +22,7 @@ describe Poll::Recount do
expect(poll_recount.white_amount_log).to eq(":0:33:32") expect(poll_recount.white_amount_log).to eq(":0:33:32")
end end
it "should update null_amount_log if null_amount changes" do it "updates null_amount_log if null_amount changes" do
poll_recount.null_amount = 33 poll_recount.null_amount = 33
expect(poll_recount.null_amount_log).to eq("") expect(poll_recount.null_amount_log).to eq("")
@@ -37,7 +37,7 @@ describe Poll::Recount do
expect(poll_recount.null_amount_log).to eq(":0:33:32") expect(poll_recount.null_amount_log).to eq(":0:33:32")
end end
it "should update total_amount_log if total_amount changes" do it "updates total_amount_log if total_amount changes" do
poll_recount.total_amount = 33 poll_recount.total_amount = 33
expect(poll_recount.total_amount_log).to eq("") expect(poll_recount.total_amount_log).to eq("")
@@ -52,7 +52,7 @@ describe Poll::Recount do
expect(poll_recount.total_amount_log).to eq(":0:33:32") expect(poll_recount.total_amount_log).to eq(":0:33:32")
end end
it "should update officer_assignment_id_log if amount changes" do it "updates officer_assignment_id_log if amount changes" do
poll_recount.white_amount = 33 poll_recount.white_amount = 33
expect(poll_recount.white_amount_log).to eq("") expect(poll_recount.white_amount_log).to eq("")
@@ -74,7 +74,7 @@ describe Poll::Recount do
expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102") expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102")
end end
it "should update author_id if amount changes" do it "updates author_id if amount changes" do
poll_recount.white_amount = 33 poll_recount.white_amount = 33
expect(poll_recount.white_amount_log).to eq("") expect(poll_recount.white_amount_log).to eq("")

View File

@@ -10,43 +10,43 @@ describe Poll::Shift do
describe "validations" do describe "validations" do
let(:shift) { build(:poll_shift) } let(:shift) { build(:poll_shift) }
it "should be valid" do it "is valid" do
expect(shift).to be_valid expect(shift).to be_valid
end end
it "should not be valid without a booth" do it "is not valid without a booth" do
shift.booth = nil shift.booth = nil
expect(shift).to_not be_valid expect(shift).to_not be_valid
end end
it "should not be valid without an officer" do it "is not valid without an officer" do
shift.officer = nil shift.officer = nil
expect(shift).to_not be_valid expect(shift).to_not be_valid
end end
it "should not be valid without a date" do it "is not valid without a date" do
shift.date = nil shift.date = nil
expect(shift).to_not be_valid expect(shift).to_not be_valid
end end
it "should not be valid without a task" do it "is not valid without a task" do
shift.task = nil shift.task = nil
expect(shift).to_not be_valid expect(shift).to_not be_valid
end end
it "should not be valid with same booth, officer, date and task" do it "is not valid with same booth, officer, date and task" do
recount_shift.save recount_shift.save
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).to_not be_valid expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).to_not be_valid
end end
it "should be valid with same booth, officer and date but different task" do it "is valid with same booth, officer and date but different task" do
recount_shift.save recount_shift.save
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid
end end
it "should be valid with same booth, officer and task but different date" do it "is valid with same booth, officer and task but different date" do
recount_shift.save recount_shift.save
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid
@@ -56,7 +56,7 @@ describe Poll::Shift do
describe "officer_assignments" do describe "officer_assignments" do
it "should create and destroy corresponding officer_assignments" do it "creates and destroy corresponding officer_assignments" do
poll2 = create(:poll) poll2 = create(:poll)
poll3 = create(:poll) poll3 = create(:poll)
@@ -84,7 +84,7 @@ describe Poll::Shift do
expect { described_class.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2) expect { described_class.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2)
end end
it "should create final officer_assignments" do it "creates final officer_assignments" do
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
recount_shift.save recount_shift.save
@@ -104,14 +104,14 @@ describe Poll::Shift do
describe "#persist_data" do describe "#persist_data" do
let(:shift) { create(:poll_shift, officer: officer, booth: booth) } let(:shift) { create(:poll_shift, officer: officer, booth: booth) }
it "should maintain officer data after destroying associated user" do it "maintains officer data after destroying associated user" do
shift.officer.user.destroy shift.officer.user.destroy
expect(shift.officer_name).to eq "Ana" expect(shift.officer_name).to eq "Ana"
expect(shift.officer_email).to eq "ana@example.com" expect(shift.officer_email).to eq "ana@example.com"
end end
it "should maintain officer data after destroying officer role" do it "maintains officer data after destroying officer role" do
shift.officer.destroy shift.officer.destroy
expect(shift.officer_name).to eq "Ana" expect(shift.officer_name).to eq "Ana"

View File

@@ -9,27 +9,27 @@ describe Poll::Voter do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(voter).to be_valid expect(voter).to be_valid
end end
it "should not be valid without a user" do it "is not valid without a user" do
voter.user = nil voter.user = nil
expect(voter).to_not be_valid expect(voter).to_not be_valid
end end
it "should not be valid without a poll" do it "is not valid without a poll" do
voter.poll = nil voter.poll = nil
expect(voter).to_not be_valid expect(voter).to_not be_valid
end end
it "should be valid if has not voted" do it "is valid if has not voted" do
voter = build(:poll_voter, :valid_document) voter = build(:poll_voter, :valid_document)
expect(voter).to be_valid expect(voter).to be_valid
end end
it "should not be valid if the user has already voted in the same poll or booth_assignment" do it "is not valid if the user has already voted in the same poll or booth_assignment" do
user = create(:user, :level_two) user = create(:user, :level_two)
voter1 = create(:poll_voter, user: user, poll: poll) voter1 = create(:poll_voter, user: user, poll: poll)
@@ -39,7 +39,7 @@ describe Poll::Voter do
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"]) expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
end end
it "should not be valid if the user has already voted in the same poll/booth" do it "is not valid if the user has already voted in the same poll/booth" do
user = create(:user, :level_two) user = create(:user, :level_two)
voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment) voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
@@ -49,7 +49,7 @@ describe Poll::Voter do
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"]) expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
end end
it "should not be valid if the user has already voted in different booth in the same poll" do it "is not valid if the user has already voted in different booth in the same poll" do
booth_assignment1 = create(:poll_booth_assignment, poll: poll) booth_assignment1 = create(:poll_booth_assignment, poll: poll)
booth_assignment2 = create(:poll_booth_assignment, poll: poll) booth_assignment2 = create(:poll_booth_assignment, poll: poll)
@@ -62,7 +62,7 @@ describe Poll::Voter do
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"]) expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
end end
it "should be valid if the user has already voted in the same booth in different poll" do it "is valid if the user has already voted in the same booth in different poll" do
booth_assignment1 = create(:poll_booth_assignment, booth: booth) booth_assignment1 = create(:poll_booth_assignment, booth: booth)
booth_assignment2 = create(:poll_booth_assignment, booth: booth, poll: poll) booth_assignment2 = create(:poll_booth_assignment, booth: booth, poll: poll)
@@ -74,7 +74,7 @@ describe Poll::Voter do
expect(voter2).to be_valid expect(voter2).to be_valid
end end
it "should not be valid if the user has voted via web" do it "is not valid if the user has voted via web" do
answer = create(:poll_answer) answer = create(:poll_answer)
answer.record_voter_participation('token') answer.record_voter_participation('token')
@@ -85,22 +85,22 @@ describe Poll::Voter do
context "origin" do context "origin" do
it "should not be valid without an origin" do it "is not valid without an origin" do
voter.origin = nil voter.origin = nil
expect(voter).to_not be_valid expect(voter).to_not be_valid
end end
it "should not be valid without a valid origin" do it "is not valid without a valid origin" do
voter.origin = "invalid_origin" voter.origin = "invalid_origin"
expect(voter).to_not be_valid expect(voter).to_not be_valid
end end
it "should be valid with a booth origin" do it "is valid with a booth origin" do
voter.origin = "booth" voter.origin = "booth"
expect(voter).to be_valid expect(voter).to be_valid
end end
it "should be valid with a web origin" do it "is valid with a web origin" do
voter.origin = "web" voter.origin = "web"
expect(voter).to be_valid expect(voter).to be_valid
end end

View File

@@ -3,21 +3,21 @@ require 'rails_helper'
describe ProposalNotification do describe ProposalNotification do
let(:notification) { build(:proposal_notification) } let(:notification) { build(:proposal_notification) }
it "should be valid" do it "is valid" do
expect(notification).to be_valid expect(notification).to be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
notification.title = nil notification.title = nil
expect(notification).to_not be_valid expect(notification).to_not be_valid
end end
it "should not be valid without a body" do it "is not valid without a body" do
notification.body = nil notification.body = nil
expect(notification).to_not be_valid expect(notification).to_not be_valid
end end
it "should not be valid without an associated proposal" do it "is not valid without an associated proposal" do
notification.proposal = nil notification.proposal = nil
expect(notification).to_not be_valid expect(notification).to_not be_valid
end end
@@ -50,7 +50,7 @@ describe ProposalNotification do
Setting[:proposal_notification_minimum_interval_in_days] = 3 Setting[:proposal_notification_minimum_interval_in_days] = 3
end end
it "should not be valid if below minium interval" do it "is not valid if below minium interval" do
proposal = create(:proposal) proposal = create(:proposal)
notification1 = create(:proposal_notification, proposal: proposal) notification1 = create(:proposal_notification, proposal: proposal)
@@ -60,7 +60,7 @@ describe ProposalNotification do
expect(notification2).to_not be_valid expect(notification2).to_not be_valid
end end
it "should be valid if notifications above minium interval" do it "is valid if notifications above minium interval" do
proposal = create(:proposal) proposal = create(:proposal)
notification1 = create(:proposal_notification, proposal: proposal, created_at: 4.days.ago) notification1 = create(:proposal_notification, proposal: proposal, created_at: 4.days.ago)
@@ -70,7 +70,7 @@ describe ProposalNotification do
expect(notification2).to be_valid expect(notification2).to be_valid
end end
it "should be valid if no notifications sent" do it "is valid if no notifications sent" do
notification1 = build(:proposal_notification) notification1 = build(:proposal_notification)
expect(notification1).to be_valid expect(notification1).to be_valid

View File

@@ -10,96 +10,96 @@ describe Proposal do
it_behaves_like "map validations" it_behaves_like "map validations"
end end
it "should be valid" do it "is valid" do
expect(proposal).to be_valid expect(proposal).to be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
proposal.author = nil proposal.author = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid without a summary" do it "is not valid without a summary" do
proposal.summary = nil proposal.summary = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
describe "#title" do describe "#title" do
it "should not be valid without a title" do it "is not valid without a title" do
proposal.title = nil proposal.title = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very short" do it "is not valid when very short" do
proposal.title = "abc" proposal.title = "abc"
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
proposal.title = "a" * 81 proposal.title = "a" * 81
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
end end
describe "#description" do describe "#description" do
it "should be sanitized" do it "is sanitized" do
proposal.description = "<script>alert('danger');</script>" proposal.description = "<script>alert('danger');</script>"
proposal.valid? proposal.valid?
expect(proposal.description).to eq("alert('danger');") expect(proposal.description).to eq("alert('danger');")
end end
it "should not be valid when very long" do it "is not valid when very long" do
proposal.description = "a" * 6001 proposal.description = "a" * 6001
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
end end
describe "#question" do describe "#question" do
it "should not be valid without a question" do it "is not valid without a question" do
proposal.question = nil proposal.question = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very short" do it "is not valid when very short" do
proposal.question = "abc" proposal.question = "abc"
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
proposal.question = "a" * 141 proposal.question = "a" * 141
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
end end
describe "#video_url" do describe "#video_url" do
it "should not be valid when URL is not from Youtube or Vimeo" do it "is not valid when URL is not from Youtube or Vimeo" do
proposal.video_url = "https://twitter.com" proposal.video_url = "https://twitter.com"
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should be valid when URL is from Youtube or Vimeo" do it "is valid when URL is from Youtube or Vimeo" do
proposal.video_url = "https://vimeo.com/112681885" proposal.video_url = "https://vimeo.com/112681885"
expect(proposal).to be_valid expect(proposal).to be_valid
end end
end end
describe "#responsible_name" do describe "#responsible_name" do
it "should be mandatory" do it "is mandatory" do
proposal.responsible_name = nil proposal.responsible_name = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very short" do it "is not valid when very short" do
proposal.responsible_name = "abc" proposal.responsible_name = "abc"
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should not be valid when very long" do it "is not valid when very long" do
proposal.responsible_name = "a" * 61 proposal.responsible_name = "a" * 61
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should be the document_number if level two user" do it "is the document_number if level two user" do
author = create(:user, :level_two, document_number: "12345678Z") author = create(:user, :level_two, document_number: "12345678Z")
proposal.author = author proposal.author = author
proposal.responsible_name = nil proposal.responsible_name = nil
@@ -108,7 +108,7 @@ describe Proposal do
proposal.responsible_name = "12345678Z" proposal.responsible_name = "12345678Z"
end end
it "should be the document_number if level two user" do it "is the document_number if level two user" do
author = create(:user, :level_three, document_number: "12345678Z") author = create(:user, :level_three, document_number: "12345678Z")
proposal.author = author proposal.author = author
proposal.responsible_name = nil proposal.responsible_name = nil
@@ -117,7 +117,7 @@ describe Proposal do
proposal.responsible_name = "12345678Z" proposal.responsible_name = "12345678Z"
end end
it "should not be updated when the author is deleted" do it "is not updated when the author is deleted" do
author = create(:user, :level_three, document_number: "12345678Z") author = create(:user, :level_three, document_number: "12345678Z")
proposal.author = author proposal.author = author
proposal.save proposal.save
@@ -130,29 +130,29 @@ describe Proposal do
end end
describe "tag_list" do describe "tag_list" do
it "should sanitize the tag list" do it "sanitizes the tag list" do
proposal.tag_list = "user_id=1" proposal.tag_list = "user_id=1"
proposal.valid? proposal.valid?
expect(proposal.tag_list).to eq(['user_id1']) expect(proposal.tag_list).to eq(['user_id1'])
end end
it "should not be valid with a tag list of more than 6 elements" do it "is not valid with a tag list of more than 6 elements" do
proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"]
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should be valid with a tag list of up to 6 elements" do it "is valid with a tag list of up to 6 elements" do
proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
expect(proposal).to be_valid expect(proposal).to be_valid
end end
end end
it "should not be valid without accepting terms of service" do it "is not valid without accepting terms of service" do
proposal.terms_of_service = nil proposal.terms_of_service = nil
expect(proposal).to_not be_valid expect(proposal).to_not be_valid
end end
it "should have a code" do it "has a code" do
Setting["proposal_code_prefix"] = "TEST" Setting["proposal_code_prefix"] = "TEST"
proposal = create(:proposal) proposal = create(:proposal)
expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime('%Y-%m')}-#{proposal.id}" expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime('%Y-%m')}-#{proposal.id}"
@@ -166,18 +166,18 @@ describe Proposal do
before(:each) {Setting["max_votes_for_proposal_edit"] = 5} before(:each) {Setting["max_votes_for_proposal_edit"] = 5}
after(:each) {Setting["max_votes_for_proposal_edit"] = 1000} after(:each) {Setting["max_votes_for_proposal_edit"] = 1000}
it "should be true if proposal has no votes yet" do it "is true if proposal has no votes yet" do
expect(proposal.total_votes).to eq(0) expect(proposal.total_votes).to eq(0)
expect(proposal.editable?).to be true expect(proposal.editable?).to be true
end end
it "should be true if proposal has less than limit votes" do it "is true if proposal has less than limit votes" do
create_list(:vote, 4, votable: proposal) create_list(:vote, 4, votable: proposal)
expect(proposal.total_votes).to eq(4) expect(proposal.total_votes).to eq(4)
expect(proposal.editable?).to be true expect(proposal.editable?).to be true
end end
it "should be false if proposal has more than limit votes" do it "is false if proposal has more than limit votes" do
create_list(:vote, 6, votable: proposal) create_list(:vote, 6, votable: proposal)
expect(proposal.total_votes).to eq(6) expect(proposal.total_votes).to eq(6)
expect(proposal.editable?).to be false expect(proposal.editable?).to be false
@@ -187,17 +187,17 @@ describe Proposal do
describe "#votable_by?" do describe "#votable_by?" do
let(:proposal) { create(:proposal) } let(:proposal) { create(:proposal) }
it "should be true for level two verified users" do it "is true for level two verified users" do
user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111")
expect(proposal.votable_by?(user)).to be true expect(proposal.votable_by?(user)).to be true
end end
it "should be true for level three verified users" do it "is true for level three verified users" do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
expect(proposal.votable_by?(user)).to be true expect(proposal.votable_by?(user)).to be true
end end
it "should be false for anonymous users" do it "is false for anonymous users" do
user = create(:user) user = create(:user)
expect(proposal.votable_by?(user)).to be false expect(proposal.votable_by?(user)).to be false
end end
@@ -207,27 +207,27 @@ describe Proposal do
let(:proposal) { create(:proposal) } let(:proposal) { create(:proposal) }
describe "from level two verified users" do describe "from level two verified users" do
it "should register vote" do it "registers vote" do
user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111") user = create(:user, residence_verified_at: Time.current, confirmed_phone: "666333111")
expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(1) expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(1)
end end
end end
describe "from level three verified users" do describe "from level three verified users" do
it "should register vote" do it "registers vote" do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(1) expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(1)
end end
end end
describe "from anonymous users" do describe "from anonymous users" do
it "should not register vote" do it "does not register vote" do
user = create(:user) user = create(:user)
expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0) expect {proposal.register_vote(user, 'yes')}.to change{proposal.reload.votes_for.size}.by(0)
end end
end end
it "should not register vote for archived proposals" do it "does not register vote for archived proposals" do
user = create(:user, verified_at: Time.current) user = create(:user, verified_at: Time.current)
archived_proposal = create(:proposal, :archived) archived_proposal = create(:proposal, :archived)
@@ -239,7 +239,7 @@ describe Proposal do
describe "with deprecated long tag list" do describe "with deprecated long tag list" do
it "should increase number of cached_total_votes" do it "increases number of cached_total_votes" do
proposal = create(:proposal) proposal = create(:proposal)
tag_list = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"] tag_list = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"]
@@ -349,47 +349,47 @@ describe Proposal do
describe "cache" do describe "cache" do
let(:proposal) { create(:proposal) } let(:proposal) { create(:proposal) }
it "should expire cache when it has a new comment" do it "expires cache when it has a new comment" do
expect { create(:comment, commentable: proposal) } expect { create(:comment, commentable: proposal) }
.to change { proposal.updated_at } .to change { proposal.updated_at }
end end
it "should expire cache when it has a new vote" do it "expires cache when it has a new vote" do
expect { create(:vote, votable: proposal) } expect { create(:vote, votable: proposal) }
.to change { proposal.updated_at } .to change { proposal.updated_at }
end end
it "should expire cache when it has a new flag" do it "expires cache when it has a new flag" do
expect { create(:flag, flaggable: proposal) } expect { create(:flag, flaggable: proposal) }
.to change { proposal.reload.updated_at } .to change { proposal.reload.updated_at }
end end
it "should expire cache when it has a new tag" do it "expires cache when it has a new tag" do
expect { proposal.update(tag_list: "new tag") } expect { proposal.update(tag_list: "new tag") }
.to change { proposal.updated_at } .to change { proposal.updated_at }
end end
it "should expire cache when hidden" do it "expires cache when hidden" do
expect { proposal.hide } expect { proposal.hide }
.to change { proposal.updated_at } .to change { proposal.updated_at }
end end
it "should expire cache when the author is hidden" do it "expires cache when the author is hidden" do
expect { proposal.author.hide } expect { proposal.author.hide }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end end
it "should expire cache when the author is erased" do it "expires cache when the author is erased" do
expect { proposal.author.erase } expect { proposal.author.erase }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end end
it "should expire cache when its author changes" do it "expires cache when its author changes" do
expect { proposal.author.update(username: "Eva") } expect { proposal.author.update(username: "Eva") }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end end
it "should expire cache when the author's organization get verified" do it "expires cache when the author's organization get verified" do
create(:organization, user: proposal.author) create(:organization, user: proposal.author)
expect { proposal.author.organization.verify } expect { proposal.author.organization.verify }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.updated_at, proposal.author.updated_at] }
@@ -588,7 +588,7 @@ describe Proposal do
context "reorder" do context "reorder" do
it "should be able to reorder by hot_score after searching" do it "is able to reorder by hot_score after searching" do
lowest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 1) lowest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 1)
highest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 2) highest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 2)
average_score = create(:proposal, title: 'stop corruption', cached_votes_up: 3) average_score = create(:proposal, title: 'stop corruption', cached_votes_up: 3)
@@ -610,7 +610,7 @@ describe Proposal do
expect(results.third).to eq(lowest_score) expect(results.third).to eq(lowest_score)
end end
it "should be able to reorder by confidence_score after searching" do it "is able to reorder by confidence_score after searching" do
lowest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 1) lowest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 1)
highest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 2) highest_score = create(:proposal, title: 'stop corruption', cached_votes_up: 2)
average_score = create(:proposal, title: 'stop corruption', cached_votes_up: 3) average_score = create(:proposal, title: 'stop corruption', cached_votes_up: 3)
@@ -632,7 +632,7 @@ describe Proposal do
expect(results.third).to eq(lowest_score) expect(results.third).to eq(lowest_score)
end end
it "should be able to reorder by created_at after searching" do it "is able to reorder by created_at after searching" do
recent = create(:proposal, title: 'stop corruption', cached_votes_up: 1, created_at: 1.week.ago) recent = create(:proposal, title: 'stop corruption', cached_votes_up: 1, created_at: 1.week.ago)
newest = create(:proposal, title: 'stop corruption', cached_votes_up: 2, created_at: Time.current) 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) oldest = create(:proposal, title: 'stop corruption', cached_votes_up: 3, created_at: 1.month.ago)
@@ -650,7 +650,7 @@ describe Proposal do
expect(results.third).to eq(oldest) expect(results.third).to eq(oldest)
end end
it "should be able to reorder by most commented after searching" do it "is able to reorder by most commented after searching" do
least_commented = create(:proposal, title: 'stop corruption', cached_votes_up: 1, comments_count: 1) least_commented = create(:proposal, title: 'stop corruption', cached_votes_up: 1, comments_count: 1)
most_commented = create(:proposal, title: 'stop corruption', cached_votes_up: 2, comments_count: 100) 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) some_comments = create(:proposal, title: 'stop corruption', cached_votes_up: 3, comments_count: 10)
@@ -704,12 +704,12 @@ describe Proposal do
end end
describe "#last_week" do describe "#last_week" do
it "should return proposals created this week" do it "returns proposals created this week" do
proposal = create(:proposal) proposal = create(:proposal)
expect(described_class.last_week).to include(proposal) expect(described_class.last_week).to include(proposal)
end end
it "should not return proposals created more than a week ago" do it "does not return proposals created more than a week ago" do
proposal = create(:proposal, created_at: 8.days.ago) proposal = create(:proposal, created_at: 8.days.ago)
expect(described_class.last_week).to_not include(proposal) expect(described_class.last_week).to_not include(proposal)
end end
@@ -719,14 +719,14 @@ describe Proposal do
context "categories" do context "categories" do
it "should return proposals tagged with a category" do it "returns proposals tagged with a category" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture') proposal = create(:proposal, tag_list: 'culture')
expect(described_class.for_summary.values.flatten).to include(proposal) expect(described_class.for_summary.values.flatten).to include(proposal)
end end
it "should not return proposals tagged without a category" do it "does not return proposals tagged without a category" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'parks') proposal = create(:proposal, tag_list: 'parks')
@@ -736,14 +736,14 @@ describe Proposal do
context "districts" do context "districts" do
it "should return proposals with a geozone" do it "returns proposals with a geozone" do
california = create(:geozone, name: 'california') california = create(:geozone, name: 'california')
proposal = create(:proposal, geozone: california) proposal = create(:proposal, geozone: california)
expect(described_class.for_summary.values.flatten).to include(proposal) expect(described_class.for_summary.values.flatten).to include(proposal)
end end
it "should not return proposals without a geozone" do it "does not return proposals without a geozone" do
create(:geozone, name: 'california') create(:geozone, name: 'california')
proposal = create(:proposal) proposal = create(:proposal)
@@ -751,19 +751,19 @@ describe Proposal do
end end
end end
it "should return proposals created this week" do it "returns proposals created this week" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture') proposal = create(:proposal, tag_list: 'culture')
expect(described_class.for_summary.values.flatten).to include(proposal) expect(described_class.for_summary.values.flatten).to include(proposal)
end end
it "should not return proposals created more than a week ago" do it "does not return proposals created more than a week ago" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
proposal = create(:proposal, tag_list: 'culture', created_at: 8.days.ago) proposal = create(:proposal, tag_list: 'culture', created_at: 8.days.ago)
expect(described_class.for_summary.values.flatten).to_not include(proposal) expect(described_class.for_summary.values.flatten).to_not include(proposal)
end end
it "should order proposals by votes" do it "orders proposals by votes" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 2) create(:proposal, tag_list: 'culture').update_column(:confidence_score, 2)
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10) create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10)
@@ -776,7 +776,7 @@ describe Proposal do
expect(results.third.confidence_score).to be(2) expect(results.third.confidence_score).to be(2)
end end
it "should order groups alphabetically" do it "orders groups alphabetically" do
create(:tag, :category, name: 'health') create(:tag, :category, name: 'health')
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
create(:tag, :category, name: 'social services') create(:tag, :category, name: 'social services')
@@ -792,7 +792,7 @@ describe Proposal do
expect(results.third).to eq(social_proposal) expect(results.third).to eq(social_proposal)
end end
it "should return proposals grouped by tag" do it "returns proposals grouped by tag" do
create(:tag, :category, name: 'culture') create(:tag, :category, name: 'culture')
create(:tag, :category, name: 'health') create(:tag, :category, name: 'health')
@@ -809,7 +809,7 @@ describe Proposal do
end end
describe "#to_param" do describe "#to_param" do
it "should return a friendly url" do it "returns a friendly url" do
expect(proposal.to_param).to eq "#{proposal.id} #{proposal.title}".parameterize expect(proposal.to_param).to eq "#{proposal.id} #{proposal.title}".parameterize
end end
end end
@@ -876,7 +876,7 @@ describe Proposal do
describe "#user_to_notify" do describe "#user_to_notify" do
it "should return voters and followers" do it "returns voters and followers" do
proposal = create(:proposal) proposal = create(:proposal)
voter = create(:user, :level_two) voter = create(:user, :level_two)
follower = create(:user, :level_two) follower = create(:user, :level_two)
@@ -886,7 +886,7 @@ describe Proposal do
expect(proposal.users_to_notify).to eq([voter, follower]) expect(proposal.users_to_notify).to eq([voter, follower])
end end
it "should return voters and followers discarding duplicates" do it "returns voters and followers discarding duplicates" do
proposal = create(:proposal) proposal = create(:proposal)
voter_and_follower = create(:user, :level_two) voter_and_follower = create(:user, :level_two)
follow = create(:follow, user: voter_and_follower, followable: proposal) follow = create(:follow, user: voter_and_follower, followable: proposal)
@@ -901,13 +901,13 @@ describe Proposal do
let(:user) { create(:user) } let(:user) { create(:user) }
it "Should not return any proposals when user has not interests" do it "does not return any proposals when user has not interests" do
create(:proposal) create(:proposal)
expect(described_class.recommendations(user).size).to eq 0 expect(described_class.recommendations(user).size).to eq 0
end end
it "Should return proposals ordered by cached_votes_up" do it "returns proposals ordered by cached_votes_up" do
proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport") proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport")
proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport") proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport")
proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport") proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport")
@@ -921,7 +921,7 @@ describe Proposal do
expect(result.third).to eq proposal1 expect(result.third).to eq proposal1
end end
it "Should return proposals related with user interests" do it "returns proposals related with user interests" do
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
proposal2 = create(:proposal, tag_list: "Sport") proposal2 = create(:proposal, tag_list: "Sport")
proposal3 = create(:proposal, tag_list: "Politics") proposal3 = create(:proposal, tag_list: "Politics")
@@ -933,7 +933,7 @@ describe Proposal do
expect(result).to eq [proposal2] expect(result).to eq [proposal2]
end end
it "Should not return proposals when user is follower" do it "does not return proposals when user is follower" do
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user) create(:follow, followable: proposal1, user: user)
@@ -942,7 +942,7 @@ describe Proposal do
expect(result.size).to eq 0 expect(result.size).to eq 0
end end
it "Should not return proposals when user is the author" do it "does not return proposals when user is the author" do
proposal1 = create(:proposal, author: user, tag_list: "Sport") proposal1 = create(:proposal, author: user, tag_list: "Sport")
proposal2 = create(:proposal, tag_list: "Sport") proposal2 = create(:proposal, tag_list: "Sport")
proposal3 = create(:proposal, tag_list: "Sport") proposal3 = create(:proposal, tag_list: "Sport")
@@ -954,7 +954,7 @@ describe Proposal do
expect(result).to eq [proposal2] expect(result).to eq [proposal2]
end end
it "should not return archived proposals" do it "does not return archived proposals" do
proposal1 = create(:proposal, cached_votes_up: 5, tag_list: "Sport") proposal1 = create(:proposal, cached_votes_up: 5, tag_list: "Sport")
proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport") proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport")
archived_proposal = create(:proposal, :archived) archived_proposal = create(:proposal, :archived)
@@ -965,7 +965,7 @@ describe Proposal do
expect(result).to eq([proposal2]) expect(result).to eq([proposal2])
end end
it "should not return already supported proposals" do it "does not return already supported proposals" do
proposal1 = create(:proposal, cached_votes_up: 5, tag_list: "Health") proposal1 = create(:proposal, cached_votes_up: 5, tag_list: "Health")
proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Health") proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Health")
proposal3 = create(:proposal, cached_votes_up: 5, tag_list: "Health") proposal3 = create(:proposal, cached_votes_up: 5, tag_list: "Health")

View File

@@ -5,19 +5,19 @@ describe RelatedContent do
let(:parent_relationable) { create([:proposal, :debate].sample) } let(:parent_relationable) { create([:proposal, :debate].sample) }
let(:child_relationable) { create([:proposal, :debate].sample) } let(:child_relationable) { create([:proposal, :debate].sample) }
it "should allow relationables from various classes" do it "allows relationables from various classes" do
expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid
expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid
expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid expect(build(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable)).to be_valid
end end
it "should not allow empty relationables" do it "does not allow empty relationables" do
expect(build(:related_content)).not_to be_valid expect(build(:related_content)).not_to be_valid
expect(build(:related_content, parent_relationable: parent_relationable)).not_to be_valid expect(build(:related_content, parent_relationable: parent_relationable)).not_to be_valid
expect(build(:related_content, child_relationable: child_relationable)).not_to be_valid expect(build(:related_content, child_relationable: child_relationable)).not_to be_valid
end end
it "should not allow repeated related contents" do it "does not allow repeated related contents" do
related_content = create(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) related_content = create(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user))
new_related_content = build(:related_content, parent_relationable: related_content.parent_relationable, child_relationable: related_content.child_relationable) new_related_content = build(:related_content, parent_relationable: related_content.parent_relationable, child_relationable: related_content.child_relationable)
expect(new_related_content).not_to be_valid expect(new_related_content).not_to be_valid

View File

@@ -7,24 +7,24 @@ describe Verification::Residence do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(residence).to be_valid expect(residence).to be_valid
end end
describe "dates" do describe "dates" do
it "should be valid with a valid date of birth" do it "is valid with a valid date of birth" do
residence = described_class.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) expect(residence.errors[:date_of_birth].size).to eq(0)
end end
it "should not be valid without a date of birth" do it "is not valid without a date of birth" do
residence = described_class.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).to_not be_valid
expect(residence.errors[:date_of_birth]).to include("can't be blank") expect(residence.errors[:date_of_birth]).to include("can't be blank")
end end
end end
it "should validate user has allowed age" do it "validates user has allowed age" do
residence = described_class.new("date_of_birth(3i)" => "1", residence = described_class.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1", "date_of_birth(2i)" => "1",
"date_of_birth(1i)" => 5.years.ago.year.to_s) "date_of_birth(1i)" => 5.years.ago.year.to_s)
@@ -32,7 +32,7 @@ describe Verification::Residence do
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
end end
it "should validate uniquness of document_number" do it "validates uniquness of document_number" do
user = create(:user) user = create(:user)
residence.user = user residence.user = user
residence.save residence.save
@@ -43,7 +43,7 @@ describe Verification::Residence do
expect(residence.errors[:document_number]).to include("has already been taken") expect(residence.errors[:document_number]).to include("has already been taken")
end end
it "should validate census terms" do it "validates census terms" do
residence.terms_of_service = nil residence.terms_of_service = nil
expect(residence).to_not be_valid expect(residence).to_not be_valid
end end
@@ -51,12 +51,12 @@ describe Verification::Residence do
end end
describe "new" do describe "new" do
it "should upcase document number" do it "upcases document number" do
residence = described_class.new(document_number: "x1234567z") residence = described_class.new(document_number: "x1234567z")
expect(residence.document_number).to eq("X1234567Z") expect(residence.document_number).to eq("X1234567Z")
end end
it "should remove all characters except numbers and letters" do it "removes all characters except numbers and letters" do
residence = described_class.new(document_number: " 12.345.678 - B") residence = described_class.new(document_number: " 12.345.678 - B")
expect(residence.document_number).to eq("12345678B") expect(residence.document_number).to eq("12345678B")
end end
@@ -64,7 +64,7 @@ describe Verification::Residence do
describe "save" do describe "save" do
it "should store document number, document type, geozone, date of birth and gender" do it "stores document number, document type, geozone, date of birth and gender" do
user = create(:user) user = create(:user)
residence.user = user residence.user = user
residence.save residence.save
@@ -82,13 +82,13 @@ describe Verification::Residence do
end end
describe "tries" do describe "tries" do
it "should increase tries after a call to the Census" do it "increases tries after a call to the Census" do
residence.postal_code = "28011" residence.postal_code = "28011"
residence.valid? residence.valid?
expect(residence.user.lock.tries).to eq(1) expect(residence.user.lock.tries).to eq(1)
end end
it "should not increase tries after a validation error" do it "does not increase tries after a validation error" do
residence.postal_code = "" residence.postal_code = ""
residence.valid? residence.valid?
expect(residence.user.lock).to be nil expect(residence.user.lock).to be nil

View File

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

View File

@@ -6,11 +6,11 @@ describe SignatureSheet do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(signature_sheet).to be_valid expect(signature_sheet).to be_valid
end end
it "should be valid with a valid signable" do it "is valid with a valid signable" do
signature_sheet.signable = create(:proposal) signature_sheet.signable = create(:proposal)
expect(signature_sheet).to be_valid expect(signature_sheet).to be_valid
@@ -18,22 +18,22 @@ describe SignatureSheet do
expect(signature_sheet).to be_valid expect(signature_sheet).to be_valid
end end
it "should not be valid without signable" do it "is not valid without signable" do
signature_sheet.signable = nil signature_sheet.signable = nil
expect(signature_sheet).to_not be_valid expect(signature_sheet).to_not be_valid
end end
it "should not be valid without a valid signable" do it "is not valid without a valid signable" do
signature_sheet.signable = create(:comment) signature_sheet.signable = create(:comment)
expect(signature_sheet).to_not be_valid expect(signature_sheet).to_not be_valid
end end
it "should not be valid without document numbers" do it "is not valid without document numbers" do
signature_sheet.document_numbers = nil signature_sheet.document_numbers = nil
expect(signature_sheet).to_not be_valid expect(signature_sheet).to_not be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
signature_sheet.author = nil signature_sheet.author = nil
expect(signature_sheet).to_not be_valid expect(signature_sheet).to_not be_valid
end end

View File

@@ -6,11 +6,11 @@ describe Signature do
describe "validations" do describe "validations" do
it "should be valid" do it "is valid" do
expect(signature).to be_valid expect(signature).to be_valid
end end
it "should not be valid without a document number" do it "is not valid without a document number" do
signature.document_number = nil signature.document_number = nil
expect(signature).to_not be_valid expect(signature).to_not be_valid
@@ -21,7 +21,7 @@ describe Signature do
expect(signature).to_not be_valid expect(signature).to_not be_valid
end end
it "should not be valid without an associated signature sheet" do it "is not valid without an associated signature sheet" do
signature.signature_sheet = nil signature.signature_sheet = nil
expect(signature).to_not be_valid expect(signature).to_not be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe SiteCustomization::ContentBlock, type: :model do RSpec.describe SiteCustomization::ContentBlock, type: :model do
let(:block) { build(:site_customization_content_block) } let(:block) { build(:site_customization_content_block) }
it "should be valid" do it "is valid" do
expect(block).to be_valid expect(block).to be_valid
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe SiteCustomization::Page, type: :model do RSpec.describe SiteCustomization::Page, type: :model do
let(:custom_page) { build(:site_customization_page) } let(:custom_page) { build(:site_customization_page) }
it "should be valid" do it "is valid" do
expect(custom_page).to be_valid expect(custom_page).to be_valid
end end

View File

@@ -1,12 +1,12 @@
require 'rails_helper' require 'rails_helper'
describe Verification::Sms do describe Verification::Sms do
it "should be valid" do it "is valid" do
sms = build(:verification_sms) sms = build(:verification_sms)
expect(sms).to be_valid expect(sms).to be_valid
end end
it "should validate uniqness of phone" do it "validates uniqness of phone" do
create(:user, confirmed_phone: "699999999") create(:user, confirmed_phone: "699999999")
sms = described_class.new(phone: "699999999") sms = described_class.new(phone: "699999999")
expect(sms).to_not be_valid expect(sms).to_not be_valid

View File

@@ -7,21 +7,21 @@ describe Topic do
it_behaves_like "notifiable" it_behaves_like "notifiable"
end end
it "should be valid" do it "is valid" do
expect(topic).to be_valid expect(topic).to be_valid
end end
it "should not be valid without an author" do it "is not valid without an author" do
topic.author = nil topic.author = nil
expect(topic).to_not be_valid expect(topic).to_not be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
topic.title = nil topic.title = nil
expect(topic).to_not be_valid expect(topic).to_not be_valid
end end
it "should not be valid without a description" do it "is not valid without a description" do
topic.description = nil topic.description = nil
expect(topic).to_not be_valid expect(topic).to_not be_valid
end end

View File

@@ -74,37 +74,37 @@ describe User do
describe 'preferences' do describe 'preferences' do
describe 'email_on_comment' do describe 'email_on_comment' do
it 'should be false by default' do it 'is false by default' do
expect(subject.email_on_comment).to eq(false) expect(subject.email_on_comment).to eq(false)
end end
end end
describe 'email_on_comment_reply' do describe 'email_on_comment_reply' do
it 'should be false by default' do it 'is false by default' do
expect(subject.email_on_comment_reply).to eq(false) expect(subject.email_on_comment_reply).to eq(false)
end end
end end
describe 'subscription_to_website_newsletter' do describe 'subscription_to_website_newsletter' do
it 'should be true by default' do it 'is true by default' do
expect(subject.newsletter).to eq(true) expect(subject.newsletter).to eq(true)
end end
end end
describe 'email_digest' do describe 'email_digest' do
it 'should be true by default' do it 'is true by default' do
expect(subject.email_digest).to eq(true) expect(subject.email_digest).to eq(true)
end end
end end
describe 'email_on_direct_message' do describe 'email_on_direct_message' do
it 'should be true by default' do it 'is true by default' do
expect(subject.email_on_direct_message).to eq(true) expect(subject.email_on_direct_message).to eq(true)
end end
end end
describe 'official_position_badge' do describe 'official_position_badge' do
it 'should be false by default' do it 'is false by default' do
expect(subject.official_position_badge).to eq(false) expect(subject.official_position_badge).to eq(false)
end end
end end
@@ -415,17 +415,17 @@ describe User do
describe "cache" do describe "cache" do
let(:user) { create(:user) } let(:user) { create(:user) }
it "should expire cache with becoming a moderator" do it "expires cache with becoming a moderator" do
expect { create(:moderator, user: user) } expect { create(:moderator, user: user) }
.to change { user.updated_at} .to change { user.updated_at}
end end
it "should expire cache with becoming an admin" do it "expires cache with becoming an admin" do
expect { create(:administrator, user: user) } expect { create(:administrator, user: user) }
.to change { user.updated_at} .to change { user.updated_at}
end end
it "should expire cache with becoming a veridied organization" do it "expires cache with becoming a veridied organization" do
create(:organization, user: user) create(:organization, user: user)
expect { user.organization.verify } expect { user.organization.verify }
.to change { user.reload.updated_at} .to change { user.reload.updated_at}
@@ -433,13 +433,13 @@ describe User do
end end
describe "document_number" do describe "document_number" do
it "should upcase document number" do it "upcases document number" do
user = described_class.new(document_number: "x1234567z") user = described_class.new(document_number: "x1234567z")
user.valid? user.valid?
expect(user.document_number).to eq("X1234567Z") expect(user.document_number).to eq("X1234567Z")
end end
it "should remove all characters except numbers and letters" do it "removes all characters except numbers and letters" do
user = described_class.new(document_number: " 12.345.678 - B") user = described_class.new(document_number: " 12.345.678 - B")
user.valid? user.valid?
expect(user.document_number).to eq("12345678B") expect(user.document_number).to eq("12345678B")
@@ -660,14 +660,14 @@ describe User do
describe "#interests" do describe "#interests" do
let(:user) { create(:user) } let(:user) { create(:user) }
it "should return followed object tags" do it "returns followed object tags" do
proposal = create(:proposal, tag_list: "Sport") proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user) create(:follow, followable: proposal, user: user)
expect(user.interests).to eq ["Sport"] expect(user.interests).to eq ["Sport"]
end end
it "should discard followed objects duplicated tags" do it "discards followed objects duplicated tags" do
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
proposal2 = create(:proposal, tag_list: "Sport") proposal2 = create(:proposal, tag_list: "Sport")
budget_investment = create(:budget_investment, tag_list: "Sport") budget_investment = create(:budget_investment, tag_list: "Sport")

View File

@@ -3,13 +3,13 @@ require 'rails_helper'
describe Valuator do describe Valuator do
describe "#description_or_email" do describe "#description_or_email" do
it "should return description if present" do it "returns description if present" do
valuator = create(:valuator, description: "Urbanism manager") valuator = create(:valuator, description: "Urbanism manager")
expect(valuator.description_or_email).to eq("Urbanism manager") expect(valuator.description_or_email).to eq("Urbanism manager")
end end
it "should return email if not description present" do it "returns email if not description present" do
valuator = create(:valuator) valuator = create(:valuator)
expect(valuator.description_or_email).to eq(valuator.email) expect(valuator.description_or_email).to eq(valuator.email)

View File

@@ -3,27 +3,27 @@ shared_examples "acts as imageable" do |imageable_factory|
let!(:image) { build(:image, imageable_factory.to_sym) } let!(:image) { build(:image, imageable_factory.to_sym) }
let!(:imageable) { image.imageable } let!(:imageable) { image.imageable }
it "should be valid" do it "is valid" do
expect(image).to be_valid expect(image).to be_valid
end end
describe "file extension" do describe "file extension" do
it "should not be valid with '.png' extension" do it "is not valid with '.png' extension" do
image.attachment = File.new("spec/fixtures/files/clippy.png") image.attachment = File.new("spec/fixtures/files/clippy.png")
expect(image).to_not be_valid expect(image).to_not be_valid
expect(image.errors[:attachment].size).to eq(1) expect(image.errors[:attachment].size).to eq(1)
end end
it "should not be valid with '.gif' extension" do it "is not valid with '.gif' extension" do
image.attachment = File.new("spec/fixtures/files/clippy.gif") image.attachment = File.new("spec/fixtures/files/clippy.gif")
expect(image).to_not be_valid expect(image).to_not be_valid
expect(image.errors[:attachment].size).to eq(1) expect(image.errors[:attachment].size).to eq(1)
end end
it "should be valid with '.jpg' extension" do it "is valid with '.jpg' extension" do
image.attachment = File.new("spec/fixtures/files/clippy.jpg") image.attachment = File.new("spec/fixtures/files/clippy.jpg")
expect(image).to be_valid expect(image).to be_valid
@@ -33,11 +33,11 @@ shared_examples "acts as imageable" do |imageable_factory|
describe "image dimmessions" do describe "image dimmessions" do
it "should be valid when image dimmessions are 475X475 at least" do it "is valid when image dimmessions are 475X475 at least" do
expect(image).to be_valid expect(image).to be_valid
end end
it "should not be valid when image dimmensions are smaller than 475X475" do it "is not valid when image dimmensions are smaller than 475X475" do
image.attachment = File.new("spec/fixtures/files/logo_header.jpg") image.attachment = File.new("spec/fixtures/files/logo_header.jpg")
expect(image).not_to be_valid expect(image).not_to be_valid
@@ -46,19 +46,19 @@ shared_examples "acts as imageable" do |imageable_factory|
describe "title" do describe "title" do
it "should not be valid when correct image attached but no image title provided" do it "is not valid when correct image attached but no image title provided" do
image.title = '' image.title = ''
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should not be valid when image title is too short" do it "is not valid when image title is too short" do
image.title = 'a' * 3 image.title = 'a' * 3
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should not be valid when image title is too long" do it "is not valid when image title is too long" do
image.title = 'a' * 81 image.title = 'a' * 81
expect(image).to_not be_valid expect(image).to_not be_valid

View File

@@ -7,23 +7,23 @@ shared_examples "document validations" do |documentable_factory|
let!(:maxfilesize) { max_file_size(document.documentable.class) } let!(:maxfilesize) { max_file_size(document.documentable.class) }
let!(:acceptedcontenttypes) { accepted_content_types(document.documentable.class) } let!(:acceptedcontenttypes) { accepted_content_types(document.documentable.class) }
it "should be valid" do it "is valid" do
expect(document).to be_valid expect(document).to be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
document.title = nil document.title = nil
expect(document).to_not be_valid expect(document).to_not be_valid
end end
it "should not be valid without an attachment" do it "is not valid without an attachment" do
document.attachment = nil document.attachment = nil
expect(document).to_not be_valid expect(document).to_not be_valid
end end
it "should be valid for all accepted content types" do it "is valid for all accepted content types" do
acceptedcontenttypes.each do |content_type| acceptedcontenttypes.each do |content_type|
extension = content_type.split("/").last extension = content_type.split("/").last
document.attachment = File.new("spec/fixtures/files/empty.#{extension}") document.attachment = File.new("spec/fixtures/files/empty.#{extension}")
@@ -32,27 +32,27 @@ shared_examples "document validations" do |documentable_factory|
end end
end end
it "should not be valid for attachments larger than documentable max_file_size definition" do it "is not valid for attachments larger than documentable max_file_size definition" do
document.stub(:attachment_file_size).and_return(maxfilesize.megabytes + 1.byte) document.stub(:attachment_file_size).and_return(maxfilesize.megabytes + 1.byte)
expect(document).to_not be_valid expect(document).to_not be_valid
expect(document.errors[:attachment]).to include "must be in between 0 Bytes and #{maxfilesize} MB" expect(document.errors[:attachment]).to include "must be in between 0 Bytes and #{maxfilesize} MB"
end end
it "should not be valid without a user_id" do it "is not valid without a user_id" do
document.user_id = nil document.user_id = nil
expect(document).to_not be_valid expect(document).to_not be_valid
end end
it "should not be valid without a documentable_id" do it "is not valid without a documentable_id" do
document.save document.save
document.documentable_id = nil document.documentable_id = nil
expect(document).to_not be_valid expect(document).to_not be_valid
end end
it "should not be valid without a documentable_type" do it "is not valid without a documentable_type" do
document.save document.save
document.documentable_type = nil document.documentable_type = nil

View File

@@ -6,23 +6,23 @@ shared_examples "image validations" do |imageable_factory|
let!(:imageable) { image.imageable } let!(:imageable) { image.imageable }
let!(:acceptedcontenttypes) { imageable_accepted_content_types } let!(:acceptedcontenttypes) { imageable_accepted_content_types }
it "should be valid" do it "is valid" do
expect(image).to be_valid expect(image).to be_valid
end end
it "should not be valid without a title" do it "is not valid without a title" do
image.title = nil image.title = nil
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should not be valid without an attachment" do it "is not valid without an attachment" do
image.attachment = nil image.attachment = nil
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should be valid for all accepted content types" do it "is valid for all accepted content types" do
acceptedcontenttypes.each do |content_type| acceptedcontenttypes.each do |content_type|
extension = content_type.split("/").last extension = content_type.split("/").last
image.attachment = File.new("spec/fixtures/files/clippy.#{extension}") image.attachment = File.new("spec/fixtures/files/clippy.#{extension}")
@@ -31,7 +31,7 @@ shared_examples "image validations" do |imageable_factory|
end end
end end
it "should not be valid for png and gif image content types" do it "is not valid for png and gif image content types" do
["gif", "png"].each do |content_type| ["gif", "png"].each do |content_type|
extension = content_type.split("/").last extension = content_type.split("/").last
image.attachment = File.new("spec/fixtures/files/clippy.#{extension}") image.attachment = File.new("spec/fixtures/files/clippy.#{extension}")
@@ -40,27 +40,27 @@ shared_examples "image validations" do |imageable_factory|
end end
end end
it "should not be valid for attachments larger than imageable max_file_size definition" do it "is not valid for attachments larger than imageable max_file_size definition" do
allow(image).to receive(:attachment_file_size).and_return(Image::MAX_IMAGE_SIZE + 1.byte) allow(image).to receive(:attachment_file_size).and_return(Image::MAX_IMAGE_SIZE + 1.byte)
expect(image).to_not be_valid expect(image).to_not be_valid
expect(image.errors[:attachment]).to include "must be in between 0 Bytes and 1 MB" expect(image.errors[:attachment]).to include "must be in between 0 Bytes and 1 MB"
end end
it "should not be valid without a user_id" do it "is not valid without a user_id" do
image.user_id = nil image.user_id = nil
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should not be valid without a imageable_id" do it "is not valid without a imageable_id" do
image.save image.save
image.imageable_id = nil image.imageable_id = nil
expect(image).to_not be_valid expect(image).to_not be_valid
end end
it "should not be valid without a imageable_type" do it "is not valid without a imageable_type" do
image.save image.save
image.imageable_type = nil image.imageable_type = nil

View File

@@ -12,21 +12,21 @@ shared_examples "map validations" do
Setting["feature.map"] = nil Setting["feature.map"] = nil
end end
it "should be valid with a map location" do it "is valid with a map location" do
mappable.map_location = build(:map_location) mappable.map_location = build(:map_location)
mappable.skip_map = nil mappable.skip_map = nil
expect(mappable).to be_valid expect(mappable).to be_valid
end end
it "should be valid accepting that the mappable has no map" do it "is valid accepting that the mappable has no map" do
mappable.skip_map = "1" mappable.skip_map = "1"
mappable.map_location = nil mappable.map_location = nil
expect(mappable).to be_valid expect(mappable).to be_valid
end end
it "should be valid when the feature map is deactivated" do it "is valid when the feature map is deactivated" do
Setting["feature.map"] = nil Setting["feature.map"] = nil
mappable.map_location = nil mappable.map_location = nil
@@ -35,14 +35,14 @@ shared_examples "map validations" do
expect(mappable).to be_valid expect(mappable).to be_valid
end end
it "should not be valid without a map location" do it "is not valid without a map location" do
mappable.map_location = nil mappable.map_location = nil
mappable.skip_map = nil mappable.skip_map = nil
expect(mappable).to_not be_valid expect(mappable).to_not be_valid
end end
it "should not be valid without accepting that the mappable has no map" do it "is not valid without accepting that the mappable has no map" do
mappable.skip_map = nil mappable.skip_map = nil
expect(mappable).to_not be_valid expect(mappable).to_not be_valid
@@ -52,7 +52,7 @@ shared_examples "map validations" do
describe "cache" do describe "cache" do
it "should expire cache when the map is updated" do it "expires cache when the map is updated" do
map_location = create(:map_location) map_location = create(:map_location)
mappable.map_location = map_location mappable.map_location = map_location
mappable.save mappable.save