|
107 | 107 | end |
108 | 108 | end |
109 | 109 |
|
| 110 | + context 'approval-based registrations without invite' do |
| 111 | + around do |example| |
| 112 | + registrations_mode = Setting.registrations_mode |
| 113 | + example.run |
| 114 | + Setting.registrations_mode = registrations_mode |
| 115 | + end |
| 116 | + |
| 117 | + subject do |
| 118 | + Setting.registrations_mode = 'approved' |
| 119 | + request.headers["Accept-Language"] = accept_language |
| 120 | + post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678' } } |
| 121 | + end |
| 122 | + |
| 123 | + it 'redirects to login page' do |
| 124 | + subject |
| 125 | + expect(response).to redirect_to new_user_session_path |
| 126 | + end |
| 127 | + |
| 128 | + it 'creates user' do |
| 129 | + subject |
| 130 | + user = User.find_by(email: 'test@example.com') |
| 131 | + expect(user).to_not be_nil |
| 132 | + expect(user.locale).to eq(accept_language) |
| 133 | + expect(user.approved).to eq(false) |
| 134 | + end |
| 135 | + end |
| 136 | + |
| 137 | + context 'approval-based registrations with expired invite' do |
| 138 | + around do |example| |
| 139 | + registrations_mode = Setting.registrations_mode |
| 140 | + example.run |
| 141 | + Setting.registrations_mode = registrations_mode |
| 142 | + end |
| 143 | + |
| 144 | + subject do |
| 145 | + Setting.registrations_mode = 'approved' |
| 146 | + request.headers["Accept-Language"] = accept_language |
| 147 | + invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago) |
| 148 | + post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', 'invite_code': invite.code } } |
| 149 | + end |
| 150 | + |
| 151 | + it 'redirects to login page' do |
| 152 | + subject |
| 153 | + expect(response).to redirect_to new_user_session_path |
| 154 | + end |
| 155 | + |
| 156 | + it 'creates user' do |
| 157 | + subject |
| 158 | + user = User.find_by(email: 'test@example.com') |
| 159 | + expect(user).to_not be_nil |
| 160 | + expect(user.locale).to eq(accept_language) |
| 161 | + expect(user.approved).to eq(false) |
| 162 | + end |
| 163 | + end |
| 164 | + |
| 165 | + context 'approval-based registrations with valid invite' do |
| 166 | + around do |example| |
| 167 | + registrations_mode = Setting.registrations_mode |
| 168 | + example.run |
| 169 | + Setting.registrations_mode = registrations_mode |
| 170 | + end |
| 171 | + |
| 172 | + subject do |
| 173 | + Setting.registrations_mode = 'approved' |
| 174 | + request.headers["Accept-Language"] = accept_language |
| 175 | + invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.from_now) |
| 176 | + post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', 'invite_code': invite.code } } |
| 177 | + end |
| 178 | + |
| 179 | + it 'redirects to login page' do |
| 180 | + subject |
| 181 | + expect(response).to redirect_to new_user_session_path |
| 182 | + end |
| 183 | + |
| 184 | + it 'creates user' do |
| 185 | + subject |
| 186 | + user = User.find_by(email: 'test@example.com') |
| 187 | + expect(user).to_not be_nil |
| 188 | + expect(user.locale).to eq(accept_language) |
| 189 | + expect(user.approved).to eq(true) |
| 190 | + end |
| 191 | + end |
| 192 | + |
110 | 193 | it 'does nothing if user already exists' do |
111 | 194 | Fabricate(:user, account: Fabricate(:account, username: 'test')) |
112 | 195 | subject |
|
0 commit comments