|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe Character do |
4 | | - pending "add some examples to (or delete) #{__FILE__}" |
| 4 | + context 'validation' do |
| 5 | + it 'has a valid factory' do |
| 6 | + expect(FactoryGirl.create(:character)).to be_valid |
| 7 | + end |
| 8 | + |
| 9 | + it 'is invalid without a name' do |
| 10 | + expect(FactoryGirl.build(:character, name: nil)).to_not be_valid |
| 11 | + end |
| 12 | + |
| 13 | + it 'is invalid if name is more than 80 characters' do |
| 14 | + expect(FactoryGirl.build(:character, name: "as"*41)).to_not be_valid |
| 15 | + end |
| 16 | + |
| 17 | + it 'is invalid without an affinity' do |
| 18 | + expect(FactoryGirl.build(:character, affinity_id: nil)).to_not be_valid |
| 19 | + end |
| 20 | + |
| 21 | + it 'is invalid without a tier' do |
| 22 | + expect(FactoryGirl.build(:character, tier_id: nil)).to_not be_valid |
| 23 | + end |
| 24 | + |
| 25 | + it 'is invalid without stats' do |
| 26 | + expect(FactoryGirl.build(:character, stat_hp: nil)).to_not be_valid |
| 27 | + expect(FactoryGirl.build(:character, stat_str: nil)).to_not be_valid |
| 28 | + expect(FactoryGirl.build(:character, stat_def: nil)).to_not be_valid |
| 29 | + expect(FactoryGirl.build(:character, stat_spd: nil)).to_not be_valid |
| 30 | + expect(FactoryGirl.build(:character, stat_int: nil)).to_not be_valid |
| 31 | + expect(FactoryGirl.build(:character, stat_luck: nil)).to_not be_valid |
| 32 | + end |
| 33 | + |
| 34 | + it 'is invalid with stats than 0' do |
| 35 | + expect(FactoryGirl.build(:character, stat_str: -1)).to_not be_valid |
| 36 | + end |
| 37 | + |
| 38 | + it 'is invalid with non-integer stats' do |
| 39 | + expect(FactoryGirl.build(:character, stat_str: 1.5)).to_not be_valid |
| 40 | + end |
| 41 | + |
| 42 | + it 'is invalid when it shares a name with another character in the same series' do |
| 43 | + bob1 = FactoryGirl.create(:character, name: "Bob", series_id: 1) |
| 44 | + bob2 = FactoryGirl.build(:character, name: "Bob", series_id: 1) |
| 45 | + expect(bob2).to_not be_valid |
| 46 | + end |
| 47 | + |
| 48 | + it 'is valid when it shares a name with another character in a different series' do |
| 49 | + bob1 = FactoryGirl.create(:character, name: "Bob", series_id: 1) |
| 50 | + bob2 = FactoryGirl.build(:character, name: "Bob", series_id: 2) |
| 51 | + expect(bob2).to be_valid |
| 52 | + end |
| 53 | + end |
5 | 54 | end |
0 commit comments