Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:06:40+00:00 2026-06-06T00:06:40+00:00

I keep running into the same testing Failure, and I can’t figure out quite

  • 0

I keep running into the same testing Failure, and I can’t figure out quite why. I’m new to programming, so I’ve posted all the files I’ve worked on since my last passing test.

Any insight would be greatly appreciated!

Failures:

  1) Static pages Home page for signed-in users should render the user's feed
Failure/Error: page.should have_selector("li##{item.id}", text: item.content)
   expected css "li#2" with text "Dolor sit amet" to return something
 # ./spec/requests/static_pages_spec.rb:31:in `block (5 levels) in <top (required)>'
 # ./spec/requests/static_pages_spec.rb:30:in `block (4 levels) in <top (required)>'

Finished in 5.66 seconds
101 examples, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:29 # Static pages Home page for signed-in users should     render the user's feed

Here is the static_pages_spec.rb:

require 'spec_helper'

describe "Static pages" do  
  subject { page }

  shared_examples_for "all static pages" do
    it { should have_selector('h1', text: heading) }
    it { should have_selector('title', text: full_title(page_title)) }
end

  describe "Home page" do
    before { visit root_path }
   let(:heading)   { 'Sample App' }
   let(:page_title) { '' } 

   it_should_behave_like "all static pages"
   it { should_not have_selector 'title',   text: '| Home' }


    describe "for signed-in users" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
        FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet")
        sign_in user
        visit root_path
      end

  it "should render the user's feed" do
    user.feed.each do |item|
      page.should have_selector("li##{item.id}", text: item.content)
    end
  end
end
 end 

  describe "Help page" do
    before { visit help_path }
  let(:heading) { 'Help' }
  let(:page_title) { 'Help' }
end

  describe "About Us page" do
    before { visit about_path }
  let(:heading) { 'About Us' }
  let(:page_title) { 'About Us' }
end

  describe "Contact page" do
    before { visit contact_path }
  let(:heading) { 'Contact' }
  let(:page_title) { 'Contact' }
end

end

Here is the user_spec.rb

require 'spec_helper'

describe User do

  before do
    @user = User.new(name: "Example User", email: "user@example.com", 
                  password: "foobar", password_confirmation: "foobar")
  end

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password_digest) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }
  it { should respond_to(:remember_token) }
  it { should respond_to(:authenticate) }

  it { should be_valid }

  it { should respond_to(:admin) }
  it { should respond_to(:authenticate) }

  it { should respond_to(:authenticate) }
  it { should respond_to(:microposts) }
  it { should respond_to(:feed) }

  it { should be_valid }
  it { should_not be_admin }

  describe "with admin attribute set to 'true'" do
    before { @user.toggle!(:admin) }

    it { should be_admin }
  end


  describe "when password is not present" do
    before { @user.password = @user.password_confirmation = " " }
    it { should_not be_valid }
  end

  describe "when password doesn't match confirmation" do
    before { @user.password_confirmation = "mismatch" }
    it { should_not be_valid}
  end

  describe "when password confirmation is nil" do
    before { @user.password_confirmation = nil }
    it { should_not be_valid }
  end

  describe "with a password that's too short" do
    before { @user.password = @user.password_confirmation = "a" * 5}
    it { should be_invalid }
  end

  describe "return value of authenticate method" do
    before { @user.save }
    let(:found_user) { User.find_by_email(@user.email) }

    describe "with valid password" do
      it { should == found_user.authenticate(@user.password) }
    end

    describe "with invalid password" do
      let(:user_for_invalid_password) { found_user.authenticate("invalid") }

      it { should_not == user_for_invalid_password }
      specify { user_for_invalid_password.should be_false }
    end
  end


    describe "remember token" do
     before { @user.save }
     its(:remember_token) { should_not be_blank }
   end

  describe "when name is not present" do
    before { @user.name = " " }
    it { should_not be_valid }
  end

  describe "when name is too long" do
    before { @user.name = "a" * 51 }
    it { should_not be_valid }
  end

  describe "when email is not present" do
    before { @user.email = " " }
    it { should_not be_valid}
  end

  describe "when email format is invalid" do
    it "should be invalid" do
      addresses = %w[user@foo,com user_at_foo.org example.user@foo.
                       foo@bar_baz.com foo@bar+baz.com]
      addresses.each do |invalid_address|
        @user.email = invalid_address
        @user.should_not be_valid
      end      
    end
  end

  describe "when email format is valid" do
    it "should be valid" do
      addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
      addresses.each do |valid_address|
        @user.email = valid_address
        @user.should be_valid
      end      
    end
  end
  describe "when email address is already taken" do
    before do
      user_with_same_email = @user.dup
      user_with_same_email.email = @user.email.upcase
      user_with_same_email.save
    end

    it { should_not be_valid }
  end

  describe "micropost associations" do

    before { @user.save }
    let!(:older_micropost) do 
      FactoryGirl.create(:micropost, user: @user, created_at: 1.day.ago)
    end
    let!(:newer_micropost) do
      FactoryGirl.create(:micropost, user: @user, created_at: 1.hour.ago)
    end

    it "should have the right microposts in the right order" do
      @user.microposts.should == [ newer_micropost, older_micropost]
    end

    describe "status" do
      let(:unfollowed_post) do
        FactoryGirl.create(:micropost, user: FactoryGirl.create(:user))
      end

      its(:feed) { should include(newer_micropost) }
      its(:feed) { should include(older_micropost) }
      its(:feed) { should_not include(unfollowed_post) }
    end



    it "should destroy associated microposts" do
      microposts = @user.microposts
      @user.destroy
      microposts.each do |micropost|
        Micropost.find_by_id(micropost.id).should be_nil
      end
    end
  end 
end

Here is the user.rb

class User < ActiveRecord::Base

  attr_accessible :email, :name, :password, :password_confirmation
  has_secure_password
  has_many :microposts, dependent: :destroy

  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token

  validates :name, presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  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

  def feed
    Micropost.where("user_id = ?", id)
  end

  private

    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end
end

Here is the static_pages_controller.rb

class StaticPagesController < ApplicationController

  def home
    if signed_in?
        @micropost = current_user.microposts.build 
        @feed_items = current_user.feed.paginate(page: params[:page])
    end
  end

  def help
  end

  def about
  end

  def contact
  end

end

Here is the feed.html.erb

<% if @feed_items.any? %>
<ol class="microposts">
    <% render partial: 'shared/feed_item', collection: @feed_items %>
</ol>
<%= will_paginate @feed_items %>

Here is the feed_item.html.erb

    <li id="<%= feed_item.id %>">
  <%= link_to gravatar_for(feed_item.user), feed_item.user %>
  <span class="user">
    <%= link_to feed_item.user.name, feed_item.user %>
  </span>
  <span class="content"><%= feed_item.content %></span>
  <span class="timestamp">
    Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
  </span>
</li>

Here is the home.html.erb

<% if signed_in? %>
<div class="row">
    <aside class="span4">
        <section>
            <%= render 'shared/user_info' %>
        </section>
        <section>
            <%= render 'shared/micropost_form' %>
        </section>
    </aside>
    <div class="span8">
        <h3>Micropost Feed</h3>
        <%= render 'shared/feed' %>
    </div>
</div>
<% else %>
<div class="center hero-unit">

<h1>Welcome to the Sample App</h1>

<h2>
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
    sample application. 
</h2>

<%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
<% end %>

Here is the microposts_controller.rb

    class MicropostsController < ApplicationController
  before_filter :signed_in_user

  def create
    @micropost = current_user.microposts.build(params[:micropost])
    if @micropost.save
      flash[:success] = "Micropost created!"
      redirect_to root_path
    else
      @feed_items = [ ]
      render 'static_pages/home'
    end
  end

  def destroy
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:06:42+00:00Added an answer on June 6, 2026 at 12:06 am

    I figured it out. The feed.html.erb was missing an = before render. So before, it looked like this:

        <% if @feed_items.any? %>
    <ol class="microposts">
        <% render partial: 'shared/feed_item', collection: @feed_items %>
    </ol>
    <%= will_paginate @feed_items %>
    

    But it needed to look like this (change is on line 3):

    <% if @feed_items.any? %>
    <ol class="microposts">
        <%= render partial: 'shared/feed_item', collection: @feed_items %>
    </ol>
    <%= will_paginate @feed_items %> 
    

    So, I think this is because the <% with = makes ruby evaluate the expression and then call it into action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know Rails' flash hash is nothing new, but I keep running into the
I am trying to run heroku rake db:migrate and keep running into the same
I keep running into this design problem, and I'm not happy with my solution
I keep running into enq: TX - row lock contention, when I run the
I keep running into this error MemCacheError (Broken pipe): Broken pipe on my Rails
I've been using RhinoMocks lately but I keep running into an issue. If I
I'm working on some generative art projects in AS3, and I keep running into
I keep running in to this awful OAuth Verification Failure, it seems to not
i keep running in this issue where it will jump out of the for
We're running into the same problem as reported here: PDF Export Huge Report We're

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.