Commit 9d674677a9c5cbc348da484ae82aeb0e7edec38e
Committed by
Rafael Manzo
1 parent
fc94859e
Exists in
colab
and in
4 other branches
Project validation tests.
Unit tests.
Showing
2 changed files
with
53 additions
and
0 deletions
Show diff stats
spec/models/project_spec.rb
| @@ -59,4 +59,25 @@ describe Project do | @@ -59,4 +59,25 @@ describe Project do | ||
| 59 | end | 59 | end |
| 60 | end | 60 | end |
| 61 | end | 61 | end |
| 62 | + | ||
| 63 | + describe 'validations' do | ||
| 64 | + subject {FactoryGirl.build(:project)} | ||
| 65 | + context 'active model validations' do | ||
| 66 | + before :each do | ||
| 67 | + Project.expects(:all).at_least_once.returns([]) | ||
| 68 | + end | ||
| 69 | + it { should validate_presence_of(:name) } | ||
| 70 | + end | ||
| 71 | + | ||
| 72 | + context 'kalibro validations' do | ||
| 73 | + before :each do | ||
| 74 | + Project.expects(:request).returns(42) | ||
| 75 | + end | ||
| 76 | + | ||
| 77 | + it 'should validate uniqueness' do | ||
| 78 | + KalibroUniquenessValidator.any_instance.expects(:validate_each).with(subject, :name, subject.name) | ||
| 79 | + subject.save | ||
| 80 | + end | ||
| 81 | + end | ||
| 82 | + end | ||
| 62 | end | 83 | end |
spec/models/validators/kalibro_uniqueness_validator_spec.rb
0 → 100644
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe KalibroUniquenessValidator do | ||
| 4 | + describe 'methods' do | ||
| 5 | + describe 'validate_each' do | ||
| 6 | + context 'without saved projects' do | ||
| 7 | + before :each do | ||
| 8 | + Project.expects(:all).returns([]) | ||
| 9 | + Project.expects(:request).returns(42) | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + subject { FactoryGirl.build(:project) } | ||
| 13 | + it 'should contain no errors' do | ||
| 14 | + subject.save | ||
| 15 | + subject.errors.should be_empty | ||
| 16 | + end | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + context 'with name already taken' do | ||
| 20 | + before :each do | ||
| 21 | + @subject = FactoryGirl.build(:project) | ||
| 22 | + Project.expects(:all).returns([@subject]) | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + it 'should contain errors' do | ||
| 26 | + @subject.save | ||
| 27 | + @subject.errors[:name].should eq(["There's already a Project with name #{@subject.name}! Please, choose another one."]) | ||
| 28 | + end | ||
| 29 | + end | ||
| 30 | + end | ||
| 31 | + end | ||
| 32 | +end | ||
| 0 | \ No newline at end of file | 33 | \ No newline at end of file |