Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class User
:message => "Make your username from letters, numbers, underscores('_'), and dots('.')."
validates_length_of :username, :in => (1..32),
:message => "Your username needs at least 1 character but no more than 32."
validates_uniqueness_of :username,
:message => "User name has been taken already. Please try another"

def to_param
self.username
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Components used by the form builder to generate a complete input. You can remove
# any of them, change the order, or even add your own components to the stack.
# config.components = [ :placeholder, :label_input, :hint, :error ]
config.components = [ :placeholder, :label_input, :hint ]
config.components = [ :placeholder, :label_input, :hint, :error ]

# Default tag used on hints.
# config.hint_tag = :span
Expand Down
6 changes: 5 additions & 1 deletion features/signup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ Feature: Sign up for an account

Scenario: Create an account via the signup form
When I register a new account
Then I should be logged in with my new account
Then I should be logged in with my new account

Scenario: Try to sign up using existing user name
When I register a duplicate account
Then I should see validation errors
34 changes: 24 additions & 10 deletions features/step_definitions/signup_steps.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
When /^I register a new account$/ do
@user_info = {:username => "username", :password => "password", :email => "test@example.com"}

def register_user(user)
visit new_user_registration_path

fill_in("Username", :with => @user_info[:username])
fill_in("Email", :with => @user_info[:email])
fill_in("Password", :with => @user_info[:password])
fill_in("Password confirmation", :with => @user_info[:password])
fill_in("Username", :with => user[:username])
fill_in("Email", :with => user[:email])
fill_in("Password", :with => user[:password])
fill_in("Password confirmation", :with => user[:password])

click_button "Sign up"
end

When /^I register a new account$/ do
@new_user = {:username => "username", :password => "password", :email => "test@example.com"}
register_user @new_user
end

When /^I register a duplicate account$/ do
@existing_user = User.create!(username: "existing_user",
email: "existing_user@example.com",
password: "foobar",
password_confirmation: "foobar")
register_user @existing_user
end

When /^I should be logged in with my new account$/ do
page.should have_content("You have signed up successfully")
page.should have_content(@user_info[:username])
end
page.should have_content(@new_user[:username])
end

Then /^I should see validation errors$/ do
page.should have_selector(".error_notification")
end