1
votes

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

show.html.erb from project's view's

<% title(@project.name, "Projects") %>
<h2><%= @project.name %></h2>
<%= link_to "Edit Project", edit_project_path(@project) %>
<%= link_to "Delete Project", project_path(@project),
            method: :delete,
            data: {confirm:
                    "Are you sure you want to delete this project?"
                    } %>
<%= link_to "New Ticket", new_project_ticket_path(@project) %>

<ul id="tickets">
    <% @project.tickets.each do |ticket| %>
    <li>
        #<%= ticket.id %> -
        <%= link_to ticket.title, [@project, ticket] %>
    </li>
    <% end %>
</ul>

Tickets show.html.erb

<div id="ticket">
    <h2><%= @ticket.title %></h2>
    <%= link_to "Edit Ticket", [:edit, @project, @ticket] %>
    <%= simple_format(@ticket.description) %>
</div>

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 '

1
Use 2 spaces for indenting your Ruby code, not 4 (or Tab)madcow

1 Answers

1
votes

After your edit form submits, the user is not redirected to the show.html.erb page. That is why the assertion is failing.

Add an edit action that on sucess renders your show page.

render :show