Merge with master
This commit is contained in:
@@ -20,6 +20,9 @@ describe "Abilities::Administrator" do
|
||||
let(:budget_investment_document) { build(:document, documentable: budget_investment) }
|
||||
let(:poll_question_document) { build(:document, documentable: poll_question) }
|
||||
|
||||
let(:proposal_image) { build(:image, imageable: proposal) }
|
||||
let(:budget_investment_image) { build(:image, imageable: budget_investment) }
|
||||
|
||||
let(:hidden_debate) { create(:debate, :hidden) }
|
||||
let(:hidden_comment) { create(:comment, :hidden) }
|
||||
let(:hidden_proposal) { create(:proposal, :hidden) }
|
||||
@@ -78,15 +81,11 @@ describe "Abilities::Administrator" do
|
||||
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'valuating'))) }
|
||||
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'finished'))) }
|
||||
|
||||
it { should be_able_to(:new, proposal_document) }
|
||||
it { should be_able_to(:create, proposal_document) }
|
||||
it { should be_able_to(:destroy, proposal_document) }
|
||||
|
||||
it { should be_able_to(:new, budget_investment_document) }
|
||||
it { should be_able_to(:create, budget_investment_document) }
|
||||
it { should be_able_to(:destroy, budget_investment_document) }
|
||||
|
||||
it { should be_able_to(:new, poll_question_document) }
|
||||
it { should be_able_to(:create, poll_question_document) }
|
||||
it { should be_able_to(:destroy, poll_question_document) }
|
||||
|
||||
it { should be_able_to(:destroy, proposal_image) }
|
||||
it { should be_able_to(:destroy, budget_investment_image) }
|
||||
|
||||
end
|
||||
|
||||
@@ -59,6 +59,11 @@ describe "Abilities::Common" do
|
||||
let(:own_budget_investment_document) { build(:document, documentable: own_investment_in_accepting_budget) }
|
||||
let(:budget_investment_document) { build(:document, documentable: investment_in_accepting_budget) }
|
||||
|
||||
let(:own_proposal_image) { build(:image, imageable: own_proposal) }
|
||||
let(:proposal_image) { build(:image, imageable: proposal) }
|
||||
let(:own_budget_investment_image) { build(:image, imageable: own_investment_in_accepting_budget) }
|
||||
let(:budget_investment_image) { build(:image, imageable: investment_in_accepting_budget) }
|
||||
|
||||
it { should be_able_to(:index, Debate) }
|
||||
it { should be_able_to(:show, debate) }
|
||||
it { should be_able_to(:vote, debate) }
|
||||
@@ -87,25 +92,18 @@ describe "Abilities::Common" do
|
||||
it { should_not be_able_to(:create, DirectMessage) }
|
||||
it { should_not be_able_to(:show, DirectMessage) }
|
||||
|
||||
it { should be_able_to(:new_nested, Document) }
|
||||
it { should be_able_to(:destroy_upload, Document) }
|
||||
|
||||
it { should be_able_to(:new, own_proposal_document) }
|
||||
it { should be_able_to(:create, own_proposal_document) }
|
||||
it { should be_able_to(:destroy, own_proposal_document) }
|
||||
|
||||
it { should_not be_able_to(:new, proposal_document) }
|
||||
it { should_not be_able_to(:create, proposal_document) }
|
||||
it { should_not be_able_to(:destroy, proposal_document) }
|
||||
|
||||
it { should be_able_to(:new, own_budget_investment_document) }
|
||||
it { should be_able_to(:create, own_budget_investment_document) }
|
||||
it { should be_able_to(:destroy, own_budget_investment_document) }
|
||||
|
||||
it { should_not be_able_to(:new, budget_investment_document) }
|
||||
it { should_not be_able_to(:create, budget_investment_document) }
|
||||
it { should_not be_able_to(:destroy, budget_investment_document) }
|
||||
|
||||
it { should be_able_to(:destroy, own_proposal_image) }
|
||||
it { should_not be_able_to(:destroy, proposal_image) }
|
||||
|
||||
it { should be_able_to(:destroy, own_budget_investment_image) }
|
||||
it { should_not be_able_to(:destroy, budget_investment_image) }
|
||||
|
||||
describe 'flagging content' do
|
||||
it { should be_able_to(:flag, debate) }
|
||||
it { should be_able_to(:unflag, debate) }
|
||||
|
||||
@@ -29,6 +29,8 @@ describe Budget::Investment do
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "acts as imageable", "budget_investment_image"
|
||||
|
||||
it "sanitizes description" do
|
||||
investment.description = "<script>alert('danger');</script>"
|
||||
investment.valid?
|
||||
@@ -103,7 +105,7 @@ describe Budget::Investment do
|
||||
let(:investment) { create(:budget_investment) }
|
||||
|
||||
it "returns the proposal id" do
|
||||
expect(investment.code).to include((investment.id).to_s)
|
||||
expect(investment.code).to include(investment.id.to_s)
|
||||
end
|
||||
|
||||
it "returns the administrator id when assigned" do
|
||||
@@ -393,7 +395,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, :feasible, budget: budget)
|
||||
investment3 = create(:budget_investment, :unfeasible, budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, {}, :feasible)
|
||||
results = Budget::Investment.apply_filters_and_search(budget, {}, :feasible)
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
@@ -405,7 +407,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, :unfeasible, budget: budget)
|
||||
investment3 = create(:budget_investment, :feasible, budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, {}, :unfeasible)
|
||||
results = Budget::Investment.apply_filters_and_search(budget, {}, :unfeasible)
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
@@ -419,7 +421,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, :feasible, :selected, budget: budget)
|
||||
investment3 = create(:budget_investment, :feasible, :unselected, budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, {}, :selected)
|
||||
results = Budget::Investment.apply_filters_and_search(budget, {}, :selected)
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
@@ -433,7 +435,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, :feasible, :unselected, budget: budget)
|
||||
investment3 = create(:budget_investment, :feasible, :selected, budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, {}, :unselected)
|
||||
results = Budget::Investment.apply_filters_and_search(budget, {}, :unselected)
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
@@ -450,7 +452,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, heading: heading1, budget: budget)
|
||||
investment3 = create(:budget_investment, heading: heading2, budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, heading_id: heading1.id)
|
||||
results = Budget::Investment.apply_filters_and_search(budget, heading_id: heading1.id)
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
@@ -462,7 +464,7 @@ describe Budget::Investment do
|
||||
investment2 = create(:budget_investment, title: "improved health", budget: budget)
|
||||
investment3 = create(:budget_investment, title: "finance", budget: budget)
|
||||
|
||||
results = Budget::Investment::apply_filters_and_search(budget, search: "health")
|
||||
results = Budget::Investment.apply_filters_and_search(budget, search: "health")
|
||||
|
||||
expect(results).to include investment1
|
||||
expect(results).to include investment2
|
||||
|
||||
@@ -687,12 +687,12 @@ describe Debate do
|
||||
describe "#last_week" do
|
||||
it "should return debates created this week" do
|
||||
debate = create(:debate)
|
||||
expect(Debate.last_week.all).to include (debate)
|
||||
expect(Debate.last_week.all).to include debate
|
||||
end
|
||||
|
||||
it "should not show debates created more than a week ago" do
|
||||
debate = create(:debate, created_at: 8.days.ago)
|
||||
expect(Debate.last_week.all).to_not include (debate)
|
||||
expect(Debate.last_week.all).to_not include debate
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
65
spec/models/direct_upload_spec.rb
Normal file
65
spec/models/direct_upload_spec.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe DirectUpload do
|
||||
|
||||
context "configurations" do
|
||||
|
||||
it "should be 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, :image)).to be_valid
|
||||
expect(build(:direct_upload, :budget_investment, :documents)).to be_valid
|
||||
expect(build(:direct_upload, :budget_investment, :image)).to be_valid
|
||||
end
|
||||
|
||||
it "should not be 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, :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, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without resource_type" do
|
||||
expect(build(:direct_upload, :proposal, :documents, resource_type: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without resource_relation" do
|
||||
expect(build(:direct_upload, :proposal, :documents, resource_relation: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without attachment" do
|
||||
expect(build(:direct_upload, :proposal, :documents, attachment: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without user" do
|
||||
expect(build(:direct_upload, :proposal, :documents, user: nil)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "save_attachment" do
|
||||
|
||||
it "should save uploaded file" do
|
||||
proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)
|
||||
|
||||
proposal_document_direct_upload.save_attachment
|
||||
|
||||
expect(File.exists?(proposal_document_direct_upload.relation.attachment.path)).to eq(true)
|
||||
expect(proposal_document_direct_upload.relation.attachment.path).to include('cached_attachments')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "destroy_attachment" do
|
||||
|
||||
it "should remove uploaded file" do
|
||||
proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)
|
||||
|
||||
proposal_document_direct_upload.save_attachment
|
||||
uploaded_path = proposal_document_direct_upload.relation.attachment.path
|
||||
proposal_document_direct_upload.destroy_attachment
|
||||
|
||||
expect(File.exists?(uploaded_path)).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
8
spec/models/image_spec.rb
Normal file
8
spec/models/image_spec.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Image do
|
||||
|
||||
it_behaves_like "image validations", "budget_investment_image"
|
||||
it_behaves_like "image validations", "proposal_image"
|
||||
|
||||
end
|
||||
@@ -1,40 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe :final_recount do
|
||||
|
||||
it "should update count_log if count changes" do
|
||||
final_recount = create(:poll_final_recount, count: 33)
|
||||
|
||||
expect(final_recount.count_log).to eq("")
|
||||
|
||||
final_recount.count = 33
|
||||
final_recount.save
|
||||
final_recount.count = 32
|
||||
final_recount.save
|
||||
final_recount.count = 34
|
||||
final_recount.save
|
||||
|
||||
expect(final_recount.count_log).to eq(":33:32")
|
||||
end
|
||||
|
||||
it "should update officer_assignment_id_log if count changes" do
|
||||
final_recount = create(:poll_final_recount, count: 33)
|
||||
|
||||
expect(final_recount.count_log).to eq("")
|
||||
|
||||
final_recount.count = 33
|
||||
final_recount.officer_assignment = create(:poll_officer_assignment, id: 111)
|
||||
final_recount.save
|
||||
|
||||
final_recount.count = 32
|
||||
final_recount.officer_assignment = create(:poll_officer_assignment, id: 112)
|
||||
final_recount.save
|
||||
|
||||
final_recount.count = 34
|
||||
final_recount.officer_assignment = create(:poll_officer_assignment, id: 113)
|
||||
final_recount.save
|
||||
|
||||
expect(final_recount.officer_assignment_id_log).to eq(":111:112")
|
||||
end
|
||||
|
||||
end
|
||||
@@ -27,7 +27,7 @@ describe Verification::Residence do
|
||||
it "should validate user has allowed age" do
|
||||
residence = Verification::Residence.new("date_of_birth(3i)" => "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)
|
||||
expect(residence).to_not be_valid
|
||||
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user