require 'features/helper'

describe "User Account Spec" do
  describe "Creating an Account" do
    it "Persists the user in the database" do
      visit root_path
      click_link_or_button "create_account"
      within "#user_form" do
        fill_in ".user_name", with: "zee"
        fill_in ".email_address", with: "zee@example.com"
        fill_in ".password", with: "password"
        fill_in ".password_confirmation", with: "password"

        click_link_or_button ".create_user"
      end

      expect(page).to have_content("Account created for zee@examplecom")
      expect(User.exists?(email_address: "zee@example.com")).to be_truthy
      expect(current_path).to eq(root_path)
    end
  end
end

require 'features/helper'

describe "User Account Spec" do
  describe "Creating an Account" do
    it "Persists the user in the database" do
      visit root_path
      click_link_or_button "create_account"

      fill_in "user_email", with: "zee@example.com"
      fill_in "user_password", with: "password"
      fill_in "user_password_confirmation", with: "password"

      click_link_or_button "Sign up"

      expect(page).to have_content("Account created for zee@examplecom")
      expect(User.exists?(email_address: "zee@example.com")).to be_truthy
      expect(current_path).to eq(root_path)
    end
  end
end

Bring account creation test in line with devise defaults
Bring account creation test in line with devise defaults

Since I didn't remember what Devise does by default, I had to change my
test to match the form that it presents.

To get these I used my browsers debugger tools to find the `id`
attribute on each of the form fields.

While you *can* use the content of the label (I.e "Email"); this makes
your tests brittle. A designer or wordsmith may want to change the
content; if so, it's better not to have to change your tests. When you
introduce internationalization; you'll wind up needing to change quite a
few tests as well.

You'll notice I had to use the content for the "Sign up" button. This is
because devise doesn't provide an id for the form submit button! Ah
well.
