diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-02-24 13:36:58 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-02-24 13:36:58 +0000 |
commit | b7822e944b75e97db31b1d56249058ee02ce198b (patch) | |
tree | 1412a43c70b0ef6a2a245953d5b4583297ce65ab /spec/models | |
parent | f7974a3c5243279f9a739a7d84174af953b38434 (diff) | |
parent | d8b9ea8bfe9fdf534504044774f0dcdb4bba20f2 (diff) |
Merge branch '2160-banned-user-edits' into rails-3-develop
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/about_me_validator_spec.rb | 53 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 18 |
2 files changed, 71 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7dcd3ab8a..2245a024f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -369,3 +369,21 @@ describe User, "when calculating if a user has exceeded the request limit" do end + +describe User do + + describe :banned? do + + it 'is banned if the user has ban_text' do + user = FactoryGirl.build(:user, :ban_text => 'banned') + expect(user).to be_banned + end + + it 'is not banned if the user has no ban_text' do + user = FactoryGirl.build(:user, :ban_text => '') + expect(user).to_not be_banned + end + + end + +end |