@@ -161,33 +161,26 class AccountControllerTest < ActionController::TestCase | |||||
161 | assert_nil @request.session[:user_id] |
|
161 | assert_nil @request.session[:user_id] | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | context "GET #register" do |
|
164 | def test_get_register_with_registration_on | |
165 |
|
|
165 | with_settings :self_registration => '3' do | |
166 | setup do |
|
166 | get :register | |
167 | Setting.self_registration = '3' |
|
167 | assert_response :success | |
168 | get :register |
|
168 | assert_template 'register' | |
169 | end |
|
169 | assert_not_nil assigns(:user) | |
170 |
|
||||
171 | should_respond_with :success |
|
|||
172 | should_render_template :register |
|
|||
173 | should_assign_to :user |
|
|||
174 | end |
|
170 | end | |
|
171 | end | |||
175 |
|
172 | |||
176 | context "with self registration off" do |
|
173 | def test_get_register_with_registration_off_should_redirect | |
177 | setup do |
|
174 | with_settings :self_registration => '0' do | |
178 | Setting.self_registration = '0' |
|
175 | get :register | |
179 | get :register |
|
176 | assert_redirected_to '/' | |
180 | end |
|
|||
181 |
|
||||
182 | should_redirect_to('/') { home_url } |
|
|||
183 | end |
|
177 | end | |
184 | end |
|
178 | end | |
185 |
|
179 | |||
186 | # See integration/account_test.rb for the full test |
|
180 | # See integration/account_test.rb for the full test | |
187 | context "POST #register" do |
|
181 | def test_post_register_with_registration_on | |
188 |
|
|
182 | with_settings :self_registration => '3' do | |
189 | setup do |
|
183 | assert_difference 'User.count' do | |
190 | Setting.self_registration = '3' |
|
|||
191 | post :register, :user => { |
|
184 | post :register, :user => { | |
192 | :login => 'register', |
|
185 | :login => 'register', | |
193 | :password => 'test', |
|
186 | :password => 'test', | |
@@ -196,28 +189,27 class AccountControllerTest < ActionController::TestCase | |||||
196 | :lastname => 'Doe', |
|
189 | :lastname => 'Doe', | |
197 | :mail => 'register@example.com' |
|
190 | :mail => 'register@example.com' | |
198 | } |
|
191 | } | |
|
192 | assert_redirected_to '/my/account' | |||
199 | end |
|
193 | end | |
200 |
|
194 | user = User.first(:order => 'id DESC') | ||
201 | should_respond_with :redirect |
|
195 | assert_equal 'register', user.login | |
202 | should_assign_to :user |
|
196 | assert user.active? | |
203 | should_redirect_to('my page') { {:controller => 'my', :action => 'account'} } |
|
|||
204 |
|
||||
205 | should_create_a_new_user { User.last(:conditions => {:login => 'register'}) } |
|
|||
206 |
|
||||
207 | should 'set the user status to active' do |
|
|||
208 | user = User.last(:conditions => {:login => 'register'}) |
|
|||
209 | assert user |
|
|||
210 | assert_equal User::STATUS_ACTIVE, user.status |
|
|||
211 | end |
|
|||
212 | end |
|
197 | end | |
213 |
|
198 | end | ||
214 | context "with self registration off" do |
|
199 | ||
215 | setup do |
|
200 | def test_post_register_with_registration_off_should_redirect | |
216 |
|
|
201 | with_settings :self_registration => '0' do | |
217 | post :register |
|
202 | assert_no_difference 'User.count' do | |
|
203 | post :register, :user => { | |||
|
204 | :login => 'register', | |||
|
205 | :password => 'test', | |||
|
206 | :password_confirmation => 'test', | |||
|
207 | :firstname => 'John', | |||
|
208 | :lastname => 'Doe', | |||
|
209 | :mail => 'register@example.com' | |||
|
210 | } | |||
|
211 | assert_redirected_to '/' | |||
218 | end |
|
212 | end | |
219 |
|
||||
220 | should_redirect_to('/') { home_url } |
|
|||
221 | end |
|
213 | end | |
222 | end |
|
214 | end | |
223 | end |
|
215 | end |
@@ -207,15 +207,6 class ActiveSupport::TestCase | |||||
207 | end |
|
207 | end | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def self.should_create_a_new_user(&block) |
|
|||
211 | should "create a new user" do |
|
|||
212 | user = instance_eval &block |
|
|||
213 | assert user |
|
|||
214 | assert_kind_of User, user |
|
|||
215 | assert !user.new_record? |
|
|||
216 | end |
|
|||
217 | end |
|
|||
218 |
|
||||
219 | # Test that a request allows the three types of API authentication |
|
210 | # Test that a request allows the three types of API authentication | |
220 | # |
|
211 | # | |
221 | # * HTTP Basic with username and password |
|
212 | # * HTTP Basic with username and password |
General Comments 0
You need to be logged in to leave comments.
Login now