From 576086304379c1cdee18898448cee6a65a23eb76 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Wed, 22 Oct 2014 13:37:33 -0200 Subject: [PATCH] Unit tests for NameScriptPresenceValidator --- spec/models/validators/name_script_validator_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+), 0 deletions(-) create mode 100644 spec/models/validators/name_script_validator_spec.rb diff --git a/spec/models/validators/name_script_validator_spec.rb b/spec/models/validators/name_script_validator_spec.rb new file mode 100644 index 0000000..f8e4b43 --- /dev/null +++ b/spec/models/validators/name_script_validator_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +describe NameScriptPresenceValidator, :type => :model do + describe 'methods' do + describe 'validate' do + let!(:compound_metric_configuration){ FactoryGirl.build(:compound_metric_configuration) } + + before :each do + CodeUniquenessValidator.any_instance.stubs(:validate_each) + end + + context 'with blank name' do + before :each do + compound_metric_configuration.metric.name = "" + end + + it 'is expected to return a error for the name field' do + compound_metric_configuration.save + expect(compound_metric_configuration.errors[:name]).to include("can't be blank") + end + + context 'with blank script' do + before :each do + compound_metric_configuration.metric.script = "" + end + + it 'is expected to return a error for the name and script fields' do + compound_metric_configuration.save + expect(compound_metric_configuration.errors[:name]).to include("can't be blank") + expect(compound_metric_configuration.errors[:script]).to include("can't be blank") + end + end + end + end + end +end \ No newline at end of file -- libgit2 0.21.2