1
0

registrations_controller_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. require 'rails_helper'
  2. module Users
  3. describe RegistrationsController do
  4. describe "POST create" do
  5. before do
  6. @request.env["devise.mapping"] = Devise.mappings[:user]
  7. end
  8. context 'with valid params' do
  9. it "imports the default scenario for the new user" do
  10. expect(DefaultScenarioImporter).to receive(:import).with(kind_of(User))
  11. post :create, params: {
  12. :user => {username: 'jdoe', email: 'jdoe@example.com',
  13. password: 's3cr3t55', password_confirmation: 's3cr3t55', invitation_code: 'try-huginn'}
  14. }
  15. end
  16. end
  17. context 'with invalid params' do
  18. it "does not import the default scenario" do
  19. allow(DefaultScenarioImporter).to receive(:import).with(kind_of(User)) { fail "Should not attempt import" }
  20. setup_controller_for_warden
  21. post :create, params: {:user => {}}
  22. end
  23. it 'does not allow to set the admin flag' do
  24. expect { post :create, params: {:user => {admin: 'true'}} }.to raise_error(ActionController::UnpermittedParameters)
  25. end
  26. end
  27. end
  28. end
  29. end