Guest User

Untitled

a guest
Mar 11th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. def create_user(user_options = {}, other_options = {})
  2. base_options = { :login => 'unique', :email => 'unique@example.com',
  3. :first_name => 'bob', :last_name => 'testerperson', :address => "123 Main St",
  4. :city => "Santa Carla", :state => "CA", :zip => "95000", :subscription => "Tier 1",
  5. :role => 'Member',
  6. :password => 'quire69', :password_confirmation => 'quire69',:accept_terms => true }
  7. post :create, {:user => (base_options.merge(user_options))}.merge(other_options)
  8. end
  9.  
  10. it 'should set permissions on create' do
  11. pretend_to_be_authenticated("Administrator")
  12. quentin = users( :quentin)
  13. quentin.stub!( :match_permissions_with_subscription!)
  14. rebecca = content_categories(:rebecca)
  15. todd = content_categories(:todd)
  16. howard = content_categories(:howard)
  17. brian = content_categories(:brian)
  18. ContentCategory.should_receive(:find_by_name).with("REBECCA RUNKLE").and_return(rebecca)
  19. ContentCategory.should_receive(:find_by_name).with("TODD JORDAN").and_return(todd)
  20. ContentCategory.should_receive(:find_by_name).with("HOWARD PENNEY").and_return(howard)
  21. ContentCategory.should_receive(:find_by_name).with("BRIAN McGOUGH").and_return(brian)
  22. quentin.should_receive(:set_permission).with(rebecca, Permission::TIER_1, nil, nil)
  23. quentin.should_receive(:set_permission).with(todd, Permission::TIER_2, nil, nil)
  24. quentin.should_receive(:set_permission).with(howard, Permission::TRIAL_FULL_TEXT, "1/1/2011", "1/7/2011")
  25. quentin.should_receive(:set_permission).with(brian, Permission::TRIAL_REWIND, "1/8/2011", "1/15/2011")
  26. quentin.should_receive(:permissions_valid?).and_return(true)
  27. quentin.stub!(:valid?).and_return(true)
  28. quentin.stub!(:credit_card_subscriber?).and_return(false)
  29. quentin.should_receive(:activate)
  30. quentin.should_receive(:save!)
  31. User.stub!(:find_by_email).and_return(quentin)
  32. create_user({:subscription => "Tier 1" },
  33. {
  34. :permissions => {
  35. "REBECCA RUNKLE" => {:permission_type => Permission::TIER_1},
  36. "TODD JORDAN" => {:permission_type => Permission::TIER_2},
  37. "HOWARD PENNEY" => {:permission_type => Permission::TRIAL_FULL_TEXT, :trial_start => "1/1/2011", :trial_end => "1/7/2011"},
  38. "BRIAN McGOUGH" => {:permission_type => Permission::TRIAL_REWIND, :trial_start => "1/8/2011", :trial_end => "1/15/2011"}
  39. }
  40. })
  41. end
  42.  
  43. it 'should remove specified permissions on create' do
  44. pretend_to_be_authenticated("Administrator")
  45. quentin = users( :quentin)
  46. quentin.stub!( :match_permissions_with_subscription!)
  47. rebecca = content_categories(:rebecca)
  48. todd = content_categories(:todd)
  49. howard = content_categories(:howard)
  50. brian = content_categories(:brian)
  51. ContentCategory.should_receive(:find_by_name).with("REBECCA RUNKLE").and_return(rebecca)
  52. ContentCategory.should_receive(:find_by_name).with("TODD JORDAN").and_return(todd)
  53. ContentCategory.should_receive(:find_by_name).with("HOWARD PENNEY").and_return(howard)
  54. ContentCategory.should_receive(:find_by_name).with("BRIAN McGOUGH").and_return(brian)
  55. quentin.should_receive(:set_permission).with(rebecca, Permission::NONE, nil, nil)
  56. quentin.should_receive(:set_permission).with(todd, Permission::NONE, nil, nil)
  57. quentin.should_receive(:set_permission).with(howard, Permission::TRIAL_FULL_TEXT, "1/1/2011", "1/7/2011")
  58. quentin.should_receive(:set_permission).with(brian, Permission::TRIAL_REWIND, "1/8/2011", "1/15/2011")
  59. quentin.should_receive(:permissions_valid?).and_return(true)
  60. quentin.stub!(:valid?).and_return(true)
  61. quentin.stub!(:credit_card_subscriber?).and_return(false)
  62. quentin.should_receive(:activate)
  63. quentin.should_receive(:save!)
  64. User.stub!(:find_by_email).and_return(quentin)
  65. create_user({:subscription => "Tier 1" },
  66. {
  67. :permissions => {
  68. "REBECCA RUNKLE" => {:permission_type => Permission::NONE},
  69. "TODD JORDAN" => {:permission_type => Permission::NONE},
  70. "HOWARD PENNEY" => {:permission_type => Permission::TRIAL_FULL_TEXT, :trial_start => "1/1/2011", :trial_end => "1/7/2011"},
  71. "BRIAN McGOUGH" => {:permission_type => Permission::TRIAL_REWIND, :trial_start => "1/8/2011", :trial_end => "1/15/2011"}
  72. }
  73. })
  74. end
Add Comment
Please, Sign In to add comment