No idea why is it doing so the otherone passed this doesent
require 'spec_helper'
feature "Editing tickets" do
let!(:project) {FactoryGirl.create(:project)}
let!(:ticket) {FactoryGirl.create(:ticket, project: project)}
before do
visit '/'
click_link project.name
click_link ticket.title
click_link "Edit Ticket"
end
scenario "Updating a ticket" do
fill_in "Title", with: "Make it really shiny!"
click_button "Update Ticket"
expect(page).to have_content "Ticket has been updated."
within("#ticket h2") do
expect(page).to have_content("Make it really shiny!")
end
expect(page).to_not have_content ticket.title
end
scenario "Updating a ticket with invalid information" do
fill_in "Title", with: ""
click_button "Update Ticket"
expect(page).to have_content("Ticket has not been updated.")
end
end
_form.html.erb
<%= form_for [@project, @ticket] do |f| %>
<% if @ticket.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@ticket.errors.count, "error") %>
prohibited this ticket from being saved.</h2>
<ul>
<% @ticket.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title , "Title" %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :description, "Description" %><br />
<%= f.text_area :description %>
</p>
<%= f.submit %>
<% end %>
Ticket's controller
class TicketsController < ApplicationController
before_action :set_project
before_action :set_ticket, only: [:show, :edit, :update, :destroy]
def new
@ticket = @project.tickets.build
end
def create
@ticket = @project.tickets.build(ticket_params)
if @ticket.save
flash[:notice] = "Ticket has been created."
redirect_to [@project, @ticket]
else
flash[:alert] = "Ticket has not been created."
render 'new'
end
end
private
def ticket_params
params.require(:ticket).permit(:title, :description)
end
private
def set_project
@project = Project.find(params[:project_id])
end
private
def set_ticket
@ticket = @project.tickets.find(params[:id])
end
end
And the error is
1) Editing tickets Updating a ticket Failure/Error: fill_in "title", with: "Make it really shiny!" Capybara::ElementNotFound: Unable to find field "title" # ./spec/features/editing_tickets_spec.rb:16:in `block (2 levels) in '
2) Editing tickets Updating a ticket with invalid information Failure/Error: fill_in "Title", with: "" Capybara::ElementNotFound: Unable to find field "Title" # ./spec/features/editing_tickets_spec.rb:29:in `block (2 levels) in '
Aucun commentaire:
Enregistrer un commentaire