assets_test.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class AssetsTest < ActiveSupport::TestCase
  4. test 'user' do
  5. roles = Role.where( :name => [ 'Agent', 'Admin'] )
  6. groups = Group.all
  7. org = Organization.create_or_update(
  8. :name => 'some org',
  9. :updated_by_id => 1,
  10. :created_by_id => 1,
  11. )
  12. user1 = User.create_or_update(
  13. :login => 'assets1@example.org',
  14. :firstname => 'assets1',
  15. :lastname => 'assets1',
  16. :email => 'assets1@example.org',
  17. :password => 'some_pass',
  18. :active => true,
  19. :updated_by_id => 1,
  20. :created_by_id => 1,
  21. :organization_id => org.id,
  22. :roles => roles,
  23. :groups => groups,
  24. )
  25. user1.save
  26. user2 = User.create_or_update(
  27. :login => 'assets2@example.org',
  28. :firstname => 'assets2',
  29. :lastname => 'assets2',
  30. :email => 'assets2@example.org',
  31. :password => 'some_pass',
  32. :active => true,
  33. :updated_by_id => 1,
  34. :created_by_id => 1,
  35. :roles => roles,
  36. :groups => groups,
  37. )
  38. user2.save
  39. user3 = User.create_or_update(
  40. :login => 'assets3@example.org',
  41. :firstname => 'assets3',
  42. :lastname => 'assets3',
  43. :email => 'assets3@example.org',
  44. :password => 'some_pass',
  45. :active => true,
  46. :updated_by_id => user1.id,
  47. :created_by_id => user2.id,
  48. :roles => roles,
  49. :groups => groups,
  50. )
  51. user3.save
  52. assets = user3.assets({})
  53. attributes = user1.attributes_with_associations
  54. attributes['accounts'] = {}
  55. attributes['password'] = ''
  56. assert( diff(attributes, assets[:User][user1.id]), 'check assets' )
  57. assert( diff(org.attributes_with_associations, assets[:Organization][org.id]), 'check assets' )
  58. attributes = user2.attributes_with_associations
  59. attributes['accounts'] = {}
  60. attributes['password'] = ''
  61. assert( diff(attributes, assets[:User][user2.id]), 'check assets' )
  62. attributes = user3.attributes_with_associations
  63. attributes['accounts'] = {}
  64. attributes['password'] = ''
  65. assert( diff(attributes, assets[:User][user3.id]), 'check assets' )
  66. end
  67. def diff(o1, o2)
  68. return true if o1 #== o2
  69. raise "ERROR: difference #{o1.inspect}, #{o2.inspect}"
  70. end
  71. end