Hartl Tutorial Chapter 10: param micropost not found - ruby-on-rails

I am currently between Listing 10.32 and 10.33 of this tutorial: http://ruby.railstutorial.org/chapters/user-microposts#sec-manipulating_microposts
And I have ran into a problem while running the test. The output is as follows:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: expect { click_button "Post" }.not_to change(Micropost, :count)
ActionController::ParameterMissing:
param not found: micropost
# ./app/controllers/microposts_controller.rb:23:in `micropost_params'
# ./app/controllers/microposts_controller.rb:8:in `create'
# ./spec/requests/micropost_pages_spec.rb:16:in `block (5 levels) in <top (required)>'
# ./spec/requests/micropost_pages_spec.rb:16:in `block (4 levels) in <top (required)>'
2) Micropost pages micropost creation with invalid information error messages
Failure/Error: before { click_button "Post" }
ActionController::ParameterMissing:
param not found: micropost
# ./app/controllers/microposts_controller.rb:23:in `micropost_params'
# ./app/controllers/microposts_controller.rb:8:in `create'
# ./spec/requests/micropost_pages_spec.rb:20:in `block (5 levels) in <top (required)>'
3) Micropost pages micropost creation with valid information should create a micropost
Failure/Error: before { fill_in 'micropost_content', with: "Lorem ipsum" }
Capybara::ElementNotFound:
Unable to find field "micropost_content"
# ./spec/requests/micropost_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
Finished in 0.56491 seconds
3 examples, 3 failures
Failed examples:
rspec ./spec/requests/micropost_pages_spec.rb:15 # Micropost pages micropost creation with invalid information should not create a micropost
rspec ./spec/requests/micropost_pages_spec.rb:21 # Micropost pages micropost creation with invalid information error messages
rspec ./spec/requests/micropost_pages_spec.rb:28 # Micropost pages micropost creation with valid information should create a micropost
And here is the currently failing test:
require 'spec_helper'
describe "Micropost pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "micropost creation" do
before { visit root_path }
describe "with invalid information" do
it "should not create a micropost" do
expect { click_button "Post" }.not_to change(Micropost, :count)
end
describe "error messages" do
before { click_button "Post" }
it { should have_content('error') }
end
end
describe "with valid information" do
before { fill_in 'micropost_content', with: "Lorem ipsum" }
it "should create a micropost" do
expect { click_button "Post" }.to change(Micropost, :count).by(1)
end
end
end
end
Which means the #micropost variable is clearly not being set, but it is set in the static pages controller. I have checked for a while now do discover differences from the tutorial, but have not succeeded in finding any.
The git repository is here: https://github.com/afuhrtrumpet/sample_app/tree/user-microposts
Does anyone see this issue?

The issue was a missing '=' sign here:
<%= f.text_area :content, placeholder: "Compose new micropost..." %>

Related

Michael Hart's Ruby on Rails Tutorial - Chapter 8 Failing Tests

I am currently working on Chapter 8 of Michael Hartl's Ruby on Rails tutorial. I encountered a problem with my tests failing and tried to solve this myself, but I realize it's useless, so I have to ask here. Here is the error message I'm getting.
Failures:
1) Authentication signin with invalid information after visiting another page
Failure/Error: it { should_not have_selector('div.alert.alert-error') }
expected #has_selector?("div.alert.alert-error") to return false, got true
# ./spec/requests/authentication_pages_spec.rb:18:in `block (5 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbc9d5868>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfdf53a0>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfcf5ea0>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
5) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfc0ccc8>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
6) User pages signup with valid information should create a user
Failure/Error: fill_in "Confirmation", with: "foobar"
Capybara::ElementNotFound:
Unable to find field "Confirmation"
# ./spec/requests/user_pages_spec.rb:24:in `block (4 levels) in <top (required)>'
Finished in 0.60967 seconds
41 examples, 6 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:18 # Authentication signin with invalid information after visiting another page
rspec ./spec/requests/authentication_pages_spec.rb:30 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:32 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:31 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:33 # Authentication signin with valid information
rspec ./spec/requests/user_pages_spec.rb:27 # User pages signup with valid information should create a user
Randomized with seed 17229
Here is my authentication pages spec file
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
it { should have_selector('div.alert.alert-error') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
Here is my sessions_controller.rb file
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to user
else
# Create an error message and re-render the signin form
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
end
The main failure I'm trying to solve, that should be green is 1. I passed the flash.now hash to indicate that I want the flash to disappear after a second request, but rspec says no.
I'm stumped as to what the problem is. Any help would be greatly appreciated
RSpec tells you that method sign_in does not exists. If you look at the chapter 8.2.2 you will find a helper with this method.
#app/helpers/sessions_helper.rb
module SessionsHelper
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.digest(remember_token))
self.current_user = user
end
end

Failure/Error with Ruby on Rails Tutorial Chapter 9

Can anyone who has done this exercises help me out?
It's my first time using this programming language and not much to this, but I need to finish well until chapter 10 that is a final evaluation.
1) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc283f8c>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
2) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xb67b1cc>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
3) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc224244>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
4) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc562690>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
5) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc0559a4>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
6) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
7) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
8) User pages index should list each user
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
9) Authentication authorization after signing in should render the desired protected page
Failure/Error: expect(page).to have_title('Edit user')
expected #has_title?("Edit user") to return true, got false
# ./spec/requests/authentication_pages_spec.rb:84:in `block (4 levels) in <top (required)>'
Finished in 2.25 seconds
72 examples, 9 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:114 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:115 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:112 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:113 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:111 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:15 # User pages index
rspec ./spec/requests/user_pages_spec.rb:16 # User pages index
rspec ./spec/requests/user_pages_spec.rb:18 # User pages index should list each user
rspec ./spec/requests/authentication_pages_spec.rb:83 # Authentication authorization after signing in should render the desired protected page
Edit
Here is my code:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
before do
sign_in FactoryGirl.create(:user)
FactoryGirl.create(:user, name: "Bob", email: "bob#example.com")
FactoryGirl.create(:user, name: "Ben", email: "ben#example.com")
visit users_path
end
it { should have_title('All users') }
it { should have_content('All users') }
it "should list each user" do
User.all.each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_title('Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by(email: 'user#example.com') }
it { should have_link('Sign out') }
it { should have_title(user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new#example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_title(new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { expect(user.reload.name).to eq new_name }
specify { expect(user.reload.email).to eq new_email }
end
end
end
If your code is formatted like this:
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
I can see that it is probably broken without reading any of your code.
Are all your code blocks properly closed? Does not look so!
In addition to the unclosed blocks that phoet pointed out, which are causing your "undefined method describe" errors, you're getting errors in /app/views/users/index.html.erb line 5. The error is undefined method `each' for nil:NilClass which means there's a variable on that line that you're doing variable.each with, but you're either not setting that variable or when you're setting it, it's getting set to nil.
In general, the way for you to successfully get through this is to read the error messages and try to fix what they're complaining about. If you search for each error message individually, you'll find stack overflow questions about the specific issue that will help you.

NoMethodError: undefined method `email' for nil:NilClass (Rspec/factory girl/cancan/devise)

I am following Hartl's Rails tutorial but I used devise/cancan/rolify so some things are not the same.
On my users_pages_spec.rb test, I keep getting this error in spite of all I tried:
1) User pages index delete links as an admin user
Failure/Error: sign_in #superadmin
NoMethodError:
undefined method `email' for nil:NilClass
# ./spec/support/utilities.rb:14:in `sign_in'
# ./spec/requests/user_pages_spec.rb:91:in `block (5 levels) in <top (required)>'
2) User pages index delete links as an admin user
Failure/Error: sign_in #superadmin
NoMethodError:
undefined method `email' for nil:NilClass
# ./spec/support/utilities.rb:14:in `sign_in'
# ./spec/requests/user_pages_spec.rb:91:in `block (5 levels) in <top (required)>'
3) User pages index delete links as an admin user should be able to delete another user
Failure/Error: sign_in #superadmin
NoMethodError:
undefined method `email' for nil:NilClass
# ./spec/support/utilities.rb:14:in `sign_in'
# ./spec/requests/user_pages_spec.rb:91:in `block (5 levels) in <top (required)>'
4) User pages index delete links as an admin user
Failure/Error: sign_in #superadmin
NoMethodError:
undefined method `email' for nil:NilClass
# ./spec/support/utilities.rb:14:in `sign_in'
# ./spec/requests/user_pages_spec.rb:91:in `block (5 levels) in <top (required)>'
I don't understand why, does nil::nilClass mean factory girl actually does not manage to create this superadmin user?
Here is the sample of my user_pages_spec.rb file:
require 'spec_helper'
require 'cancan/matchers'
# Test if targeted words appears in displayed content
describe "User pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong#example.com") }
let(:non_admin) { FactoryGirl.create(:user) }
let(:submit) { "Sign in" }
describe "index" do
describe "delete links" do
it { should_not have_link('delete') }
describe "as an admin user" do
let(:superadmin) { FactoryGirl.create(:superadmin) }
before do
sign_in #superadmin
visit users_path
end
it { should have_title('List of users') }
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect { click_link('delete') }.to change(User, :count).by(-1)
end
it { should_not have_link('delete', href: user_path(superadmin)) }
end
end
end
end
my spec/utilities.rb defining sign_in method
include ApplicationHelper
def sign_in(user)
visit new_user_session_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Login"
#populate cookie when not using capybara
cookies[:authentication_token] = user.authentication_token
end
and my spec/factories/user.rb
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:email) { |n| "person_#{n}#example.com"}
password "beta"
password_confirmation "beta"
# required if the Devise Confirmable module is used
confirmed_at Time.now
confirmation_token nil
factory :superadmin do
after(:create) {|user| user.add_role(:superadmin)}
end
end
end
I do have in cancan/rolify a superadmin role defined.
If anybody has a clue, I'd take it! i can update the question with additional file needed if not already here.
Your let call is setting superadmin, but you're referencing #superadmin, which is going to be nil, since it hasn't been set. BTW, this is a good reason to generally avoid using instance variables in your tests, as they silently default to nil when referenced if uninitialized.

RoR. Chapter 8, Section 8.2.4 - Undefined method for Signin

I'm working on RoR tutorial, Chapter 8. I am trying to complete section 8.2.4 - Changing the layout links and ran $ bundle exec rspec spec/ and I got the following error:
Failures:
1) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b85fd0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b33eb0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef6698bba8>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef68286130>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
Finished in 1.34 seconds
44 examples, 4 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:39 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:40 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:38 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:41 # Authentication signin with valid information
Based on the output, I checked spec/requests/authentication_pages_spec.rb, but I can't seem to find the error. This is what I have:
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting antoher page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
I can't seem to find the error. Any suggestions on where I should look based on the error output? Thank you.
Check your config/routes.rb file to make sure that:
match '/signin', to: 'sessions#new'
matches what your session controllers is seeing. The create method for your "sessions_controller.rb" should have:
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
Just my guess. I'm currently around that area too in the tutorial. Best of luck and I hope that helps!
A bit late probably but anyways...
Check if you got "include SessionsHelper" in app/controllers/application_controller.rb
helpers are included into views by default but you have to explicitly include them in controllers

Ruby on Rails Tutorial - Getting Errors, pulling my hair out

Im following [Michael Hartl's tutorial][1] and did the exercises in Chapter 7, and now have 4 errors that I cant figure out how to fix for the life of me. When I test the production app manually, the errors dont exist at all. So I don't know if there is something wrong with my text development or something, but Im at a total loss so I thought I'd post here to see if my total noobness is blinding me...thanks for your help!
Here's the 4 error messages I'm getting:
Failures:
1) signup with invalid information after submission
Failure/Error: it { should have_selector('title', text: "Sign up") }
expected css "title" with text "Sign up" to return something
# ./spec/requests/user_pages_spec.rb:38:in `block (4 levels) in <top (required)>'
2) signup with invalid information after submission
Failure/Error: it { should have_content('error') }
expected there to be content "error" in "after submission"
# ./spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
3) signup after saving the user
Failure/Error: it { should have_selector('title', text: user.name) }
NoMethodError:
undefined method `name' for nil:NilClass
# ./spec/requests/user_pages_spec.rb:60:in `block (3 levels) in <top (required)>'
4) signup after saving the user
Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') }
expected css "div.alert.alert-success" with text "Welcome" to return something
# ./spec/requests/user_pages_spec.rb:61:in `block (3 levels) in <top (required)>'
Finished in 6.8 seconds
10 examples, 4 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:38 # signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:39 # signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:60 # signup after saving the user
rspec ./spec/requests/user_pages_spec.rb:61 # signup after saving the user
Here's the code on my user_pages_spec.rb:
require 'spec_helper'
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_selector('title', text: "Sign up") }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('user#example.com') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
end
[1]: http://ruby.railstutorial.org/
Here's the template code for views/users/show.html.erb
<% provide(:title, #user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for #user %>
<%= #user.name %>
</h1>
</section>
</aside>
</div>
and then here's the users_controller.rb
class UsersController < ApplicationController
def show
#user = User.find(params[:id])
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
end
Allright y'all,
I dont know if not answering my question was some sort of torturous initiation for noobs in this forum, but after almost 24 hours and a good night sleep, I solved the problem!
After a few G searches, I found that I could be stopping some of the variables from passing through by having "end" in the wrong places. It turns out there were 2 main areas where I was doing this. Once I found and fixed those, all the errors went away.
I will now pat myself on the back. I hope this helps any total noobs who run into this same problem in the future.

Resources