Created
February 29, 2012 03:31
-
-
Save andrewhl/1937370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% provide :title, "Edit user" %> | |
<h2>Edit user</h2> | |
<%= form_for(@user) do |f| %> | |
<%= render 'shared/error_messages' %> | |
<div class="field"> | |
<%= f.label :first_name %><br /> | |
<%= f.text_field :first_name %> | |
</div> | |
<div class="field"> | |
<%= f.label :last_name %><br /> | |
<%= f.text_field :last_name %> | |
</div> | |
<div class="field"> | |
<%= f.label :email %><br /> | |
<%= f.text_field :email %> | |
</div> | |
<div class="field"> | |
<%= f.label :password %><br /> | |
<%= f.password_field :password %> | |
</div> | |
<div class="field"> | |
<%= f.label :password_confirmation, "Confirmation" %><br /> | |
<%= f.password_field :password_confirmation %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Update" %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) User pages edit with invalid information | |
Failure/Error: before { click_button "Update" } | |
ActionView::MissingTemplate: | |
Missing template users/update, application/update with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: | |
* "/Users/andrew/Sites/www.leobaeck.ca/SignupSystem/app/views" | |
# (eval):2:in `click_button' | |
# ./spec/requests/user_pages_spec.rb:83:in `block (4 levels) in <top (required)>' | |
Finished in 1.76 seconds | |
14 examples, 1 failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "User pages" do | |
subject { page } | |
shared_examples_for "all user pages" do | |
it { should have_selector('h2', text: heading) } | |
it { should have_selector('title', text: page_title) } | |
end | |
describe "signup page" do | |
before { visit signup_path } | |
let(:heading) { 'Sign up' } | |
let(:page_title) { 'Sign up' } | |
it_should_behave_like "all user pages" | |
end | |
describe "profile page" do | |
let(:user) { FactoryGirl.create(:user) } | |
before { visit user_path(user) } | |
it { should have_selector('h2', text: user.first_name) } | |
it { should have_selector('title', text: user.first_name) } | |
end | |
describe "signup" do | |
before { visit signup_path } | |
describe "with invalid information" do | |
it "should not create a user" do | |
expect { click_button "Sign up" }.not_to change(User, :count) | |
end | |
end | |
describe "with valid information" do | |
before do | |
fill_in "First name", with: "Example" | |
fill_in "Last name", with: "User" | |
fill_in "Email", with: "sample@example.com" | |
fill_in "Password", with: "foobar" | |
fill_in "Confirmation", with: "foobar" | |
end | |
describe "after saving the user" do | |
before { click_button "Sign up" } | |
let(:user) { User.find_by_email('sample@example.com') } | |
it { should have_selector('title', text: user.first_name) } | |
it { should have_selector('div.flash.success', text: 'Welcome') } | |
it { should have_link('Sign out') } | |
end | |
it "should create a user" do | |
expect { click_button "Sign up" }.to change(User, :count) | |
end | |
end | |
describe "error messages" do | |
before { click_button "Sign up" } | |
let(:error) { 'errors prohibited this user from being saved' } | |
it { should have_selector('title', text: 'Sign up') } | |
it { should have_content(error) } | |
end | |
end | |
describe "edit" do | |
let(:user) { FactoryGirl.create(:user) } | |
before { visit edit_user_path(user) } | |
describe "page" do | |
it { should have_selector('h2', text: "Edit user") } | |
it { should have_selector('title', text: "Edit user") } | |
end | |
describe "with invalid information" do | |
let(:error) { '1 error prohibited this user from being saved' } | |
before { click_button "Update" } | |
it { should have_content(error) } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def index | |
end | |
def update | |
end | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
sign_in @user | |
flash[:success] = "Welcome to the Sample App!" | |
redirect_to @user | |
else | |
render 'new' | |
end | |
end | |
def show | |
@user = User.find(params[:id]) | |
end | |
def edit | |
@user = User.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment