The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mikimiki (9) [Avatar] Offline
#1
I am running into problems with this section.

Here is the cucumber output.

Given there are the following users:
| email | password | admin |
| admin@ticketee.com | password | true |
And I am signed in as one of those users
And there are the following users:
| email | password |
| user@ticketee.com | password |
And I am on the home page
When I follow the "Admin" link
And I follow the "Users" link
And I follow the "user@ticketee.com" link
And I follow the "Edit User" link

Scenario: Updating a user's details
When I fill in the "Email" field with "new_user@ticketee.com"
{"email"=>"new_user@ticketee.com", "admin"=>"0"}
And I press the "Update User" button
Then I should see the "User has been successfully updated."
And I should see "new_user@ticketee.com"
expected there to be content "new_user@ticketee.com" in "Ticketee


User has been successfully updated.


Ticketee
Admin
Signed in as admin@ticketee.com
New User

admin@ticketee.com (Admin)
user@ticketee.com (User)
" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/projects_steps.rb:68:in `/^I should see "([^"]*)"$/'
features/editing_users.feature:24:in `And I should see "new_user@ticketee.com"'
And I should not see "user@ticketee.com"

Scenario: Toggling an user's Admin attribute
When I check the "Admin" checkbox
{"email"=>"user@ticketee.com", "admin"=>"1"}
And I press the "Update User" button
Then I should see the "User has been successfully updated."
And I should see "user@ticketee.com (Admin)"

Scenario: Updating an user with an invalid email should fail
When I fill in the "Email" field with "bad_email_field"
And I press the "Update User" button
Then I should see the "User has not been updated." message
And I should see the "Email is invalid" message

Failing Scenarios:
cucumber features/editing_users.feature:20 # Scenario: Updating a user's details

Clearly the update seems to be successful, and when I look at the test logs I see this:

Started PUT "/admin/users/2" for 127.0.0.1 at 2012-01-30 17:25:19 -0800
Processing by Admin::UsersController#update as HTML
Parameters: {"utf8"=>"✓", "user"=>{"email"=>"new_user@ticketee.com", "password"=>"[FILTERED]", "admin"=>"0"}, "commit"=>"Update User", "id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
 (0.1ms) SAVEPOINT active_record_1
WARNING: Can't mass-assign protected attributes: admin
 (0.1ms) SELECT 1 FROM "users" WHERE ("users"."email" = 'new_user@ticketee.com' AND "users"."id" != 2) LIMIT 1
 (0.3ms) UPDATE "users" SET "unconfirmed_email" = 'new_user@ticketee.com', "updated_at" = '2012-01-31 01:25:19.165473' WHERE "users"."id" = 2
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'myjjxkSN8DYmrc6D1bkF' LIMIT 1
 (0.1ms) UPDATE "users" SET "unconfirmed_email" = 'new_user@ticketee.com', "updated_at" = '2012-01-31 01:25:19.165473', "confirmation_token" = 'myjjxkSN8DYmrc6D1bkF', "confirmation_sent_at" = '2012-01-31 01:25:19.168097' WHERE "users"."id" = 2
Rendered /opt/c/ruby/local/lib/ruby/gems/1.9.1/gems/devise-2.0.0/app/views/devise/mailer/confirmation_instructions.html.erb (0.8ms)

Sent mail to new_user@ticketee.com (5ms)
Date: Mon, 30 Jan 2012 17:25:19 -0800
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: new_user@ticketee.com
Message-ID: <4f2742ff2c99d_34b4d91084549c2@miki-linux.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

Welcome user@ticketee.com!



You can confirm your account email through the link below:



Confirm my account


 (0.1ms) RELEASE SAVEPOINT active_record_1
Redirected to http://www.example.com/admin/users
Completed 302 Found in 29ms

My understanding is that updating the email generates a confirmation request from the user, which the test scenario fails to respond to, and hence the first cucumber feature fails. Any help how to do this right much appreciated.

Rails 3.1.3
Devise 2.0.0
Cucumber-Rails 1.2.1
ryanbigg (423) [Avatar] Offline
#2
Re: 7.7 Editing users
I suspect it may be Devise 2.0 that's doing this. Can you check to see if you can assign a user's email address manually in the console? Like this:

# You may have to create a user first
user = User.first
user.email
user.update_attributes(:email => "somethingelse@example.com"smilie
user.reload
user.email

That should return "somethingelse@example.com"
mikimiki (9) [Avatar] Offline
#3
Re: 7.7 Editing users
$ bundle exec rails console
Loading development environment (Rails 3.1.3)
irb(main):001:0> user = User.create!({email: "user@ticketee.com", password: "password", password_confirmation: "password"})
(0.3ms) SELECT 1 FROM "users" WHERE "users"."email" = 'user@ticketee.com' LIMIT 1
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '79zuyusGFwAWqDdPUd4P' LIMIT 1
Binary data inserted for `string` type on column `encrypted_password`
SQL (4.6ms) INSERT INTO "users" ("admin", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "unconfirmed_email", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["admin", false], ["confirmation_sent_at", Wed, 01 Feb 2012 00:51:44 UTC +00:00], ["confirmation_token", "79zuyusGFwAWqDdPUd4P"], ["confirmed_at", nil], ["created_at", Wed, 01 Feb 2012 00:51:44 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "user@ticketee.com"], ["encrypted_password", "$2a$10$Ob/o9afHy.w4mBacsk8houTG4akHABtBdUT/g5C3znN79yiRUpsZm"], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["unconfirmed_email", nil], ["updated_at", Wed, 01 Feb 2012 00:51:44 UTC +00:00]]
=> #<User id: 1, email: "user@ticketee.com", encrypted_password: "$2a$10$Ob/o9afHy.w4mBacsk8houTG4akHABtBdUT/g5C3znN7...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-02-01 00:51:44", updated_at: "2012-02-01 00:51:44", confirmation_token: "79zuyusGFwAWqDdPUd4P", confirmed_at: nil, confirmation_sent_at: "2012-02-01 00:51:44", unconfirmed_email: nil, admin: false>
irb(main):003:0> user.confirm!
(0.6ms) UPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2012-02-01 00:52:35.148196', "updated_at" = '2012-02-01 00:52:35.149849' WHERE "users"."id" = 1
=> true
irb(main):004:0> user.email
=> "user@ticketee.com"
irb(main):005:0> user.update_attributes({email: "new_user@ticketee.com"})
(0.5ms) SELECT 1 FROM "users" WHERE ("users"."email" = 'new_user@ticketee.com' AND "users"."id" != 1) LIMIT 1
(0.5ms) UPDATE "users" SET "unconfirmed_email" = 'new_user@ticketee.com', "updated_at" = '2012-02-01 00:53:50.858618' WHERE "users"."id" = 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '6wDrUHFR4xwsNTFsocyh' LIMIT 1
(0.4ms) UPDATE "users" SET "unconfirmed_email" = 'new_user@ticketee.com', "updated_at" = '2012-02-01 00:53:50.858618', "confirmation_token" = '6wDrUHFR4xwsNTFsocyh', "confirmation_sent_at" = '2012-02-01 00:53:50.863115' WHERE "users"."id" = 1
=> true
irb(main):006:0> user.reload
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
=> #<User id: 1, email: "user@ticketee.com", encrypted_password: "$2a$10$Ob/o9afHy.w4mBacsk8houTG4akHABtBdUT/g5C3znN7...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-02-01 00:51:44", updated_at: "2012-02-01 00:53:50", confirmation_token: "6wDrUHFR4xwsNTFsocyh", confirmed_at: "2012-02-01 00:52:35", confirmation_sent_at: "2012-02-01 00:53:50", unconfirmed_email: "new_user@ticketee.com", admin: false>
irb(main):007:0> user.email
=> "user@ticketee.com"
irb(main):008:0> user.confirm!
(0.3ms) SELECT 1 FROM "users" WHERE ("users"."email" = 'new_user@ticketee.com' AND "users"."id" != 1) LIMIT 1
(4.2ms) UPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2012-02-01 00:59:24.188537', "email" = 'new_user@ticketee.com', "unconfirmed_email" = NULL, "updated_at" = '2012-02-01 00:59:24.198047' WHERE "users"."id" = 1
=> true
irb(main):009:0> user.reload
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
=> #<User id: 1, email: "new_user@ticketee.com", encrypted_password: "$2a$10$Ob/o9afHy.w4mBacsk8houTG4akHABtBdUT/g5C3znN7...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-02-01 00:51:44", updated_at: "2012-02-01 00:59:24", confirmation_token: nil, confirmed_at: "2012-02-01 00:59:24", confirmation_sent_at: "2012-02-01 00:53:50", unconfirmed_email: nil, admin: false>
irb(main):010:0> user.email
=> "new_user@ticketee.com"
irb(main):011:0>
mikimiki (9) [Avatar] Offline
#4
Re: 7.7 Editing users
For Devise 2.0 an email update in the users model needs a confirmation, it seems.

Thank you for the feedback Ryan. By the way, your responses on this forum are nothing short of heroic! This is a great book and I am enjoying it very deeply. Thank you for this great book!