Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing users #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
/log/*
!/log/.keep
/tmp

# Ignore application configuration
/config/application.yml
11 changes: 9 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

ruby '2.2.0'
gem 'rails', '4.2.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
Expand All @@ -22,9 +22,10 @@ gem 'puma'
gem 'bootstrap-sass'
gem 'faker'
gem 'devise'
gem 'figaro'

group :development do
gem 'sqlite3'
gem 'sqlite3', '~> 1.3.10'
gem 'better_errors'
gem 'binding_of_caller'
end
Expand All @@ -37,3 +38,9 @@ group :development, :test do
gem 'spring'
end

group :production do
gem 'pg'
gem 'rails_12factor'

end

13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ GEM
railties (>= 3.0.0)
faker (1.4.3)
i18n (~> 0.5)
figaro (1.0.0)
thor (~> 0.14)
globalid (0.3.3)
activesupport (>= 4.1.0)
hike (1.2.3)
Expand All @@ -106,6 +108,7 @@ GEM
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
pg (0.18.1)
puma (2.11.1)
rack (>= 1.1, < 2.0)
rack (1.6.0)
Expand All @@ -130,6 +133,11 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.3)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
Expand Down Expand Up @@ -204,14 +212,17 @@ DEPENDENCIES
devise
factory_girl_rails (~> 4.0)
faker
figaro
jbuilder (~> 2.0)
jquery-rails
pg
puma
rails (= 4.2.0)
rails_12factor
rspec-rails (~> 3.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
sqlite3
sqlite3 (~> 1.3.10)
turbolinks
uglifier (>= 1.3.0)
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module ApplicationHelper
end
end
19 changes: 12 additions & 7 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>

<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, autofocus: true, class: 'form-control' %>
</div>

<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
<%= f.email_field :email, class: 'form-control' %>
</div>

<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
Expand All @@ -14,26 +19,26 @@

<div class="form-group">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>

<div class="form-group">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>

<div class="form-group">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
<%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %>
</div>

<div class="form-group">
<%= f.submit "Update" %>
<%= f.submit "Update" , class: 'btn btn-success'%>
</div>
<% end %>

<h3>Cancel my account</h3>

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger' %></p>

<%= link_to "Back", :back %>
<%= link_to "Back", :back, class: 'btn btn-primary' %>
1 change: 1 addition & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<%= f.label :name %>
<%= f.text_field :name, autofocus: true, class: 'form-control', placeholder: "Enter name" %>
</div>

<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, class: 'form-control', placeholder: "Enter email" %>
Expand Down
11 changes: 5 additions & 6 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@

<div class="pull-right user-info"
<% if current_user %>
Hello <%= link_to (current_user.name || current_user.email), current_user %>!
Hello <%= link_to (current_user.name || current_user.email) %>!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this link will only display the user's name or email but not actually link to anything. Was that intentional?

<%= link_to edit_user_registration_path, class: 'btn btn-primary btn-sm' do %>
<span class="glyphicon glyphicon-user"></span>
<% end %>
<%= link_to destroy_user_session_path, method: :delete, class: 'btn btn-primary btn-sm' do %>
<span class="glyphicon glyphicon-log-out"></span>
<% end %>
<% end %>
<%= link_to "Sign out", destroy_user_session_path, method: :delete, class: 'btn btn-primary btn-sm' %>

<% else %>
<%= link_to "Sign In", new_user_session_path %> or
<%= link_to "Sign In", new_user_session_path %> |
<%= link_to "Sign Up", new_user_registration_path %>
<% end %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/application.example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SENDGRID_PASSWORD:
SENDGRID_USERNAME:
3 changes: 3 additions & 0 deletions config/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SENDGRID_PASSWORD: zx0wd0ff

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want this file appearing in your source control. You may have added it before you changed your .gitignore file.

SENDGRID_USERNAME: [email protected]
SECRET_KEY_BASE: 314938c9e3d27bef9aeb1ad15e0276cac9beecac5afdb55e0f79b7c6f5693eb1f01b2c3dc3c78ea8d2828ae5869d49de1cde45900c7d1d1846c9b20e6432b3ff
4 changes: 3 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = true

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand All @@ -41,4 +41,6 @@
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

end

12 changes: 12 additions & 0 deletions config/initializers/setup_mail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if Rails.env.development?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
authentication: :plain,
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com',
enable_starttls_auto: true
}
end
56 changes: 56 additions & 0 deletions spec/features/edit_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'rails_helper'

describe "Edit user attributes" do

describe "change user password" do
before do
@user = create(:user)

#Sign in User
visit new_user_session_path

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Log in"
expect( current_path ).to eq(root_path)
visit edit_user_registration_path
end

it "is not updated without current password" do

fill_in "Password", with: 'newpassword'
fill_in "Password confirmation", with: 'newpassword'
fill_in "Current password", with: ''
click_button "Update"
expect( page ).to have_content("Current password can't be blank")
end

it "is not updated if 'password confirmation' does not mach password" do

fill_in "Password", with: 'newpassword'
fill_in "Password confirmation", with: 'password'
fill_in "Current password", with: @user.password
click_button "Update"
expect( page ).to have_content("Password confirmation doesn't match Password")
end

it "is not updated if password is shorter than 8 characters" do

fill_in "Password", with: 'word'
fill_in "Password confirmation", with: 'word'
fill_in "Current password", with: @user.password
click_button "Update"
expect( page ).to have_content("Password is too short")
end

it "updates password with all fields correctly entered" do
fill_in "Password", with: 'newpassword'
fill_in "Password confirmation", with: 'newpassword'
fill_in "Current password", with: @user.password
click_button "Update"
expect( current_path ).to eq(root_path) #I'd like to test expect( flash[:notice] ).to eq "User was updated successfully"
end

end
end

48 changes: 48 additions & 0 deletions spec/features/sign_in_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'rails_helper'

describe 'User sign-in' do

describe "successful sign-in" do
before do
@user = create(:user)
end

it "allows confirmed user to sign-in" do

visit new_user_session_path

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Log in"
expect( current_path ).to eq(root_path)
end
end

describe "navigation changes to reflect #current_user" do
before do
@user = create(:user)
end

it "shows #user.name when signed in" do

visit new_user_session_path

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Log in"
expect( page ).to have_content(@user.name)
end

it "shows link to 'sign-in' when no user is signed in" do

visit root_path

within '.user-info' do
expect( page ).to have_content("Sign In")
end
end
end
end



52 changes: 46 additions & 6 deletions spec/features/sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,59 @@
describe "successful sign-up" do
before do
@user = create(:user)
@user1 = create(:user)
end

it "allows user to sign-up" do
visit root_path
within '.user-info' do
click_link 'Sign Up'
end
it "sends confirmation email following successful sign-up" do

sign_up_nav

fill_in "Name", with: @user.name
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
fill_in "Password confirmation", with: @user.password_confirmation
click_button 'Sign up'
expect( @user.confirmed_at ).not_to be nil
end
end

describe "unsuccessful sign-up" do
before do
@user = create(:user)
end

it "prohibits user from signing up with duplicate email" do

sign_up_nav

fill_in "Name", with: @user.name
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
fill_in "Password confirmation", with: @user.password_confirmation
click_button 'Sign up'
expect(@user.confirmation_sent_at).to eq(Time.now)
expect( page ).to have_content('Email has already been taken')
end

it "prohibits user from signing up with invalid email" do

@user1 = create(:user)

sign_up_nav

fill_in "Name", with: @user1.name
fill_in "Email", with: 'chad@123'
fill_in "Password", with: @user1.password
fill_in "Password confirmation", with: @user1.password_confirmation
click_button 'Sign up'
expect( page ).to have_content('Email is invalid')
end
end
end

def sign_up_nav
visit root_path
within '.user-info' do
click_link 'Sign Up'
end
end

Expand Down