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 8695923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:09:26+00:00 2026-06-13T01:09:26+00:00

So I made my first Rails app without testing. Now I’m redoing the app

  • 0

So I made my first Rails app without testing. Now I’m redoing the app with testing first. I’m making a request spec for the model I’m creating (Task). I’m testing for the form for creating a new Task.

The number of tasks is supposed to change by 1 (i.e., a new task was saved), but it isn’t changing. I basically followed Michael Hartl’s code for this.

Error:
1) Task Pages Creating a Task with valid information creates a Task
   Failure/Error: expect { click_button "Create task" }.to change(Task, :count).by(1)
   count should have been changed by 1, but was changed by 0
# ./spec/requests/tasks_pages_spec.rb:22:in `block (4 levels) in <top (required)>'

Relevant Code:
Model

class Task < ActiveRecord::Base
  attr_accessible :begin_time, :day, :end_time, :gear, :notes, :preset, :room, :setup,                  
  :strike

  validates :room, presence: true
  validates :begin_time, presence: true
  validates :end_time, presence: true
  validates :gear, presence: true
  validates :day, presence: true
end

Controller

def new
  @task = Task.new
end

def create
  @task = Task.new(params[:task])

  if @task.save
    redirect_to root_path
  else
    render 'new'
  end
end

Integration Test

require 'spec_helper'

describe "Task Pages" do

  subject { page }

  describe "Creating a Task" do

    let(:submit) { "Create task" }
    before { visit new_task_path }

    describe "with valid information" do 
      before do 
        fill_in "Day",    with: Date.today
        fill_in "Room",   with: "6W-002"
        fill_in "Begin",  with: Time.now
        fill_in "End",    with: 1.hour.from_now
        fill_in "Gear",   with: "LCD"
      end

      it "creates a Task" do 
        expect { click_button "Create task" }.to change(Task, :count).by(1)
      end

    end
  end
end

And the form

<%= form_for(@task) do |t| %>

  <%= t.label :day %>
  <%= t.text_field :day %>

  <%= t.label :room %>
  <%= t.text_field :room %> 

  <%= t.label :begin_time, "Begin" %>
  <%= t.text_field :begin_time %> 

  <%= t.label :end_time, "End" %>
  <%= t.text_field :end_time %> 

  <%= t.label :gear %>
  <%= t.text_field :gear  %> 

  <%= t.label :day %>
  <%= t.text_field :day %> 

  <%= t.submit "Create task", class: "btn btn-large btn-primary" %>
<% 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-13T01:09:27+00:00Added an answer on June 13, 2026 at 1:09 am

    Your form has the :day field twice. The 1st is probably populated by your test and then clobbered by the empty value in the 2nd.

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

Sidebar

Related Questions

I'm making a recipe-manager (who isn't as their first app?) in Rails, and here
I'm creating my first ROR application. Details: creating new app -> rails new simple_cms
Background: I made a new rails 3 app with User model and the model
First I made an app and I set its application icon to a icon
I am building my first Ruby on Rails app which is going to be
There is Ruby on Rails (1.8, 2.3.2) project. First version of project was made
I am developing my first Rails app, a web replacement to a paper form
I just made my first setup of RoR, and creating a new application works
I'm currently building my first Rails 3 app, but can't quite figure out how
I want to make some request from iPhone app to my web service (Rails)

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.