123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- # encoding: utf-8
- require 'test_helper'
- class UserTest < ActiveSupport::TestCase
- test 'user' do
- tests = [
- {
- :name => '#1 - simple create',
- :create => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :email => 'some@example.com',
- :login => 'some@example.com',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :image => 'none',
- :email => 'some@example.com',
- :login => 'some@example.com',
- },
- },
- {
- :name => '#2 - simple create - no lastname',
- :create => {
- :firstname => 'Firstname Lastname',
- :lastname => '',
- :email => 'some@example.com',
- :login => 'some@example.com',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :image => 'none',
- :email => 'some@example.com',
- :login => 'some@example.com',
- },
- },
- {
- :name => '#3 - simple create - nil as lastname',
- :create => {
- :firstname => 'Firstname Lastname',
- :lastname => nil,
- :email => 'some@example.com',
- :login => 'some@example.com',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :image => 'none',
- :email => 'some@example.com',
- :login => 'some@example.com',
- },
- },
- {
- :name => '#4 - simple create - no lastname, firstname with ","',
- :create => {
- :firstname => 'Lastname, Firstname',
- :lastname => '',
- :email => 'some@example.com',
- :login => 'some@example.com',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :email => 'some@example.com',
- :login => 'some@example.com',
- },
- },
- {
- :name => '#5 - simple create - no lastname/firstname',
- :create => {
- :firstname => '',
- :lastname => '',
- :email => 'firstname.lastname@example.com',
- :login => 'login-1',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :email => 'firstname.lastname@example.com',
- :login => 'login-1',
- },
- },
- {
- :name => '#6 - simple create - no lastname/firstnam',
- :create => {
- :firstname => '',
- :lastname => '',
- :email => 'FIRSTNAME.lastname@example.com',
- :login => 'login-2',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :email => 'firstname.lastname@example.com',
- :login => 'login-2',
- },
- },
- {
- :name => '#7 - simple create - nill as fristname and lastname',
- :create => {
- :firstname => nil,
- :lastname => nil,
- :email => 'FIRSTNAME.lastname@example.com',
- :login => 'login-3',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Firstname',
- :lastname => 'Lastname',
- :email => 'firstname.lastname@example.com',
- :login => 'login-3',
- },
- },
- {
- :name => '#8 - update with avatar check',
- :create => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :email => 'bob.smith@example.com',
- :login => 'login-4',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :image => 'none',
- :image_md5 => '76fdc28c07e4f3d7802b75aacfccdf6a',
- :email => 'bob.smith@example.com',
- :login => 'login-4',
- },
- :update => {
- :email => 'unit-test1@znuny.com',
- },
- :update_verify => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :image => '9f19a507f4574b8455543408a7ef2257',
- :image_md5 => '9f19a507f4574b8455543408a7ef2257',
- :email => 'unit-test1@znuny.com',
- :login => 'login-4',
- }
- },
- {
- :name => '#9 - update create with avatar check',
- :create => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :email => 'unit-test2@znuny.com',
- :login => 'login-5',
- :updated_by_id => 1,
- :created_by_id => 1,
- },
- :create_verify => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :image => 'fb83638ff260b20555b25173169135dd',
- :image_md5 => 'fb83638ff260b20555b25173169135dd',
- :email => 'unit-test2@znuny.com',
- :login => 'login-5',
- },
- :update => {
- :email => 'unit-test1@znuny.com',
- },
- :update_verify => {
- :firstname => 'Bob',
- :lastname => 'Smith',
- :image => '9f19a507f4574b8455543408a7ef2257',
- :image_md5 => '9f19a507f4574b8455543408a7ef2257',
- :email => 'unit-test1@znuny.com',
- :login => 'login-5',
- }
- },
- ]
- tests.each { |test|
- # check if user exists
- user = User.where( :login => test[:create][:login] ).first
- if user
- user.destroy
- end
- user = User.create( test[:create] )
- test[:create_verify].each { |key, value|
- next if key == :image_md5
- assert_equal( value, user[key], "create check #{ key } in (#{ test[:name] })" )
- }
- if test[:create_verify][:image_md5]
- file = user.get_image
- file_md5 = Digest::MD5.hexdigest( file[:content] )
- assert_equal( test[:create_verify][:image_md5], file_md5, "create avatar md5 check in (#{ test[:name] })" )
- end
- if test[:update]
- user.update_attributes( test[:update] )
- test[:update_verify].each { |key, value|
- next if key == :image_md5
- assert_equal( value, user[key], "update check #{ key } in (#{ test[:name] })" )
- }
- if test[:update_verify][:image_md5]
- file = user.get_image
- file_md5 = Digest::MD5.hexdigest( file[:content] )
- assert_equal( test[:update_verify][:image_md5], file_md5, "update avatar md5 check in (#{ test[:name] })" )
- end
- end
- user.destroy
- }
- end
- end
|