Commit 576086304379c1cdee18898448cee6a65a23eb76
1 parent
7941cd80
Exists in
colab
and in
4 other branches
Unit tests for NameScriptPresenceValidator
Signed off by: Renan Fichberg <rfichberg@gmail.com>
Showing
1 changed file
with
36 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 1 | +require 'rails_helper' | ||
| 2 | + | ||
| 3 | +describe NameScriptPresenceValidator, :type => :model do | ||
| 4 | + describe 'methods' do | ||
| 5 | + describe 'validate' do | ||
| 6 | + let!(:compound_metric_configuration){ FactoryGirl.build(:compound_metric_configuration) } | ||
| 7 | + | ||
| 8 | + before :each do | ||
| 9 | + CodeUniquenessValidator.any_instance.stubs(:validate_each) | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + context 'with blank name' do | ||
| 13 | + before :each do | ||
| 14 | + compound_metric_configuration.metric.name = "" | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + it 'is expected to return a error for the name field' do | ||
| 18 | + compound_metric_configuration.save | ||
| 19 | + expect(compound_metric_configuration.errors[:name]).to include("can't be blank") | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + context 'with blank script' do | ||
| 23 | + before :each do | ||
| 24 | + compound_metric_configuration.metric.script = "" | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + it 'is expected to return a error for the name and script fields' do | ||
| 28 | + compound_metric_configuration.save | ||
| 29 | + expect(compound_metric_configuration.errors[:name]).to include("can't be blank") | ||
| 30 | + expect(compound_metric_configuration.errors[:script]).to include("can't be blank") | ||
| 31 | + end | ||
| 32 | + end | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + end | ||
| 36 | +end | ||
| 0 | \ No newline at end of file | 37 | \ No newline at end of file |