Files
nairobi/spec/models/sdg/goal_spec.rb
Javi Martín 428644cd3e Add SDG goal model
Since data for this model (title and description) is not generated in
CONSUL but by the United Nations, we aren't storing it in the database
but in our YAML translation files.

The reasoning is as follows. Suppose that, a few months after CONSUL
gets SDG support, a new language is added to CONSUL.

With YAML files, getting the texts in the new language would mean
updating CONSUL to include the new language.

But if we store these texts in the database, it means we have to update
the databases of all existing CONSUL installations, either each
installation by themselves (duplicating efforts) or running a rake task
(which we would have to write each time).

So we believe using translations works better in this case.

We're still storing records in the database with the code, so they can
be easily referenced via `has_many` or `has_many :through` associations.
2020-12-02 12:13:02 +01:00

32 lines
751 B
Ruby

require "rails_helper"
describe SDG::Goal do
it "is valid" do
expect(build(:sdg_goal)).to be_valid
end
it "is not valid without a code" do
expect(build(:sdg_goal, code: nil)).not_to be_valid
end
it "translates title" do
goal = SDG::Goal.where(code: "1").first_or_create!
expect(goal.title).to eq "No Poverty"
I18n.with_locale(:es) do
expect(goal.title).to eq "Fin de la pobreza"
end
end
it "translates description" do
goal = SDG::Goal.where(code: "1").first_or_create!
expect(goal.description).to eq "End poverty in all its forms, everywhere."
I18n.with_locale(:es) do
expect(goal.description).to eq "Poner fin a la pobreza en todas sus formas en todo el mundo."
end
end
end