Add SDG::Review model

and its relation with relatables

Note about sdg_review factory: Cannot use the constantize method on
the relatable_type as long as the relatable classes will be loaded and
this will throw an exception because the database is not available at
factiry definition time.
This commit is contained in:
Senén Rodero Rodríguez
2020-12-21 16:04:19 +01:00
parent 60c3c6b6e2
commit 0368aa459f
7 changed files with 67 additions and 0 deletions

View File

@@ -117,6 +117,18 @@ describe SDG::Relatable do
end
end
describe "#sdg_review" do
it "returns nil when relatable is not reviewed" do
expect(relatable.sdg_review).to be_blank
end
it "returns the review when relatable is reviewed" do
review = create(:sdg_review, relatable: relatable)
expect(relatable.sdg_review).to eq(review)
end
end
describe ".by_goal" do
it "returns everything if no code is provided" do
expect(relatable.class.by_goal("")).to eq [relatable]

View File

@@ -0,0 +1,23 @@
require "rails_helper"
describe SDG::Review do
describe "Validations" do
it "is valid for any given relatable" do
review = build(:sdg_review, :debate_review)
expect(review).to be_valid
end
it "is not valid without a relatable" do
review = build(:sdg_review, relatable: nil)
expect(review).not_to be_valid
end
it "is not valid when a review for given relatable already exists" do
relatable = create(:sdg_review, :proposal_review).relatable
expect(build(:sdg_review, relatable: relatable)).not_to be_valid
end
end
end