aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-02-18 14:43:58 +0000
committerGareth Rees <gareth@mysociety.org>2015-02-24 13:23:17 +0000
commit362a7b967819ca0a58dd251ab77842ab18aa7f64 (patch)
treeb449f0fbb41372fd2f585e15cbdebd516e2b41e1 /spec
parentae648fc4ff414eb33ef17744d4434a0e4a43e606 (diff)
Add specs to AboutMeValidator
Diffstat (limited to 'spec')
-rw-r--r--spec/models/about_me_validator_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/about_me_validator_spec.rb b/spec/models/about_me_validator_spec.rb
new file mode 100644
index 000000000..5610cead8
--- /dev/null
+++ b/spec/models/about_me_validator_spec.rb
@@ -0,0 +1,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