Skip to content

Commit

Permalink
Continued work on roles features.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam committed Mar 7, 2016
1 parent 7e3bb6f commit c172b45
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.2.0
ruby-2.2.1
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ KNOWN ISSUES:
- Move code for form fields into helpers (so parsely validators don't need to be repeated)
- Alphabetize roles list in user profile/index
- Change error message for when password confirmation doesn't match password
- Localize error messages
- Localize error messages (forms.js.erb)
- Make custom user_path (my_profile_path if current_user, otherwise user_path(@user)). Remove logic that does this in users controller and views.
- Change vendor assets to CDN
- Remember Me? Checkbox test (sign_in.feature)

POSSIBLE FUTURE FEATURES:
- Add name of user updated/deleted to confirmation message
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class Role < ActiveRecord::Base

# String of User emails (seperated by commas)
def print_users
users.map(&:email).join(', ')
users.map(&:email).sort.join(', ')
end
end
6 changes: 3 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ en:
other_title: "Edit User %{user_id}"
errors:
password:
min_length: 'Must be at least 6 characters.'
min_length: 'Must be at least 6 characters'
password_confirmation:
match_password: 'Must match password.'
match_password: 'Must match password'
roles:
required: 'At least one role must be selected.'
required: 'At least one role must be selected'
fields:
current_password: 'Current'
email: 'Email'
Expand Down
32 changes: 27 additions & 5 deletions features/roles/roles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Feature: Roles
Given I have signed in as "admin1@admin.com"
When I navigate to the "new role" page
And I fill out the "new role" form with the following values:
| field | value |
| Name | test |
| field | value |
| Name | test |
And I click on the "Submit" button
Then I should be redirected to the "test" role page
And I should see "test" in the "Name" row
Expand All @@ -25,6 +25,20 @@ Feature: Roles
And I should see an alert message saying "Successfully updated user."
And I should see "test" in the "Role" row

Scenario Outline: An admin tries to create an invalid role
Given I have signed in as "admin1@admin.com"
When I navigate to the "new role" page
And I fill out the "new role" form with the following values:
| field | value |
| Name | Admin |
And I click on the "Submit" button
Then I should see an error message saying "" near the "Name" field

Examples:
| name | message |
| Admin | Role name is already in use. |
| | Can't be blank. |

Scenario: A visitor tries to access the roles index
Given I have not signed in
Then I should not be able to navigate to the "roles" page
Expand All @@ -33,7 +47,15 @@ Feature: Roles
Given I have signed in as "user1@user.com"
Then I should not be able to navigate to the "roles" page

Scenario: An admin views the roles index
Scenario Outline: An admin views a role in the role index
Given I have signed in as "admin1@admin.com"
When I naviagate to the "roles" page
Then I should see some stuff
When I navigate to the "roles" page
Then I should see a row for "<role>" in the "roles" table
And I should see "<users>" in the "<role>" row
And I should not see "<missing>" in the "<role>" row
And I should see the following actions in the "<role>" row: "Show, Update, Delete"

Examples:
| role | users | missing |
| Admin | admin1@admin.com, admin2@admin.com | user1@user.com, user2@user.com |
| User | user1@user.com, user2@user.com | admin1@admin.com, admin2@admin.com |
6 changes: 3 additions & 3 deletions features/step_definitions/general/verification_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
end

Then(/^I should( not)? see "(.*?)" in the "(.*?)" row$/) do |negate, value, row|
cell = page.find(:css, 'td', text: row).find(:xpath, '..').find(:css, 'td', text: value)
expect(cell).send(negate ? :to : :to_not, be_nil)
table = page.find(:css, 'td', text: row).find(:xpath, '..')
expect(table).send(negate ? :to_not : :to, have_selector('td', text: value))
end

Then(/^I should see( not)? a row for "(.*?)" in the "(.*?)" table$/) do |negate, row, table|
Expand All @@ -71,7 +71,7 @@
end

Then(/^I should( not)? see the following actions in the "(.*?)" row: "(.*?)"$/) do |negate, row_text, actions|
row = page.find(:css, 'tr', text: row_text)
row = page.all(:css, 'tr', text: row_text).last
actions.split(/, | and /).each do |action|
expect(row).send(negate ? :to_not : :to, have_selector(:link_or_button, action))
end
Expand Down
26 changes: 13 additions & 13 deletions features/unauthenticated/forgot_your_password.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Feature: Forgot Your Password
And an email with a password change link should be sent to "user1@user.com"
When I click on the link in the email
And I fill out the "Change Your Password" form with the following values:
| field | value |
| Password | asdqwe |
| Confirm | asdqwe |
| field | value |
| Password | asdqwe |
| Confirm | asdqwe |
And I click on the "Submit" button
Then I should be automatically signed in
And I should see an alert message saying "Your password was changed successfully. You are now signed in."
Expand All @@ -26,9 +26,9 @@ Feature: Forgot Your Password
Then I should see an error message saying "<message>" near the "Email" field

Examples:
| email | message |
| idontexist@user.com | Could not find a user with that email address |
| bad-email | This value should be a valid email |
| email | message |
| idontexist@user.com | Could not find a user with that email address. |
| bad-email | This value should be a valid email. |

Scenario Outline: A visitor tries to changes their password to an invalid password
When I navigate to the "forgot your password" page
Expand All @@ -46,11 +46,11 @@ Feature: Forgot Your Password
Then I should see an error message saying "<message>" near the "<field>" field

Examples:
| password | confirm | field | message |
| asdqw | asdqw | Password | Must be at least 6 characters |
| | | Password | Can't be blank |
| asdqwe | asdqwee | Confirm | Must match password |
| | | Confirm | Can't be blank |
| password | confirm | field | message |
| asdqw | asdqw | Password | Must be at least 6 characters. |
| | | Password | Can't be blank. |
| asdqwe | asdqwee | Confirm | Must match password. |
| | | Confirm | Can't be blank. |

Scenario Outline: A visitor clicks a link on the Forgot Your Password page
Given I have not signed in
Expand All @@ -59,7 +59,7 @@ Feature: Forgot Your Password
Then I should see the "<page>" page

Examples:
| action | page |
| action | page |
| Sign In | Sign In |
| Sign Up | Sign Up |

Expand All @@ -71,4 +71,4 @@ Feature: Forgot Your Password
Examples:
| user |
| admin1@admin.com |
| user1@user.com |
| user1@user.com |
10 changes: 5 additions & 5 deletions features/unauthenticated/sign_in.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Feature: Sign In
Then I should see an error message saying "<message>"

Examples:
| field | value | message |
| Email | wrong@user.com | Could not find a user with that email address |
| Password | wrong | Incorrect password |
| field | value | message |
| Email | wrong@user.com | Could not find a user with that email address. |
| Password | wrong | Incorrect password. |

# Scenario: A visitor checks the Remember Me checkbox on the Sign In form
# Given I have not signed in
Expand All @@ -42,7 +42,7 @@ Feature: Sign In
Then I should see the "<page>" page

Examples:
| action | page |
| action | page |
| Sign Up | Sign Up |
| Forgot your password? | Forgot Your Password |

Expand All @@ -54,4 +54,4 @@ Feature: Sign In
Examples:
| user |
| admin1@admin.com |
| user1@user.com |
| user1@user.com |
20 changes: 10 additions & 10 deletions features/unauthenticated/sign_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ Feature: Sign Up
| Email | user1@user.com |
| Password | asdqwe |
| Confirm | asdqwe |
| <field> | <value> |
| <field> | <value> |
And I click on the "Sign Up" button
Then I should see an error message saying "<message>" near the "<field>" field

Examples:
| field | value | message |
| Email | invalidemail | This value should be a valid email |
| Email | user1@user.com | Email has already been taken |
| Email | | Can't be blank |
| Password | asdqw | Must be at least 6 characters |
| Password | | Can't be blank |
| Confirm | asdqwee | Must match password |
| Confirm | | Can't be blank |
| field | value | message |
| Email | invalidemail | This value should be a valid email. |
| Email | user1@user.com | Email has already been taken. |
| Email | | Can't be blank. |
| Password | asdqw | Must be at least 6 characters. |
| Password | | Can't be blank. |
| Confirm | asdqwee | Must match password. |
| Confirm | | Can't be blank. |

Scenario: Visitor clicks the Sign In link on the Sign Up page
Scenario: Visitor clicks the sign in link on the sign up page
Given I have not signed in
And I have navigated to the "Sign Up" page
When I click on the "Sign In" link
Expand Down
40 changes: 20 additions & 20 deletions features/users/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Edit User
And I enter "updated@updated.com" in the "Email" field
And I click on the "Submit" button
Then I should see an alert message saying "Successfully updated user."
And I should be able to sign in as "updated@updated.com"
And I should be able to sign in as "updated@updated.com"
And I should not be able to sign in as "<user>"

Examples:
Expand All @@ -33,11 +33,11 @@ Feature: Edit User
Then I should see an error message saying "<message>" near the "Email" field

Examples:
| user | email | message |
| user1@user.com | user1 | This value should be a valid email. |
| user1@user.com | user2@user.com | Email has already been taken. |
| admin1@admin.com | user1 | This value should be a valid email. |
| admin1@admin.com | user2@user.com | Email has already been taken. |
| user | email | message |
| user1@user.com | user1 | This value should be a valid email. |
| user1@user.com | user2@user.com | Email has already been taken. |
| admin1@admin.com | user1 | This value should be a valid email. |
| admin1@admin.com | user2@user.com | Email has already been taken. |

Scenario Outline: An admin tries to change somebody else's email
Given I have signed in as "admin1@admin.com"
Expand Down Expand Up @@ -77,19 +77,19 @@ Feature: Edit User
Then I should see an error message saying "<message>" near the "<field>" field

Examples:
| user | current | new | confirm | field | message |
| user1@user.com | asdqw | asdqwe | asdqwe | Current | Incorrect current password |
| user1@user.com | | asdqwe | asdqwe | Current | Can't be blank |
| user1@user.com | asdqwe | asdqw | asdqwe | New | Must be at least 6 characters |
| user1@user.com | asdqwe | | | New | Can't be blank |
| user1@user.com | asdqwe | asdqwe | asdqwee | Confirm | Must match password |
| user1@user.com | asdqwe | | | Confirm | Can't be blank |
| admin1@admin.com | asdqw | asdqwe | asdqwe | Current | Incorrect current password |
| admin1@admin.com | | asdqwe | asdqwe | Current | Can't be blank |
| admin1@admin.com | asdqwe | asdqw | asdqwe | New | Must be at least 6 characters |
| admin1@admin.com | asdqwe | | | New | Can't be blank |
| admin1@admin.com | asdqwe | asdqwe | asdqwee | Confirm | Must match password |
| admin1@admin.com | asdqwe | | | Confirm | Can't be blank |
| user | current | new | confirm | field | message |
| user1@user.com | asdqw | asdqwe | asdqwe | Current | Incorrect current password. |
| user1@user.com | | asdqwe | asdqwe | Current | Can't be blank. |
| user1@user.com | asdqwe | asdqw | asdqwe | New | Must be at least 6 characters. |
| user1@user.com | asdqwe | | | New | Can't be blank. |
| user1@user.com | asdqwe | asdqwe | asdqwee | Confirm | Must match password. |
| user1@user.com | asdqwe | | | Confirm | Can't be blank. |
| admin1@admin.com | asdqw | asdqwe | asdqwe | Current | Incorrect current password. |
| admin1@admin.com | | asdqwe | asdqwe | Current | Can't be blank. |
| admin1@admin.com | asdqwe | asdqw | asdqwe | New | Must be at least 6 characters. |
| admin1@admin.com | asdqwe | | | New | Can't be blank. |
| admin1@admin.com | asdqwe | asdqwe | asdqwee | Confirm | Must match password. |
| admin1@admin.com | asdqwe | | | Confirm | Can't be blank. |

Scenario Outline: An admin tries to change somebody else's password
Given I have signed in as "admin1@admin.com"
Expand Down Expand Up @@ -122,4 +122,4 @@ Feature: Edit User
| admin1@admin.com | User |
| admin1@admin.com | Admin, User |
| admin2@admin.com | User |
| admin2@admin.com | Admin, User |
| admin2@admin.com | Admin, User |
32 changes: 16 additions & 16 deletions features/users/new.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ Feature: New User
Given I have signed in as "admin1@admin.com"
And I have navigated to the "new user" page
When I fill out the "new user" form with the following values:
| field | value |
| Email | test@test.com |
| Password | asdqwe |
| Confirm | asdqwe |
| field | value |
| Email | test@test.com |
| Password | asdqwe |
| Confirm | asdqwe |
And I click on the "Submit" button
Then I should be able to sign in as "test@test.com"

Scenario Outline: An admin tries to create a new user with an invalid attribute
Given I have signed in as "admin1@admin.com"
And I have navigated to the "new user" page
When I fill out the "new user" form with the following values:
| field | value |
| Email | test@test.com |
| Password | asdqwe |
| Confirm | asdqwe |
| field | value |
| Email | test@test.com |
| Password | asdqwe |
| Confirm | asdqwe |
And I enter "<value>" in the "<field>" field
And I click on the "Submit" button
Then I should see an error message saying "<message>" near the "<field>" field

Examples:
| field | value | message |
| Email | invalidemail | This value should be a valid email |
| Email | user1@user.com | Email has already been taken |
| Email | | Can't be blank |
| Password | asdqw | Must be at least 6 characters |
| Password | | Can't be blank |
| Confirm | asdqwee | Must match password |
| Confirm | | Can't be blank |
| field | value | message |
| Email | invalidemail | This value should be a valid email. |
| Email | user1@user.com | Email has already been taken. |
| Email | | Can't be blank. |
| Password | asdqw | Must be at least 6 characters. |
| Password | | Can't be blank. |
| Confirm | asdqwee | Must match password. |
| Confirm | | Can't be blank. |

0 comments on commit c172b45

Please sign in to comment.