From 2503350526626c349bbb71bef81f07a995f6df26 Mon Sep 17 00:00:00 2001 From: juandefelix Date: Sat, 3 Oct 2015 11:59:54 -0500 Subject: [PATCH] added models tests for tag_list count validation --- spec/models/debate_spec.rb | 20 ++++++++++++++++---- spec/models/proposal_spec.rb | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index c4ac619b0..a9ef3892a 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -57,10 +57,22 @@ describe Debate do end end - it "should sanitize the tag list" do - debate.tag_list = "user_id=1" - debate.valid? - expect(debate.tag_list).to eq(['user_id1']) + describe "#tag_list" do + it "should sanitize the tag list" do + debate.tag_list = "user_id=1" + debate.valid? + expect(debate.tag_list).to eq(['user_id1']) + end + + it "should not be 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"] + expect(debate).to_not be_valid + end + + it "should be valid with a tag list of 6 elements" do + debate.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] + expect(debate).to be_valid + end end it "should not be valid without accepting terms of service" do diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 8b58d0eec..ac7c1edfb 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -99,10 +99,22 @@ describe Proposal do end end - it "should sanitize the tag list" do - proposal.tag_list = "user_id=1" - proposal.valid? - expect(proposal.tag_list).to eq(['user_id1']) + describe "tag_list" do + it "should sanitize the tag list" do + proposal.tag_list = "user_id=1" + proposal.valid? + expect(proposal.tag_list).to eq(['user_id1']) + end + + it "should not be 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"] + expect(proposal).to_not be_valid + end + + it "should be valid with a tag list of more than 6 elements" do + proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"] + expect(proposal).to be_valid + end end it "should not be valid without accepting terms of service" do