Add proposal translations
Adapt retire form to include needed translations and move validations from controller to model. Also change sanitizable concern to sanitize not marked for destruction translations.
This commit is contained in:
committed by
voodoorai2000
parent
5343448c5a
commit
02be0c61f9
@@ -8,6 +8,7 @@ describe Proposal do
|
||||
it_behaves_like "has_public_author"
|
||||
it_behaves_like "notifiable"
|
||||
it_behaves_like "map validations"
|
||||
it_behaves_like "globalizable", :proposal
|
||||
end
|
||||
|
||||
it "is valid" do
|
||||
@@ -44,10 +45,36 @@ describe Proposal do
|
||||
describe "#description" do
|
||||
it "is sanitized" do
|
||||
proposal.description = "<script>alert('danger');</script>"
|
||||
|
||||
proposal.valid?
|
||||
|
||||
expect(proposal.description).to eq("alert('danger');")
|
||||
end
|
||||
|
||||
it "is sanitized using globalize accessors" do
|
||||
proposal.description_en = "<script>alert('danger');</script>"
|
||||
|
||||
proposal.valid?
|
||||
|
||||
expect(proposal.description_en).to eq("alert('danger');")
|
||||
end
|
||||
|
||||
it "is html_safe" do
|
||||
proposal.description = "<script>alert('danger');</script>"
|
||||
|
||||
proposal.valid?
|
||||
|
||||
expect(proposal.description).to be_html_safe
|
||||
end
|
||||
|
||||
it "is html_safe using globalize accessors" do
|
||||
proposal.description_en = "<script>alert('danger');</script>"
|
||||
|
||||
proposal.valid?
|
||||
|
||||
expect(proposal.description_en).to be_html_safe
|
||||
end
|
||||
|
||||
it "is not valid when very long" do
|
||||
proposal.description = "a" * 6001
|
||||
expect(proposal).not_to be_valid
|
||||
@@ -143,6 +170,46 @@ describe Proposal do
|
||||
Setting["proposal_code_prefix"] = "MAD"
|
||||
end
|
||||
|
||||
describe "#retired_explanation" do
|
||||
it "is valid when retired timestamp is present and retired explanation is defined" do
|
||||
proposal.retired_at = Time.current
|
||||
proposal.retired_explanation = "Duplicated of ..."
|
||||
proposal.retired_reason = "duplicated"
|
||||
expect(proposal).to be_valid
|
||||
end
|
||||
|
||||
it "is not valid when retired_at is present and retired explanation is empty" do
|
||||
proposal.retired_at = Time.current
|
||||
proposal.retired_explanation = nil
|
||||
proposal.retired_reason = "duplicated"
|
||||
expect(proposal).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#retired_reason" do
|
||||
it "is valid when retired timestamp is present and retired reason is defined" do
|
||||
proposal.retired_at = Time.current
|
||||
proposal.retired_explanation = "Duplicated of ..."
|
||||
proposal.retired_reason = "duplicated"
|
||||
expect(proposal).to be_valid
|
||||
end
|
||||
|
||||
it "is not valid when retired timestamp is present but defined retired reason
|
||||
is not included in retired reasons" do
|
||||
proposal.retired_at = Time.current
|
||||
proposal.retired_explanation = "Duplicated of ..."
|
||||
proposal.retired_reason = "duplicate"
|
||||
expect(proposal).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid when retired_at is present and retired reason is empty" do
|
||||
proposal.retired_at = Time.current
|
||||
proposal.retired_explanation = "Duplicated of ..."
|
||||
proposal.retired_reason = nil
|
||||
expect(proposal).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#editable?" do
|
||||
let(:proposal) { create(:proposal) }
|
||||
|
||||
@@ -820,7 +887,7 @@ describe Proposal do
|
||||
|
||||
describe "retired" do
|
||||
let!(:proposal1) { create(:proposal) }
|
||||
let!(:proposal2) { create(:proposal, retired_at: Time.current) }
|
||||
let!(:proposal2) { create(:proposal, :retired) }
|
||||
|
||||
it "retired? is true" do
|
||||
expect(proposal1.retired?).to eq false
|
||||
|
||||
Reference in New Issue
Block a user