I am using Devise in my application and trying to write a specification to update the email id. The user interface works, but the specification does not work. I also reload the user object before testing for the changed email id.
One thing that I am observing is that the UPDATE USERS statement is executed in the database.
What is the correct way to write a specification?
RSpec Specification:
it "should update email" do @user = subject.current_user patch :update, id: @user, user: {:email => " john.doe@example1.com "} @user.reload expect(@user.email).to eq(" john.doe@example1.com ") end
RSpec error log:
1) Users::RegistrationsController logged in user should update email Failure/Error: expect(@user.email).to eq(" john.doe@example1.com ") expected: " john.doe@example1.com " got: " john.doe@example.com " (compared using ==)
test.log:
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations" (0.2ms) BEGIN (0.4ms) SAVEPOINT active_record_1 User Exists (0.9ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ' john.doe@example.com ' LIMIT 1 SQL (4.1ms) INSERT INTO "users" ("created_at", "email", "encrypted_password", "first_name", "last_name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["created_at", Sat, 22 Jun 2013 13:12:28 UTC +00:00], ["email", " john.doe@example.com "], ["encrypted_password", "$2a$04$LIRWzphxstpCLTuZjicA..YMW.Ei2V/LlYWP32gfx39nBjhFg5tLe"], ["first_name", "John"], ["last_name", "Doe"], ["updated_at", Sat, 22 Jun 2013 13:12:28 UTC +00:00]] (0.1ms) RELEASE SAVEPOINT active_record_1 User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 457 ORDER BY "users"."id" ASC LIMIT 1 Processing by Users::RegistrationsController