Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Rspec error "undefined method" (railsturoial Chapter 10)
    primarykey
    data
    text
    <p>I'm going through Michael Hartl's priceless tutorial and I got stuck with some Rspec errors. I've double checked everything but it seems like I'm still missing something. Here's what the error messages look like.</p> <p><img src="https://i.imgur.com/khRPL80.jpg" alt="error"></p> <p>The thing that's bothering me the most is when I was generating the Microposts model I accidentally made a typo in one of the options so I did rails destroy model Microposts to undo the generate command before generating the model again. I'm wondering if that has anything to do with the errors I'm seeing.</p> <p>I really wish to finish this tutorial ASAP so I can get on with building my own web application. ANY help would be appreciated.</p> <p>Here's what my code looks like.</p> <p><strong>micropost_pages_spec.rb</strong></p> <pre><code>require 'spec_helper' describe "MicropostPages" 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 end end </code></pre> <p><strong>microposts_controller.rb</strong></p> <pre><code>class MicropostsController &lt; ApplicationController before_filter :signed_in_user, only: [:create, :destroy] def create @micropost = current_user.micropost.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to root_path else render 'static_pages/home' end end def destroy end end </code></pre> <p><strong>static_pages_controller.rb</strong></p> <pre><code>class StaticPagesController &lt; ApplicationController def home @micropost = current_user.microposts.build if signed_in? end def help end def about end def contact end end </code></pre> <p><strong>user.rb (User model)</strong></p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :email, :name, :password, :password_confirmation has_secure_password has_many :microposts, dependent: :destroy before_save {self.email.downcase!} before_save :create_remember_token VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :name, presence: true, length: {maximum: 50} validates :email, presence: true, format: {with: VALID_EMAIL_REGEX}, uniqueness: {case_sensitive: false} validates :password, presence: true, length: {minimum: 6} validates :password_confirmation, presence: true private def create_remember_token self.remember_token = SecureRandom.urlsafe_base64 end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload