以下规范用于通过:
it "should allow me to register" do
fill_in "First name", with: "John"
fill_in "Last name", with: "Peters"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Password confirmation", with: "foobar"
expect { click_button submit }.to change(User, :count).by(1)
end
test.log
输出为:
Started GET "/users/sign_up" for 127.0.0.1 at 2013-08-16 13:12:45 -0400
Processing by RegistrationsController#new as HTML
Rendered users/shared/_service.html.haml (1.9ms)
Rendered users/registrations/_newfields.haml (149.9ms)
Rendered users/shared/_links.haml (3.9ms)
Rendered users/registrations/new.html.haml within layouts/application (180.3ms)
Rendered shared/_header.haml (10.0ms)
Rendered shared/_footer.haml (12.4ms)
Completed 200 OK in 411ms (Views: 331.7ms | ActiveRecord: 30.0ms)
(120.9ms) SELECT COUNT(*) FROM `users`
Started POST "/users" for 127.0.0.1 at 2013-08-16 13:12:47 -0400
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "user"=>{"first_name"=>"John", "last_name"=>"Peters", "email"=>"user@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.4ms) BEGIN
User Exists (0.4ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'user@example.com' LIMIT 1
SQL (1.5ms) INSERT INTO `users` (<values>) VALUES (NULL, NULL, NULL, NULL, 'USA', '2013-08-16 17:12:47', NULL, NULL, 'user@example.com', '$2a$10$E4/LZAvbf7HvFobBjFQxjOnHuO8cnBNJzMPQ3MMT9oVnou98DGqty', 'John', 1, '--- []\n', NULL, 'Peters', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, '2013-08-16 17:12:47', NULL)
(30.4ms) COMMIT
(0.1ms) BEGIN
(0.5ms) UPDATE `users` SET `last_sign_in_at` = '2013-08-16 17:12:47', `current_sign_in_at` = '2013-08-16 17:12:47', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2013-08-16 17:12:47', `interest_areas` = '--- []\n' WHERE `users`.`id` = 1
(0.5ms) COMMIT
Redirected to http://www.example.com/
Completed 302 Found in 210ms (ActiveRecord: 0.0ms)
Started GET "/" for 127.0.0.1 at 2013-08-16 13:12:47 -0400
但是,运行后bundle update
,测试现在失败并出现错误:
Failure/Error: expect { click_button submit }.to change(User, :count).by(1)
count should have been changed by 1, but was changed by 0
和test.log
输出:
Started GET "/users/sign_up" for 127.0.0.1 at 2013-08-16 13:09:19 -0400
Processing by RegistrationsController#new as HTML
Rendered users/shared/_service.html.haml (2.0ms)
Rendered users/registrations/_newfields.haml (183.5ms)
Rendered users/shared/_links.haml (5.8ms)
Rendered users/registrations/new.html.haml within layouts/application (220.0ms)
Rendered shared/_header.haml (10.2ms)
Rendered shared/_footer.haml (10.7ms)
Completed 200 OK in 623ms (Views: 522.2ms | ActiveRecord: 57.1ms)
(17.3ms) SELECT COUNT(*) FROM `users`
Started POST "/users" for 127.0.0.1 at 2013-08-16 13:09:20 -0400
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "user"=>{"first_name"=>"John", "last_name"=>"Peters", "email"=>"user@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.2ms) BEGIN
(0.1ms) ROLLBACK
Redirected to http://www.example.com/users/sign_up
Completed 302 Found in 11ms (ActiveRecord: 0.3ms)
Started GET "/users/sign_up" for 127.0.0.1 at 2013-08-16 13:09:20 -0400
分歧发生在BEGIN
数据库查询的行之后;新版本会ROLLBACK
立即执行。
只有宝石在通过案例和失败案例之间发生了变化。两个提交之间的差异(主要是Gemfile.lock
文件之间的差异)可以在这里找到:http: //pastie.org/private/d4a49zoegu0j3faigfjfw
有谁知道更新这些宝石是否会导致此错误?
编辑 - 这是注册控制器的 #create 代码:
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
## logic of path
redirect_to new_user_registration_path, alert: resource.errors.full_messages.join('<br />')
end
end