pxlmngr (1) [Avatar] Offline
#1
Can someone else confirm this?

When running the first feature (signing_in) under email-spec, it took me a long time to figure out email-spec was erring on having no email to process because no email was actually being sent. It seems as if in the book, it lists :confirmable as a default feature for Devise, but it wasn't the case in my install.

Once I rake db:rollback'd and edited the migration, migrated, and edited user model to also reflect the change - the test passed as intended.
ryanbigg (423) [Avatar] Offline
#2
Re: Chapter 6, Devise :confirmable
Hey pxlmngr,

I can confirm this. It looks like Devise has switched this from being an on-by-default module to an off-by-default module between versions.

I'm just writing a section for this change now which involves making the changes that you did (the user model and the migration) and it'll be available in the next MEAP.

Thanks for bringing this up!
oldroy (43) [Avatar] Offline
#3
Re: Chapter 6, Devise :confirmable
Yes - same thing for me.

1. rake db:rollback - this rolls back the last migration which is the initial user table migration

2. edit the migration 2010...._devise_create_users in db/migrations/
uncomment the t.confirmable line.

3. rerun rake db:migrate

Worked for me after that.
oldroy (43) [Avatar] Offline
#4
Re: Chapter 6, Devise :confirmable
doh...and rerun rake db:test:prepare also........
thoth (3) [Avatar] Offline
#5
Re: Chapter 6, Devise :confirmable
I've done the rollback, ensured t.confirmable was uncommented, re-migrated test and prod, re-ran the test, and got:

[ 11:02 PM (9smilie aleph:thoth ~/Source/ticketee ] > bundle exec cucumber features/signing_in.feature
Using the default profile...
............F

(:smilie failed steps (:smilie

expected #has_content?("Signed in successfully.") to return true, got false (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:111
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:109:in `/^(?smilieI )should see "([^"]*)"(?: within "([^"]*)")?$/'
features/signing_in.feature:24:in `Then I should see "Signed in successfully."'

Failing Scenarios:
cucumber features/signing_in.feature:17 # Scenario: Signing in via form

2 scenarios (1 failed, 1 passed)
12 steps (1 failed, 11 passed)
0m0.384s

Showing the page indicates that I can't sign in until I've confirmed. So apparently the test doesn't think I've confirmed.

The test is, to the best of my knowledge, identical to the book:

Feature: Signing in
In order to use the site
As a user
I want to be able to sign in

Background:
Given there are the following users:
| email | password | unconfirmed |
| user@ticketee.com | password | true |

Scenario: Signing in via confirmation
And "user@ticketee.com" opens the email with subject "Confirmation instructions"
And they click the first link in the email
Then I should see "Your account was successfully confirmed"
Then I should see "Signed in as user@ticketee.com"

Scenario: Signing in via form
And I am on the homepage
When I follow "Sign in"
And I fill in "Email" with "user@ticketee.com"
And I fill in "Password" with "password"
And I press "Sign in"
# Then show me the page
Then I should see "Signed in successfully."

I believe it is Devise, not I, that is supposed to generate the "Signed in successfully" message as a flash notice, but... Anyone else seeing the same thing? This test simply doesn't work for me.

OS X 10.6.5
Rails 3.0.3
Cucumber 0.10.0
Devise 1.1.3

Thanks,
steven
ryanbigg (423) [Avatar] Offline
#6
Re: Chapter 6, Devise :confirmable
Hey Steven, could you please put your version of this project on GitHub? That will allow me to take a closer look at what's not working correctly and figure it. I can't figure it out off the top of my head right now.

Thanks!
metaele (17) [Avatar] Offline
#7
Re: Chapter 6, Devise :confirmable
Same thing here.
metaele (17) [Avatar] Offline
#8
Re: Chapter 6, Devise :confirmable
Steve, though I'm still a rails n00b I think you are right that the second scenario requires a confirmation. To ascertain this you could simply replace the message for the last step;

"Signed in successfully."

with

"You have to confirm your account before continuing."

and you'll see the last step passing.

I think the problem is because each scenario is independent from each other but in this case the first scenario is the only one that makes the confirmation which does not persist till the second scenario. A probable solution may be to have a shared email confirmation (i.e in the Backgroundsmilie with some "signout" step that allows subsequent scenarios to "sign in" for themselves.

But like I said i''m a newbie and there is a strong possibility that i'm barking at the wrong tree.

Thanks.
metaele (17) [Avatar] Offline
#9
Re: Chapter 6, Devise :confirmable
This is what I roughly meant. The modified feature below passes. (Note some original parts are commented out)

Feature: Signing in
In order to use the site
As a user
I want to be able to sign in

Background:
Given there are the following users:
| email | password | unconfirmed |
| user@ticketee.com | password | true |

#Scenario: Signing in via confirmation
And "user@ticketee.com" opens the email with subject "Confirmation instructions"
And they click the first link in the email
Then I should see "Your account was successfully confirmed"
Then I should see "Signed in as user@ticketee.com"
Then I follow "Sign out"

Scenario: Signing in via form
#And I am on the homepage
When I follow "Sign in"
And I fill in "Email" with "user@ticketee.com"
And I fill in "Password" with "password"
And I press "Sign in"
#Then I should see "You have to confirm your account before continuing."
Then I should see "Signed in successfully."

I had to add to

<%= link_to "Sign out", destroy_user_session_path %>

under

Signed in as <%= current_user.email %>

in the application.html.erb to make it pass. The commented out scenario (first) make its former steps now part of the background.

But Ryan has the last word.
HTH

Thanks.
thoth (3) [Avatar] Offline
#10
Re: Chapter 6, Devise :confirmable
Hi metaele, thanks for the suggestions. Following them, everything works for me. (I actually moved on in the book, and extracted a lot of the Cucumber code to the "I am signed in as them" user step, see section 6.5.5, but it still works.)

Summary: When the scenario Signing in via confirmation is commented out (and therefore part of the background), all the tests pass. When it is not commented out, thereby being a separate scenario, it fails _when running the signing_in feature_. Note the "I am signed in as them" step in user_steps.rb (which essentially duplicates all the content from the "Signing in via form" feature) works fine from the deleting_tickets feature, but fails, if the first scenario is not commented out, in the signing_in feature. Why this would be is curious to me.

Ryan, do you still want me to post my project to github?
Thanks,
steven
ryanbigg (423) [Avatar] Offline
#11
Re: Chapter 6, Devise :confirmable
yes, please post the project to github so I can take a look to see what you've got.
metaele (17) [Avatar] Offline
#12
Re: Chapter 6, Devise :confirmable
Steven, you are welcome if my suggestions proved to be of value to you. We'll await Ryan's take though.

Thanks
ryanbigg (423) [Avatar] Offline
#13
Re: Chapter 6, Devise :confirmable
Is anybody able to post this project to GitHub so I can see the error for myself?
eamiller (6) [Avatar] Offline
#14
Re: Chapter 6, Devise :confirmable
I came across this issue as well. Since each scenario is separate I modified the second scenario to include the confirm message, and added a third scenario which used a second user I setup, which specified unconfirmed as false. This failed initially because of the code in user_steps.rb. The unconfirmed variable is set from the table, but it's a string, not a boolean, so I modified the last line (the confirm! line) to check for the string 'false' rather than a boolean. I tried leaving the field blank too, but it seems to pass a "" which also isn't false. I've copied the snippets I mentioned below, and if you want to see the git repo it's at https://github.com/badelat/Ticketee.

signing_in.feature:

Background:
Given there are the following users:
| email | password | unconfirmed |
| user@ticketee.com | password | true |
| user2@ticketee.com| password | false |
...(skip scenario 1)...
Scenario: Signing in via form to an unconfirmed account
And I am on the homepage
When I follow "Sign in"
And I fill in "Email" with "user@ticketee.com"
And I fill in "Password" with "password"
And I press "Sign in"
Then I should see "You have to confirm your account before continuing."

Scenario: Signing in via form to a confirmed account
And I am on the homepage
When I follow "Sign in"
And I fill in "Email" with "user2@ticketee.com"
And I fill in "Password" with "password"
And I press "Sign in"
Then I should see "Signed in successfully."


user_steps.rb:

unconfirmed = attributes.delete("unconfirmed")
@user = User.create!(attributes.merge!(:password_confirmation => attributes[:password]))
@user.confirm! if unconfirmed == 'false'
eamiller (6) [Avatar] Offline
#15
Re: Chapter 6, Devise :confirmable
Forgot to mention that in doing this I added two code smells:
1. I duplicated a bunch of code in the last scenario. I couldn't really put it in the background given the first scenario. Are there any other ways to avoid that?
2. I'm not thrilled with the check for false. I'd rather have a .to_boolean function or something that converts 'false' to a boolean. Not sure if that exists, or if I'd need to code it though.

If anyone knows a nice fix for either, I'd be glad of some direction.
protoiyer (14) [Avatar] Offline
#16
Re: Chapter 6, Devise :confirmable
@ryanbigg: I have posted it to github so that you can check the error message (if you haven't already): https://github.com/protoiyer/ticketee

The particular commits would be (thought I should mention 'which commit' since I would go on committing further stuff into the repository as I work through the rest of the book): https://github.com/protoiyer/ticketee/commit/3e7ae6fb986f58d6640d466bceeeb6a901af5610
and the one prior to that
https://github.com/protoiyer/ticketee/commit/67b5b88fc0c67d6361dfb6b815e292ea6ed6a6f4

Anyways, what I have checked in follows the advise provided elsewhere in this thread by @metaele.

***

The second scenario in the feature as provided in the current meap version (today is 23May11) fails since the user won't have been confirmed, and so you won't see "signed in successfully" but "you need to confirm first".

If you are taking my version, to see the error, kindly make the following 3 changes:

1. Uncomment line# 11:
# Scenario: Signing in via confirmation

2. Uncomment line# 19:
# And I am on the homepage

3. Delete line# 16:
Then I follow "Sign out"

This is the error I get if I follow the above instructions:

And I press "Sign in" # features/step_definitions/web_steps.rb:52
Then I should see "Signed in successfully." # features/step_definitions/web_steps.rb:105
expected there to be content "Signed in successfully." in "Ticketee

You have to confirm your account before continuing.

Ticketee
Sign up
Sign in
Sign in


Email

Password

Remember me




Sign upForgot your password?Didn't receive confirmation instructions?" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:107:in `/^(?smilieI )should see "([^"]*)"$/'
features/signing_in.feature:26:in `Then I should see "Signed in successfully."'

***

I think to avoid confusion to the readers, it would be great if this could be resolved in the next version.

Also, please note that the signing_in.feature code available over at the book's github page is different from what is available in the text (and uses "signed in as THEM (in small)" as the last line!): https://github.com/rails3book/ticketee/blob/master/features/signing_in.feature

Which is more correct? The book or the github? smilie

Message was edited by:
protoiyer