aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/about_me_validator_spec.rb
blob: 5610cead8c1ca6ecae4ec79c57bf7b23d8293f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe AboutMeValidator do

  describe :new do

    it 'sets each supported attribute on the instance' do
      params = { :about_me => 'My description' }
      validator = AboutMeValidator.new(params)
      expect(validator.about_me).to eq('My description')
    end

  end

  describe :valid? do

    it 'is valid if about_me is =< 500' do
      params = { :about_me => 'a'*500 }
      validator = AboutMeValidator.new(params)
      expect(validator).to be_valid
    end

    it 'is valid if about_me is blank' do
      params = { :about_me => '' }
      validator = AboutMeValidator.new(params)
      expect(validator).to be_valid
    end

    it 'is valid if about_me is nil' do
      params = { :about_me => nil }
      validator = AboutMeValidator.new(params)
      expect(validator).to be_valid
    end

    it 'is invalid if about_me is > 500' do
      params = { :about_me => 'a'*501 }
      validator = AboutMeValidator.new(params)
      expect(validator).to have(1).error_on(:about_me)
    end

  end

  describe :about_me do

    it 'has an attribute accessor' do
      params = { :about_me => 'My description' }
      validator = AboutMeValidator.new(params)
      expect(validator.about_me).to eq('My description')
    end

  end

end